Commit 381b7065 authored by Rémy Coutable's avatar Rémy Coutable

Move EE-specific migrations under ee/db/

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent d3061333
...@@ -13,11 +13,24 @@ AllCops: ...@@ -13,11 +13,24 @@ AllCops:
- 'db/*' - 'db/*'
- 'db/fixtures/**/*' - 'db/fixtures/**/*'
- 'db/geo/*' - 'db/geo/*'
- 'ee/db/geo/*'
- 'tmp/**/*' - 'tmp/**/*'
- 'bin/**/*' - 'bin/**/*'
- 'generator_templates/**/*' - 'generator_templates/**/*'
- 'builds/**/*' - 'builds/**/*'
# This cop checks whether some constant value isn't a
# mutable literal (e.g. array or hash).
Style/MutableConstant:
Enabled: true
Exclude:
- 'db/migrate/**/*'
- 'db/post_migrate/**/*'
- 'db/geo/migrate/**/*'
- 'ee/db/migrate/**/*'
- 'ee/db/post_migrate/**/*'
- 'ee/db/geo/migrate/**/*'
# Gitlab ################################################################### # Gitlab ###################################################################
Gitlab/ModuleWithInstanceVariables: Gitlab/ModuleWithInstanceVariables:
......
...@@ -12,3 +12,12 @@ unless ENV['SKIP_POST_DEPLOYMENT_MIGRATIONS'] ...@@ -12,3 +12,12 @@ unless ENV['SKIP_POST_DEPLOYMENT_MIGRATIONS']
ActiveRecord::Migrator.migrations_paths << path ActiveRecord::Migrator.migrations_paths << path
end end
end end
migrate_paths = Rails.application.config.paths['db/migrate'].to_a
migrate_paths.each do |migrate_path|
absolute_migrate_path = Pathname.new(migrate_path).realpath(Rails.root)
ee_migrate_path = Rails.root.join('ee/', absolute_migrate_path.relative_path_from(Rails.root))
Rails.application.config.paths['db/migrate'] << ee_migrate_path.to_s
ActiveRecord::Migrator.migrations_paths << ee_migrate_path.to_s
end
...@@ -167,7 +167,7 @@ otherwise it may fail with an encryption error. ...@@ -167,7 +167,7 @@ otherwise it may fail with an encryption error.
Secondary Geo nodes track data about what has been downloaded in a second Secondary Geo nodes track data about what has been downloaded in a second
PostgreSQL database that is distinct from the production GitLab database. PostgreSQL database that is distinct from the production GitLab database.
The database configuration is set in `config/database_geo.yml`. The database configuration is set in `config/database_geo.yml`.
`db/geo` contains the schema and migrations for this database. `ee/db/geo` contains the schema and migrations for this database.
To write a migration for the database, use the `GeoMigrationGenerator`: To write a migration for the database, use the `GeoMigrationGenerator`:
......
...@@ -12,6 +12,6 @@ class GeoMigrationGenerator < ActiveRecord::Generators::MigrationGenerator ...@@ -12,6 +12,6 @@ class GeoMigrationGenerator < ActiveRecord::Generators::MigrationGenerator
def create_migration_file def create_migration_file
set_local_assigns! set_local_assigns!
validate_file_name! validate_file_name!
migration_template @migration_template, "db/geo/migrate/#{file_name}.rb" migration_template @migration_template, "ee/db/geo/migrate/#{file_name}.rb"
end end
end end
...@@ -5,7 +5,7 @@ module Gitlab ...@@ -5,7 +5,7 @@ module Gitlab
DATABASE_CONFIG = 'config/database.yml'.freeze DATABASE_CONFIG = 'config/database.yml'.freeze
GEO_DATABASE_CONFIG = 'config/database_geo.yml'.freeze GEO_DATABASE_CONFIG = 'config/database_geo.yml'.freeze
GEO_DB_DIR = 'db/geo'.freeze GEO_DB_DIR = 'ee/db/geo'.freeze
def method_missing(method_name, *args, &block) def method_missing(method_name, *args, &block)
with_geo_db do with_geo_db do
......
...@@ -41,14 +41,14 @@ namespace :geo do ...@@ -41,14 +41,14 @@ namespace :geo do
puts "Current version: #{Gitlab::Geo::DatabaseTasks.version}" puts "Current version: #{Gitlab::Geo::DatabaseTasks.version}"
end end
desc 'Drops and recreates the database from db/geo/schema.rb for the current environment and loads the seeds.' desc 'Drops and recreates the database from ee/db/geo/schema.rb for the current environment and loads the seeds.'
task reset: [:environment] do task reset: [:environment] do
ns['drop'].invoke ns['drop'].invoke
ns['create'].invoke ns['create'].invoke
ns['setup'].invoke ns['setup'].invoke
end end
desc 'Load the seed data from db/geo/seeds.rb' desc 'Load the seed data from ee/db/geo/seeds.rb'
task seed: [:environment] do task seed: [:environment] do
ns['abort_if_pending_migrations'].invoke ns['abort_if_pending_migrations'].invoke
...@@ -97,7 +97,7 @@ namespace :geo do ...@@ -97,7 +97,7 @@ namespace :geo do
Gitlab::Geo::DatabaseTasks.load_schema_current(:ruby, ENV['SCHEMA']) Gitlab::Geo::DatabaseTasks.load_schema_current(:ruby, ENV['SCHEMA'])
end end
desc 'Create a db/geo/schema.rb file that is portable against any DB supported by AR' desc 'Create a ee/db/geo/schema.rb file that is portable against any DB supported by AR'
task dump: [:environment] do task dump: [:environment] do
Gitlab::Geo::DatabaseTasks::Schema.dump Gitlab::Geo::DatabaseTasks::Schema.dump
......
require 'spec_helper' require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20171103152048_geo_drain_redis_queues') require Rails.root.join('ee', 'db', 'post_migrate', '20171103152048_geo_drain_redis_queues')
describe GeoDrainRedisQueues, :clean_gitlab_redis_shared_state do describe GeoDrainRedisQueues, :clean_gitlab_redis_shared_state do
subject(:migration) { described_class.new } subject(:migration) { described_class.new }
......
require "spec_helper" require 'spec_helper'
require Rails.root.join("db", "post_migrate", "20170811082658_remove_system_hook_from_geo_nodes.rb") require Rails.root.join('ee', 'db', 'post_migrate', '20170811082658_remove_system_hook_from_geo_nodes.rb')
describe RemoveSystemHookFromGeoNodes, :migration do describe RemoveSystemHookFromGeoNodes, :migration do
let(:geo_nodes) { table(:geo_nodes) } let(:geo_nodes) { table(:geo_nodes) }
......
require 'spec_helper' require 'spec_helper'
require Rails.root.join('db', 'migrate', '20170626202753_update_authorized_keys_file.rb') require Rails.root.join('ee', 'db', 'migrate', '20170626202753_update_authorized_keys_file.rb')
describe UpdateAuthorizedKeysFile, :migration do describe UpdateAuthorizedKeysFile, :migration do
let(:migration) { described_class.new } let(:migration) { described_class.new }
......
...@@ -5,7 +5,11 @@ require 'spec_helper' ...@@ -5,7 +5,11 @@ require 'spec_helper'
describe ActiveRecord::Schema do describe ActiveRecord::Schema do
let(:latest_migration_timestamp) do let(:latest_migration_timestamp) do
migrations = Dir[Rails.root.join('db', 'migrate', '*'), Rails.root.join('db', 'post_migrate', '*')] migrations_paths =
%w[db ee/db].product(%w[migrate post_migrate]).each_with_object([]) do |migration_dir, memo|
memo << Rails.root.join(*migration_dir, '*')
end
migrations = Dir[*migrations_paths]
migrations.map { |migration| File.basename(migration).split('_').first.to_i }.max migrations.map { |migration| File.basename(migration).split('_').first.to_i }.max
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