Commit ea31f75a authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'make-ci-structure-common' into 'master'

Make `ci_structure.sql` to be equal

See merge request gitlab-org/gitlab!67433
parents f74b0c27 7cd9058f
......@@ -37,6 +37,7 @@ AllCops:
- 'file_hooks/**/*'
- 'workhorse/**/*'
- 'spec/support/*.git/**/*' # e.g. spec/support/gitlab-git-test.git
- 'db/ci_migrate/*.rb' # since the `db/ci_migrate` is a symlinked to `db/migrate`
CacheRootDirectory: tmp
MaxFilesInCache: 25000
......
# frozen_string_literal: true
ci_db_config = Gitlab::Application.config.database_configuration[Rails.env]["ci"]
if ci_db_config.present?
raise "migrations_paths setting for ci database must be `db/ci_migrate`" unless ci_db_config["migrations_paths"] == 'db/ci_migrate'
end
migrate
\ No newline at end of file
# frozen_string_literal: true
class CreateCiInstanceVariablesOnCi < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
def up
unless table_exists?(:ci_instance_variables)
create_table :ci_instance_variables do |t|
t.integer :variable_type, null: false, limit: 2, default: 1
t.boolean :masked, default: false, allow_null: false
t.boolean :protected, default: false, allow_null: false
t.text :key, null: false
t.text :encrypted_value
t.text :encrypted_value_iv
t.index [:key], name: 'index_ci_instance_variables_on_key', unique: true, using: :btree
end
end
add_text_limit(:ci_instance_variables, :key, 255)
# Use constraint_name generated from db/migrate/20200625193358_increase_size_on_instance_level_variable_values.rb
add_text_limit(:ci_instance_variables, :encrypted_value, 13_579, constraint_name: 'check_956afd70f1')
add_text_limit(:ci_instance_variables, :encrypted_value_iv, 255)
end
def down
drop_table :ci_instance_variables
end
end
1b74312f59f6f8937cd0dd754d22dc72e9bdc7302e6254a2fda5762afebe303c
\ No newline at end of file
CREATE TABLE ar_internal_metadata (
key character varying NOT NULL,
value character varying,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);
CREATE TABLE ci_instance_variables (
id bigint NOT NULL,
variable_type smallint DEFAULT 1 NOT NULL,
masked boolean DEFAULT false,
protected boolean DEFAULT false,
key text NOT NULL,
encrypted_value text,
encrypted_value_iv text,
CONSTRAINT check_07a45a5bcb CHECK ((char_length(encrypted_value_iv) <= 255)),
CONSTRAINT check_5aede12208 CHECK ((char_length(key) <= 255)),
CONSTRAINT check_956afd70f1 CHECK ((char_length(encrypted_value) <= 13579))
);
CREATE SEQUENCE ci_instance_variables_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE ci_instance_variables_id_seq OWNED BY ci_instance_variables.id;
CREATE TABLE schema_migrations (
version character varying NOT NULL
);
ALTER TABLE ONLY ci_instance_variables ALTER COLUMN id SET DEFAULT nextval('ci_instance_variables_id_seq'::regclass);
ALTER TABLE ONLY ar_internal_metadata
ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key);
ALTER TABLE ONLY ci_instance_variables
ADD CONSTRAINT ci_instance_variables_pkey PRIMARY KEY (id);
ALTER TABLE ONLY schema_migrations
ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);
CREATE UNIQUE INDEX index_ci_instance_variables_on_key ON ci_instance_variables USING btree (key);
structure.sql
\ No newline at end of file
......@@ -61,7 +61,6 @@ development:
adapter: postgresql
encoding: unicode
database: gitlabhq_development_ci
migrations_paths: db/ci_migrate
host: /path/to/gdk/postgresql
pool: 10
prepared_statements: false
......@@ -82,7 +81,6 @@ test: &test
adapter: postgresql
encoding: unicode
database: gitlabhq_test_ci
migrations_paths: db/ci_migrate
host: /path/to/gdk/postgresql
pool: 10
prepared_statements: false
......
......@@ -6,17 +6,14 @@ module Gitlab
class Context
attr_reader :connection
DEFAULT_SCHEMA_MIGRATIONS_PATH = "db/schema_migrations"
def initialize(connection)
@connection = connection
end
def schema_directory
@schema_directory ||=
if ActiveRecord::Base.configurations.primary?(database_name)
File.join(db_dir, 'schema_migrations')
else
File.join(db_dir, "#{database_name}_schema_migrations")
end
@schema_directory ||= Rails.root.join(database_schema_migrations_path).to_s
end
def versions_to_create
......@@ -32,8 +29,8 @@ module Gitlab
@database_name ||= @connection.pool.db_config.name
end
def db_dir
@db_dir ||= Rails.application.config.paths["db"].first
def database_schema_migrations_path
@connection.pool.db_config.configuration_hash[:schema_migrations_path] || DEFAULT_SCHEMA_MIGRATIONS_PATH
end
end
end
......
......@@ -3,7 +3,8 @@
require 'spec_helper'
RSpec.describe Gitlab::Database::SchemaMigrations::Context do
let(:connection) { ActiveRecord::Base.connection }
let(:connection_class) { ActiveRecord::Base }
let(:connection) { connection_class.connection }
let(:context) { described_class.new(connection) }
......@@ -12,13 +13,65 @@ RSpec.describe Gitlab::Database::SchemaMigrations::Context do
expect(context.schema_directory).to eq(File.join(Rails.root, 'db/schema_migrations'))
end
context 'multiple databases' do
let(:connection) { Ci::CiDatabaseRecord.connection }
context 'CI database' do
let(:connection_class) { Ci::CiDatabaseRecord }
it 'returns a directory path that is database specific' do
skip_if_multiple_databases_not_setup
expect(context.schema_directory).to eq(File.join(Rails.root, 'db/ci_schema_migrations'))
expect(context.schema_directory).to eq(File.join(Rails.root, 'db/schema_migrations'))
end
end
context 'multiple databases' do
let(:connection_class) do
Class.new(::ApplicationRecord) do
self.abstract_class = true
def self.name
'Gitlab::Database::SchemaMigrations::Context::TestConnection'
end
end
end
let(:configuration_overrides) { {} }
before do
connection_class.establish_connection(
ActiveRecord::Base
.connection_pool
.db_config
.configuration_hash
.merge(configuration_overrides)
)
end
after do
connection_class.remove_connection
end
context 'when `schema_migrations_path` is configured as string' do
let(:configuration_overrides) do
{ "schema_migrations_path" => "db/ci_schema_migrations" }
end
it 'returns a configured directory path that' do
skip_if_multiple_databases_not_setup
expect(context.schema_directory).to eq(File.join(Rails.root, 'db/ci_schema_migrations'))
end
end
context 'when `schema_migrations_path` is configured as symbol' do
let(:configuration_overrides) do
{ schema_migrations_path: "db/ci_schema_migrations" }
end
it 'returns a configured directory path that' do
skip_if_multiple_databases_not_setup
expect(context.schema_directory).to eq(File.join(Rails.root, 'db/ci_schema_migrations'))
end
end
end
end
......
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