PageRenderTime 27ms CodeModel.GetById 14ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/generator_templates/active_record/migration/create_table_migration.rb

https://gitlab.com/vicvega/gitlab-ce
Ruby | 43 lines | 21 code | 5 blank | 17 comment | 3 complexity | 37b38c846853a7ced2ea013fd875460d MD5 | raw file
 1# See http://doc.gitlab.com/ce/development/migration_style_guide.html
 2# for more information on how to write migrations for GitLab.
 3
 4class <%= migration_class_name %> < ActiveRecord::Migration
 5  include Gitlab::Database::MigrationHelpers
 6
 7  # Set this constant to true if this migration requires downtime.
 8  DOWNTIME = false
 9
10  # When a migration requires downtime you **must** uncomment the following
11  # constant and define a short and easy to understand explanation as to why the
12  # migration requires downtime.
13  # DOWNTIME_REASON = ''
14
15  # When using the methods "add_concurrent_index" or "add_column_with_default"
16  # you must disable the use of transactions as these methods can not run in an
17  # existing transaction. When using "add_concurrent_index" make sure that this
18  # method is the _only_ method called in the migration, any other changes
19  # should go in a separate migration. This ensures that upon failure _only_ the
20  # index creation fails and can be retried or reverted easily.
21  #
22  # To disable transactions uncomment the following line and remove these
23  # comments:
24  # disable_ddl_transaction!
25
26  def change
27    create_table :<%= table_name %> do |t|
28<% attributes.each do |attribute| -%>
29<% if attribute.password_digest? -%>
30      t.string :password_digest<%= attribute.inject_options %>
31<% else -%>
32      t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
33<% end  -%>
34<% end -%>
35<% if  options[:timestamps] %>
36      t.timestamps null: false
37<% end -%>
38    end
39<% attributes_with_index.each  do |attribute| -%>
40    add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
41<% end -%>
42  end
43end