Class: SchemaFerry::Converter::EnumCheckBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/schema_ferry/converter/enum_check_builder.rb

Overview

Builds CHECK constraints enforcing MySQL enum values on varchar columns (enum_as :check).

Instance Method Summary collapse

Instance Method Details

#call(raw_table, rule, ignored) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/schema_ferry/converter/enum_check_builder.rb', line 8

def call(raw_table, rule, ignored)
  raw_table[:columns].filter_map do |col|
    next if ignored.include?(col[:name])
    # A type override takes the column away from varchar; the caller owns
    # any constraint then.
    next if rule&.column_type_overrides&.key?(col[:name])

    values = enum_values(col[:sql_type])
    next if values.nil?

    build_constraint(raw_table[:name], col[:name], values)
  end
end