From 2fdb48d1ab884915d7f825ae7ed93431198fea45 Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Fri, 2 Mar 2018 16:32:52 -0500 Subject: [PATCH] Merge pull request #17072 from bdunne/schema_migration Move SchemaMigration from ManageIQ to ManageIQ::Schema plugin (cherry picked from commit 02f5f6bc456708e3ddd24f52ac34a00e7b829da0) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1553397 --- app/models/schema_migration.rb | 49 ---------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 app/models/schema_migration.rb diff --git a/app/models/schema_migration.rb b/app/models/schema_migration.rb deleted file mode 100644 index e3acf98c2da..00000000000 --- a/app/models/schema_migration.rb +++ /dev/null @@ -1,49 +0,0 @@ -class SchemaMigration < ApplicationRecord - def self.up_to_date? - begin - migrations = missing_db_migrations - files = missing_file_migrations - db_ver = schema_version - rescue => err - return [false, err] - end - - return [false, "database schema is not up to date. Schema version is [#{db_ver}]. Missing migrations: [#{migrations.join(", ")}]", - "database should be migrated to the latest version"] unless migrations.empty? - return [false, "database schema is from a newer version of the product and may be incompatible. Schema version is [#{db_ver}]. Missing files: [#{files.join(", ")}]", - "appliance should be updated to match database version"] unless files.empty? - - [true, "database schema version #{db_ver} is up to date"] - end - - def self.db_migration_list - @db_migration_list ||= SchemaMigration.all.collect { |s| s.version.to_i }.sort - end - - def self.file_migration_list - @file_migration_list ||= Dir.glob(Rails.root.join("db", "migrate", "*.rb")).collect do |f| - File.basename(f).split("_")[0].to_i - end.sort - end - - def self.missing_db_migrations - file_migration_list - db_migration_list - end - - def self.missing_file_migrations - # Ignore migrations prior to the collapsed initial migration - db_migration_list.reject { |m| m < initial_migration } - file_migration_list - end - - def self.schema_version - db_migration_list.last - end - - def self.initial_migration - file_migration_list.first - end - - def self.latest_migration - file_migration_list.last - end -end