Class: Torque::PostgreSQL::VersionedCommands::CommandMigration
- Inherits:
-
Struct
- Object
- Struct
- Torque::PostgreSQL::VersionedCommands::CommandMigration
- Defined in:
- lib/torque/postgresql/versioned_commands/command_migration.rb
Instance Method Summary collapse
-
#disable_ddl_transaction ⇒ Object
There is no way to setup this, so it is always false.
-
#down ⇒ Object
Find the previous command and executes it.
-
#drop ⇒ Object
Drops the type created.
-
#initialize(filename, *args) ⇒ CommandMigration
constructor
A new instance of CommandMigration.
-
#migrate(direction) ⇒ Object
Down is more complicated, then this just starts separating the logic.
-
#name ⇒ Object
Rails uses this to avoid duplicate migrations.
-
#up ⇒ Object
Simply executes the underlying command.
Constructor Details
#initialize(filename, *args) ⇒ CommandMigration
Returns a new instance of CommandMigration.
68 69 70 71 |
# File 'lib/torque/postgresql/versioned_commands/command_migration.rb', line 68 def initialize(filename, *args) super(File.(filename), *args) @migration = nil end |
Instance Method Details
#disable_ddl_transaction ⇒ Object
There is no way to setup this, so it is always 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
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
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 |
#migrate(direction) ⇒ Object
Down is more complicated, then this just starts separating the logic
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 ⇒ Object
Rails uses this to avoid duplicate migrations
74 75 76 |
# File 'lib/torque/postgresql/versioned_commands/command_migration.rb', line 74 def name "#{op}_#{type}_#{object_name}_v#{op_version}" end |
#up ⇒ Object
Simply executes the underlying command
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 |