Commit 492775d8 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'remove-dead-mysql-code' into 'master'

Remove redundant and dead code related to MySQL

See merge request gitlab-org/gitlab!20319
parents d389ade9 8e20b15e
......@@ -25,10 +25,6 @@ class ReworkRedirectRoutesIndexes < ActiveRecord::Migration[4.2]
remove_concurrent_index(:redirect_routes, :permanent)
end
# If we're on MySQL then the existing index on path is ok. But on
# Postgres we need to clean things up:
break unless Gitlab::Database.postgresql?
if_not_exists = Gitlab::Database.version.to_f >= 9.5 ? "IF NOT EXISTS" : ""
# Unique index on lower(path) across both types of redirect_routes:
......@@ -53,8 +49,6 @@ class ReworkRedirectRoutesIndexes < ActiveRecord::Migration[4.2]
disable_statement_timeout do
add_concurrent_index(:redirect_routes, :permanent)
break unless Gitlab::Database.postgresql?
execute("CREATE INDEX CONCURRENTLY #{OLD_INDEX_NAME_PATH_TPOPS} ON redirect_routes (path varchar_pattern_ops);")
execute("CREATE INDEX CONCURRENTLY #{OLD_INDEX_NAME_PATH_LOWER} ON redirect_routes (LOWER(path));")
......
......@@ -8,16 +8,10 @@ class AddSectionNameIdIndexOnCiBuildTraceSections < ActiveRecord::Migration[4.2]
disable_ddl_transaction!
def up
# MySQL may already have this as a foreign key
unless index_exists?(:ci_build_trace_sections, :section_name_id, name: INDEX_NAME)
add_concurrent_index :ci_build_trace_sections, :section_name_id, name: INDEX_NAME
end
add_concurrent_index :ci_build_trace_sections, :section_name_id, name: INDEX_NAME
end
def down
# We cannot remove index for MySQL because it's needed for foreign key
if Gitlab::Database.postgresql?
remove_concurrent_index :ci_build_trace_sections, :section_name_id, name: INDEX_NAME
end
remove_concurrent_index :ci_build_trace_sections, :section_name_id, name: INDEX_NAME
end
end
......@@ -13,28 +13,6 @@ class AddIndexesForUserActivityQueries < ActiveRecord::Migration[4.2]
def down
remove_concurrent_index :events, [:author_id, :project_id] if index_exists?(:events, [:author_id, :project_id])
patch_foreign_keys do
remove_concurrent_index :user_interacted_projects, :user_id if index_exists?(:user_interacted_projects, :user_id)
end
end
private
def patch_foreign_keys
return yield if Gitlab::Database.postgresql?
# MySQL doesn't like to remove the index with a foreign key using it.
remove_foreign_key :user_interacted_projects, :users if fk_exists?(:user_interacted_projects, :user_id)
yield
# Let's re-add the foreign key using the existing index on (user_id, project_id)
add_concurrent_foreign_key :user_interacted_projects, :users, column: :user_id unless fk_exists?(:user_interacted_projects, :user_id)
end
def fk_exists?(table, column)
foreign_keys(table).any? do |key|
key.options[:column] == column.to_s
end
remove_concurrent_index :user_interacted_projects, :user_id if index_exists?(:user_interacted_projects, :user_id)
end
end
......@@ -29,14 +29,7 @@ class DropDuplicateProtectedTags < ActiveRecord::Migration[4.2]
.where(project_id: projects)
.where.not(id: ids)
if Gitlab::Database.postgresql?
tags.delete_all
else
# Workaround needed for MySQL
sql = "SELECT id FROM (#{tags.to_sql}) protected_tags"
ProtectedTag.where("id IN (#{sql})").delete_all # rubocop:disable GitlabSecurity/SqlInjection
end
tags.delete_all
end
end
......
......@@ -8,11 +8,10 @@ class AddIndexToProjectDeployTokensDeployTokenId < ActiveRecord::Migration[4.2]
disable_ddl_transaction!
def up
# MySQL already has index inserted
add_concurrent_index :project_deploy_tokens, :deploy_token_id if Gitlab::Database.postgresql?
add_concurrent_index :project_deploy_tokens, :deploy_token_id
end
def down
remove_concurrent_index(:project_deploy_tokens, :deploy_token_id) if Gitlab::Database.postgresql?
remove_concurrent_index(:project_deploy_tokens, :deploy_token_id)
end
end
......@@ -50,17 +50,9 @@ class RemoveRedundantPipelineStages < ActiveRecord::Migration[4.2]
UPDATE ci_builds SET stage_id = NULL WHERE stage_id IN (#{redundant_stages_ids})
SQL
if Gitlab::Database.postgresql?
execute <<~SQL
DELETE FROM ci_stages WHERE id IN (#{redundant_stages_ids})
SQL
else # We can't modify a table we are selecting from on MySQL
execute <<~SQL
DELETE a FROM ci_stages AS a, ci_stages AS b
WHERE a.pipeline_id = b.pipeline_id AND a.name = b.name
AND a.id <> b.id
SQL
end
execute <<~SQL
DELETE FROM ci_stages WHERE id IN (#{redundant_stages_ids})
SQL
end
end
end
......@@ -12,11 +12,7 @@ class BuildUserInteractedProjectsTable < ActiveRecord::Migration[4.2]
disable_ddl_transaction!
def up
if Gitlab::Database.postgresql?
PostgresStrategy.new
else
MysqlStrategy.new
end.up
PostgresStrategy.new.up
if index_exists_by_name?(:user_interacted_projects, CreateUserInteractedProjectsTable::INDEX_NAME)
remove_concurrent_index_by_name :user_interacted_projects, CreateUserInteractedProjectsTable::INDEX_NAME
......@@ -140,30 +136,4 @@ class BuildUserInteractedProjectsTable < ActiveRecord::Migration[4.2]
remove_concurrent_index(*args) if index_exists?(*args)
end
end
class MysqlStrategy < ActiveRecord::Migration[4.2]
include Gitlab::Database::MigrationHelpers
def up
execute <<~SQL
INSERT INTO user_interacted_projects (user_id, project_id)
SELECT e.user_id, e.project_id
FROM (SELECT DISTINCT author_id AS user_id, project_id FROM events WHERE project_id IS NOT NULL) AS e
LEFT JOIN user_interacted_projects ucp USING (user_id, project_id)
WHERE ucp.user_id IS NULL
SQL
unless index_exists?(:user_interacted_projects, [:project_id, :user_id])
add_concurrent_index :user_interacted_projects, [:project_id, :user_id], unique: true, name: UNIQUE_INDEX_NAME
end
unless foreign_key_exists?(:user_interacted_projects, :users, column: :user_id)
add_concurrent_foreign_key :user_interacted_projects, :users, column: :user_id, on_delete: :cascade
end
unless foreign_key_exists?(:user_interacted_projects, :projects, column: :project_id)
add_concurrent_foreign_key :user_interacted_projects, :projects, column: :project_id, on_delete: :cascade
end
end
end
end
......@@ -16,37 +16,21 @@ retry gem install knapsack --no-document
cp config/gitlab.yml.example config/gitlab.yml
sed -i 's/bin_path: \/usr\/bin\/git/bin_path: \/usr\/local\/bin\/git/' config/gitlab.yml
# Determine the database by looking at the job name.
# This would make the default database postgresql.
if [[ "${CI_JOB_NAME#*mysql}" != "$CI_JOB_NAME" ]]; then
export GITLAB_DATABASE='mysql'
else
export GITLAB_DATABASE='postgresql'
fi
cp config/database.yml.$GITLAB_DATABASE config/database.yml
cp config/database.yml.postgresql config/database.yml
if [ -f config/database_geo.yml.$GITLAB_DATABASE ]; then
cp config/database_geo.yml.$GITLAB_DATABASE config/database_geo.yml
if [ -f config/database_geo.yml.postgresql ]; then
cp config/database_geo.yml.postgresql config/database_geo.yml
fi
# Set user to a non-superuser to ensure we test permissions
sed -i 's/username: root/username: gitlab/g' config/database.yml
if [ "$GITLAB_DATABASE" = 'postgresql' ]; then
sed -i 's/localhost/postgres/g' config/database.yml
sed -i 's/username: git/username: postgres/g' config/database.yml
if [ -f config/database_geo.yml ]; then
sed -i 's/localhost/postgres/g' config/database_geo.yml
sed -i 's/username: git/username: postgres/g' config/database_geo.yml
fi
else # Assume it's mysql
sed -i 's/localhost/mysql/g' config/database.yml
sed -i 's/localhost/postgres/g' config/database.yml
sed -i 's/username: git/username: postgres/g' config/database.yml
if [ -f config/database_geo.yml ]; then
sed -i 's/localhost/mysql/g' config/database_geo.yml
fi
if [ -f config/database_geo.yml ]; then
sed -i 's/localhost/postgres/g' config/database_geo.yml
sed -i 's/username: git/username: postgres/g' config/database_geo.yml
fi
cp config/resque.yml.example config/resque.yml
......@@ -63,6 +47,6 @@ sed -i 's|url:.*$|url: redis://redis:6379/12|g' config/redis.shared_state.yml
if [ "$SETUP_DB" != "false" ]; then
setup_db
elif getent hosts postgres || getent hosts mysql; then
elif getent hosts postgres; then
setup_db_user_only
fi
......@@ -14,11 +14,7 @@ function retry() {
}
function setup_db_user_only() {
if [ "$GITLAB_DATABASE" = "postgresql" ]; then
source scripts/create_postgres_user.sh
else
source scripts/create_mysql_user.sh
fi
source scripts/create_postgres_user.sh
}
function setup_db() {
......@@ -26,10 +22,6 @@ function setup_db() {
bundle exec rake db:drop db:create db:schema:load db:migrate
if [ "$GITLAB_DATABASE" = "mysql" ]; then
bundle exec rake add_limits_mysql
fi
bundle exec rake gitlab:db:setup_ee
}
......
......@@ -18,7 +18,6 @@ rspec_profiling_is_configured =
ENV['RSPEC_PROFILING_POSTGRES_URL'].present? ||
ENV['RSPEC_PROFILING']
branch_can_be_profiled =
ENV['GITLAB_DATABASE'] == 'postgresql' &&
(ENV['CI_COMMIT_REF_NAME'] == 'master' ||
ENV['CI_COMMIT_REF_NAME'] =~ /rspec-profile/)
......
# frozen_string_literal: true
require 'database_cleaner/active_record/deletion'
require_relative 'db_cleaner'
module FakeInformationSchema
# Work around a bug in DatabaseCleaner when using the deletion strategy:
# https://github.com/DatabaseCleaner/database_cleaner/issues/347
#
# On MySQL, if the information schema is said to exist, we use an inaccurate
# row count leading to some tables not being cleaned when they should
def information_schema_exists?(_connection)
false
end
end
DatabaseCleaner::ActiveRecord::Deletion.prepend(FakeInformationSchema)
RSpec.configure do |config|
include DbCleaner
......
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