Weird stuff happening with migrations #293

Closed
jeremyevans opened this Issue May 1, 2011 · 5 comments

Comments

Projects
None yet
1 participant
@jeremyevans
Owner

jeremyevans commented May 1, 2011

Using sequel 3.0.0 tag - commit 10f69a2

Scenario:

$ ls -al db/migration/
total 24
drwxr-xr-x 5 evgeny evgeny 170 Jun 3 02:01 ./
drwxr-xr-x 6 evgeny evgeny 204 Jun 3 01:27 ../
-rw-r--r-- 1 evgeny evgeny 755 Jun 3 01:57 1_create_places.rb
-rw-r--r-- 1 evgeny evgeny 361 Jun 3 01:49 2_create_properties.rb
-rw-r--r-- 1 evgeny evgeny 334 Jun 3 01:50 3_create_types.rb

$ echo 'show tables;' | mysql5 eatery_development
Tables_in_eatery_development
place_type
schema_info
types

$ sequel config/database.yml -m db/migration -M 0

$ echo 'show tables;' | mysql5 eatery_development
Tables_in_eatery_development
schema_info

$ sequel config/database.yml -m db/migration -M 1

$ echo 'show tables;' | mysql5 eatery_development
Tables_in_eatery_development
place_property
place_type
places
properties
schema_info
types

$ sequel config/database.yml -m db/migration -M 2
Sequel::DatabaseError: Mysql::Error Table 'properties' already exists
./vendor/sequel/lib/sequel/adapters/mysql.rb:166:in `query'

$ sequel config/database.yml -m db/migration -M 0

$ echo 'show tables;' | mysql5 eatery_development
Tables_in_eatery_development
schema_info

$ sequel config/database.yml -m db/migration

$ echo 'show tables;' | mysql5 eatery_development
Tables_in_eatery_development
place_type
schema_info
types

Google Code Info:
Issue #: 269
Author: evgeny.zislis
Created On: 2009-06-02T23:08:24.000Z
Closed On: 2009-06-02T23:45:10.000Z

@ghost ghost assigned jeremyevans May 1, 2011

@jeremyevans jeremyevans closed this May 1, 2011

@jeremyevans

This comment has been minimized.

Show comment Hide comment
@jeremyevans

jeremyevans May 1, 2011

Owner

my problem again, which makes this problem a bit different.

I created 1_create_places.rb that included 5 tables, places, properties, place_property, types, place_type;
Then I refactored it into 2_create_properties with just properties and place_property, and 3_create_types with just
types and place_types -- but forgot to clean the first file, so the file 1_create_places.rb still had 5 tables created
(and dropped in down).

But why didn't it shout on me when I did a migration without specifying -M at all???

Google Code Info:
Author: evgeny.zislis
Created On: 2009-06-02T23:12:54.000Z

Owner

jeremyevans commented May 1, 2011

my problem again, which makes this problem a bit different.

I created 1_create_places.rb that included 5 tables, places, properties, place_property, types, place_type;
Then I refactored it into 2_create_properties with just properties and place_property, and 3_create_types with just
types and place_types -- but forgot to clean the first file, so the file 1_create_places.rb still had 5 tables created
(and dropped in down).

But why didn't it shout on me when I did a migration without specifying -M at all???

Google Code Info:
Author: evgeny.zislis
Created On: 2009-06-02T23:12:54.000Z

@jeremyevans

This comment has been minimized.

Show comment Hide comment
@jeremyevans

jeremyevans May 1, 2011

Owner

even after i fixed it .. without -M it migrates only to the latest file, so the tables from (1) and (2) are not there.

And when I use -M with a number it migrates only that migration, so other tables are not there.

Google Code Info:
Author: evgeny.zislis
Created On: 2009-06-02T23:15:46.000Z

Owner

jeremyevans commented May 1, 2011

even after i fixed it .. without -M it migrates only to the latest file, so the tables from (1) and (2) are not there.

And when I use -M with a number it migrates only that migration, so other tables are not there.

Google Code Info:
Author: evgeny.zislis
Created On: 2009-06-02T23:15:46.000Z

@jeremyevans

This comment has been minimized.

Show comment Hide comment
@jeremyevans

jeremyevans May 1, 2011

Owner

You should include the -E or -l switches when running the migrations if you want to
see what Sequel is doing. It'll log the SQL to the standard output or a file.

-M isn't required when using -m. When it is not specified, it migrates to the latest
migration version. If you use -M, it should run all migrations between the current
version and the version you specify. If you don't think this is happening, run it
with -E to see what SQL is being sent.

Google Code Info:
Author: jeremyev...@gmail.com
Created On: 2009-06-02T23:30:48.000Z

Owner

jeremyevans commented May 1, 2011

You should include the -E or -l switches when running the migrations if you want to
see what Sequel is doing. It'll log the SQL to the standard output or a file.

-M isn't required when using -m. When it is not specified, it migrates to the latest
migration version. If you use -M, it should run all migrations between the current
version and the version you specify. If you don't think this is happening, run it
with -E to see what SQL is being sent.

Google Code Info:
Author: jeremyev...@gmail.com
Created On: 2009-06-02T23:30:48.000Z

@jeremyevans

This comment has been minimized.

Show comment Hide comment
@jeremyevans

jeremyevans May 1, 2011

Owner

okay - think its my fault again.
as i've said, i moved the first file into the second two ... and i forgot to rename the Class in the process. most
probably this was the cause of all the confusion.

sorry to waste your time :(

Google Code Info:
Author: evgeny.zislis
Created On: 2009-06-02T23:32:33.000Z

Owner

jeremyevans commented May 1, 2011

okay - think its my fault again.
as i've said, i moved the first file into the second two ... and i forgot to rename the Class in the process. most
probably this was the cause of all the confusion.

sorry to waste your time :(

Google Code Info:
Author: evgeny.zislis
Created On: 2009-06-02T23:32:33.000Z

@jeremyevans

This comment has been minimized.

Show comment Hide comment
@jeremyevans

jeremyevans May 1, 2011

Owner

No problem. I recommend using the following format for migrations to reduce the risk
of class name reuse:

Class.new(Sequel::Migration) do
def up
end
def down
end
end

That'll create an anonymous class, so it's not possible to have a conflict with
another migration.

Google Code Info:
Author: jeremyev...@gmail.com
Created On: 2009-06-02T23:45:10.000Z

Owner

jeremyevans commented May 1, 2011

No problem. I recommend using the following format for migrations to reduce the risk
of class name reuse:

Class.new(Sequel::Migration) do
def up
end
def down
end
end

That'll create an anonymous class, so it's not possible to have a conflict with
another migration.

Google Code Info:
Author: jeremyev...@gmail.com
Created On: 2009-06-02T23:45:10.000Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment