Class: Potter::Migrations::Migration
- Inherits:
-
Object
- Object
- Potter::Migrations::Migration
- Defined in:
- lib/potter/migrations.rb
Instance Method Summary collapse
- #change ⇒ Object
- #column_names ⇒ Object
- #create_or_change_table(name) ⇒ Object
-
#initialize(model) ⇒ Migration
constructor
A new instance of Migration.
Constructor Details
#initialize(model) ⇒ Migration
Returns a new instance of Migration.
6 7 8 |
# File 'lib/potter/migrations.rb', line 6 def initialize(model) @model = model end |
Instance Method Details
#change ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/potter/migrations.rb', line 22 def change create_or_change_table(model.table_name) do |t| model.fields.each do |f| t.column f.name, f.type.to_sym, null: f.optional? end end end |
#column_names ⇒ Object
10 11 |
# File 'lib/potter/migrations.rb', line 10 def column_names end |
#create_or_change_table(name) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/potter/migrations.rb', line 13 def create_or_change_table(name, **, &) return create_table(name, **, &) unless table_exists?(name) change_table(name, **) do |t| t.remove_columns(*(t.columns.map(&:name) - %w[id])) yield t end end |