From 0b022b50df48206e8659994881a84bafa5ea00db Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Thu, 14 Sep 2017 14:27:18 -0300 Subject: Fix migrations --- ...9_change_project_id_to_not_null_in_project_features.rb | 15 --------------- ...20170913180600_fix_projects_without_project_feature.rb | 6 +++++- db/schema.rb | 2 +- 3 files changed, 6 insertions(+), 17 deletions(-) delete mode 100644 db/post_migrate/20170913150359_change_project_id_to_not_null_in_project_features.rb diff --git a/db/post_migrate/20170913150359_change_project_id_to_not_null_in_project_features.rb b/db/post_migrate/20170913150359_change_project_id_to_not_null_in_project_features.rb deleted file mode 100644 index 20531c3fe29..00000000000 --- a/db/post_migrate/20170913150359_change_project_id_to_not_null_in_project_features.rb +++ /dev/null @@ -1,15 +0,0 @@ -class ChangeProjectIdToNotNullInProjectFeatures < ActiveRecord::Migration - DOWNTIME = false - - def up - # Deletes corrupted project features - delete_project_features_sql = "DELETE FROM project_features WHERE project_id IS NULL" - execute(delete_project_features_sql) - - change_column_null :project_features, :project_id, false - end - - def down - change_column_null :project_features, :project_id, true - end -end diff --git a/db/post_migrate/20170913180600_fix_projects_without_project_feature.rb b/db/post_migrate/20170913180600_fix_projects_without_project_feature.rb index 76e75837304..bfa9ad80c7d 100644 --- a/db/post_migrate/20170913180600_fix_projects_without_project_feature.rb +++ b/db/post_migrate/20170913180600_fix_projects_without_project_feature.rb @@ -2,6 +2,10 @@ class FixProjectsWithoutProjectFeature < ActiveRecord::Migration DOWNTIME = false def up + # Deletes corrupted project features + sql = "DELETE FROM project_features WHERE project_id IS NULL" + execute(sql) + # Creates missing project features with private visibility sql = %Q{ @@ -16,7 +20,7 @@ class FixProjectsWithoutProjectFeature < ActiveRecord::Migration 10 as snippets_access_level, projects.created_at, projects.updated_at - FROM "projects" + FROM projects LEFT OUTER JOIN project_features ON project_features.project_id = projects.id WHERE (project_features.id IS NULL) } diff --git a/db/schema.rb b/db/schema.rb index 04680f5ddf6..863a84242e8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1113,7 +1113,7 @@ ActiveRecord::Schema.define(version: 20170913180600) do add_index "project_authorizations", ["user_id", "project_id", "access_level"], name: "index_project_authorizations_on_user_id_project_id_access_level", unique: true, using: :btree create_table "project_features", force: :cascade do |t| - t.integer "project_id", null: false + t.integer "project_id" t.integer "merge_requests_access_level" t.integer "issues_access_level" t.integer "wiki_access_level" -- cgit v1.2.1