Class: SchemaFerry::Config
- Inherits:
-
Object
- Object
- SchemaFerry::Config
- Defined in:
- lib/schema_ferry/config.rb
Defined Under Namespace
Classes: TableRule
Instance Attribute Summary collapse
-
#enum_mode ⇒ Object
readonly
Returns the value of attribute enum_mode.
-
#global_type_overrides ⇒ Object
readonly
Returns the value of attribute global_type_overrides.
-
#ignored_tables ⇒ Object
readonly
Returns the value of attribute ignored_tables.
-
#source_url ⇒ Object
readonly
Returns the value of attribute source_url.
-
#table_rules ⇒ Object
readonly
Returns the value of attribute table_rules.
-
#target_url ⇒ Object
readonly
Returns the value of attribute target_url.
Class Method Summary collapse
-
.build(&block) ⇒ Object
Ruby entry point.
-
.load_file(path) ⇒ Object
CLI entry point.
Instance Method Summary collapse
-
#enum_as(mode) ⇒ Object
How to convert MySQL enum columns: :string — plain varchar, values not enforced (default) :check — varchar plus a CHECK constraint restricting the values.
- #ignore_table(table_name) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #map_type(mysql_type, to:) ⇒ Object
- #source(url) ⇒ Object
- #table(table_name) ⇒ Object
- #target(url) ⇒ Object
- #validate! ⇒ Object
Constructor Details
Instance Attribute Details
#enum_mode ⇒ Object (readonly)
Returns the value of attribute enum_mode.
5 6 7 |
# File 'lib/schema_ferry/config.rb', line 5 def enum_mode @enum_mode end |
#global_type_overrides ⇒ Object (readonly)
Returns the value of attribute global_type_overrides.
5 6 7 |
# File 'lib/schema_ferry/config.rb', line 5 def global_type_overrides @global_type_overrides end |
#ignored_tables ⇒ Object (readonly)
Returns the value of attribute ignored_tables.
5 6 7 |
# File 'lib/schema_ferry/config.rb', line 5 def ignored_tables @ignored_tables end |
#source_url ⇒ Object (readonly)
Returns the value of attribute source_url.
5 6 7 |
# File 'lib/schema_ferry/config.rb', line 5 def source_url @source_url end |
#table_rules ⇒ Object (readonly)
Returns the value of attribute table_rules.
5 6 7 |
# File 'lib/schema_ferry/config.rb', line 5 def table_rules @table_rules end |
#target_url ⇒ Object (readonly)
Returns the value of attribute target_url.
5 6 7 |
# File 'lib/schema_ferry/config.rb', line 5 def target_url @target_url end |
Class Method Details
.build(&block) ⇒ Object
Ruby entry point
13 14 15 |
# File 'lib/schema_ferry/config.rb', line 13 def build(&block) evaluate { |config| config.instance_eval(&block) } end |
.load_file(path) ⇒ Object
CLI entry point
18 19 20 |
# File 'lib/schema_ferry/config.rb', line 18 def load_file(path) evaluate { |config| config.instance_eval(File.read(path), path.to_s, 1) } end |
Instance Method Details
#enum_as(mode) ⇒ Object
How to convert MySQL enum columns:
:string — plain varchar, values not enforced (default)
:check — varchar plus a CHECK constraint restricting the values
64 65 66 67 68 69 70 71 |
# File 'lib/schema_ferry/config.rb', line 64 def enum_as(mode) modes = %i[string check] unless modes.include?(mode.to_sym) raise ConfigError, "enum_as accepts #{modes.map(&:inspect).join(" or ")}, got #{mode.inspect}" end @enum_mode = mode.to_sym end |
#ignore_table(table_name) ⇒ Object
57 58 59 |
# File 'lib/schema_ferry/config.rb', line 57 def ignore_table(table_name) @ignored_tables << table_name.to_s end |
#map_type(mysql_type, to:) ⇒ Object
47 48 49 |
# File 'lib/schema_ferry/config.rb', line 47 def map_type(mysql_type, to:) @global_type_overrides[mysql_type.to_sym] = to.to_sym end |
#source(url) ⇒ Object
39 40 41 |
# File 'lib/schema_ferry/config.rb', line 39 def source(url) @source_url = url end |
#table(table_name) ⇒ Object
51 52 53 54 55 |
# File 'lib/schema_ferry/config.rb', line 51 def table(table_name, &) rule = TableRule.new(table_name) rule.instance_eval(&) @table_rules[table_name.to_s] = rule end |
#target(url) ⇒ Object
43 44 45 |
# File 'lib/schema_ferry/config.rb', line 43 def target(url) @target_url = url end |
#validate! ⇒ Object
73 74 75 76 |
# File 'lib/schema_ferry/config.rb', line 73 def validate! raise ConfigError, 'source is not configured. Add: source "mysql2://..."' unless @source_url raise ConfigError, 'target is not configured. Add: target "postgresql://..."' unless @target_url end |