Class: ROM::SQL::Migration::SQLMigration Private

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/rom/sql/migration/sql_migration.rb

Overview

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.

A migration translated from a .sql file by SQLParser.

Constant Summary collapse

Filename =

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.

Types::Coercible::String
Settings =

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.

Types::Strict::Hash.default { {} }
Direction =

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.

Types::Strict::Symbol.enum(:up, :down)
Statements =

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.

Types::Array.of(Types.Instance(Statement))
SUBSTITUTION =

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.

Matches ${NAME} substitution references in statement bodies when the env=true pragma is set. Only the braced form is recognized, leaving $$-quoted bodies and $1 positional params untouched.

/\$\{(?<name>[A-Za-z_]\w*)\}/

Instance Method Summary collapse

Instance Method Details

#apply(db, direction) ⇒ 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.

Execute the statements for the given direction against the database.

Parameters:

  • db (Sequel::Database)
  • direction (:up, :down)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rom/sql/migration/sql_migration.rb', line 59

def apply(db, direction)
  unless Direction.valid?(direction)
    raise ArgumentError, "Invalid migration direction specified (#{direction.inspect})"
  end

  statements = public_send(direction) or return

  # Resolve every statement before running any, so a missing environment
  # variable aborts before producing side effects.
  finalized = statements.map { |statement| apply_env(statement) }

  finalized.each do |statement|
    db.run(statement.sql)
  rescue Sequel::DatabaseError => e
    raise annotate(e, statement, direction)
  end
end

#use_transactions ⇒ true, ...

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.

Whether to run inside a transaction.

Returns:

  • (true, false, nil) —

    nil leaves the choice to the database default



49
50
51
# File 'lib/rom/sql/migration/sql_migration.rb', line 49

def use_transactions
  settings[:transaction]
end

#with(**settings) ⇒ 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.

Return a copy with additional settings merged in.



40
41
42
# File 'lib/rom/sql/migration/sql_migration.rb', line 40

def with(**settings)
  new(settings: self.settings.merge(settings))
end