Class: ROM::SQL::Schema::Inferrer Private

Inherits:
Object
  • Object
show all
Extended by:
Dry::Core::ClassAttributes
Defined in:
lib/rom/sql/schema/inferrer.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

CONSTRAINT_DB_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'add_constraint'.freeze
DECIMAL_REGEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/(?:decimal|numeric)\((\d+)(?:,\s*(\d+))?\)/.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](type) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
# File 'lib/rom/sql/schema/inferrer.rb', line 38

def self.[](type)
  Class.new(self) { db_type(type) }
end

.get(type) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



42
43
44
# File 'lib/rom/sql/schema/inferrer.rb', line 42

def self.get(type)
  db_registry[type]
end

.inherited(klass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
35
36
# File 'lib/rom/sql/schema/inferrer.rb', line 32

def self.inherited(klass)
  super

  Inferrer.db_registry[klass.db_type] = klass unless klass.name.nil?
end

.on_error(relation, e) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
49
50
51
52
# File 'lib/rom/sql/schema/inferrer.rb', line 46

def self.on_error(relation, e)
  warn "[#{relation}] failed to infer schema. " \
       "Make sure tables exist before ROM container is set up. " \
       "This may also happen when your migration tasks load ROM container, " \
       "which is not needed for migrations as only the connection is required " \
       "(#{e.message})"
end

Instance Method Details

#call(source, gateway) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rom/sql/schema/inferrer.rb', line 55

def call(source, gateway)
  dataset = source.dataset

  columns = filter_columns(gateway.connection.schema(dataset))
  all_indexes = indexes_for(gateway, dataset)
  fks = fks_for(gateway, dataset)

  inferred = columns.map do |(name, definition)|
    indexes = column_indexes(all_indexes, name)
    type = build_type(**definition, foreign_key: fks[name], indexes: indexes)

    if type
      type.meta(name: name, source: source)
    end
  end.compact

  [inferred, columns.map(&:first) - inferred.map { |attr| attr.meta[:name] }]
end