A platform for community discussion. Free, open, simple.
DEV: Check if IntermediateDB schema is valid (#32975)
Gerhard Schlager58a01d1e03ac
diff --git a/migrations/lib/cli/schema_sub_command.rb b/migrations/lib/cli/schema_sub_command.rbindex 78d422db7d8..09c74ec35e9 100644--- a/migrations/lib/cli/schema_sub_command.rb+++ b/migrations/lib/cli/schema_sub_command.rb@@ -22,6 +22,8 @@ module Migrations::CLIwrite_db_schema(config, header, schema)write_db_models(config, header, schema)+ validate_schema(db)+puts "Done"end@@ -83,6 +85,19 @@ module Migrations::CLIYAML.load_file(config_path, symbolize_names: true)end+ def validate_schema(type)+ Tempfile.create do |tempfile|+ begin+ ::Migrations::Database.migrate(+ tempfile,+ migrations_path: ::Migrations::Database.schema_path(type),+ )+ rescue Extralite::SQLError => e+ print_error("Invalid schema: #{e.message}")+ end+ end+ end+def print_error(message)$stderr.puts "ERROR: ".red + messageenddiff --git a/migrations/lib/database.rb b/migrations/lib/database.rbindex 2b5946e34f6..ddde43dd47e 100644--- a/migrations/lib/database.rb+++ b/migrations/lib/database.rb@@ -31,6 +31,19 @@ module Migrationsnilend+ def self.schema_path(type)+ case type+ when "intermediate_db"+ INTERMEDIATE_DB_SCHEMA_PATH+ when "mappings_db"+ MAPPINGS_DB_SCHEMA_PATH+ when "uploads_db"+ UPLOADS_DB_SCHEMA_PATH+ else+ raise "Unknown type: #{type}"+ end+ end+def self.format_datetime(value)value&.utc&.iso8601end