Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add a migrator that works with timestamped migrations
This commit splits Migrator into IntegerMigrator and TimestampMigrator, both subclasses of Migrator. Migrator maintains the same API (apply and run), and picks which subclass to use based on the migration file names. TimestampMigrator allows you to apply migrations out of order. I tried to handle the corner cases I could think of, such as: * Migrations with the same timestamp (Sequel allows this as they have different filenames) * Applied migrations that are not in the file system (Sequel raises an exception) * Migrating to a specific timestamp where you have to migrate some migrations up (because they haven't been applied and the timestamp is less than the target) and other migrations down (because they have been applied and the timestamp is greater than the target). * Converting the old schema_info table format to the new schema_migrations format, even when not all migration files from the old format have been applied, or the target version doesn't include all old style integer migration files. Currently, there's only integration tests available for the TimestampMigrator. I'll be adding real specs later, but they take more time to write.
- Loading branch information
1 parent
d9b4db7
commit 44c90cc
Showing
21 changed files
with
493 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateSessions < Sequel::Migration | ||
def up | ||
create_table(:sm1111){Integer :smc1} | ||
end | ||
|
||
def down | ||
get(:asdfsadfas) | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Class.new(Sequel::Migration) do | ||
def up | ||
create_table(:sm2222){Integer :smc2} | ||
end | ||
|
||
def down | ||
drop_table(:sm2222) | ||
end | ||
end |
3 changes: 3 additions & 0 deletions
3
spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Sequel.migration do | ||
up{get(:asdfsadfas)} | ||
end |
9 changes: 9 additions & 0 deletions
9
spec/files/convert_to_timestamp_migrations/001_create_sessions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateSessions < Sequel::Migration | ||
def up | ||
create_table(:sm1111){Integer :smc1} | ||
end | ||
|
||
def down | ||
drop_table(:sm1111) | ||
end | ||
end |
Oops, something went wrong.