-
Notifications
You must be signed in to change notification settings - Fork 42
change_column produces bad SQL on Postgres #26
Comments
Trapped into the same pit, when I was trying to add an Enum to a class. require 'dm-core'
require 'dm-types'
require 'dm-migrations'
require 'dm-migrations/migration_runner'
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, "postgres://user:pass@localhost:5432/mydb")
class Switch
include DataMapper::Resource
property :id, Serial
end
DataMapper.auto_migrate!
migration 1, :add_enum_value do
up do
modify_table :switches do
add_column :state, Enum[:off, :on, :broken], :default => :off
end
end
end
DataMapper.migrate_up! results in: ALTER TABLE "switches" ADD COLUMN "state" INTEGER DEFAULT 'off' I'd be happy to help. Let me know I can supply more information. |
Similar boat here... in my case I actually want to leave the column type the same, but add it as part of the primary key. Seems the syntax doesn't allow that, and I need to re-specify the datatype, which then causes this issue. |
I get the same problem here when attempting to increase the length of a String field. Has anyone a patch or suggestions on fixing this? |
For now, I've managed to get around this problem by explicitly adding 'type' into the migration statements. For example: migration 50, :increase_size_of_events_title do
up do
modify_table :events do
change_column :title, 'type varchar', size: 100
end
end
down do
modify_table :events do
change_column :title, 'type varchar', size: 50
end
end
end I'd take a look later as to where this statement has to be updated (or if this is something that has to be overwritten). I'm not sure if this is a PostgreSQL specific syntax bug. |
So I've noticed a similar problem when attempting to update the falsifiability of the null state of a column, I'd have to do this to have proper SQL generated. migration 20, :prevent_empty_on_column_address_in_galleries do
up do
Site::Models::Gallery.all do |gallery|
if gallery.address.empty?
gallery.address = 'New York, New York, United States'
gallery.save
end
end
modify_table :galleries do
# NOTE: Use 'set' to change state, no need for type information.
change_column :address, 'set', allow_nil: false
end
end
down do
modify_table :galleries do
# NOTE: Use 'set' to change state, no need for type information.
change_column :address, 'set', allow_nil: true
end
end
end |
The following migration:
Produces this invalid SQL on PostgreSQL (version 8.4):
It should produce:
System info:
jruby 1.6.1 (ruby-1.8.7-p330) (2011-04-12 85838f6) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_24) [darwin-x86_64-java]
postgres (PostgreSQL) 8.4.4
The text was updated successfully, but these errors were encountered: