summaryrefslogtreecommitdiff
path: root/config/initializers
diff options
context:
space:
mode:
Diffstat (limited to 'config/initializers')
-rw-r--r--config/initializers/0_post_deployment_migrations.rb12
-rw-r--r--config/initializers/3_extra_migrations.rb29
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