Module: PGTrunk::Migration
- Defined in:
- lib/pg_trunk/core/railtie/migration.rb
Overview
The module goes around the ActiveRecord::Migration's method_missing
.
This is necessary because +ActiveRecord::Migration#method_missing+ forces the first argument to be a proper table name.
In Rails migrations the first argument specifies the +table+, while the +name+ of the object can be specified by option:
pg_trunk_create_index :users, %w[id name], name: 'users_idx'
in PGTrunk the positional argument is always specify the name of the the current object (type, function, table etc.):
pg_trunk_create_index 'users_ids', table: 'users', columns: %w[id name] create_enum 'currency', values: %w[USD EUR BTC]
With this fix we can also use the options-only syntax like:
pg_trunk_create_enum name: 'currency', values: %w[USD EUR BTC]
or even skip any name when it can be generated from options:
pg_trunk_create_index do |i| i.table 'users' i.column 'id' end
Class Method Summary collapse
Class Method Details
.register(klass) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/pg_trunk/core/railtie/migration.rb', line 34 def self.register(klass) define_method(klass.ruby_name) do |*args, &block| say_with_time "#{klass.ruby_name}(#{_pretty_args(*args)})" do connection.send(klass.ruby_name, *args, &block) end end end |