Class: Potter::Migrations::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/potter/migrations.rb

Instance Method Summary collapse

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

#changeObject



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_namesObject



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