diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-03-16 16:01:14 -0600 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-03-16 16:01:14 -0600 |
commit | 8825c2fc89506443c4416178e2040c26c3a299f6 (patch) | |
tree | e55dc2cf66a71719d3724cca2681ec5c8215e5c2 /config/initializers | |
parent | 92da8e98e8845852c01dfc005aa948604820991d (diff) | |
download | gitlab-ce-release-migrations.tar.gz |
POC for zero downtime migrations without having to manually manage what migration goes into what releaserelease-migrations
Diffstat (limited to 'config/initializers')
-rw-r--r-- | config/initializers/0_post_deployment_migrations.rb | 12 | ||||
-rw-r--r-- | config/initializers/3_extra_migrations.rb | 29 |
2 files changed, 29 insertions, 12 deletions
diff --git a/config/initializers/0_post_deployment_migrations.rb b/config/initializers/0_post_deployment_migrations.rb deleted file mode 100644 index 0068a03d214..00000000000 --- a/config/initializers/0_post_deployment_migrations.rb +++ /dev/null @@ -1,12 +0,0 @@ -# Post deployment migrations are included by default. This file must be loaded -# before other initializers as Rails may otherwise memoize a list of migrations -# excluding the post deployment migrations. -unless ENV['SKIP_POST_DEPLOYMENT_MIGRATIONS'] - path = Rails.root.join('db', 'post_migrate').to_s - - Rails.application.config.paths['db/migrate'] << path - - # Rails memoizes migrations at certain points where it won't read the above - # path just yet. As such we must also update the following list of paths. - ActiveRecord::Migrator.migrations_paths << path -end diff --git a/config/initializers/3_extra_migrations.rb b/config/initializers/3_extra_migrations.rb new file mode 100644 index 00000000000..e2d55349425 --- /dev/null +++ b/config/initializers/3_extra_migrations.rb @@ -0,0 +1,29 @@ +current_version = Gitlab::VersionInfo.parse(Gitlab::VERSION) + +past_version_paths = Dir.glob(Rails.root.join('db', 'release_migrations', '*').to_s).select do |path| + version_string = path.match(%r{db/release_migrations/((\d+)\.(\d+)\.(\d+))})[1] + version = Gitlab::VersionInfo.parse(version_string) + version <= current_version +end + +migrate_paths = past_version_paths.map { |path| File.join(path, 'migrate') } + +Rails.application.config.paths['db/migrate'].concat(migrate_paths) + +# Rails memoizes migrations at certain points where it won't read the above +# path just yet. As such we must also update the following list of paths. +ActiveRecord::Migrator.migrations_paths.concat(migrate_paths) + +# Post deployment migrations are included by default. This file must be loaded +# before other initializers as Rails may otherwise memoize a list of migrations +# excluding the post deployment migrations. +unless ENV['SKIP_POST_DEPLOYMENT_MIGRATIONS'] + post_migrate_paths = past_version_paths.map { |path| File.join(path, 'post_migrate') } + post_migrate_paths << Rails.root.join('db', 'post_migrate').to_s + + Rails.application.config.paths['db/migrate'].concat(post_migrate_paths) + + # Rails memoizes migrations at certain points where it won't read the above + # path just yet. As such we must also update the following list of paths. + ActiveRecord::Migrator.migrations_paths.concat(post_migrate_paths) +end |