mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 01:56:58 +08:00

* Splits the existing script into multiple classes * Adds command for generating IntermediateDB schema (`migrations/bin/cli schema generate`) * Changes the syntax of the IntermediateDB schema config * Adds validation for the schema config * It uses YAML schema aka JSON schema to validate the config file * It generates the SQL schema file and Ruby classes for storing data in the IntermediateDB
47 lines
946 B
Ruby
47 lines
946 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Migrations::Database::Schema
|
|
class ConfigValidator
|
|
attr_reader :errors
|
|
|
|
def initialize
|
|
@errors = []
|
|
end
|
|
|
|
def validate(config)
|
|
@errors.clear
|
|
|
|
validate_with_json_schema(config)
|
|
return self if has_errors?
|
|
|
|
validate_output_config(config)
|
|
validate_schema_config(config)
|
|
validate_plugins(config)
|
|
|
|
self
|
|
end
|
|
|
|
def has_errors?
|
|
@errors.any?
|
|
end
|
|
|
|
private
|
|
|
|
def validate_with_json_schema(config)
|
|
Validation::JsonSchemaValidator.new(config, @errors).validate
|
|
end
|
|
|
|
def validate_output_config(config)
|
|
Validation::OutputConfigValidator.new(config, @errors).validate
|
|
end
|
|
|
|
def validate_schema_config(config)
|
|
Validation::SchemaConfigValidator.new(config, @errors).validate
|
|
end
|
|
|
|
def validate_plugins(config)
|
|
Validation::PluginConfigValidator.new(config, @errors).validate
|
|
end
|
|
end
|
|
end
|