I create a migration script that included the following line:
add_column :appt_service_logins, :id, :primary_key
This threw an error when running 'rake migrate' against my PostgreSQL DB that essentially boiled down to migrations trying to run the following SQL
ALTER TABLE appt_service_logins ADD id
Obviously missing the datatype for the column. I tracked this down to type_to_sql returning nil. This was because native_database_types define a Hash where primary key does not map to another array with a :name key. Therefore the following in def type_to_sql would return nil since it specifically looks for the value using the :name key.
def type_to_sql(type, limit = nil) #:nodoc:
native = native_database_types[type]
limit ||= native[:limit]
column_type_sql = native[:name]
column_type_sql << "(#{limit})" if limit
column_type_sql
end
To get around this I modified def type_to_sql to use the native value if column_type_sql was nil.
def type_to_sql(type, limit = nil) #:nodoc:
native = native_database_types[type]
limit ||= native[:limit]
column_type_sql = native[:name]
column_type_sql << "(#{limit})" if limit
if column_type_sql
column_type_sql
else
native
end
end
I have no idea what the implications of such a change would be which is why I am submitting this as bug first and not a patch.
In the meantime I am just adding the column as unique and non null and creating an index for it, which is equivalent.