20120101000001_create_base.rb 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. class CreateBase < ActiveRecord::Migration
  2. def up
  3. # clear old caches to start from scratch
  4. Cache.clear
  5. create_table :sessions do |t|
  6. t.string :session_id, null: false
  7. t.boolean :persistent, null: true
  8. t.text :data
  9. t.timestamps null: false
  10. end
  11. add_index :sessions, :session_id
  12. add_index :sessions, :updated_at
  13. add_index :sessions, :persistent
  14. create_table :users do |t|
  15. t.references :organization, null: true
  16. t.string :login, limit: 255, null: false
  17. t.string :firstname, limit: 100, null: true, default: ''
  18. t.string :lastname, limit: 100, null: true, default: ''
  19. t.string :email, limit: 255, null: true, default: ''
  20. t.string :image, limit: 100, null: true
  21. t.string :image_source, limit: 200, null: true
  22. t.string :web, limit: 100, null: true, default: ''
  23. t.string :password, limit: 100, null: true
  24. t.string :phone, limit: 100, null: true, default: ''
  25. t.string :fax, limit: 100, null: true, default: ''
  26. t.string :mobile, limit: 100, null: true, default: ''
  27. t.string :department, limit: 200, null: true, default: ''
  28. t.string :street, limit: 120, null: true, default: ''
  29. t.string :zip, limit: 100, null: true, default: ''
  30. t.string :city, limit: 100, null: true, default: ''
  31. t.string :country, limit: 100, null: true, default: ''
  32. t.string :address, limit: 500, null: true, default: ''
  33. t.boolean :vip, default: false
  34. t.boolean :verified, null: false, default: false
  35. t.boolean :active, null: false, default: true
  36. t.string :note, limit: 250, null: true, default: ''
  37. t.timestamp :last_login, limit: 3, null: true
  38. t.string :source, limit: 200, null: true
  39. t.integer :login_failed, null: false, default: 0
  40. t.string :preferences, limit: 8000, null: true
  41. t.integer :updated_by_id, null: false
  42. t.integer :created_by_id, null: false
  43. t.timestamps limit: 3, null: false
  44. end
  45. add_index :users, [:login], unique: true
  46. add_index :users, [:email]
  47. #add_index :users, [:email], unique: => true
  48. add_index :users, [:organization_id]
  49. add_index :users, [:image]
  50. add_index :users, [:department]
  51. add_index :users, [:phone]
  52. add_index :users, [:fax]
  53. add_index :users, [:mobile]
  54. add_index :users, [:source]
  55. add_index :users, [:created_by_id]
  56. add_foreign_key :users, :users, column: :created_by_id
  57. add_foreign_key :users, :users, column: :updated_by_id
  58. create_table :signatures do |t|
  59. t.string :name, limit: 100, null: false
  60. t.text :body, limit: 10.megabytes + 1, null: true
  61. t.boolean :active, null: false, default: true
  62. t.string :note, limit: 250, null: true
  63. t.integer :updated_by_id, null: false
  64. t.integer :created_by_id, null: false
  65. t.timestamps limit: 3, null: false
  66. end
  67. add_index :signatures, [:name], unique: true
  68. add_foreign_key :signatures, :users, column: :created_by_id
  69. add_foreign_key :signatures, :users, column: :updated_by_id
  70. create_table :email_addresses do |t|
  71. t.integer :channel_id, null: true
  72. t.string :realname, limit: 250, null: false
  73. t.string :email, limit: 250, null: false
  74. t.boolean :active, null: false, default: true
  75. t.string :note, limit: 250, null: true
  76. t.string :preferences, limit: 2000, null: true
  77. t.integer :updated_by_id, null: false
  78. t.integer :created_by_id, null: false
  79. t.timestamps limit: 3, null: false
  80. end
  81. add_index :email_addresses, [:email], unique: true
  82. add_foreign_key :email_addresses, :users, column: :created_by_id
  83. add_foreign_key :email_addresses, :users, column: :updated_by_id
  84. create_table :groups do |t|
  85. t.references :signature, null: true
  86. t.references :email_address, null: true
  87. t.string :name, limit: 160, null: false
  88. t.integer :assignment_timeout, null: true
  89. t.string :follow_up_possible, limit: 100, null: false, default: 'yes'
  90. t.boolean :follow_up_assignment, null: false, default: true
  91. t.boolean :active, null: false, default: true
  92. t.string :note, limit: 250, null: true
  93. t.integer :updated_by_id, null: false
  94. t.integer :created_by_id, null: false
  95. t.timestamps limit: 3, null: false
  96. end
  97. add_index :groups, [:name], unique: true
  98. add_foreign_key :groups, :signatures
  99. add_foreign_key :groups, :email_addresses
  100. add_foreign_key :groups, :users, column: :created_by_id
  101. add_foreign_key :groups, :users, column: :updated_by_id
  102. create_table :roles do |t|
  103. t.string :name, limit: 100, null: false
  104. t.text :preferences, limit: 500.kilobytes + 1, null: true
  105. t.boolean :default_at_signup, null: true, default: false
  106. t.boolean :active, null: false, default: true
  107. t.string :note, limit: 250, null: true
  108. t.integer :updated_by_id, null: false
  109. t.integer :created_by_id, null: false
  110. t.timestamps limit: 3, null: false
  111. end
  112. add_index :roles, [:name], unique: true
  113. add_foreign_key :roles, :users, column: :created_by_id
  114. add_foreign_key :roles, :users, column: :updated_by_id
  115. create_table :permissions do |t|
  116. t.string :name, limit: 255, null: false
  117. t.string :note, limit: 500, null: true
  118. t.string :preferences, limit: 10_000, null: true
  119. t.boolean :active, null: false, default: true
  120. t.timestamps limit: 3, null: false
  121. end
  122. add_index :permissions, [:name], unique: true
  123. create_table :permissions_roles, id: false do |t|
  124. t.belongs_to :role, index: true
  125. t.belongs_to :permission, index: true
  126. end
  127. create_table :organizations do |t|
  128. t.string :name, limit: 100, null: false
  129. t.boolean :shared, null: false, default: true
  130. t.string :domain, limit: 250, null: true, default: ''
  131. t.boolean :domain_assignment, null: false, default: false
  132. t.boolean :active, null: false, default: true
  133. t.string :note, limit: 250, null: true, default: ''
  134. t.integer :updated_by_id, null: false
  135. t.integer :created_by_id, null: false
  136. t.timestamps limit: 3, null: false
  137. end
  138. add_index :organizations, [:name], unique: true
  139. add_index :organizations, [:domain]
  140. add_foreign_key :users, :organizations
  141. add_foreign_key :organizations, :users, column: :created_by_id
  142. add_foreign_key :organizations, :users, column: :updated_by_id
  143. create_table :roles_users, id: false do |t|
  144. t.references :user
  145. t.references :role
  146. end
  147. add_index :roles_users, [:user_id]
  148. add_index :roles_users, [:role_id]
  149. add_foreign_key :roles_users, :users
  150. add_foreign_key :roles_users, :roles
  151. create_table :groups_users, id: false do |t|
  152. t.references :user
  153. t.references :group
  154. end
  155. add_index :groups_users, [:user_id]
  156. add_index :groups_users, [:group_id]
  157. add_foreign_key :groups_users, :users
  158. add_foreign_key :groups_users, :groups
  159. create_table :organizations_users, id: false do |t|
  160. t.references :user
  161. t.references :organization
  162. end
  163. add_index :organizations_users, [:user_id]
  164. add_index :organizations_users, [:organization_id]
  165. add_foreign_key :organizations_users, :users
  166. add_foreign_key :organizations_users, :organizations
  167. create_table :authorizations do |t|
  168. t.string :provider, limit: 250, null: false
  169. t.string :uid, limit: 250, null: false
  170. t.string :token, limit: 250, null: true
  171. t.string :secret, limit: 250, null: true
  172. t.string :username, limit: 250, null: true
  173. t.references :user, null: false
  174. t.timestamps limit: 3, null: false
  175. end
  176. add_index :authorizations, [:uid, :provider]
  177. add_index :authorizations, [:user_id]
  178. add_index :authorizations, [:username]
  179. add_foreign_key :authorizations, :users
  180. create_table :locales do |t|
  181. t.string :locale, limit: 20, null: false
  182. t.string :alias, limit: 20, null: true
  183. t.string :name, limit: 255, null: false
  184. t.boolean :active, null: false, default: true
  185. t.timestamps limit: 3, null: false
  186. end
  187. add_index :locales, [:locale], unique: true
  188. add_index :locales, [:name], unique: true
  189. create_table :translations do |t|
  190. t.string :locale, limit: 10, null: false
  191. t.string :source, limit: 500, null: false
  192. t.string :target, limit: 500, null: false
  193. t.string :target_initial, limit: 500, null: false
  194. t.string :format, limit: 20, null: false, default: 'string'
  195. t.integer :updated_by_id, null: false
  196. t.integer :created_by_id, null: false
  197. t.timestamps limit: 3, null: false
  198. end
  199. add_index :translations, [:source], length: 255
  200. add_index :translations, [:locale]
  201. add_foreign_key :translations, :users, column: :created_by_id
  202. add_foreign_key :translations, :users, column: :updated_by_id
  203. create_table :object_lookups do |t|
  204. t.string :name, limit: 250, null: false
  205. t.timestamps limit: 3, null: false
  206. end
  207. add_index :object_lookups, [:name], unique: true
  208. create_table :type_lookups do |t|
  209. t.string :name, limit: 250, null: false
  210. t.timestamps limit: 3, null: false
  211. end
  212. add_index :type_lookups, [:name], unique: true
  213. create_table :tokens do |t|
  214. t.references :user, null: false
  215. t.boolean :persistent
  216. t.string :name, limit: 100, null: false
  217. t.string :action, limit: 40, null: false
  218. t.string :label, limit: 255, null: true
  219. t.text :preferences, limit: 500.kilobytes + 1, null: true
  220. t.timestamp :last_used_at, limit: 3, null: true
  221. t.date :expires_at, null: true
  222. t.timestamps limit: 3, null: false
  223. end
  224. add_index :tokens, :user_id
  225. add_index :tokens, [:name, :action], unique: true
  226. add_index :tokens, :created_at
  227. add_index :tokens, :persistent
  228. add_foreign_key :tokens, :users
  229. create_table :packages do |t|
  230. t.string :name, limit: 250, null: false
  231. t.string :version, limit: 50, null: false
  232. t.string :vendor, limit: 150, null: false
  233. t.string :state, limit: 50, null: false
  234. t.integer :updated_by_id, null: false
  235. t.integer :created_by_id, null: false
  236. t.timestamps limit: 3, null: false
  237. end
  238. add_foreign_key :packages, :users, column: :created_by_id
  239. add_foreign_key :packages, :users, column: :updated_by_id
  240. create_table :package_migrations do |t|
  241. t.string :name, limit: 250, null: false
  242. t.string :version, limit: 250, null: false
  243. t.timestamps limit: 3, null: false
  244. end
  245. create_table :taskbars do |t|
  246. t.references :user, null: false
  247. t.datetime :last_contact, null: false
  248. t.string :client_id, null: false
  249. t.string :key, limit: 100, null: false
  250. t.string :callback, limit: 100, null: false
  251. t.text :state, limit: 20.megabytes + 1, null: true
  252. t.text :preferences, limit: 5.megabytes + 1, null: true
  253. t.string :params, limit: 2000, null: true
  254. t.integer :prio, null: false
  255. t.boolean :notify, null: false, default: false
  256. t.boolean :active, null: false, default: false
  257. t.timestamps limit: 3, null: false
  258. end
  259. add_index :taskbars, [:user_id]
  260. add_index :taskbars, [:client_id]
  261. add_index :taskbars, [:key]
  262. add_foreign_key :taskbars, :users
  263. create_table :tag_objects do |t|
  264. t.string :name, limit: 250, null: false
  265. t.timestamps limit: 3, null: false
  266. end
  267. add_index :tag_objects, [:name], unique: true
  268. create_table :tag_items do |t|
  269. t.string :name, limit: 250, null: false
  270. t.string :name_downcase, limit: 250, null: false
  271. t.timestamps limit: 3, null: false
  272. end
  273. add_index :tag_items, [:name_downcase]
  274. create_table :tags do |t|
  275. t.references :tag_item, null: false
  276. t.references :tag_object, null: false
  277. t.integer :o_id, null: false
  278. t.integer :created_by_id, null: false
  279. t.timestamps limit: 3, null: false
  280. end
  281. add_index :tags, [:o_id]
  282. add_index :tags, [:tag_object_id]
  283. add_foreign_key :tags, :tag_items
  284. add_foreign_key :tags, :tag_objects
  285. add_foreign_key :tags, :users, column: :created_by_id
  286. create_table :recent_views do |t|
  287. t.references :recent_view_object, null: false
  288. t.integer :o_id, null: false
  289. t.integer :created_by_id, null: false
  290. t.timestamps limit: 3, null: false
  291. end
  292. add_index :recent_views, [:o_id]
  293. add_index :recent_views, [:created_by_id]
  294. add_index :recent_views, [:created_at]
  295. add_index :recent_views, [:recent_view_object_id]
  296. add_foreign_key :recent_views, :object_lookups, column: :recent_view_object_id
  297. add_foreign_key :recent_views, :users, column: :created_by_id
  298. create_table :activity_streams do |t|
  299. t.references :activity_stream_type, null: false
  300. t.references :activity_stream_object, null: false
  301. t.references :permission, null: true
  302. t.references :group, null: true
  303. t.integer :o_id, null: false
  304. t.integer :created_by_id, null: false
  305. t.timestamps limit: 3, null: false
  306. end
  307. add_index :activity_streams, [:o_id]
  308. add_index :activity_streams, [:created_by_id]
  309. add_index :activity_streams, [:permission_id]
  310. add_index :activity_streams, [:group_id]
  311. add_index :activity_streams, [:created_at]
  312. add_index :activity_streams, [:activity_stream_object_id]
  313. add_index :activity_streams, [:activity_stream_type_id]
  314. add_foreign_key :activity_streams, :type_lookups, column: :activity_stream_type_id
  315. add_foreign_key :activity_streams, :object_lookups, column: :activity_stream_object_id
  316. add_foreign_key :activity_streams, :permissions
  317. add_foreign_key :activity_streams, :groups
  318. add_foreign_key :activity_streams, :users, column: :created_by_id
  319. create_table :history_types do |t|
  320. t.string :name, limit: 250, null: false
  321. t.timestamps limit: 3, null: false
  322. end
  323. add_index :history_types, [:name], unique: true
  324. create_table :history_objects do |t|
  325. t.string :name, limit: 250, null: false
  326. t.string :note, limit: 250, null: true
  327. t.timestamps limit: 3, null: false
  328. end
  329. add_index :history_objects, [:name], unique: true
  330. create_table :history_attributes do |t|
  331. t.string :name, limit: 250, null: false
  332. t.timestamps limit: 3, null: false
  333. end
  334. add_index :history_attributes, [:name], unique: true
  335. create_table :histories do |t|
  336. t.references :history_type, null: false
  337. t.references :history_object, null: false
  338. t.references :history_attribute, null: true
  339. t.integer :o_id, null: false
  340. t.integer :related_o_id, null: true
  341. t.integer :related_history_object_id, null: true
  342. t.integer :id_to, null: true
  343. t.integer :id_from, null: true
  344. t.string :value_from, limit: 500, null: true
  345. t.string :value_to, limit: 500, null: true
  346. t.integer :created_by_id, null: false
  347. t.timestamps limit: 3, null: false
  348. end
  349. add_index :histories, [:o_id]
  350. add_index :histories, [:created_by_id]
  351. add_index :histories, [:created_at]
  352. add_index :histories, [:history_object_id]
  353. add_index :histories, [:history_attribute_id]
  354. add_index :histories, [:history_type_id]
  355. add_index :histories, [:id_to]
  356. add_index :histories, [:id_from]
  357. add_index :histories, [:value_from], length: 255
  358. add_index :histories, [:value_to], length: 255
  359. add_foreign_key :histories, :history_types
  360. add_foreign_key :histories, :history_objects
  361. add_foreign_key :histories, :history_attributes
  362. add_foreign_key :histories, :users, column: :created_by_id
  363. create_table :settings do |t|
  364. t.string :title, limit: 200, null: false
  365. t.string :name, limit: 200, null: false
  366. t.string :area, limit: 100, null: false
  367. t.string :description, limit: 2000, null: false
  368. t.string :options, limit: 2000, null: true
  369. t.text :state_current, limit: 200.kilobytes + 1, null: true
  370. t.string :state_initial, limit: 2000, null: true
  371. t.boolean :frontend, null: false
  372. t.text :preferences, limit: 200.kilobytes + 1, null: true
  373. t.timestamps limit: 3, null: false
  374. end
  375. add_index :settings, [:name], unique: true
  376. add_index :settings, [:area]
  377. add_index :settings, [:frontend]
  378. create_table :store_objects do |t|
  379. t.string :name, limit: 250, null: false
  380. t.string :note, limit: 250, null: true
  381. t.timestamps limit: 3, null: false
  382. end
  383. add_index :store_objects, [:name], unique: true
  384. create_table :store_files do |t|
  385. t.string :sha, limit: 128, null: false
  386. t.string :provider, limit: 20, null: true
  387. t.timestamps limit: 3, null: false
  388. end
  389. add_index :store_files, [:sha], unique: true
  390. add_index :store_files, [:provider]
  391. create_table :stores do |t|
  392. t.references :store_object, null: false
  393. t.references :store_file, null: false
  394. t.integer :o_id, limit: 8, null: false
  395. t.string :preferences, limit: 2500, null: true
  396. t.string :size, limit: 50, null: true
  397. t.string :filename, limit: 250, null: false
  398. t.integer :created_by_id, null: false
  399. t.timestamps limit: 3, null: false
  400. end
  401. add_index :stores, [:store_object_id, :o_id]
  402. add_foreign_key :stores, :store_objects
  403. add_foreign_key :stores, :store_files
  404. add_foreign_key :stores, :users, column: :created_by_id
  405. create_table :store_provider_dbs do |t|
  406. t.string :sha, limit: 128, null: false
  407. t.binary :data, limit: 200.megabytes, null: true
  408. t.timestamps limit: 3, null: false
  409. end
  410. add_index :store_provider_dbs, [:sha], unique: true
  411. create_table :avatars do |t|
  412. t.integer :o_id, null: false
  413. t.integer :object_lookup_id, null: false
  414. t.boolean :default, null: false, default: false
  415. t.boolean :deletable, null: false, default: true
  416. t.boolean :initial, null: false, default: false
  417. t.integer :store_full_id, null: true
  418. t.integer :store_resize_id, null: true
  419. t.string :store_hash, limit: 32, null: true
  420. t.string :source, limit: 100, null: false
  421. t.string :source_url, limit: 512, null: true
  422. t.integer :updated_by_id, null: false
  423. t.integer :created_by_id, null: false
  424. t.timestamps limit: 3, null: false
  425. end
  426. add_index :avatars, [:o_id, :object_lookup_id]
  427. add_index :avatars, [:store_hash]
  428. add_index :avatars, [:source]
  429. add_index :avatars, [:default]
  430. add_foreign_key :avatars, :users, column: :created_by_id
  431. add_foreign_key :avatars, :users, column: :updated_by_id
  432. create_table :online_notifications do |t|
  433. t.integer :o_id, null: false
  434. t.integer :object_lookup_id, null: false
  435. t.integer :type_lookup_id, null: false
  436. t.integer :user_id, null: false
  437. t.boolean :seen, null: false, default: false
  438. t.integer :updated_by_id, null: false
  439. t.integer :created_by_id, null: false
  440. t.timestamps limit: 3, null: false
  441. end
  442. add_index :online_notifications, [:user_id]
  443. add_index :online_notifications, [:seen]
  444. add_index :online_notifications, [:created_at]
  445. add_index :online_notifications, [:updated_at]
  446. add_foreign_key :online_notifications, :users, column: :created_by_id
  447. add_foreign_key :online_notifications, :users, column: :updated_by_id
  448. create_table :schedulers do |t|
  449. t.string :name, limit: 250, null: false
  450. t.string :method, limit: 250, null: false
  451. t.integer :period, null: true
  452. t.integer :running, null: false, default: false
  453. t.timestamp :last_run, limit: 3, null: true
  454. t.integer :prio, null: false
  455. t.string :pid, limit: 250, null: true
  456. t.string :note, limit: 250, null: true
  457. t.boolean :active, null: false, default: false
  458. t.integer :updated_by_id, null: false
  459. t.integer :created_by_id, null: false
  460. t.timestamps limit: 3, null: false
  461. end
  462. add_index :schedulers, [:name], unique: true
  463. add_foreign_key :schedulers, :users, column: :created_by_id
  464. add_foreign_key :schedulers, :users, column: :updated_by_id
  465. create_table :calendars do |t|
  466. t.string :name, limit: 250, null: true
  467. t.string :timezone, limit: 250, null: true
  468. t.string :business_hours, limit: 3000, null: true
  469. t.boolean :default, null: false, default: false
  470. t.string :ical_url, limit: 500, null: true
  471. t.text :public_holidays, limit: 500.kilobytes + 1, null: true
  472. t.text :last_log, limit: 500.kilobytes + 1, null: true
  473. t.timestamp :last_sync, limit: 3, null: true
  474. t.integer :updated_by_id, null: false
  475. t.integer :created_by_id, null: false
  476. t.timestamps limit: 3, null: false
  477. end
  478. add_index :calendars, [:name], unique: true
  479. add_foreign_key :calendars, :users, column: :created_by_id
  480. add_foreign_key :calendars, :users, column: :updated_by_id
  481. create_table :user_devices do |t|
  482. t.references :user, null: false
  483. t.string :name, limit: 250, null: false
  484. t.string :os, limit: 150, null: true
  485. t.string :browser, limit: 250, null: true
  486. t.string :location, limit: 150, null: true
  487. t.string :device_details, limit: 2500, null: true
  488. t.string :location_details, limit: 2500, null: true
  489. t.string :fingerprint, limit: 160, null: true
  490. t.string :user_agent, limit: 250, null: true
  491. t.string :ip, limit: 160, null: true
  492. t.timestamps limit: 3, null: false
  493. end
  494. add_index :user_devices, [:user_id]
  495. add_index :user_devices, [:os, :browser, :location]
  496. add_index :user_devices, [:fingerprint]
  497. add_index :user_devices, [:updated_at]
  498. add_index :user_devices, [:created_at]
  499. add_foreign_key :user_devices, :users
  500. create_table :external_credentials do |t|
  501. t.string :name
  502. t.string :credentials, limit: 2500, null: false
  503. t.timestamps limit: 3, null: false
  504. end
  505. create_table :object_manager_attributes do |t|
  506. t.references :object_lookup, null: false
  507. t.string :name, limit: 200, null: false
  508. t.string :display, limit: 200, null: false
  509. t.string :data_type, limit: 100, null: false
  510. t.string :data_option, limit: 8000, null: true
  511. t.string :data_option_new, limit: 8000, null: true
  512. t.boolean :editable, null: false, default: true
  513. t.boolean :active, null: false, default: true
  514. t.string :screens, limit: 2000, null: true
  515. t.boolean :to_create, null: false, default: false
  516. t.boolean :to_migrate, null: false, default: false
  517. t.boolean :to_delete, null: false, default: false
  518. t.boolean :to_config, null: false, default: false
  519. t.integer :position, null: false
  520. t.integer :created_by_id, null: false
  521. t.integer :updated_by_id, null: false
  522. t.timestamps limit: 3, null: false
  523. end
  524. add_index :object_manager_attributes, [:object_lookup_id, :name], unique: true
  525. add_index :object_manager_attributes, [:object_lookup_id]
  526. add_foreign_key :object_manager_attributes, :object_lookups
  527. add_foreign_key :object_manager_attributes, :users, column: :created_by_id
  528. add_foreign_key :object_manager_attributes, :users, column: :updated_by_id
  529. create_table :delayed_jobs, force: true do |t|
  530. t.integer :priority, default: 0 # Allows some jobs to jump to the front of the queue
  531. t.integer :attempts, default: 0 # Provides for retries, but still fail eventually.
  532. t.text :handler # YAML-encoded string of the object that will do work
  533. t.text :last_error # reason for last failure (See Note below)
  534. t.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
  535. t.datetime :locked_at # Set when a client is working on this object
  536. t.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
  537. t.string :locked_by # Who is working on this object (if locked)
  538. t.string :queue # The name of the queue this job is in
  539. t.timestamps limit: 3, null: false
  540. end
  541. add_index :delayed_jobs, [:priority, :run_at], name: 'delayed_jobs_priority'
  542. create_table :external_syncs do |t|
  543. t.string :source, limit: 100, null: false
  544. t.string :source_id, limit: 200, null: false
  545. t.string :object, limit: 100, null: false
  546. t.integer :o_id, null: false
  547. t.text :last_payload, limit: 500.kilobytes + 1, null: true
  548. t.timestamps limit: 3, null: false
  549. end
  550. add_index :external_syncs, [:source, :source_id], unique: true
  551. add_index :external_syncs, [:source, :source_id, :object, :o_id], name: 'index_external_syncs_on_source_and_source_id_and_object_o_id'
  552. add_index :external_syncs, [:object, :o_id]
  553. create_table :import_jobs do |t|
  554. t.string :name, limit: 250, null: false
  555. t.boolean :dry_run, default: false
  556. t.text :payload, limit: 80_000
  557. t.text :result, limit: 80_000
  558. t.datetime :started_at
  559. t.datetime :finished_at
  560. t.timestamps null: false
  561. end
  562. create_table :cti_logs do |t|
  563. t.string :direction, limit: 20, null: false
  564. t.string :state, limit: 20, null: false
  565. t.string :from, limit: 100, null: false
  566. t.string :from_comment, limit: 250, null: true
  567. t.string :to, limit: 100, null: false
  568. t.string :to_comment, limit: 250, null: true
  569. t.string :call_id, limit: 250, null: false
  570. t.string :comment, limit: 500, null: true
  571. t.timestamp :start, limit: 3, null: true
  572. t.timestamp :end, limit: 3, null: true
  573. t.boolean :done, null: false, default: true
  574. t.text :preferences, limit: 500.kilobytes + 1, null: true
  575. t.timestamps limit: 3, null: false
  576. end
  577. add_index :cti_logs, [:call_id], unique: true
  578. add_index :cti_logs, [:direction]
  579. add_index :cti_logs, [:from]
  580. create_table :cti_caller_ids do |t|
  581. t.string :caller_id, limit: 100, null: false
  582. t.string :comment, limit: 500, null: true
  583. t.string :level, limit: 100, null: false
  584. t.string :object, limit: 100, null: false
  585. t.integer :o_id, null: false
  586. t.references :user, null: true
  587. t.text :preferences, limit: 500.kilobytes + 1, null: true
  588. t.timestamps limit: 3, null: false
  589. end
  590. add_index :cti_caller_ids, [:caller_id]
  591. add_index :cti_caller_ids, [:caller_id, :level]
  592. add_index :cti_caller_ids, [:caller_id, :user_id]
  593. add_index :cti_caller_ids, [:object, :o_id]
  594. add_foreign_key :cti_caller_ids, :users
  595. create_table :stats_stores do |t|
  596. t.references :stats_store_object, null: false
  597. t.integer :o_id, null: false
  598. t.string :key, limit: 250, null: true
  599. t.integer :related_o_id, null: true
  600. t.integer :related_stats_store_object_id, null: true
  601. t.string :data, limit: 5000, null: true
  602. t.integer :created_by_id, null: false
  603. t.timestamps limit: 3, null: false
  604. end
  605. add_index :stats_stores, [:o_id]
  606. add_index :stats_stores, [:key]
  607. add_index :stats_stores, [:stats_store_object_id]
  608. add_index :stats_stores, [:created_by_id]
  609. add_index :stats_stores, [:created_at]
  610. add_foreign_key :stats_stores, :users, column: :created_by_id
  611. create_table :http_logs do |t|
  612. t.column :direction, :string, limit: 20, null: false
  613. t.column :facility, :string, limit: 100, null: false
  614. t.column :method, :string, limit: 100, null: false
  615. t.column :url, :string, limit: 255, null: false
  616. t.column :status, :string, limit: 20, null: true
  617. t.column :ip, :string, limit: 50, null: true
  618. t.column :request, :string, limit: 10_000, null: false
  619. t.column :response, :string, limit: 10_000, null: false
  620. t.column :updated_by_id, :integer, null: true
  621. t.column :created_by_id, :integer, null: true
  622. t.timestamps limit: 3, null: false
  623. end
  624. add_index :http_logs, [:facility]
  625. add_index :http_logs, [:created_by_id]
  626. add_index :http_logs, [:created_at]
  627. add_foreign_key :http_logs, :users, column: :created_by_id
  628. add_foreign_key :http_logs, :users, column: :updated_by_id
  629. end
  630. end