20120101000001_create_base.rb 24 KB

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