summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-05-28 20:01:56 +0900
committerShinya Maeda <shinya@gitlab.com>2018-05-28 20:01:56 +0900
commit1d20679e9c8b1ba16bebaf982255946e7207b4d4 (patch)
tree128685af66ca56c751b505a8314ca79dd3b54b34 /db
parent8e92e25b62ca108de775362e6d2981e54535f094 (diff)
parent014f5f6a69f63ee42bd94454108268f189b62b18 (diff)
downloadgitlab-ce-1d20679e9c8b1ba16bebaf982255946e7207b4d4.tar.gz
Merge branch 'master' into per-project-pipeline-iid
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20180503175053_ensure_missing_columns_to_project_mirror_data.rb15
-rw-r--r--db/migrate/20180517082340_add_not_null_constraints_to_project_authorizations.rb38
-rw-r--r--db/migrate/20180521171529_increase_mysql_text_limit_for_gpg_keys.rb2
-rw-r--r--db/migrate/gpg_keys_limits_to_mysql.rb15
-rw-r--r--db/optional_migrations/composite_primary_keys.rb63
-rw-r--r--db/post_migrate/20180514161336_remove_gemnasium_service.rb15
-rw-r--r--db/schema.rb8
7 files changed, 152 insertions, 4 deletions
diff --git a/db/migrate/20180503175053_ensure_missing_columns_to_project_mirror_data.rb b/db/migrate/20180503175053_ensure_missing_columns_to_project_mirror_data.rb
new file mode 100644
index 00000000000..970a53d68d0
--- /dev/null
+++ b/db/migrate/20180503175053_ensure_missing_columns_to_project_mirror_data.rb
@@ -0,0 +1,15 @@
+class EnsureMissingColumnsToProjectMirrorData < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ add_column :project_mirror_data, :status, :string unless column_exists?(:project_mirror_data, :status)
+ add_column :project_mirror_data, :jid, :string unless column_exists?(:project_mirror_data, :jid)
+ add_column :project_mirror_data, :last_error, :text unless column_exists?(:project_mirror_data, :last_error)
+ end
+
+ def down
+ # db/migrate/20180502122856_create_project_mirror_data.rb will remove the table
+ end
+end
diff --git a/db/migrate/20180517082340_add_not_null_constraints_to_project_authorizations.rb b/db/migrate/20180517082340_add_not_null_constraints_to_project_authorizations.rb
new file mode 100644
index 00000000000..3b7b877232b
--- /dev/null
+++ b/db/migrate/20180517082340_add_not_null_constraints_to_project_authorizations.rb
@@ -0,0 +1,38 @@
+class AddNotNullConstraintsToProjectAuthorizations < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ def up
+ if Gitlab::Database.postgresql?
+ # One-pass version for PostgreSQL
+ execute <<~SQL
+ ALTER TABLE project_authorizations
+ ALTER COLUMN user_id SET NOT NULL,
+ ALTER COLUMN project_id SET NOT NULL,
+ ALTER COLUMN access_level SET NOT NULL
+ SQL
+ else
+ change_column_null :project_authorizations, :user_id, false
+ change_column_null :project_authorizations, :project_id, false
+ change_column_null :project_authorizations, :access_level, false
+ end
+ end
+
+ def down
+ if Gitlab::Database.postgresql?
+ # One-pass version for PostgreSQL
+ execute <<~SQL
+ ALTER TABLE project_authorizations
+ ALTER COLUMN user_id DROP NOT NULL,
+ ALTER COLUMN project_id DROP NOT NULL,
+ ALTER COLUMN access_level DROP NOT NULL
+ SQL
+ else
+ change_column_null :project_authorizations, :user_id, true
+ change_column_null :project_authorizations, :project_id, true
+ change_column_null :project_authorizations, :access_level, true
+ end
+ end
+end
diff --git a/db/migrate/20180521171529_increase_mysql_text_limit_for_gpg_keys.rb b/db/migrate/20180521171529_increase_mysql_text_limit_for_gpg_keys.rb
new file mode 100644
index 00000000000..df84898003f
--- /dev/null
+++ b/db/migrate/20180521171529_increase_mysql_text_limit_for_gpg_keys.rb
@@ -0,0 +1,2 @@
+# rubocop:disable all
+require_relative 'gpg_keys_limits_to_mysql'
diff --git a/db/migrate/gpg_keys_limits_to_mysql.rb b/db/migrate/gpg_keys_limits_to_mysql.rb
new file mode 100644
index 00000000000..780340d0564
--- /dev/null
+++ b/db/migrate/gpg_keys_limits_to_mysql.rb
@@ -0,0 +1,15 @@
+class IncreaseMysqlTextLimitForGpgKeys < ActiveRecord::Migration
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ def up
+ return unless Gitlab::Database.mysql?
+
+ change_column :gpg_keys, :key, :text, limit: 16.megabytes - 1
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/optional_migrations/composite_primary_keys.rb b/db/optional_migrations/composite_primary_keys.rb
new file mode 100644
index 00000000000..0fd3fca52dd
--- /dev/null
+++ b/db/optional_migrations/composite_primary_keys.rb
@@ -0,0 +1,63 @@
+# This migration adds a primary key constraint to tables
+# that only have a composite unique key.
+#
+# This is not strictly relevant to Rails (v4 does not
+# support composite primary keys). However this becomes
+# useful for e.g. PostgreSQL's logical replication (pglogical)
+# which requires all tables to have a primary key constraint.
+#
+# In that sense, the migration is optional and not strictly needed.
+class CompositePrimaryKeysMigration < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ Index = Struct.new(:table, :name, :columns)
+
+ TABLES = [
+ Index.new(:issue_assignees, 'index_issue_assignees_on_issue_id_and_user_id', %i(issue_id user_id)),
+ Index.new(:user_interacted_projects, 'index_user_interacted_projects_on_project_id_and_user_id', %i(project_id user_id)),
+ Index.new(:merge_request_diff_files, 'index_merge_request_diff_files_on_mr_diff_id_and_order', %i(merge_request_diff_id relative_order)),
+ Index.new(:merge_request_diff_commits, 'index_merge_request_diff_commits_on_mr_diff_id_and_order', %i(merge_request_diff_id relative_order)),
+ Index.new(:project_authorizations, 'index_project_authorizations_on_user_id_project_id_access_level', %i(user_id project_id access_level)),
+ Index.new(:push_event_payloads, 'index_push_event_payloads_on_event_id', %i(event_id)),
+ Index.new(:schema_migrations, 'unique_schema_migrations', %(version)),
+ ]
+
+ disable_ddl_transaction!
+
+ def up
+ return unless Gitlab::Database.postgresql?
+
+ disable_statement_timeout
+ TABLES.each do |index|
+ add_primary_key(index)
+ end
+ end
+
+ def down
+ return unless Gitlab::Database.postgresql?
+
+ disable_statement_timeout
+ TABLES.each do |index|
+ remove_primary_key(index)
+ end
+ end
+
+ private
+ def add_primary_key(index)
+ execute "ALTER TABLE #{index.table} ADD PRIMARY KEY USING INDEX #{index.name}"
+ end
+
+ def remove_primary_key(index)
+ temp_index_name = "#{index.name[0..58]}_old"
+ rename_index index.table, index.name, temp_index_name if index_exists_by_name?(index.table, index.name)
+
+ # re-create unique key index
+ add_concurrent_index index.table, index.columns, unique: true, name: index.name
+
+ # This also drops the `temp_index_name` as this is owned by the constraint
+ execute "ALTER TABLE #{index.table} DROP CONSTRAINT IF EXISTS #{temp_index_name}"
+ end
+end
+
diff --git a/db/post_migrate/20180514161336_remove_gemnasium_service.rb b/db/post_migrate/20180514161336_remove_gemnasium_service.rb
new file mode 100644
index 00000000000..6d7806e8daa
--- /dev/null
+++ b/db/post_migrate/20180514161336_remove_gemnasium_service.rb
@@ -0,0 +1,15 @@
+class RemoveGemnasiumService < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def up
+ disable_statement_timeout
+
+ execute("DELETE FROM services WHERE type='GemnasiumService';")
+ end
+
+ def down
+ # noop
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 27bdb7701c1..eab5bf24703 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20180512061621) do
+ActiveRecord::Schema.define(version: 20180521171529) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -1451,9 +1451,9 @@ ActiveRecord::Schema.define(version: 20180512061621) do
add_index "personal_access_tokens", ["user_id"], name: "index_personal_access_tokens_on_user_id", using: :btree
create_table "project_authorizations", id: false, force: :cascade do |t|
- t.integer "user_id"
- t.integer "project_id"
- t.integer "access_level"
+ t.integer "user_id", null: false
+ t.integer "project_id", null: false
+ t.integer "access_level", null: false
end
add_index "project_authorizations", ["project_id"], name: "index_project_authorizations_on_project_id", using: :btree