Class: SchemaFerry::Converter::SchemaConverter

Inherits:
Object
  • Object
show all
Includes:
Warnings
Defined in:
lib/schema_ferry/converter/schema_converter.rb

Constant Summary collapse

UNSUPPORTED_INDEX_TYPES =

PostgreSQL has no FULLTEXT/SPATIAL equivalent that ridgepole can express.

%i[fulltext spatial].freeze
MISDETECTED_SPATIAL_SQL_TYPE =

MySQL spatial column types have no PostgreSQL equivalent (that would require PostGIS, which schema_ferry does not manage). Most of these already raise TypeMapper's ConversionError, since ActiveRecord's mysql2 adapter reports them as an unrecognized type (nil). POINT is the sole exception: AR matches sql_type against an unanchored /int/i regex (see register_class_with_limit in ActiveRecord::ConnectionAdapters::AbstractAdapter#initialize_type_map), which matches "point" as a substring — so it's misreported as plain :integer instead. Without this check it would sail through as a meaningless integer column instead of raising. It must be caught here, by sql_type, and raised explicitly — the same failure mode as any other unsupported type, not a warning that's easy to miss in a cron log.

/\Apoint\b/i

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ SchemaConverter

Returns a new instance of SchemaConverter.



26
27
28
29
30
31
# File 'lib/schema_ferry/converter/schema_converter.rb', line 26

def initialize(config)
  @column_converter = ColumnConverter.new(TypeMapper.new(config.global_type_overrides))
  @table_rules      = config.table_rules
  @ignored_tables   = config.ignored_tables
  @enum_check       = (EnumCheckBuilder.new if config.enum_mode == :check)
end

Instance Method Details

#convert(raw_tables) ⇒ Object



33
34
35
36
37
# File 'lib/schema_ferry/converter/schema_converter.rb', line 33

def convert(raw_tables)
  kept_tables = raw_tables.reject { |t| @ignored_tables.include?(t[:name]) }
  fk_columns  = collect_fk_columns(kept_tables)
  kept_tables.map { |t| convert_table(t, fk_columns.fetch(t[:name], [])) }
end