nullable constraint in migration definition not applied to database?

2 views
Skip to first unread message

baaz

unread,
Nov 26, 2008, 6:27:19 AM11/26/08
to DataMapper
Hey all,

I use DataMapper (surprise :) ) and MySQL. I've created the following
migration to add a user name to the database:

migration 1, :add_user_name do
up do
modify_table :users do
add_column :name, String, :nullable? => false, :length =>
(2..100)
end
end

down do
modify_table :users do
drop_column :name
end
end
end

When I run this migration with db:migrate:up the 'name' column is
correctly added to the user table but the NOT NULL constraint is not.
I also tried to replace :nullable and :null for :nullable? above but
to no avail. I read in an earlier thread (http://groups.google.com/
group/datamapper/browse_thread/thread/7f3eb3b1341c13fc/
c5a4e005b8a9a49a?lnk=gst&q=migrations+constraints#c5a4e005b8a9a49a)
that some constraints were not applied in the database, is this still
the case?

Thank you for your help,
Balint

crantz

unread,
Nov 28, 2008, 7:05:45 AM11/28/08
to DataMapper
On 26 Nov, 12:27, baaz <balint.e...@gmail.com> wrote:
> When I run this migration with db:migrate:up the 'name' column is
> correctly added to the user table but the NOT NULL constraint is not.
> I also tried to replace :nullable and :null for :nullable? above but
> to no avail.

I recently had the same problem. I fixed it by making the following
change to dm-migrations:

--- /usr/lib/ruby/user-gems/1.8/gems/dm-migrations-0.9.7/lib/sql/
table_creator.rb 2008-11-25 21:46:34.000000000 +0100
+++ ./gems/dm-migrations-0.9.7/lib/sql/table_creator.rb 2008-11-28
11:52:04.000000000 +0100
@@ -57,8 +57,8 @@

def build_type(type_class)
schema = {:name => @name, :quote_column_name =>
quoted_name}.merge(@opts)
- schema[:serial?] ||= schema[:serial]
- schema[:nullable?] ||= schema[:nullable] || !schema
[:not_null]
+ schema[:serial?] = [schema[:serial?], schema[:serial],
false].compact.first
+ schema[:nullable?] = [schema[:nullable?], schema[:nullable],
(!schema[:not_null] unless schema[:not_null].nil?),
true].compact.first
if type_class.is_a?(String)
schema[:primitive] = type_class
else

Reply all
Reply to author
Forward
0 new messages