Commit 89aed37e authored by Kamil Trzcinski's avatar Kamil Trzcinski

Make migrations reversible

parent 9f69a0b2
class AddBuildEventsToServices < ActiveRecord::Migration class AddBuildEventsToServices < ActiveRecord::Migration
def up def change
add_column :services, :build_events, :boolean, default: false, null: false add_column :services, :build_events, :boolean, default: false, null: false
add_column :web_hooks, :build_events, :boolean, default: false, null: false add_column :web_hooks, :build_events, :boolean, default: false, null: false
end end
......
...@@ -10,4 +10,7 @@ class MigrateCiWebHooks < ActiveRecord::Migration ...@@ -10,4 +10,7 @@ class MigrateCiWebHooks < ActiveRecord::Migration
'JOIN projects ON ci_projects.gitlab_id = projects.id' 'JOIN projects ON ci_projects.gitlab_id = projects.id'
) )
end end
def down
end
end end
class AddCiToProject < ActiveRecord::Migration class AddCiToProject < ActiveRecord::Migration
def up def change
add_column :projects, :ci_id, :integer add_column :projects, :ci_id, :integer
add_column :projects, :builds_enabled, :boolean, default: true, null: false add_column :projects, :builds_enabled, :boolean, default: true, null: false
add_column :projects, :shared_runners_enabled, :boolean, default: true, null: false add_column :projects, :shared_runners_enabled, :boolean, default: true, null: false
......
class AddProjectIdToCi < ActiveRecord::Migration class AddProjectIdToCi < ActiveRecord::Migration
def up def change
add_column :ci_builds, :gl_project_id, :integer add_column :ci_builds, :gl_project_id, :integer
add_column :ci_runner_projects, :gl_project_id, :integer add_column :ci_runner_projects, :gl_project_id, :integer
add_column :ci_triggers, :gl_project_id, :integer add_column :ci_triggers, :gl_project_id, :integer
......
...@@ -14,6 +14,10 @@ class MigrateCiToProject < ActiveRecord::Migration ...@@ -14,6 +14,10 @@ class MigrateCiToProject < ActiveRecord::Migration
migrate_ci_service migrate_ci_service
end end
def down
# We can't reverse the data
end
def migrate_project_id_for_table(table) def migrate_project_id_for_table(table)
subquery = "SELECT gitlab_id FROM ci_projects WHERE ci_projects.id = #{table}.project_id" subquery = "SELECT gitlab_id FROM ci_projects WHERE ci_projects.id = #{table}.project_id"
execute("UPDATE #{table} SET gl_project_id=(#{subquery}) WHERE gl_project_id IS NULL") execute("UPDATE #{table} SET gl_project_id=(#{subquery}) WHERE gl_project_id IS NULL")
......
class AddIndexToCiTables < ActiveRecord::Migration class AddIndexToCiTables < ActiveRecord::Migration
def up def change
add_index :ci_builds, :gl_project_id add_index :ci_builds, :gl_project_id
add_index :ci_runner_projects, :gl_project_id add_index :ci_runner_projects, :gl_project_id
add_index :ci_triggers, :gl_project_id add_index :ci_triggers, :gl_project_id
......
class DropNullForCiTables < ActiveRecord::Migration class DropNullForCiTables < ActiveRecord::Migration
def up def change
remove_index :ci_variables, :project_id remove_index :ci_variables, :project_id
remove_index :ci_runner_projects, :project_id remove_index :ci_runner_projects, :project_id
change_column_null :ci_triggers, :project_id, true change_column_null :ci_triggers, :project_id, true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment