20120101000001_create_base.rb 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. class CreateBase < ActiveRecord::Migration
  2. def up
  3. create_table :sessions do |t|
  4. t.string :session_id, :null => false
  5. t.text :data
  6. t.timestamps
  7. end
  8. add_index :sessions, :session_id
  9. add_index :sessions, :updated_at
  10. create_table :users do |t|
  11. t.references :organization, :null => true
  12. t.column :login, :string, :limit => 100, :null => false
  13. t.column :firstname, :string, :limit => 100, :null => true
  14. t.column :lastname, :string, :limit => 100, :null => true
  15. t.column :email, :string, :limit => 140, :null => true
  16. t.column :image, :string, :limit => 200, :null => true
  17. t.column :web, :string, :limit => 100, :null => true
  18. t.column :password, :string, :limit => 100, :null => true
  19. t.column :phone, :string, :limit => 100, :null => true
  20. t.column :fax, :string, :limit => 100, :null => true
  21. t.column :mobile, :string, :limit => 100, :null => true
  22. t.column :street, :string, :limit => 120, :null => true
  23. t.column :zip, :string, :limit => 100, :null => true
  24. t.column :city, :string, :limit => 100, :null => true
  25. t.column :country, :string, :limit => 100, :null => true
  26. t.column :verified, :boolean, :null => false, :default => false
  27. t.column :active, :boolean, :null => false, :default => true
  28. t.column :note, :string, :limit => 250, :null => true
  29. t.column :source, :string, :limit => 200, :null => true
  30. t.column :preferences, :string, :limit => 4000,:null => true
  31. t.column :created_by_id, :integer, :null => false
  32. t.timestamps
  33. end
  34. add_index :users, [:login], :unique => true
  35. add_index :users, [:email]
  36. # add_index :users, [:email], :unique => true
  37. add_index :users, [:phone]
  38. add_index :users, [:fax]
  39. add_index :users, [:mobile]
  40. add_index :users, [:source]
  41. add_index :users, [:created_by_id]
  42. create_table :groups do |t|
  43. t.column :name, :string, :limit => 100, :null => false
  44. t.column :active, :boolean, :null => false, :default => true
  45. t.column :note, :string, :limit => 250, :null => true
  46. t.column :created_by_id, :integer, :null => false
  47. t.timestamps
  48. end
  49. add_index :groups, [:name], :unique => true
  50. create_table :roles do |t|
  51. t.column :name, :string, :limit => 100, :null => false
  52. t.column :active, :boolean, :null => false, :default => true
  53. t.column :note, :string, :limit => 250, :null => true
  54. t.column :created_by_id, :integer, :null => false
  55. t.timestamps
  56. end
  57. add_index :roles, [:name], :unique => true
  58. create_table :organizations do |t|
  59. t.column :name, :string, :limit => 100, :null => false
  60. t.column :shared, :boolean, :null => false, :default => true
  61. t.column :active, :boolean, :null => false, :default => true
  62. t.column :note, :string, :limit => 250, :null => true
  63. t.column :created_by_id, :integer, :null => false
  64. t.timestamps
  65. end
  66. add_index :organizations, [:name], :unique => true
  67. create_table :roles_users, :id => false do |t|
  68. t.integer :user_id
  69. t.integer :role_id
  70. end
  71. create_table :groups_users, :id => false do |t|
  72. t.integer :user_id
  73. t.integer :group_id
  74. end
  75. create_table :organizations_users, :id => false do |t|
  76. t.integer :user_id
  77. t.integer :organization_id
  78. end
  79. create_table :authorizations do |t|
  80. t.string :provider, :limit => 250, :null => false
  81. t.string :uid, :limit => 250, :null => false
  82. t.string :token, :limit => 250, :null => true
  83. t.string :secret, :limit => 250, :null => true
  84. t.string :username, :limit => 250, :null => true
  85. t.references :user, :null => false
  86. t.timestamps
  87. end
  88. add_index :authorizations, [:uid, :provider]
  89. add_index :authorizations, [:user_id]
  90. add_index :authorizations, [:username]
  91. end
  92. end