discourse/migrations/bin/cli
Gerhard Schlager 554977c7e6 MT: Refactor schema configuration from YAML to Ruby DSL
- Replace the YAML-based schema configuration with a Ruby DSL for defining intermediate database schemas
- Add table builders, conventions, enums, ignored tables, and output config as composable DSL files in `migrations/config/schema/`
- Implement schema resolver that combines DSL config with database introspection to produce resolved schemas
- Add generator that produces SQL schema, Ruby models, and enum files from the resolved schema
- Add scaffolder for bootstrapping new table configs and differ for comparing config against the database
- Add plugin manifest and introspection system to auto-detect plugin-owned columns
- Rewrite all schema CLI commands (`add`, `validate`, `diff`, `generate`, `list`, `ignore`, `refresh-plugins`) to use DSL infrastructure
- Add comprehensive specs and documentation (`migrations/docs/schema-configuration.md`)
- Remove old YAML config, JSON schema, and validation infrastructure
2026-03-19 18:10:26 +01:00

95 lines
2.9 KiB
Ruby
Executable file

#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative "../migrations"
require "colored2"
require "thor"
module Migrations
configure_zeitwerk
enable_i18n
apply_global_config
module CLI
class Application < Thor
remove_command :tree
desc "convert [FROM]", "Convert a file"
option :settings, type: :string, desc: "Path of settings file", banner: "path"
option :reset, type: :boolean, desc: "Reset database before converting data"
option :only,
type: :string,
desc: "Run only specified steps (comma-separated)",
banner: "step1,step2"
option :skip,
type: :string,
desc: "Skip specified steps (comma-separated)",
banner: "step1,step2"
def convert(converter_type)
modified_options = modify_step_options
::Migrations::CLI::ConvertCommand.new(converter_type, modified_options).execute
end
desc "import", "Import a file"
option :reset, type: :boolean, desc: "Reset MappingsDB before importing data"
option :only,
type: :string,
desc: "Run only specified steps (comma-separated)",
banner: "step1,step2"
option :skip,
type: :string,
desc: "Skip specified steps (comma-separated)",
banner: "step1,step2"
def import
modified_options = modify_step_options
::Migrations::CLI::ImportCommand.new(modified_options).execute
end
desc "upload", "Upload media uploads"
option :settings,
type: :string,
desc: "Uploads settings file path",
default: "./migrations/config/upload.yml",
aliases: "-s",
banner: "path"
option :fix_missing, type: :boolean, desc: "Fix missing uploads"
option :optimize, type: :boolean, desc: "Optimize uploads"
def upload
::Migrations::CLI::UploadCommand.new(options).execute
end
desc "schema [COMMAND]", "Manage database schema"
subcommand "schema", ::Migrations::CLI::SchemaSubCommand
def self.exit_on_failure?
true
end
private
def modify_step_options
modified_options = options.dup
modified_options[:only] = split_step_class_names(options[:only])
modified_options[:skip] = split_step_class_names(options[:skip])
modified_options
end
def split_step_class_names(class_names)
class_names.presence&.split(",")&.map { |name| name.strip.demodulize.underscore } || []
end
end
end
end
if defined?(RubyVM::YJIT)
RubyVM::YJIT.enable
else
warn "WARNING: Performance degraded: RubyVM::YJIT is not available".yellow
end
# rubocop:disable Discourse/NoChdir
Dir.chdir(File.expand_path("../..", __dir__)) do
::Migrations::CLI::ExceptionHandler.handle_and_exit { ::Migrations::CLI::Application.start }
end
# rubocop:enable Discourse/NoChdir