Guest User

Untitled

a guest
May 31st, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. class BortMigration < ActiveRecord::Migration
  2. def self.up
  3. # Create Sessions Table
  4. create_table :sessions do |t|
  5. t.string :session_id, :null => false
  6. t.text :data
  7. t.timestamps
  8. end
  9.  
  10. add_index :sessions, :session_id
  11. add_index :sessions, :updated_at
  12.  
  13. # Create OpenID Tables
  14. create_table :open_id_authentication_associations, :force => true do |t|
  15. t.integer :issued, :lifetime
  16. t.string :handle, :assoc_type
  17. t.binary :server_url, :secret
  18. end
  19.  
  20. create_table :open_id_authentication_nonces, :force => true do |t|
  21. t.integer :timestamp, :null => false
  22. t.string :server_url, :null => true
  23. t.string :salt, :null => false
  24. end
  25.  
  26. # Create Users Table
  27. create_table :users do |t|
  28. .
  29. .
  30. .
  31. t.timestamps
  32. end
  33.  
  34. add_index :users, :login, :unique => true
  35.  
  36. # Create Passwords Table
  37. create_table :passwords do |t|
  38. t.integer :user_id
  39. t.string :reset_code
  40. t.datetime :expiration_date
  41. t.timestamps
  42. end
  43.  
  44. # Create Roles Databases
  45. create_table :roles do |t|
  46. t.string :name
  47. end
  48.  
  49. create_table :roles_users, :id => false do |t|
  50. t.belongs_to :role
  51. t.belongs_to :user
  52. end
  53. ## Error
  54. # Create admin role
  55. admin_role = Role.create(:name => 'admin')
  56.  
  57. # Create default admin user
  58. user = User.create do |u|
  59. if RAILS_ENV == "production"
  60. u.login = '------------'
  61. u.password = u.password_confirmation = '---------------------'
  62. else
  63. u.login = '----------'
  64. u.password = u.password_confirmation = '-----------------'
  65. end
  66. u.email = APP_CONFIG[:admin_email]
  67. end
  68.  
  69. # Activate user
  70. user.register!
  71. user.activate!
  72.  
  73. # Add admin role to admin user
  74. user.roles << admin_role
  75. end
  76.  
  77. def self.down
  78. # Drop all Bort tables
  79. drop_table :sessions
  80. drop_table :users
  81. drop_table :passwords
  82. drop_table :roles
  83. drop_table :roles_users
  84. drop_table :open_id_authentication_associations
  85. drop_table :open_id_authentication_nonces
  86. end
  87. end
Add Comment
Please, Sign In to add comment