Class: Torque::PostgreSQL::VersionedCommands::CommandMigration

Inherits:
Struct
  • Object
show all
Defined in:
lib/torque/postgresql/versioned_commands/command_migration.rb,
sig/torque/postgresql/versioned_commands/command_migration.rbs

Instance Method Summary collapse

Constructor Details

#initialize(filename, *args) ⇒ CommandMigration

Returns a new instance of CommandMigration.

Parameters:

  • filename (String)
  • args (Object)


68
69
70
71
# File 'lib/torque/postgresql/versioned_commands/command_migration.rb', line 68

def initialize(filename, *args)
  super(File.expand_path(filename), *args)
  @migration = nil
end

Instance Method Details

#disable_ddl_transaction ⇒ false

There is no way to setup this, so it is always false

Returns:

  • (false)


79
80
81
# File 'lib/torque/postgresql/versioned_commands/command_migration.rb', line 79

def disable_ddl_transaction
  false
end

#down ⇒ Object

Find the previous command and executes it

Returns:

  • (Object)


101
102
103
104
105
106
# File 'lib/torque/postgresql/versioned_commands/command_migration.rb', line 101

def down
  return drop if op_version == 1
  dirs = @migration.pool.migrations_paths
  version = op_version - (op == 'remove' ? 0 : 1)
  execute VersionedCommands.fetch_command(dirs, type, object_name, version)
end

#drop ⇒ Object

Drops the type created

Returns:

  • (Object)

Raises:

  • (ArgumentError)


109
110
111
112
113
# File 'lib/torque/postgresql/versioned_commands/command_migration.rb', line 109

def drop
  method_name = :"drop_#{type}"
  return send(method_name) if VersionedCommands.valid_type?(type)
  raise ArgumentError, "Unknown versioned command type: #{type}"
end

#execute ⇒ Object

Parameters:

  • command (String)

Returns:

  • (Object)


36
# File 'sig/torque/postgresql/versioned_commands/command_migration.rbs', line 36

def execute: (String command) -> untyped

#filename ⇒ String

Returns:

  • (String)


21
# File 'sig/torque/postgresql/versioned_commands/command_migration.rbs', line 21

def filename: () -> String

#filename= ⇒ String

Parameters:

  • value (String)

Returns:

  • (String)


22
# File 'sig/torque/postgresql/versioned_commands/command_migration.rbs', line 22

def filename=: (String value) -> String

#migrate(direction) ⇒ Object

Down is more complicated, then this just starts separating the logic

Parameters:

  • direction (:up, :down)

Returns:

  • (Object)


84
85
86
87
88
89
90
91
# File 'lib/torque/postgresql/versioned_commands/command_migration.rb', line 84

def migrate(direction)
  @migration = ActiveRecord::Migration.allocate
  @migration.extend(Migration)
  @migration.send(:initialize, name, version, self)
  @migration.migrate(direction)
ensure
  @migration = nil
end

#name ⇒ String

Rails uses this to avoid duplicate migrations

Returns:

  • (String)


74
75
76
# File 'lib/torque/postgresql/versioned_commands/command_migration.rb', line 74

def name
  "#{op}_#{type}_#{object_name}_v#{op_version}"
end

#object_name ⇒ String

Returns:

  • (String)


29
# File 'sig/torque/postgresql/versioned_commands/command_migration.rbs', line 29

def object_name: () -> String

#object_name= ⇒ String

Parameters:

  • value (String)

Returns:

  • (String)


30
# File 'sig/torque/postgresql/versioned_commands/command_migration.rbs', line 30

def object_name=: (String value) -> String

#op ⇒ String

Returns:

  • (String)


25
# File 'sig/torque/postgresql/versioned_commands/command_migration.rbs', line 25

def op: () -> String

#op= ⇒ String

Parameters:

  • value (String)

Returns:

  • (String)


26
# File 'sig/torque/postgresql/versioned_commands/command_migration.rbs', line 26

def op=: (String value) -> String

#op_version ⇒ Integer

Returns:

  • (Integer)


31
# File 'sig/torque/postgresql/versioned_commands/command_migration.rbs', line 31

def op_version: () -> Integer

#op_version= ⇒ Integer

Parameters:

  • value (Integer)

Returns:

  • (Integer)


32
# File 'sig/torque/postgresql/versioned_commands/command_migration.rbs', line 32

def op_version=: (Integer value) -> Integer

#scope ⇒ String?

Returns:

  • (String, nil)


33
# File 'sig/torque/postgresql/versioned_commands/command_migration.rbs', line 33

def scope: () -> String?

#scope= ⇒ String?

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)


34
# File 'sig/torque/postgresql/versioned_commands/command_migration.rbs', line 34

def scope=: (String? value) -> String?

#type ⇒ String

Returns:

  • (String)


27
# File 'sig/torque/postgresql/versioned_commands/command_migration.rbs', line 27

def type: () -> String

#type= ⇒ String

Parameters:

  • value (String)

Returns:

  • (String)


28
# File 'sig/torque/postgresql/versioned_commands/command_migration.rbs', line 28

def type=: (String value) -> String

#up ⇒ Object

Simply executes the underlying command

Returns:

  • (Object)


94
95
96
97
98
# File 'lib/torque/postgresql/versioned_commands/command_migration.rb', line 94

def up
  content = File.read(filename)
  VersionedCommands.validate!(type, content, object_name)
  execute content
end

#version ⇒ Integer

Returns:

  • (Integer)


23
# File 'sig/torque/postgresql/versioned_commands/command_migration.rbs', line 23

def version: () -> Integer

#version= ⇒ Integer

Parameters:

  • value (Integer)

Returns:

  • (Integer)


24
# File 'sig/torque/postgresql/versioned_commands/command_migration.rbs', line 24

def version=: (Integer value) -> Integer