Class: Exwiw::DbIntrospector::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/exwiw/db_introspector.rb

Direct Known Subclasses

MysqlIntrospector, PostgresqlIntrospector

Constant Summary collapse

BOOLEAN_DEFAULTS =

How the two databases spell a boolean default in the catalog: MySQL stores a TINYINT(1) default as "1"/"0", PostgreSQL a boolean one as "true"/"false". Anything else is not a boolean literal and falls through to nil.

{
  "1" => true, "true" => true,
  "0" => false, "false" => false,
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(connection_config) ⇒ Base

Returns a new instance of Base.



59
60
61
# File 'lib/exwiw/db_introspector.rb', line 59

def initialize(connection_config)
  @connection_config = connection_config
end

Instance Method Details

#columns(_table_name) ⇒ Object

The table's columns as Column structs, in ordinal_position order — the order the config lists them in, which mirrors what a SELECT * returns.

Raises:

  • (NotImplementedError)


80
81
82
# File 'lib/exwiw/db_introspector.rb', line 80

def columns(_table_name)
  raise NotImplementedError
end

#foreign_keys(_table_name) ⇒ Object

The table's single-column foreign keys as sorted { table_name:, foreign_key: } hashes — the belongs_to shape. Composite foreign keys are skipped with a warning: exwiw joins on one column, so a multi-column edge cannot be expressed, and silently emitting one of its columns would produce a join that is quietly wrong.

Raises:

  • (NotImplementedError)


98
99
100
# File 'lib/exwiw/db_introspector.rb', line 98

def foreign_keys(_table_name)
  raise NotImplementedError
end

#primary_key(_table_name) ⇒ Object

The table's primary key as a String, an Array for a composite key, or nil when the table has none. The three cases are what the generator branches on, so they are kept distinct rather than normalized.

Raises:

  • (NotImplementedError)


74
75
76
# File 'lib/exwiw/db_introspector.rb', line 74

def primary_key(_table_name)
  raise NotImplementedError
end

#table_namesObject

Sorted names of the tables in the current database/schema. Views are excluded: they hold no rows of their own, so exporting one would duplicate data already covered by its underlying tables (and the restore would fail against a target where the same view exists).

Raises:

  • (NotImplementedError)


67
68
69
# File 'lib/exwiw/db_introspector.rb', line 67

def table_names
  raise NotImplementedError
end

#unique_column_names(_table_name) ⇒ Object

The names of columns covered by any unique index or constraint, or nil when the catalog could not be read. Callers treat nil as "assume every column is unique", since masking a unique column with a constant makes every row collide on restore. The primary key is included; it is unique, and the generator never masks it anyway.

Raises:

  • (NotImplementedError)


89
90
91
# File 'lib/exwiw/db_introspector.rb', line 89

def unique_column_names(_table_name)
  raise NotImplementedError
end