20120101000001_create_base.rb 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. class CreateBase < ActiveRecord::Migration
  2. def up
  3. create_table :sessions do |t|
  4. t.string :session_id, null: false
  5. t.boolean :persistent, null: true
  6. t.text :data
  7. t.timestamps null: false
  8. end
  9. add_index :sessions, :session_id
  10. add_index :sessions, :updated_at
  11. add_index :sessions, :persistent
  12. create_table :users do |t|
  13. t.references :organization, null: true
  14. t.string :login, limit: 100, null: false
  15. t.string :firstname, limit: 100, null: true, default: ''
  16. t.string :lastname, limit: 100, null: true, default: ''
  17. t.string :email, limit: 140, null: true, default: ''
  18. t.string :image, limit: 100, null: true
  19. t.string :image_source, limit: 200, null: true
  20. t.string :web, limit: 100, null: true, default: ''
  21. t.string :password, limit: 100, null: true
  22. t.string :phone, limit: 100, null: true, default: ''
  23. t.string :fax, limit: 100, null: true, default: ''
  24. t.string :mobile, limit: 100, null: true, default: ''
  25. t.string :department, limit: 200, null: true, default: ''
  26. t.string :street, limit: 120, null: true, default: ''
  27. t.string :zip, limit: 100, null: true, default: ''
  28. t.string :city, limit: 100, null: true, default: ''
  29. t.string :country, limit: 100, null: true, default: ''
  30. t.string :address, limit: 500, null: true, default: ''
  31. t.boolean :vip, default: false
  32. t.boolean :verified, null: false, default: false
  33. t.boolean :active, null: false, default: true
  34. t.string :note, limit: 250, null: true, default: ''
  35. t.timestamp :last_login, null: true
  36. t.string :source, limit: 200, null: true
  37. t.integer :login_failed, null: false, default: 0
  38. t.string :preferences, limit: 8000, null: true
  39. t.integer :updated_by_id, null: false
  40. t.integer :created_by_id, null: false
  41. t.timestamps null: false
  42. end
  43. add_index :users, [:login], unique: true
  44. add_index :users, [:email]
  45. #add_index :users, [:email], unique: => true
  46. add_index :users, [:organization_id]
  47. add_index :users, [:image]
  48. add_index :users, [:department]
  49. add_index :users, [:phone]
  50. add_index :users, [:fax]
  51. add_index :users, [:mobile]
  52. add_index :users, [:source]
  53. add_index :users, [:created_by_id]
  54. create_table :signatures do |t|
  55. t.string :name, limit: 100, null: false
  56. t.string :body, limit: 5000, null: true
  57. t.boolean :active, null: false, default: true
  58. t.string :note, limit: 250, null: true
  59. t.integer :updated_by_id, null: false
  60. t.integer :created_by_id, null: false
  61. t.timestamps null: false
  62. end
  63. add_index :signatures, [:name], unique: true
  64. create_table :email_addresses do |t|
  65. t.string :realname, limit: 250, null: false
  66. t.string :email, limit: 250, null: false
  67. t.boolean :active, null: false, default: true
  68. t.string :note, limit: 250, null: true
  69. t.integer :updated_by_id, null: false
  70. t.integer :created_by_id, null: false
  71. t.timestamps null: false
  72. end
  73. add_index :email_addresses, [:email], unique: true
  74. create_table :groups do |t|
  75. t.references :signature, null: true
  76. t.references :email_address, null: true
  77. t.string :name, limit: 160, null: false
  78. t.integer :assignment_timeout, null: true
  79. t.string :follow_up_possible, limit: 100, null: false, default: 'yes'
  80. t.boolean :follow_up_assignment, null: false, default: true
  81. t.boolean :active, null: false, default: true
  82. t.string :note, limit: 250, null: true
  83. t.integer :updated_by_id, null: false
  84. t.integer :created_by_id, null: false
  85. t.timestamps null: false
  86. end
  87. add_index :groups, [:name], unique: true
  88. create_table :roles do |t|
  89. t.string :name, limit: 100, null: false
  90. t.boolean :active, null: false, default: true
  91. t.string :note, limit: 250, null: true
  92. t.integer :updated_by_id, null: false
  93. t.integer :created_by_id, null: false
  94. t.timestamps null: false
  95. end
  96. add_index :roles, [:name], unique: true
  97. create_table :organizations do |t|
  98. t.string :name, limit: 100, null: false
  99. t.boolean :shared, null: false, default: true
  100. t.boolean :active, null: false, default: true
  101. t.string :note, limit: 250, null: true, default: ''
  102. t.integer :updated_by_id, null: false
  103. t.integer :created_by_id, null: false
  104. t.timestamps null: false
  105. end
  106. add_index :organizations, [:name], unique: true
  107. create_table :roles_users, id: false do |t|
  108. t.integer :user_id
  109. t.integer :role_id
  110. end
  111. add_index :roles_users, [:user_id]
  112. add_index :roles_users, [:role_id]
  113. create_table :groups_users, id: false do |t|
  114. t.integer :user_id
  115. t.integer :group_id
  116. end
  117. add_index :groups_users, [:user_id]
  118. add_index :groups_users, [:group_id]
  119. create_table :organizations_users, id: false do |t|
  120. t.integer :user_id
  121. t.integer :organization_id
  122. end
  123. add_index :organizations_users, [:user_id]
  124. add_index :organizations_users, [:organization_id]
  125. create_table :authorizations do |t|
  126. t.string :provider, limit: 250, null: false
  127. t.string :uid, limit: 250, null: false
  128. t.string :token, limit: 250, null: true
  129. t.string :secret, limit: 250, null: true
  130. t.string :username, limit: 250, null: true
  131. t.references :user, null: false
  132. t.timestamps null: false
  133. end
  134. add_index :authorizations, [:uid, :provider]
  135. add_index :authorizations, [:user_id]
  136. add_index :authorizations, [:username]
  137. create_table :locales do |t|
  138. t.string :locale, limit: 20, null: false
  139. t.string :alias, limit: 20, null: true
  140. t.string :name, limit: 255, null: false
  141. t.boolean :active, null: false, default: true
  142. t.timestamps null: false
  143. end
  144. add_index :locales, [:locale], unique: true
  145. add_index :locales, [:name], unique: true
  146. create_table :translations do |t|
  147. t.string :locale, limit: 10, null: false
  148. t.string :source, limit: 255, null: false
  149. t.string :target, limit: 255, null: false
  150. t.string :target_initial, limit: 255, null: false
  151. t.string :format, limit: 20, null: false, default: 'string'
  152. t.integer :updated_by_id, null: false
  153. t.integer :created_by_id, null: false
  154. t.timestamps null: false
  155. end
  156. add_index :translations, [:source]
  157. add_index :translations, [:locale]
  158. create_table :object_lookups do |t|
  159. t.string :name, limit: 250, null: false
  160. t.timestamps null: false
  161. end
  162. add_index :object_lookups, [:name], unique: true
  163. create_table :type_lookups do |t|
  164. t.string :name, limit: 250, null: false
  165. t.timestamps null: false
  166. end
  167. add_index :type_lookups, [:name], unique: true
  168. create_table :tokens do |t|
  169. t.references :user, null: false
  170. t.boolean :persistent
  171. t.string :name, limit: 100, null: false
  172. t.string :action, limit: 40, null: false
  173. t.timestamps null: false
  174. end
  175. add_index :tokens, :user_id
  176. add_index :tokens, [:name, :action], unique: true
  177. add_index :tokens, :created_at
  178. add_index :tokens, :persistent
  179. create_table :packages do |t|
  180. t.string :name, limit: 250, null: false
  181. t.string :version, limit: 50, null: false
  182. t.string :vendor, limit: 150, null: false
  183. t.string :state, limit: 50, null: false
  184. t.integer :updated_by_id, null: false
  185. t.integer :created_by_id, null: false
  186. t.timestamps null: false
  187. end
  188. create_table :package_migrations do |t|
  189. t.string :name, limit: 250, null: false
  190. t.string :version, limit: 250, null: false
  191. t.timestamps null: false
  192. end
  193. create_table :taskbars do |t|
  194. t.integer :user_id, null: false
  195. t.datetime :last_contact, null: false
  196. t.string :client_id, null: false
  197. t.string :key, limit: 100, null: false
  198. t.string :callback, limit: 100, null: false
  199. t.column :state, :text, limit: 2.megabytes + 1, null: true
  200. t.string :params, limit: 2000, null: true
  201. t.integer :prio, null: false
  202. t.boolean :notify, null: false, default: false
  203. t.boolean :active, null: false, default: false
  204. t.timestamps null: false
  205. end
  206. add_index :taskbars, [:user_id]
  207. add_index :taskbars, [:client_id]
  208. create_table :tags do |t|
  209. t.references :tag_item, null: false
  210. t.references :tag_object, null: false
  211. t.integer :o_id, null: false
  212. t.integer :created_by_id, null: false
  213. t.timestamps null: false
  214. end
  215. add_index :tags, [:o_id]
  216. add_index :tags, [:tag_object_id]
  217. create_table :tag_objects do |t|
  218. t.string :name, limit: 250, null: false
  219. t.timestamps null: false
  220. end
  221. add_index :tag_objects, [:name], unique: true
  222. create_table :tag_items do |t|
  223. t.string :name, limit: 250, null: false
  224. t.timestamps null: false
  225. end
  226. add_index :tag_items, [:name], unique: true
  227. create_table :recent_views do |t|
  228. t.references :recent_view_object, null: false
  229. t.integer :o_id, null: false
  230. t.integer :created_by_id, null: false
  231. t.timestamps null: false
  232. end
  233. add_index :recent_views, [:o_id]
  234. add_index :recent_views, [:created_by_id]
  235. add_index :recent_views, [:created_at]
  236. add_index :recent_views, [:recent_view_object_id]
  237. create_table :activity_streams do |t|
  238. t.references :activity_stream_type, null: false
  239. t.references :activity_stream_object, null: false
  240. t.references :role, null: true
  241. t.references :group, null: true
  242. t.integer :o_id, null: false
  243. t.integer :created_by_id, null: false
  244. t.timestamps null: false
  245. end
  246. add_index :activity_streams, [:o_id]
  247. add_index :activity_streams, [:created_by_id]
  248. add_index :activity_streams, [:role_id]
  249. add_index :activity_streams, [:group_id]
  250. add_index :activity_streams, [:created_at]
  251. add_index :activity_streams, [:activity_stream_object_id]
  252. add_index :activity_streams, [:activity_stream_type_id]
  253. create_table :histories do |t|
  254. t.references :history_type, null: false
  255. t.references :history_object, null: false
  256. t.references :history_attribute, null: true
  257. t.integer :o_id, null: false
  258. t.integer :related_o_id, null: true
  259. t.integer :related_history_object_id, null: true
  260. t.integer :id_to, null: true
  261. t.integer :id_from, null: true
  262. t.string :value_from, limit: 500, null: true
  263. t.string :value_to, limit: 500, null: true
  264. t.integer :created_by_id, null: false
  265. t.timestamps null: false
  266. end
  267. add_index :histories, [:o_id]
  268. add_index :histories, [:created_by_id]
  269. add_index :histories, [:created_at]
  270. add_index :histories, [:history_object_id]
  271. add_index :histories, [:history_attribute_id]
  272. add_index :histories, [:history_type_id]
  273. add_index :histories, [:id_to]
  274. add_index :histories, [:id_from]
  275. add_index :histories, [:value_from], length: 255
  276. add_index :histories, [:value_to], length: 255
  277. create_table :history_types do |t|
  278. t.string :name, limit: 250, null: false
  279. t.timestamps null: false
  280. end
  281. add_index :history_types, [:name], unique: true
  282. create_table :history_objects do |t|
  283. t.string :name, limit: 250, null: false
  284. t.string :note, limit: 250, null: true
  285. t.timestamps null: false
  286. end
  287. add_index :history_objects, [:name], unique: true
  288. create_table :history_attributes do |t|
  289. t.string :name, limit: 250, null: false
  290. t.timestamps null: false
  291. end
  292. add_index :history_attributes, [:name], unique: true
  293. create_table :settings do |t|
  294. t.string :title, limit: 200, null: false
  295. t.string :name, limit: 200, null: false
  296. t.string :area, limit: 100, null: false
  297. t.string :description, limit: 2000, null: false
  298. t.string :options, limit: 2000, null: true
  299. t.string :state_current, limit: 2000, null: true
  300. t.string :state_initial, limit: 2000, null: true
  301. t.boolean :frontend, null: false
  302. t.string :preferences, limit: 2000, null: true
  303. t.timestamps null: false
  304. end
  305. add_index :settings, [:name], unique: true
  306. add_index :settings, [:area]
  307. add_index :settings, [:frontend]
  308. create_table :stores do |t|
  309. t.references :store_object, null: false
  310. t.references :store_file, null: false
  311. t.integer :o_id, limit: 8, null: false
  312. t.string :preferences, limit: 2500, null: true
  313. t.string :size, limit: 50, null: true
  314. t.string :filename, limit: 250, null: false
  315. t.integer :created_by_id, null: false
  316. t.timestamps null: false
  317. end
  318. add_index :stores, [:store_object_id, :o_id]
  319. create_table :store_objects do |t|
  320. t.string :name, limit: 250, null: false
  321. t.string :note, limit: 250, null: true
  322. t.timestamps null: false
  323. end
  324. add_index :store_objects, [:name], unique: true
  325. create_table :store_files do |t|
  326. t.string :sha, limit: 128, null: false
  327. t.string :provider, limit: 20, null: true
  328. t.timestamps null: false
  329. end
  330. add_index :store_files, [:sha], unique: true
  331. add_index :store_files, [:provider]
  332. create_table :store_provider_dbs do |t|
  333. t.string :sha, limit: 128, null: false
  334. t.binary :data, limit: 200.megabytes, null: true
  335. t.timestamps null: false
  336. end
  337. add_index :store_provider_dbs, [:sha], unique: true
  338. create_table :avatars do |t|
  339. t.integer :o_id, null: false
  340. t.integer :object_lookup_id, null: false
  341. t.boolean :default, null: false, default: false
  342. t.boolean :deletable, null: false, default: true
  343. t.boolean :initial, null: false, default: false
  344. t.integer :store_full_id, null: true
  345. t.integer :store_resize_id, null: true
  346. t.string :store_hash, limit: 32, null: true
  347. t.string :source, limit: 100, null: false
  348. t.string :source_url, limit: 512, null: true
  349. t.integer :updated_by_id, null: false
  350. t.integer :created_by_id, null: false
  351. t.timestamps null: false
  352. end
  353. add_index :avatars, [:o_id, :object_lookup_id]
  354. add_index :avatars, [:store_hash]
  355. add_index :avatars, [:source]
  356. add_index :avatars, [:default]
  357. create_table :online_notifications do |t|
  358. t.integer :o_id, null: false
  359. t.integer :object_lookup_id, null: false
  360. t.integer :type_lookup_id, null: false
  361. t.integer :user_id, null: false
  362. t.boolean :seen, null: false, default: false
  363. t.integer :updated_by_id, null: false
  364. t.integer :created_by_id, null: false
  365. t.timestamps null: false
  366. end
  367. add_index :online_notifications, [:user_id]
  368. add_index :online_notifications, [:seen]
  369. add_index :online_notifications, [:created_at]
  370. add_index :online_notifications, [:updated_at]
  371. create_table :schedulers do |t|
  372. t.column :name, :string, limit: 250, null: false
  373. t.column :method, :string, limit: 250, null: false
  374. t.column :period, :integer, null: true
  375. t.column :running, :integer, null: false, default: false
  376. t.column :last_run, :timestamp, null: true
  377. t.column :prio, :integer, null: false
  378. t.column :pid, :string, limit: 250, null: true
  379. t.column :note, :string, limit: 250, null: true
  380. t.column :active, :boolean, null: false, default: false
  381. t.column :updated_by_id, :integer, null: false
  382. t.column :created_by_id, :integer, null: false
  383. t.timestamps null: false
  384. end
  385. add_index :schedulers, [:name], unique: true
  386. create_table :user_devices do |t|
  387. t.references :user, null: false
  388. t.string :name, limit: 250, null: false
  389. t.string :os, limit: 150, null: true
  390. t.string :browser, limit: 250, null: true
  391. t.string :location, limit: 150, null: true
  392. t.string :device_details, limit: 2500, null: true
  393. t.string :location_details, limit: 2500, null: true
  394. t.string :fingerprint, limit: 160, null: true
  395. t.string :user_agent, limit: 250, null: true
  396. t.string :ip, limit: 160, null: true
  397. t.timestamps null: false
  398. end
  399. add_index :user_devices, [:user_id]
  400. add_index :user_devices, [:os, :browser, :location]
  401. add_index :user_devices, [:fingerprint]
  402. add_index :user_devices, [:updated_at]
  403. add_index :user_devices, [:created_at]
  404. create_table :object_manager_attributes do |t|
  405. t.references :object_lookup, null: false
  406. t.column :name, :string, limit: 200, null: false
  407. t.column :display, :string, limit: 200, null: false
  408. t.column :data_type, :string, limit: 100, null: false
  409. t.column :data_option, :string, limit: 8000, null: true
  410. t.column :editable, :boolean, null: false, default: true
  411. t.column :active, :boolean, null: false, default: true
  412. t.column :screens, :string, limit: 2000, null: true
  413. t.column :pending_migration, :boolean, null: false, default: true
  414. t.column :position, :integer, null: false
  415. t.column :created_by_id, :integer, null: false
  416. t.column :updated_by_id, :integer, null: false
  417. t.timestamps null: false
  418. end
  419. add_index :object_manager_attributes, [:object_lookup_id, :name], unique: true
  420. add_index :object_manager_attributes, [:object_lookup_id]
  421. create_table :delayed_jobs, force: true do |t|
  422. t.integer :priority, default: 0 # Allows some jobs to jump to the front of the queue
  423. t.integer :attempts, default: 0 # Provides for retries, but still fail eventually.
  424. t.text :handler # YAML-encoded string of the object that will do work
  425. t.text :last_error # reason for last failure (See Note below)
  426. t.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
  427. t.datetime :locked_at # Set when a client is working on this object
  428. t.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
  429. t.string :locked_by # Who is working on this object (if locked)
  430. t.string :queue # The name of the queue this job is in
  431. t.timestamps null: false
  432. end
  433. add_index :delayed_jobs, [:priority, :run_at], name: 'delayed_jobs_priority'
  434. end
  435. end