From 4aa76dddecc048cef24963323afe59f1c120cb72 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Thu, 13 Jun 2019 14:12:28 +0100 Subject: Remove dead MySQL code None of this code can be reached any more, so it can all be removed --- config/application.rb | 5 -- config/database.yml.mysql | 60 ------------- config/initializers/active_record_data_types.rb | 100 +++++++-------------- .../initializers/active_record_mysql_timestamp.rb | 30 ------- config/initializers/ar_mysql_jsonb_support.rb | 31 ------- config/initializers/ar_native_database_types.rb | 12 --- config/initializers/connection_fix.rb | 32 ------- .../mysql_ignore_postgresql_options.rb | 42 --------- .../mysql_set_length_for_binary_indexes.rb | 30 ------- config/initializers/peek.rb | 6 +- 10 files changed, 32 insertions(+), 316 deletions(-) delete mode 100644 config/database.yml.mysql delete mode 100644 config/initializers/active_record_mysql_timestamp.rb delete mode 100644 config/initializers/ar_mysql_jsonb_support.rb delete mode 100644 config/initializers/ar_native_database_types.rb delete mode 100644 config/initializers/connection_fix.rb delete mode 100644 config/initializers/mysql_ignore_postgresql_options.rb delete mode 100644 config/initializers/mysql_set_length_for_binary_indexes.rb (limited to 'config') diff --git a/config/application.rb b/config/application.rb index df5079ba993..92240426b5a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -22,11 +22,6 @@ module Gitlab require_dependency Rails.root.join('lib/gitlab/middleware/read_only') require_dependency Rails.root.join('lib/gitlab/middleware/basic_health_check') - # This needs to be loaded before DB connection is made - # to make sure that all connections have NO_ZERO_DATE - # setting disabled - require_dependency Rails.root.join('lib/mysql_zero_date') - # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. diff --git a/config/database.yml.mysql b/config/database.yml.mysql deleted file mode 100644 index 98c2abe9f5e..00000000000 --- a/config/database.yml.mysql +++ /dev/null @@ -1,60 +0,0 @@ -# -# PRODUCTION -# -production: - adapter: mysql2 - encoding: utf8 - collation: utf8_general_ci - reconnect: false - database: gitlabhq_production - pool: 10 - username: git - password: "secure password" - host: localhost - # socket: /tmp/mysql.sock - -# -# Development specific -# -development: - adapter: mysql2 - encoding: utf8 - collation: utf8_general_ci - reconnect: false - database: gitlabhq_development - pool: 5 - username: root - password: "secure password" - host: localhost - # socket: /tmp/mysql.sock - -# -# Staging specific -# -staging: - adapter: mysql2 - encoding: utf8 - collation: utf8_general_ci - reconnect: false - database: gitlabhq_staging - pool: 10 - username: git - password: "secure password" - host: localhost - # socket: /tmp/mysql.sock - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: &test - adapter: mysql2 - encoding: utf8mb4 - collation: utf8mb4_general_ci - reconnect: false - database: gitlabhq_test - pool: 5 - username: root - password: - host: localhost - # socket: /tmp/mysql.sock - prepared_statements: false diff --git a/config/initializers/active_record_data_types.rb b/config/initializers/active_record_data_types.rb index 151bce4d130..846f28e6f66 100644 --- a/config/initializers/active_record_data_types.rb +++ b/config/initializers/active_record_data_types.rb @@ -1,83 +1,45 @@ # ActiveRecord custom data type for storing datetimes with timezone information. # See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11229 -if Gitlab::Database.postgresql? - require 'active_record/connection_adapters/postgresql_adapter' +require 'active_record/connection_adapters/postgresql_adapter' - module ActiveRecord::ConnectionAdapters::PostgreSQL::OID - # Add the class `DateTimeWithTimeZone` so we can map `timestamptz` to it. - class DateTimeWithTimeZone < DateTime - def type - :datetime_with_timezone - end +module ActiveRecord::ConnectionAdapters::PostgreSQL::OID + # Add the class `DateTimeWithTimeZone` so we can map `timestamptz` to it. + class DateTimeWithTimeZone < DateTime + def type + :datetime_with_timezone end end +end - module RegisterDateTimeWithTimeZone - # Run original `initialize_type_map` and then register `timestamptz` as a - # `DateTimeWithTimeZone`. - # - # Apparently it does not matter that the original `initialize_type_map` - # aliases `timestamptz` to `timestamp`. - # - # When schema dumping, `timestamptz` columns will be output as - # `t.datetime_with_timezone`. - def initialize_type_map(mapping = type_map) - super mapping - - mapping.register_type 'timestamptz' do |_, _, sql_type| - precision = extract_precision(sql_type) - ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::DateTimeWithTimeZone.new(precision: precision) - end - end - end - - class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter - prepend RegisterDateTimeWithTimeZone - - # Add column type `datetime_with_timezone` so we can do this in - # migrations: - # - # add_column(:users, :datetime_with_timezone) - # - NATIVE_DATABASE_TYPES[:datetime_with_timezone] = { name: 'timestamptz' } - end -elsif Gitlab::Database.mysql? - require 'active_record/connection_adapters/mysql2_adapter' - - module RegisterDateTimeWithTimeZone - # Run original `initialize_type_map` and then register `timestamp` as a - # `MysqlDateTimeWithTimeZone`. - # - # When schema dumping, `timestamp` columns will be output as - # `t.datetime_with_timezone`. - def initialize_type_map(mapping = type_map) - super mapping - - mapping.register_type(/timestamp/i) do |sql_type| - precision = extract_precision(sql_type) - ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::MysqlDateTimeWithTimeZone.new(precision: precision) - end +module RegisterDateTimeWithTimeZone + # Run original `initialize_type_map` and then register `timestamptz` as a + # `DateTimeWithTimeZone`. + # + # Apparently it does not matter that the original `initialize_type_map` + # aliases `timestamptz` to `timestamp`. + # + # When schema dumping, `timestamptz` columns will be output as + # `t.datetime_with_timezone`. + def initialize_type_map(mapping = type_map) + super mapping + + mapping.register_type 'timestamptz' do |_, _, sql_type| + precision = extract_precision(sql_type) + ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::DateTimeWithTimeZone.new(precision: precision) end end +end - class ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter - prepend RegisterDateTimeWithTimeZone - - # Add the class `DateTimeWithTimeZone` so we can map `timestamp` to it. - class MysqlDateTimeWithTimeZone < ActiveRecord::Type::DateTime - def type - :datetime_with_timezone - end - end +class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter + prepend RegisterDateTimeWithTimeZone - # Add column type `datetime_with_timezone` so we can do this in - # migrations: - # - # add_column(:users, :datetime_with_timezone) - # - NATIVE_DATABASE_TYPES[:datetime_with_timezone] = { name: 'timestamp' } - end + # Add column type `datetime_with_timezone` so we can do this in + # migrations: + # + # add_column(:users, :datetime_with_timezone) + # + NATIVE_DATABASE_TYPES[:datetime_with_timezone] = { name: 'timestamptz' } end # Ensure `datetime_with_timezone` columns are correctly written to schema.rb diff --git a/config/initializers/active_record_mysql_timestamp.rb b/config/initializers/active_record_mysql_timestamp.rb deleted file mode 100644 index af74c4ff6fb..00000000000 --- a/config/initializers/active_record_mysql_timestamp.rb +++ /dev/null @@ -1,30 +0,0 @@ -# Make sure that MySQL won't try to use CURRENT_TIMESTAMP when the timestamp -# column is NOT NULL. See https://gitlab.com/gitlab-org/gitlab-ce/issues/36405 -# And also: https://bugs.mysql.com/bug.php?id=75098 -# This patch was based on: -# https://github.com/rails/rails/blob/15ef55efb591e5379486ccf53dd3e13f416564f6/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb#L34-L36 - -if Gitlab::Database.mysql? - require 'active_record/connection_adapters/abstract/schema_creation' - - module MySQLTimestampFix - def add_column_options!(sql, options) - # By default, TIMESTAMP columns are NOT NULL, cannot contain NULL values, - # and assigning NULL assigns the current timestamp. To permit a TIMESTAMP - # column to contain NULL, explicitly declare it with the NULL attribute. - # See http://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html - if sql.end_with?('timestamp') && !options[:primary_key] - if options[:null] != false - sql << ' NULL' - elsif options[:column].default.nil? - sql << ' DEFAULT 0' - end - end - - super - end - end - - ActiveRecord::ConnectionAdapters::AbstractAdapter::SchemaCreation - .prepend(MySQLTimestampFix) -end diff --git a/config/initializers/ar_mysql_jsonb_support.rb b/config/initializers/ar_mysql_jsonb_support.rb deleted file mode 100644 index 63a0b05119a..00000000000 --- a/config/initializers/ar_mysql_jsonb_support.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -require 'active_record/connection_adapters/abstract_mysql_adapter' -require 'active_record/connection_adapters/mysql/schema_definitions' - -# MySQL (5.6) and MariaDB (10.1) are currently supported versions within GitLab, -# Since they do not support native `json` datatype we force to emulate it as `text` - -if Gitlab::Database.mysql? - module ActiveRecord - module ConnectionAdapters - class AbstractMysqlAdapter - JSON_DATASIZE = 1.megabyte - - NATIVE_DATABASE_TYPES.merge!( - json: { name: "text", limit: JSON_DATASIZE }, - jsonb: { name: "text", limit: JSON_DATASIZE } - ) - end - - module MySQL - module ColumnMethods - # We add `jsonb` helper, as `json` is already defined for `MySQL` since Rails 5 - def jsonb(*args, **options) - args.each { |name| column(name, :json, options) } - end - end - end - end - end -end diff --git a/config/initializers/ar_native_database_types.rb b/config/initializers/ar_native_database_types.rb deleted file mode 100644 index 6d397661f75..00000000000 --- a/config/initializers/ar_native_database_types.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'active_record/connection_adapters/abstract_mysql_adapter' - -module ActiveRecord - module ConnectionAdapters - class AbstractMysqlAdapter - NATIVE_DATABASE_TYPES.merge!( - bigserial: { name: 'bigint(20) auto_increment PRIMARY KEY' }, - serial: { name: 'int auto_increment PRIMARY KEY' } - ) - end - end -end diff --git a/config/initializers/connection_fix.rb b/config/initializers/connection_fix.rb deleted file mode 100644 index d0b1444f607..00000000000 --- a/config/initializers/connection_fix.rb +++ /dev/null @@ -1,32 +0,0 @@ -# from http://gist.github.com/238999 -# -# If your workers are inactive for a long period of time, they'll lose -# their MySQL connection. -# -# This hack ensures we re-connect whenever a connection is -# lost. Because, really. why not? -# -# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar) -# -# From: -# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/ - -if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) - module ActiveRecord::ConnectionAdapters - class Mysql2Adapter - alias_method :execute_without_retry, :execute - - def execute(*args) - execute_without_retry(*args) - rescue ActiveRecord::StatementInvalid => e - if e.message =~ /server has gone away/i - warn "Lost connection to MySQL server during query" - reconnect! - retry - else - raise e - end - end - end - end -end diff --git a/config/initializers/mysql_ignore_postgresql_options.rb b/config/initializers/mysql_ignore_postgresql_options.rb deleted file mode 100644 index e6a7d9bef52..00000000000 --- a/config/initializers/mysql_ignore_postgresql_options.rb +++ /dev/null @@ -1,42 +0,0 @@ -# This patches ActiveRecord so indexes created using the MySQL adapter ignore -# any PostgreSQL specific options (e.g. `using: :gin`). -# -# These patches do the following for MySQL: -# -# 1. Indexes created using the :opclasses option are ignored (as they serve no -# purpose on MySQL). -# 2. When creating an index with `using: :gin` the `using` option is discarded -# as :gin is not a valid value for MySQL. -# 3. The `:opclasses` option is stripped from add_index_options in case it's -# used anywhere other than in the add_index methods. - -if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) - module ActiveRecord - module ConnectionAdapters - class Mysql2Adapter < AbstractMysqlAdapter - alias_method :__gitlab_add_index, :add_index - alias_method :__gitlab_add_index_options, :add_index_options - - def add_index(table_name, column_name, options = {}) - unless options[:opclasses] - __gitlab_add_index(table_name, column_name, options) - end - end - - def add_index_options(table_name, column_name, options = {}) - if options[:using] && options[:using] == :gin - options = options.dup - options.delete(:using) - end - - if options[:opclasses] - options = options.dup - options.delete(:opclasses) - end - - __gitlab_add_index_options(table_name, column_name, options) - end - end - end - end -end diff --git a/config/initializers/mysql_set_length_for_binary_indexes.rb b/config/initializers/mysql_set_length_for_binary_indexes.rb deleted file mode 100644 index 552f3a20a95..00000000000 --- a/config/initializers/mysql_set_length_for_binary_indexes.rb +++ /dev/null @@ -1,30 +0,0 @@ -# This patches ActiveRecord so indexes for binary columns created using the -# MySQL adapter apply a length of 20. Otherwise MySQL can't create an index on -# binary columns. - -module MysqlSetLengthForBinaryIndexAndIgnorePostgresOptionsForSchema - # This method is used in Rails 5 schema loading as t.index - def index(column_names, options = {}) - # Ignore indexes that use opclasses, - # also see config/initializers/mysql_ignore_postgresql_options.rb - if options[:opclasses] - warn "WARNING: index on columns #{column_names} uses unsupported option, skipping." - return - end - - options[:length] ||= {} - Array(column_names).each do |column_name| - column = columns.find { |c| c.name == column_name } - - if column&.type == :binary - options[:length][column_name] = 20 - end - end - - super(column_names, options) - end -end - -if defined?(ActiveRecord::ConnectionAdapters::MySQL::TableDefinition) - ActiveRecord::ConnectionAdapters::MySQL::TableDefinition.send(:prepend, MysqlSetLengthForBinaryIndexAndIgnorePostgresOptionsForSchema) -end diff --git a/config/initializers/peek.rb b/config/initializers/peek.rb index 2aec32e878c..1ffd133239d 100644 --- a/config/initializers/peek.rb +++ b/config/initializers/peek.rb @@ -2,11 +2,7 @@ Rails.application.config.peek.adapter = :redis, { client: ::Redis.new(Gitlab::Re Peek.into Peek::Views::Host -if Gitlab::Database.mysql? - require 'peek-mysql2' - PEEK_DB_CLIENT = ::Mysql2::Client - PEEK_DB_VIEW = Peek::Views::Mysql2 -elsif Gitlab::Database.postgresql? +if Gitlab::Database.postgresql? require 'peek-pg' PEEK_DB_CLIENT = ::PG::Connection PEEK_DB_VIEW = Peek::Views::PG -- cgit v1.2.1