Welcome to mirror list, hosted at ThFree Co, Russian Federation.

context.rb « schema_migrations « database « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 35105121bbd9d2b647fdb3d9391acf16b5b5e70a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

module Gitlab
  module Database
    module SchemaMigrations
      class Context
        attr_reader :connection

        DEFAULT_SCHEMA_MIGRATIONS_PATH = "db/schema_migrations"

        def initialize(connection)
          @connection = connection
        end

        def schema_directory
          @schema_directory ||= Rails.root.join(database_schema_migrations_path).to_s
        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

        def database_schema_migrations_path
          @connection.pool.db_config.configuration_hash[:schema_migrations_path] || DEFAULT_SCHEMA_MIGRATIONS_PATH
        end
      end
    end
  end
end