2021-07-06 20:07:23 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Database
|
|
|
|
module SchemaMigrations
|
|
|
|
class Context
|
|
|
|
attr_reader :connection
|
|
|
|
|
2021-09-15 20:11:46 -04:00
|
|
|
class_attribute :default_schema_migrations_path, default: 'db/schema_migrations'
|
2021-08-05 11:09:46 -04:00
|
|
|
|
2021-07-06 20:07:23 -04:00
|
|
|
def initialize(connection)
|
|
|
|
@connection = connection
|
|
|
|
end
|
|
|
|
|
|
|
|
def schema_directory
|
2021-08-05 11:09:46 -04:00
|
|
|
@schema_directory ||= Rails.root.join(database_schema_migrations_path).to_s
|
2021-07-06 20:07:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def versions_to_create
|
|
|
|
versions_from_database = @connection.schema_migration.all_versions
|
|
|
|
versions_from_migration_files = @connection.migration_context.migrations.map { |m| m.version.to_s }
|
|
|
|
|
|
|
|
versions_from_database & versions_from_migration_files
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def database_name
|
|
|
|
@database_name ||= @connection.pool.db_config.name
|
|
|
|
end
|
|
|
|
|
2021-08-05 11:09:46 -04:00
|
|
|
def database_schema_migrations_path
|
2021-09-15 20:11:46 -04:00
|
|
|
@connection.pool.db_config.configuration_hash[:schema_migrations_path] || self.class.default_schema_migrations_path
|
2021-07-06 20:07:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|