BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
d7cfe1a5
Unverified
Commit
d7cfe1a5
authored
May 09, 2016
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added custom migration generator templates
This allows us to automatically include Gitlab::Database::MigrationHelpers into newly generated migrations.
parent
e8670990
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
0 deletions
+84
-0
create_table_migration.rb
...mplates/active_record/migration/create_table_migration.rb
+32
-0
migration.rb
lib/templates/active_record/migration/migration.rb
+52
-0
No files found.
lib/templates/active_record/migration/create_table_migration.rb
0 → 100644
View file @
d7cfe1a5
class
<
%= migration_class_name %> < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
# When using the methods "add_concurrent_index" or "add_column_with_default"
# you must disable the use of transactions as these methods can not run in an
# existing transaction. When using "add_concurrent_index" make sure that this
# method 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 failes and can be re-tried or reverted easily.
#
# 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
lib/templates/active_record/migration/migration.rb
0 → 100644
View file @
d7cfe1a5
class
<
%= migration_class_name %> < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
# When using the methods "add_concurrent_index" or "add_column_with_default"
# you must disable the use of transactions as these methods can not run in an
# existing transaction. When using "add_concurrent_index" make sure that this
# method 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 failes and can be re-tried or reverted easily.
#
# To disable transactions uncomment the following line and remove these
# comments:
# disable_ddl_transaction!
<%- if migration_action =
=
'add'
-
%>
def change
<% attributes.each do |attribute| -%>
<
%- if attribute.reference? -%>
add_reference :<%= table_name %>
,
:<
%=
attribute
.
name
%><%= attribute.inject_options %>
<
%- else -%>
add_column :<%= table_name %>
,
:<
%=
attribute
.
name
%>, :<%= attribute.type %>
<
%= attribute.inject_options %>
<%- if attribute.has_index? -%>
add_index :<%=
table_name
%>, :<%= attribute.index_name %>
<
%= attribute.inject_index_options %>
<%- end -%>
<%- end -%>
<%- end -%>
end
<%- elsif migration_action =
=
'join'
-
%>
def change
create_join_table :<%= join_tables.first %>
,
:<
%=
join_tables
.
second
%> do |t|
<%- attributes.each do |attribute| -%>
<
%= '# ' unless attribute.has_index? -%>t.index <%=
attribute
.
index_name
%><%= attribute.inject_index_options %>
<
%- end -%>
end
end
<%- else -%>
def
change
<
% attributes.each
do
|
attribute
|
-
%>
<%- if migration_action -%>
<
%- if attribute.reference? -%>
remove_reference :<%= table_name %>
,
:<
%=
attribute
.
name
%><%= attribute.inject_options %>
<
%- else -%>
<%- if attribute.has_index? -%>
remove_index
:<
%=
table_name
%>, :<%= attribute.index_name %>
<
%= attribute.inject_index_options %>
<%- end -%>
remove_column :<%=
table_name
%>, :<%= attribute.name %>
,
:<
%=
attribute
.
type
%><%= attribute.inject_options %>
<
%- end -%>
<%- end -%>
<
%- end -%>
end
<%- end -%>
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment