/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. class <%= migration_class_name %> < ActiveRecord::Migration
  4. include Gitlab::Database::MigrationHelpers
  5. # Set this constant to true if this migration requires downtime.
  6. DOWNTIME = false
  7. # When a migration requires downtime you **must** uncomment the following
  8. # constant and define a short and easy to understand explanation as to why the
  9. # migration requires downtime.
  10. # DOWNTIME_REASON = ''
  11. # When using the methods "add_concurrent_index" or "add_column_with_default"
  12. # you must disable the use of transactions as these methods can not run in an
  13. # existing transaction. When using "add_concurrent_index" make sure that this
  14. # method is the _only_ method called in the migration, any other changes
  15. # should go in a separate migration. This ensures that upon failure _only_ the
  16. # index creation fails and can be retried or reverted easily.
  17. #
  18. # To disable transactions uncomment the following line and remove these
  19. # comments:
  20. # disable_ddl_transaction!
  21. def change
  22. create_table :<%= table_name %> do |t|
  23. <% attributes.each do |attribute| -%>
  24. <% if attribute.password_digest? -%>
  25. t.string :password_digest<%= attribute.inject_options %>
  26. <% else -%>
  27. t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
  28. <% end -%>
  29. <% end -%>
  30. <% if options[:timestamps] %>
  31. t.timestamps null: false
  32. <% end -%>
  33. end
  34. <% attributes_with_index.each do |attribute| -%>
  35. add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
  36. <% end -%>
  37. end
  38. end