2018-07-25 01:16:36 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-02-21 12:09:07 +00:00
|
|
|
# See https://docs.gitlab.com/ee/development/migration_style_guide.html
|
2016-05-09 13:06:22 +00:00
|
|
|
# for more information on how to write migrations for GitLab.
|
|
|
|
|
2021-09-20 21:11:31 +00:00
|
|
|
class <%= migration_class_name %> < Gitlab::Database::Migration[<%= Gitlab::Database::Migration.current_version %>]
|
2021-03-25 21:09:13 +00:00
|
|
|
# When using the methods "add_concurrent_index" or "remove_concurrent_index"
|
|
|
|
# you must disable the use of transactions
|
2017-04-05 22:53:57 +00:00
|
|
|
# as these methods can not run in an existing transaction.
|
|
|
|
# When using "add_concurrent_index" or "remove_concurrent_index" methods make sure
|
|
|
|
# that either of them is the _only_ method called in the migration,
|
|
|
|
# any other changes should go in a separate migration.
|
|
|
|
# This ensures that upon failure _only_ the index creation or removing fails
|
|
|
|
# and can be retried or reverted easily.
|
2016-05-09 12:31:39 +00:00
|
|
|
#
|
|
|
|
# To disable transactions uncomment the following line and remove these
|
|
|
|
# comments:
|
|
|
|
# disable_ddl_transaction!
|
|
|
|
|
|
|
|
def change
|
|
|
|
create_table :<%= table_name %> do |t|
|
|
|
|
<% attributes.each do |attribute| -%>
|
|
|
|
<% if attribute.password_digest? -%>
|
|
|
|
t.string :password_digest<%= attribute.inject_options %>
|
|
|
|
<% else -%>
|
|
|
|
t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
|
|
|
|
<% end -%>
|
|
|
|
<% end -%>
|
|
|
|
<% if options[:timestamps] %>
|
|
|
|
t.timestamps null: false
|
|
|
|
<% end -%>
|
|
|
|
end
|
|
|
|
<% attributes_with_index.each do |attribute| -%>
|
|
|
|
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
|
|
|
|
<% end -%>
|
|
|
|
end
|
|
|
|
end
|