"Fossies" - the Fresh Open Source Software Archive

Member "db/migrate/20120101000001_create_base.rb" (25 Mar 2021, 37485 Bytes) of package /linux/www/zammad-4.0.0.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "20120101000001_create_base.rb": 3.5.1_vs_4.0.0.

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