Module: DagMe

Extended by:
ActiveSupport::Autoload
Defined in:
lib/dag_me.rb,
lib/dag_me/ddl.rb,
lib/dag_me/graph.rb,
lib/dag_me/macro.rb,
lib/dag_me/model.rb,
lib/dag_me/errors.rb,
lib/dag_me/railtie.rb,
lib/dag_me/version.rb,
lib/dag_me/test_helper.rb,
lib/dag_me/task_helpers.rb,
lib/dag_me/adapters/base.rb,
lib/dag_me/configuration.rb,
lib/dag_me/adapters/recursive_cte.rb,
lib/dag_me/adapters/postgresql_closure.rb,
lib/generators/dag_me/migration_generator.rb

Defined Under Namespace

Modules: Adapters, Generators, Macro, Model, TaskHelpers, TestHelper Classes: Configuration, CorruptionError, CycleError, DDL, Error, Graph, IsolationError, Railtie, ScopeError

Constant Summary collapse

KEYWORD_AREL_TABLE =

Rails main (8.2) made Arel::Table.new keyword-only.

Arel::Table.instance_method(:initialize).parameters.none? do |type, _name|
  %i[req opt].include?(type)
end
SQLSTATE_CYCLE =

The triggers raise with these custom SQLSTATEs, so translation does not depend on message wording.

'DGME1'
SQLSTATE_CROSS_SCOPE =
'DGME2'
SQLSTATE_SCOPE_CHANGE =
'DGME3'
SQLSTATE_ISOLATION =
'DGME4'
SQLSTATE_ERRORS =
{
  SQLSTATE_CYCLE => CycleError,
  SQLSTATE_CROSS_SCOPE => ScopeError,
  SQLSTATE_SCOPE_CHANGE => ScopeError,
  SQLSTATE_ISOLATION => IsolationError
}.freeze
VERSION =
'0.4.2'

Class Method Summary collapse

Class Method Details

.arel_table(name) ⇒ Object



18
19
20
# File 'lib/dag_me.rb', line 18

def self.arel_table(name)
  KEYWORD_AREL_TABLE ? Arel::Table.new(name: name) : Arel::Table.new(name)
end

.sqlstate(error) ⇒ Object



54
55
56
57
58
59
# File 'lib/dag_me/errors.rb', line 54

def sqlstate(error)
  cause = error.cause
  return unless cause.respond_to?(:result) && cause.result

  cause.result.error_field(PG::PG_DIAG_SQLSTATE)
end

.translate_errorsObject



45
46
47
48
49
50
51
52
# File 'lib/dag_me/errors.rb', line 45

def translate_errors
  yield
rescue ActiveRecord::StatementInvalid => e
  error_class = SQLSTATE_ERRORS[sqlstate(e)]
  raise error_class, e.message if error_class

  raise
end