"Fossies" - the Fresh Open Source Software Archive

Member "db/migrate/20120101000010_create_ticket.rb" (25 Mar 2021, 33987 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 "20120101000010_create_ticket.rb": 3.5.1_vs_4.0.0.

    1 class CreateTicket < ActiveRecord::Migration[4.2]
    2   def up
    3     create_table :ticket_state_types do |t|
    4       t.column :name,                 :string, limit: 250, null: false
    5       t.column :note,                 :string, limit: 250, null: true
    6       t.column :updated_by_id,        :integer,            null: false
    7       t.column :created_by_id,        :integer,            null: false
    8       t.timestamps limit: 3, null: false
    9     end
   10     add_index :ticket_state_types, [:name], unique: true
   11     add_foreign_key :ticket_state_types, :users, column: :created_by_id
   12     add_foreign_key :ticket_state_types, :users, column: :updated_by_id
   13 
   14     create_table :ticket_states do |t|
   15       t.references :state_type, null: false
   16       t.column :name,                 :string, limit: 250,  null: false
   17       t.column :next_state_id,        :integer,             null: true
   18       t.column :ignore_escalation,    :boolean,             null: false, default: false
   19       t.column :default_create,       :boolean,             null: false, default: false
   20       t.column :default_follow_up,    :boolean,             null: false, default: false
   21       t.column :note,                 :string, limit: 250,  null: true
   22       t.column :active,               :boolean,             null: false, default: true
   23       t.column :updated_by_id,        :integer,             null: false
   24       t.column :created_by_id,        :integer,             null: false
   25       t.timestamps limit: 3, null: false
   26     end
   27     add_index :ticket_states, [:name], unique: true
   28     add_index :ticket_states, [:default_create]
   29     add_index :ticket_states, [:default_follow_up]
   30     add_foreign_key :ticket_states, :ticket_state_types, column: :state_type_id
   31     add_foreign_key :ticket_states, :users, column: :created_by_id
   32     add_foreign_key :ticket_states, :users, column: :updated_by_id
   33 
   34     create_table :ticket_priorities do |t|
   35       t.column :name,                 :string, limit: 250, null: false
   36       t.column :default_create,       :boolean,            null: false, default: false
   37       t.column :ui_icon,              :string, limit: 100, null: true
   38       t.column :ui_color,             :string, limit: 100, null: true
   39       t.column :note,                 :string, limit: 250, null: true
   40       t.column :active,               :boolean,            null: false, default: true
   41       t.column :updated_by_id,        :integer,            null: false
   42       t.column :created_by_id,        :integer,            null: false
   43       t.timestamps limit: 3, null: false
   44     end
   45     add_index :ticket_priorities, [:name], unique: true
   46     add_index :ticket_priorities, [:default_create]
   47     add_foreign_key :ticket_priorities, :users, column: :created_by_id
   48     add_foreign_key :ticket_priorities, :users, column: :updated_by_id
   49 
   50     create_table :tickets do |t|
   51       t.references :group,                                                null: false
   52       t.references :priority,                                             null: false
   53       t.references :state,                                                null: false
   54       t.references :organization,                                         null: true
   55       t.column :number,                           :string,    limit: 60,  null: false
   56       t.column :title,                            :string,    limit: 250, null: false
   57       t.column :owner_id,                         :integer,               null: false
   58       t.column :customer_id,                      :integer,               null: false
   59       t.column :note,                             :string,    limit: 250, null: true
   60       t.column :first_response_at,                :timestamp, limit: 3,   null: true
   61       t.column :first_response_escalation_at,     :timestamp, limit: 3,   null: true
   62       t.column :first_response_in_min,            :integer,               null: true
   63       t.column :first_response_diff_in_min,       :integer,               null: true
   64       t.column :close_at,                         :timestamp, limit: 3,   null: true
   65       t.column :close_escalation_at,              :timestamp, limit: 3,   null: true
   66       t.column :close_in_min,                     :integer,               null: true
   67       t.column :close_diff_in_min,                :integer,               null: true
   68       t.column :update_escalation_at,             :timestamp, limit: 3,   null: true
   69       t.column :update_in_min,                    :integer,               null: true
   70       t.column :update_diff_in_min,               :integer,               null: true
   71       t.column :last_contact_at,                  :timestamp, limit: 3,   null: true
   72       t.column :last_contact_agent_at,            :timestamp, limit: 3,   null: true
   73       t.column :last_contact_customer_at,         :timestamp, limit: 3,   null: true
   74       t.column :last_owner_update_at,             :timestamp, limit: 3,   null: true
   75       t.column :create_article_type_id,           :integer,               null: true
   76       t.column :create_article_sender_id,         :integer,               null: true
   77       t.column :article_count,                    :integer,               null: true
   78       t.column :escalation_at,                    :timestamp, limit: 3,   null: true
   79       t.column :pending_time,                     :timestamp, limit: 3,   null: true
   80       t.column :type,                             :string,    limit: 100, null: true
   81       t.column :time_unit,                        :decimal, precision: 6, scale: 2, null: true
   82       t.column :preferences,                      :text, limit: 500.kilobytes + 1, null: true
   83       t.column :updated_by_id,                    :integer,               null: false
   84       t.column :created_by_id,                    :integer,               null: false
   85       t.timestamps limit: 3, null: false
   86     end
   87     add_index :tickets, [:state_id]
   88     add_index :tickets, [:priority_id]
   89     add_index :tickets, [:group_id]
   90     add_index :tickets, [:owner_id]
   91     add_index :tickets, [:customer_id]
   92     add_index :tickets, %i[customer_id state_id created_at]
   93     add_index :tickets, [:number], unique: true
   94     add_index :tickets, [:title]
   95     add_index :tickets, [:created_at]
   96     add_index :tickets, [:updated_at]
   97     add_index :tickets, [:first_response_at]
   98     add_index :tickets, [:first_response_escalation_at]
   99     add_index :tickets, [:first_response_in_min]
  100     add_index :tickets, [:first_response_diff_in_min]
  101     add_index :tickets, [:close_at]
  102     add_index :tickets, [:close_escalation_at]
  103     add_index :tickets, [:close_in_min]
  104     add_index :tickets, [:close_diff_in_min]
  105     add_index :tickets, [:escalation_at]
  106     add_index :tickets, [:update_in_min]
  107     add_index :tickets, [:update_diff_in_min]
  108     add_index :tickets, [:last_contact_at]
  109     add_index :tickets, [:last_contact_agent_at]
  110     add_index :tickets, [:last_contact_customer_at]
  111     add_index :tickets, [:last_owner_update_at]
  112     add_index :tickets, [:create_article_type_id]
  113     add_index :tickets, [:create_article_sender_id]
  114     add_index :tickets, [:created_by_id]
  115     add_index :tickets, [:pending_time]
  116     add_index :tickets, [:type]
  117     add_index :tickets, [:time_unit]
  118     add_index :tickets, %i[group_id state_id]
  119     add_index :tickets, %i[group_id state_id owner_id]
  120     add_index :tickets, %i[group_id state_id updated_at]
  121     add_index :tickets, %i[group_id state_id owner_id updated_at], name: 'index_tickets_on_group_id_state_id_owner_id_updated_at'
  122     add_index :tickets, %i[group_id state_id created_at]
  123     add_index :tickets, %i[group_id state_id owner_id created_at], name: 'index_tickets_on_group_id_state_id_owner_id_created_at'
  124     add_index :tickets, %i[group_id state_id close_at]
  125     add_index :tickets, %i[group_id state_id owner_id close_at], name: 'index_tickets_on_group_id_state_id_owner_id_close_at'
  126     add_foreign_key :tickets, :groups
  127     add_foreign_key :tickets, :users, column: :owner_id
  128     add_foreign_key :tickets, :users, column: :customer_id
  129     add_foreign_key :tickets, :ticket_priorities, column: :priority_id
  130     add_foreign_key :tickets, :ticket_states, column: :state_id
  131     add_foreign_key :tickets, :organizations
  132     add_foreign_key :tickets, :users, column: :created_by_id
  133     add_foreign_key :tickets, :users, column: :updated_by_id
  134 
  135     create_table :ticket_flags do |t|
  136       t.references :ticket,                          null: false
  137       t.column :key,            :string, limit: 50,  null: false
  138       t.column :value,          :string, limit: 50,  null: true
  139       t.column :created_by_id,  :integer,            null: false
  140       t.timestamps limit: 3, null: false
  141     end
  142     add_index :ticket_flags, %i[ticket_id created_by_id]
  143     add_index :ticket_flags, %i[ticket_id key]
  144     add_index :ticket_flags, [:ticket_id]
  145     add_index :ticket_flags, [:created_by_id]
  146     add_foreign_key :ticket_flags, :tickets, column: :ticket_id
  147     add_foreign_key :ticket_flags, :users, column: :created_by_id
  148 
  149     create_table :ticket_article_types do |t|
  150       t.column :name,                 :string, limit: 250, null: false
  151       t.column :note,                 :string, limit: 250, null: true
  152       t.column :communication,        :boolean,            null: false
  153       t.column :active,               :boolean,            null: false, default: true
  154       t.column :updated_by_id,        :integer,            null: false
  155       t.column :created_by_id,        :integer,            null: false
  156       t.timestamps limit: 3, null: false
  157     end
  158     add_index :ticket_article_types, [:name], unique: true
  159     add_foreign_key :ticket_article_types, :users, column: :created_by_id
  160     add_foreign_key :ticket_article_types, :users, column: :updated_by_id
  161 
  162     create_table :ticket_article_senders do |t|
  163       t.column :name,                 :string, limit: 250, null: false
  164       t.column :note,                 :string, limit: 250, null: true
  165       t.column :updated_by_id,        :integer,            null: false
  166       t.column :created_by_id,        :integer,            null: false
  167       t.timestamps limit: 3, null: false
  168     end
  169     add_index :ticket_article_senders, [:name], unique: true
  170     add_foreign_key :ticket_article_senders, :users, column: :created_by_id
  171     add_foreign_key :ticket_article_senders, :users, column: :updated_by_id
  172 
  173     create_table :ticket_articles do |t|
  174       t.references :ticket,                                    null: false
  175       t.references :type,                                      null: false
  176       t.references :sender,                                    null: false
  177       t.column :from,                 :string, limit: 3000,    null: true
  178       t.column :to,                   :string, limit: 3000,    null: true
  179       t.column :cc,                   :string, limit: 3000,    null: true
  180       t.column :subject,              :string, limit: 3000,    null: true
  181       t.column :reply_to,             :string, limit: 300,     null: true
  182       t.column :message_id,           :string, limit: 3000,    null: true
  183       t.column :message_id_md5,       :string, limit: 32,      null: true
  184       t.column :in_reply_to,          :string, limit: 3000,    null: true
  185       t.column :content_type,         :string, limit: 20,      null: false, default: 'text/plain'
  186       t.column :references,           :string, limit: 3200,    null: true
  187       t.column :body,                 :text,   limit: 20.megabytes + 1, null: false
  188       t.column :internal,             :boolean, null: false, default: false
  189       t.column :preferences,          :text, limit: 500.kilobytes + 1, null: true
  190       t.column :updated_by_id,        :integer,                null: false
  191       t.column :created_by_id,        :integer,                null: false
  192       t.column :origin_by_id,         :integer
  193       t.timestamps limit: 3, null: false
  194     end
  195     add_index :ticket_articles, [:ticket_id]
  196     add_index :ticket_articles, [:message_id_md5]
  197     add_index :ticket_articles, %i[message_id_md5 type_id], name: 'index_ticket_articles_message_id_md5_type_id'
  198     add_index :ticket_articles, [:created_by_id]
  199     add_index :ticket_articles, [:created_at]
  200     add_index :ticket_articles, [:internal]
  201     add_index :ticket_articles, [:type_id]
  202     add_index :ticket_articles, [:sender_id]
  203     add_foreign_key :ticket_articles, :tickets
  204     add_foreign_key :ticket_articles, :ticket_article_types, column: :type_id
  205     add_foreign_key :ticket_articles, :ticket_article_senders, column: :sender_id
  206     add_foreign_key :ticket_articles, :users, column: :created_by_id
  207     add_foreign_key :ticket_articles, :users, column: :updated_by_id
  208     add_foreign_key :ticket_articles, :users, column: :origin_by_id
  209 
  210     create_table :ticket_article_flags do |t|
  211       t.references :ticket_article,                      null: false
  212       t.column :key,                 :string, limit: 50, null: false
  213       t.column :value,               :string, limit: 50, null: true
  214       t.column :created_by_id,       :integer,           null: false
  215       t.timestamps limit: 3, null: false
  216     end
  217     add_index :ticket_article_flags, %i[ticket_article_id created_by_id], name: 'index_ticket_article_flags_on_articles_id_and_created_by_id'
  218     add_index :ticket_article_flags, %i[ticket_article_id key]
  219     add_index :ticket_article_flags, [:ticket_article_id]
  220     add_index :ticket_article_flags, [:created_by_id]
  221     add_foreign_key :ticket_article_flags, :ticket_articles, column: :ticket_article_id
  222     add_foreign_key :ticket_article_flags, :users, column: :created_by_id
  223 
  224     create_table :ticket_time_accountings do |t|
  225       t.references :ticket,                                       null: false
  226       t.references :ticket_article,                               null: true
  227       t.column :time_unit,      :decimal, precision: 6, scale: 2, null: false
  228       t.column :created_by_id,  :integer,                         null: false
  229       t.timestamps limit: 3, null: false
  230     end
  231     add_index :ticket_time_accountings, [:ticket_id]
  232     add_index :ticket_time_accountings, [:ticket_article_id]
  233     add_index :ticket_time_accountings, [:created_by_id]
  234     add_index :ticket_time_accountings, [:time_unit]
  235     add_foreign_key :ticket_time_accountings, :tickets
  236     add_foreign_key :ticket_time_accountings, :ticket_articles
  237     add_foreign_key :ticket_time_accountings, :users, column: :created_by_id
  238 
  239     create_table :ticket_counters do |t|
  240       t.column :content,              :string, limit: 100, null: false
  241       t.column :generator,            :string, limit: 100, null: false
  242     end
  243     add_index :ticket_counters, [:generator], unique: true
  244 
  245     create_table :overviews do |t|
  246       t.column :name,                 :string,  limit: 250,    null: false
  247       t.column :link,                 :string,  limit: 250,    null: false
  248       t.column :prio,                 :integer,                null: false
  249       t.column :condition,            :text, limit: 500.kilobytes + 1, null: false
  250       t.column :order,                :string,  limit: 2500,   null: false
  251       t.column :group_by,             :string,  limit: 250,    null: true
  252       t.column :group_direction,      :string,  limit: 250,    null: true
  253       t.column :organization_shared,  :boolean,                null: false, default: false
  254       t.column :out_of_office,        :boolean,                null: false, default: false
  255       t.column :view,                 :string, limit: 1000, null: false
  256       t.column :active,               :boolean,                null: false, default: true
  257       t.column :updated_by_id,        :integer,                null: false
  258       t.column :created_by_id,        :integer,                null: false
  259       t.timestamps limit: 3, null: false
  260     end
  261     add_index :overviews, [:name]
  262     add_foreign_key :overviews, :users, column: :created_by_id
  263     add_foreign_key :overviews, :users, column: :updated_by_id
  264 
  265     create_table :overviews_roles, id: false do |t|
  266       t.references :overview
  267       t.references :role
  268     end
  269     add_index :overviews_roles, [:overview_id]
  270     add_index :overviews_roles, [:role_id]
  271     add_foreign_key :overviews_roles, :overviews
  272     add_foreign_key :overviews_roles, :roles
  273 
  274     create_table :overviews_users, id: false do |t|
  275       t.references :overview
  276       t.references :user
  277     end
  278     add_index :overviews_users, [:overview_id]
  279     add_index :overviews_users, [:user_id]
  280     add_foreign_key :overviews_users, :overviews
  281     add_foreign_key :overviews_users, :users
  282 
  283     create_table :overviews_groups, id: false do |t|
  284       t.references :overview
  285       t.references :group
  286     end
  287     add_index :overviews_groups, [:overview_id]
  288     add_index :overviews_groups, [:group_id]
  289     add_foreign_key :overviews_groups, :overviews
  290     add_foreign_key :overviews_groups, :groups
  291 
  292     create_table :triggers do |t|
  293       t.column :name,                 :string, limit: 250, null: false
  294       t.column :condition,            :text, limit: 500.kilobytes + 1, null: false
  295       t.column :perform,              :text, limit: 500.kilobytes + 1, null: false
  296       t.column :disable_notification, :boolean,               null: false, default: true
  297       t.column :note,                 :string, limit: 250,    null: true
  298       t.column :active,               :boolean,               null: false, default: true
  299       t.column :updated_by_id,        :integer,               null: false
  300       t.column :created_by_id,        :integer,               null: false
  301       t.timestamps limit: 3, null: false
  302     end
  303     add_index :triggers, [:name], unique: true
  304     add_foreign_key :triggers, :users, column: :created_by_id
  305     add_foreign_key :triggers, :users, column: :updated_by_id
  306 
  307     create_table :jobs do |t|
  308       t.column :name,                 :string,  limit: 250,    null: false
  309       t.column :timeplan,             :string,  limit: 2500,   null: false
  310       t.column :condition,            :text, limit: 500.kilobytes + 1, null: false
  311       t.column :perform,              :text, limit: 500.kilobytes + 1, null: false
  312       t.column :disable_notification, :boolean,                null: false, default: true
  313       t.column :last_run_at,          :timestamp, limit: 3,    null: true
  314       t.column :next_run_at,          :timestamp, limit: 3,    null: true
  315       t.column :running,              :boolean,                null: false, default: false
  316       t.column :processed,            :integer,                null: false, default: 0
  317       t.column :matching,             :integer,                null: false
  318       t.column :pid,                  :string,  limit: 250,    null: true
  319       t.column :note,                 :string,  limit: 250,    null: true
  320       t.column :active,               :boolean,                null: false, default: false
  321       t.column :updated_by_id,        :integer,                null: false
  322       t.column :created_by_id,        :integer,                null: false
  323       t.timestamps limit: 3, null: false
  324     end
  325     add_index :jobs, [:name], unique: true
  326     add_foreign_key :jobs, :users, column: :created_by_id
  327     add_foreign_key :jobs, :users, column: :updated_by_id
  328 
  329     create_table :notifications do |t|
  330       t.column :subject,      :string, limit: 250,   null: false
  331       t.column :body,         :string, limit: 8000,  null: false
  332       t.column :content_type, :string, limit: 250,   null: false
  333       t.column :active,       :boolean,              null: false, default: true
  334       t.column :note,         :string, limit: 250,   null: true
  335       t.timestamps limit: 3, null: false
  336     end
  337 
  338     create_table :link_types do |t|
  339       t.column :name,         :string, limit: 250,   null: false
  340       t.column :note,         :string, limit: 250,   null: true
  341       t.column :active,       :boolean,              null: false, default: true
  342       t.timestamps limit: 3, null: false
  343     end
  344     add_index :link_types, [:name], unique: true
  345 
  346     create_table :link_objects do |t|
  347       t.column :name,         :string, limit: 250,   null: false
  348       t.column :note,         :string, limit: 250,   null: true
  349       t.column :active,       :boolean,              null: false, default: true
  350       t.timestamps limit: 3, null: false
  351     end
  352     add_index :link_objects, [:name], unique: true
  353 
  354     create_table :links do |t|
  355       t.references :link_type,                            null: false
  356       t.column :link_object_source_id,        :integer,   null: false
  357       t.column :link_object_source_value,     :integer,   null: false
  358       t.column :link_object_target_id,        :integer,   null: false
  359       t.column :link_object_target_value,     :integer,   null: false
  360       t.timestamps limit: 3, null: false
  361     end
  362     add_index :links, %i[link_object_source_id link_object_source_value link_object_target_id link_object_target_value link_type_id], unique: true, name: 'links_uniq_total'
  363     add_foreign_key :links, :link_types
  364 
  365     create_table :postmaster_filters do |t|
  366       t.column :name,           :string, limit: 250,    null: false
  367       t.column :channel,        :string, limit: 250,    null: false
  368       t.column :match,          :text, limit: 500.kilobytes + 1, null: false
  369       t.column :perform,        :text, limit: 500.kilobytes + 1, null: false
  370       t.column :active,         :boolean,               null: false, default: true
  371       t.column :note,           :string, limit: 250,    null: true
  372       t.column :updated_by_id,  :integer,               null: false
  373       t.column :created_by_id,  :integer,               null: false
  374       t.timestamps limit: 3, null: false
  375     end
  376     add_index :postmaster_filters, [:channel]
  377     add_foreign_key :postmaster_filters, :users, column: :created_by_id
  378     add_foreign_key :postmaster_filters, :users, column: :updated_by_id
  379 
  380     create_table :text_modules do |t|
  381       t.column :name,                 :string,  limit: 250,  null: false
  382       t.column :keywords,             :string,  limit: 500,  null: true
  383       t.column :content,              :text,    limit: 10.megabytes + 1, null: false
  384       t.column :note,                 :string,  limit: 250,  null: true
  385       t.column :active,               :boolean,              null: false, default: true
  386       t.column :foreign_id,           :integer,              null: true
  387       t.column :updated_by_id,        :integer,              null: false
  388       t.column :created_by_id,        :integer,              null: false
  389       t.timestamps limit: 3, null: false
  390     end
  391     add_index :text_modules, [:name]
  392     add_foreign_key :text_modules, :users, column: :created_by_id
  393     add_foreign_key :text_modules, :users, column: :updated_by_id
  394 
  395     create_table :text_modules_groups, id: false do |t|
  396       t.references :text_module
  397       t.references :group
  398     end
  399     add_index :text_modules_groups, [:text_module_id]
  400     add_index :text_modules_groups, [:group_id]
  401     add_foreign_key :text_modules_groups, :text_modules
  402     add_foreign_key :text_modules_groups, :groups
  403 
  404     create_table :templates do |t|
  405       t.column :name,                 :string,  limit: 250,  null: false
  406       t.column :options,              :text,    limit: 10.megabytes + 1, null: false
  407       t.column :updated_by_id,        :integer,              null: false
  408       t.column :created_by_id,        :integer,              null: false
  409       t.timestamps limit: 3, null: false
  410     end
  411     add_index :templates, [:name]
  412     add_foreign_key :templates, :users, column: :created_by_id
  413     add_foreign_key :templates, :users, column: :updated_by_id
  414 
  415     create_table :templates_groups, id: false do |t|
  416       t.references :template
  417       t.references :group
  418     end
  419     add_index :templates_groups, [:template_id]
  420     add_index :templates_groups, [:group_id]
  421     add_foreign_key :templates_groups, :templates
  422     add_foreign_key :templates_groups, :groups
  423 
  424     create_table :channels do |t|
  425       t.references :group,                             null: true
  426       t.column :area,           :string, limit: 100,   null: false
  427       t.column :options,        :text,   limit: 500.kilobytes + 1,  null: true
  428       t.column :active,         :boolean,              null: false, default: true
  429       t.column :preferences,    :string, limit: 2000,  null: true
  430       t.column :last_log_in,    :text,   limit: 500.kilobytes + 1, null: true
  431       t.column :last_log_out,   :text,   limit: 500.kilobytes + 1, null: true
  432       t.column :status_in,      :string, limit: 100,   null: true
  433       t.column :status_out,     :string, limit: 100,   null: true
  434       t.column :updated_by_id,  :integer,              null: false
  435       t.column :created_by_id,  :integer,              null: false
  436       t.timestamps limit: 3, null: false
  437     end
  438     add_index :channels, [:area]
  439     add_foreign_key :channels, :groups
  440     add_foreign_key :channels, :users, column: :created_by_id
  441     add_foreign_key :channels, :users, column: :updated_by_id
  442 
  443     create_table :slas do |t|
  444       t.references :calendar,                                   null: false
  445       t.column :name,                 :string, limit: 150,      null: true
  446       t.column :first_response_time,  :integer,                 null: true
  447       t.column :update_time,          :integer,                 null: true
  448       t.column :solution_time,        :integer,                 null: true
  449       t.column :condition,            :text, limit: 500.kilobytes + 1, null: true
  450       t.column :updated_by_id,        :integer,                 null: false
  451       t.column :created_by_id,        :integer,                 null: false
  452       t.timestamps limit: 3, null: false
  453     end
  454     add_index :slas, [:name], unique: true
  455     add_foreign_key :slas, :users, column: :created_by_id
  456     add_foreign_key :slas, :users, column: :updated_by_id
  457 
  458     create_table :macros do |t|
  459       t.string  :name,                   limit: 250, null: true
  460       t.text    :perform,                limit: 500.kilobytes + 1, null: false
  461       t.boolean :active,                                null: false, default: true
  462       t.string  :ux_flow_next_up,                       null: false, default: 'none'
  463       t.string  :note, limit: 250, null: true
  464       t.integer :updated_by_id,                         null: false
  465       t.integer :created_by_id,                         null: false
  466       t.timestamps limit: 3, null: false
  467     end
  468     add_index :macros, [:name], unique: true
  469     add_foreign_key :macros, :users, column: :created_by_id
  470     add_foreign_key :macros, :users, column: :updated_by_id
  471 
  472     create_table :chats do |t|
  473       t.string  :name, limit: 250, null: true
  474       t.integer :max_queue, null: false, default: 5
  475       t.string  :note, limit: 250, null: true
  476       t.boolean :active,                              null: false, default: true
  477       t.boolean :public,                              null: false, default: false
  478       t.string  :block_ip,               limit: 5000, null: true
  479       t.string  :block_country,          limit: 5000, null: true
  480       t.string  :whitelisted_websites,   limit: 5000, null: true
  481       t.string  :preferences,            limit: 5000, null: true
  482       t.integer :updated_by_id,                       null: false
  483       t.integer :created_by_id,                       null: false
  484       t.timestamps limit: 3, null: false
  485     end
  486     add_index :chats, [:name], unique: true
  487     add_foreign_key :chats, :users, column: :created_by_id
  488     add_foreign_key :chats, :users, column: :updated_by_id
  489 
  490     create_table :chat_topics do |t|
  491       t.integer :chat_id,                             null: false
  492       t.string  :name,                   limit: 250,  null: false
  493       t.string  :note,                   limit: 250,  null: true
  494       t.integer :updated_by_id,                       null: false
  495       t.integer :created_by_id,                       null: false
  496       t.timestamps limit: 3, null: false
  497     end
  498     add_index :chat_topics, [:name], unique: true
  499     add_foreign_key :chat_topics, :users, column: :created_by_id
  500     add_foreign_key :chat_topics, :users, column: :updated_by_id
  501 
  502     create_table :chat_sessions do |t|
  503       t.references :chat,                             null: false
  504       t.string  :session_id,                          null: false
  505       t.string  :name,                   limit: 250,  null: true
  506       t.string  :state,                  limit:  50,  null: false, default: 'waiting' # running, closed
  507       t.references :user,                             null: true
  508       t.text    :preferences, limit: 100.kilobytes + 1, null: true
  509       t.integer :updated_by_id,                       null: true
  510       t.integer :created_by_id,                       null: true
  511       t.timestamps limit: 3, null: false
  512     end
  513     add_index :chat_sessions, [:session_id]
  514     add_index :chat_sessions, [:state]
  515     add_index :chat_sessions, [:user_id]
  516     add_index :chat_sessions, [:chat_id]
  517     add_foreign_key :chat_sessions, :chats
  518     add_foreign_key :chat_sessions, :users
  519     add_foreign_key :chat_sessions, :users, column: :created_by_id
  520     add_foreign_key :chat_sessions, :users, column: :updated_by_id
  521 
  522     create_table :chat_messages do |t|
  523       t.references :chat_session, null: false
  524       t.text    :content, limit: 20.megabytes + 1, null: false
  525       t.integer :created_by_id, null: true
  526       t.timestamps limit: 3, null: false
  527     end
  528     add_index :chat_messages, [:chat_session_id]
  529     add_foreign_key :chat_messages, :chat_sessions
  530     add_foreign_key :chat_messages, :users, column: :created_by_id
  531 
  532     create_table :chat_agents do |t|
  533       t.boolean :active,                              null: false, default: true
  534       t.integer :concurrent,                          null: false, default: 5
  535       t.integer :updated_by_id,                       null: false
  536       t.integer :created_by_id,                       null: false
  537       t.timestamps limit: 3, null: false
  538     end
  539     add_index :chat_agents, [:active]
  540     add_index :chat_agents, [:updated_by_id], unique: true
  541     add_index :chat_agents, [:created_by_id], unique: true
  542     add_foreign_key :chat_agents, :users, column: :created_by_id
  543     add_foreign_key :chat_agents, :users, column: :updated_by_id
  544 
  545     create_table :report_profiles do |t|
  546       t.column :name,           :string, limit: 150, null: true
  547       t.column :condition,      :text, limit: 500.kilobytes + 1, null: true
  548       t.column :active,         :boolean,               null: false, default: true
  549       t.column :updated_by_id,  :integer,               null: false
  550       t.column :created_by_id,  :integer,               null: false
  551       t.timestamps limit: 3, null: false
  552     end
  553     add_index :report_profiles, [:name], unique: true
  554     add_foreign_key :report_profiles, :users, column: :created_by_id
  555     add_foreign_key :report_profiles, :users, column: :updated_by_id
  556 
  557     create_table :karma_users do |t|
  558       t.references :user,                           null: false
  559       t.integer :score,                             null: false
  560       t.string  :level, limit: 200, null: false
  561       t.timestamps limit: 3, null: false
  562     end
  563     add_index :karma_users, [:user_id], unique: true
  564     add_foreign_key :karma_users, :users
  565 
  566     create_table :karma_activities do |t|
  567       t.string  :name,                limit: 200,    null: false
  568       t.string  :description,         limit: 200,    null: false
  569       t.integer :score,                              null: false
  570       t.integer :once_ttl,                           null: false
  571       t.timestamps limit: 3, null: false
  572     end
  573     add_index :karma_activities, [:name], unique: true
  574 
  575     create_table :karma_activity_logs do |t|
  576       t.integer :o_id,                          null: false
  577       t.integer :object_lookup_id,              null: false
  578       t.references :user,                       null: false
  579       t.integer :activity_id,                   null: false
  580       t.integer :score,                         null: false
  581       t.integer :score_total,                   null: false
  582       t.timestamps limit: 3, null: false
  583     end
  584     add_index :karma_activity_logs, [:user_id]
  585     add_index :karma_activity_logs, [:created_at]
  586     add_index :karma_activity_logs, %i[o_id object_lookup_id]
  587     add_foreign_key :karma_activity_logs, :users
  588     add_foreign_key :karma_activity_logs, :karma_activities, column: :activity_id
  589 
  590     create_table :webhooks do |t|
  591       t.column :name,                       :string, limit: 250,  null: false
  592       t.column :endpoint,                   :string, limit: 300,  null: false
  593       t.column :signature_token,            :string, limit: 200,  null: true
  594       t.column :ssl_verify,                 :boolean,             null: false, default: true
  595       t.column :note,                       :string, limit: 500,  null: true
  596       t.column :active,                     :boolean,             null: false, default: true
  597       t.column :updated_by_id,              :integer,             null: false
  598       t.column :created_by_id,              :integer,             null: false
  599       t.timestamps limit: 3, null: false
  600     end
  601 
  602   end
  603 
  604   def self.down
  605     drop_table :karma_activity_logs
  606     drop_table :karma_activities
  607     drop_table :karma_users
  608     drop_table :report_profiles
  609     drop_table :chat_topics
  610     drop_table :chat_sessions
  611     drop_table :chat_messages
  612     drop_table :chat_agents
  613     drop_table :chats
  614     drop_table :macros
  615     drop_table :slas
  616     drop_table :channels
  617     drop_table :templates_groups
  618     drop_table :templates
  619     drop_table :text_modules_groups
  620     drop_table :text_modules
  621     drop_table :postmaster_filters
  622     drop_table :notifications
  623     drop_table :triggers
  624     drop_table :links
  625     drop_table :link_types
  626     drop_table :link_objects
  627     drop_table :overviews
  628     drop_table :ticket_counters
  629     drop_table :ticket_time_accounting
  630     drop_table :ticket_article_flags
  631     drop_table :ticket_articles
  632     drop_table :ticket_article_types
  633     drop_table :ticket_article_senders
  634     drop_table :ticket_flags
  635     drop_table :tickets
  636     drop_table :ticket_priorities
  637     drop_table :ticket_states
  638     drop_table :ticket_state_types
  639     drop_table :webhooks
  640   end
  641 end