20120101000001_create_base.rb 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 => 100, :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 :department, :string, :limit => 200, :null => true
  23. t.column :street, :string, :limit => 120, :null => true
  24. t.column :zip, :string, :limit => 100, :null => true
  25. t.column :city, :string, :limit => 100, :null => true
  26. t.column :country, :string, :limit => 100, :null => true
  27. t.column :verified, :boolean, :null => false, :default => false
  28. t.column :active, :boolean, :null => false, :default => true
  29. t.column :note, :string, :limit => 250, :null => true
  30. t.column :last_login, :timestamp, :null => true
  31. t.column :source, :string, :limit => 200, :null => true
  32. t.column :preferences, :string, :limit => 8000,:null => true
  33. t.column :updated_by_id, :integer, :null => false
  34. t.column :created_by_id, :integer, :null => false
  35. t.timestamps
  36. end
  37. add_index :users, [:login], :unique => true
  38. add_index :users, [:email]
  39. # add_index :users, [:email], :unique => true
  40. add_index :users, [:department]
  41. add_index :users, [:phone]
  42. add_index :users, [:fax]
  43. add_index :users, [:mobile]
  44. add_index :users, [:source]
  45. add_index :users, [:created_by_id]
  46. create_table :signatures do |t|
  47. t.column :name, :string, :limit => 100, :null => false
  48. t.column :body, :string, :limit => 5000, :null => true
  49. t.column :active, :boolean, :null => false, :default => true
  50. t.column :note, :string, :limit => 250, :null => true
  51. t.column :updated_by_id, :integer, :null => false
  52. t.column :created_by_id, :integer, :null => false
  53. t.timestamps
  54. end
  55. add_index :signatures, [:name], :unique => true
  56. create_table :email_addresses do |t|
  57. t.column :realname, :string, :limit => 250, :null => false
  58. t.column :email, :string, :limit => 250, :null => false
  59. t.column :active, :boolean, :null => false, :default => true
  60. t.column :note, :string, :limit => 250, :null => true
  61. t.column :updated_by_id, :integer, :null => false
  62. t.column :created_by_id, :integer, :null => false
  63. t.timestamps
  64. end
  65. add_index :email_addresses, [:email], :unique => true
  66. create_table :groups do |t|
  67. t.references :signature, :null => true
  68. t.references :email_address, :null => true
  69. t.column :name, :string, :limit => 100, :null => false
  70. t.column :assignment_timeout, :integer, :null => true
  71. t.column :follow_up_possible, :string, :limit => 100, :null => false, :default => 'yes'
  72. t.column :follow_up_assignment, :boolean, :null => false, :default => true
  73. t.column :active, :boolean, :null => false, :default => true
  74. t.column :note, :string, :limit => 250, :null => true
  75. t.column :updated_by_id, :integer, :null => false
  76. t.column :created_by_id, :integer, :null => false
  77. t.timestamps
  78. end
  79. add_index :groups, [:name], :unique => true
  80. create_table :roles do |t|
  81. t.column :name, :string, :limit => 100, :null => false
  82. t.column :active, :boolean, :null => false, :default => true
  83. t.column :note, :string, :limit => 250, :null => true
  84. t.column :updated_by_id, :integer, :null => false
  85. t.column :created_by_id, :integer, :null => false
  86. t.timestamps
  87. end
  88. add_index :roles, [:name], :unique => true
  89. create_table :organizations do |t|
  90. t.column :name, :string, :limit => 100, :null => false
  91. t.column :shared, :boolean, :null => false, :default => true
  92. t.column :active, :boolean, :null => false, :default => true
  93. t.column :note, :string, :limit => 250, :null => true
  94. t.column :updated_by_id, :integer, :null => false
  95. t.column :created_by_id, :integer, :null => false
  96. t.timestamps
  97. end
  98. add_index :organizations, [:name], :unique => true
  99. create_table :roles_users, :id => false do |t|
  100. t.integer :user_id
  101. t.integer :role_id
  102. end
  103. create_table :groups_users, :id => false do |t|
  104. t.integer :user_id
  105. t.integer :group_id
  106. end
  107. create_table :organizations_users, :id => false do |t|
  108. t.integer :user_id
  109. t.integer :organization_id
  110. end
  111. create_table :authorizations do |t|
  112. t.string :provider, :limit => 250, :null => false
  113. t.string :uid, :limit => 250, :null => false
  114. t.string :token, :limit => 250, :null => true
  115. t.string :secret, :limit => 250, :null => true
  116. t.string :username, :limit => 250, :null => true
  117. t.references :user, :null => false
  118. t.timestamps
  119. end
  120. add_index :authorizations, [:uid, :provider]
  121. add_index :authorizations, [:user_id]
  122. add_index :authorizations, [:username]
  123. create_table :translations do |t|
  124. t.column :locale, :string, :limit => 10, :null => false
  125. t.column :source, :string, :limit => 255, :null => false
  126. t.column :target, :string, :limit => 255, :null => false
  127. t.column :target_initial, :string, :limit => 255, :null => false
  128. t.column :updated_by_id, :integer, :null => false
  129. t.column :created_by_id, :integer, :null => false
  130. t.timestamps
  131. end
  132. add_index :translations, [:source]
  133. add_index :translations, [:locale]
  134. create_table :object_lookups do |t|
  135. t.column :name, :string, :limit => 250, :null => false
  136. t.timestamps
  137. end
  138. add_index :object_lookups, [:name], :unique => true
  139. create_table :type_lookups do |t|
  140. t.column :name, :string, :limit => 250, :null => false
  141. t.timestamps
  142. end
  143. add_index :type_lookups, [:name], :unique => true
  144. end
  145. end