Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote-tracking branch 'pvh/iscurrent'

  • Loading branch information...
commit 73208256ba3ba166c925c3b1fdf6241acec9ac16 2 parents d4e10bf + 5fcb974
@jeremyevans authored
View
12 lib/sequel/extensions/migration.rb
@@ -361,6 +361,10 @@ def self.run(db, directory, opts={})
migrator_class(directory).new(db, directory, opts).run
end
+ def self.is_current?(db, directory, opts={})
+ migrator_class(directory).new(db, directory, opts).is_current?
+ end
+
# Choose the Migrator subclass to use. Uses the TimestampMigrator
# if the version number appears to be a unix time integer for a year
# after 2005, otherwise uses the IntegerMigrator.
@@ -500,6 +504,10 @@ def run
target
end
+ def is_current?
+ current_migration_version == target
+ end
+
private
# Gets the current migration version stored in the database. If no version
@@ -616,6 +624,10 @@ def run
nil
end
+ def is_current?
+ migration_tuples.empty?
+ end
+
private
# Convert the schema_info table to the new schema_migrations table format,
View
15 spec/extensions/migration_spec.rb
@@ -272,11 +272,10 @@ def table_exists?(name)
@db.dataset.columns.should == [:sic]
end
- specify "should apply migrations correctly in the up direction if no target is given" do
+ specify "should be able to tell whether there are outstanding migrations" do
+ Sequel::Migrator.is_current?(@db, @dirname).should be_false
Sequel::Migrator.apply(@db, @dirname)
- @db.creates.should == [1111, 2222, 3333]
- @db.version.should == 3
- @db.sqls.map{|x| x =~ /\AUPDATE.*(\d+)/ ? $1.to_i : nil}.compact.should == [1, 2, 3]
+ Sequel::Migrator.is_current?(@db, @dirname).should be_true
end
specify "should apply migrations correctly in the up direction with target" do
@@ -448,6 +447,14 @@ def create_table(name, *args, &block)
@db[:schema_migrations].select_order_map(:filename).should == %w'1273253849_create_sessions.rb'
end
+ specify "should not be current when there are migrations to apply" do
+ @dir = 'spec/files/timestamped_migrations'
+ @m.apply(@db, @dir)
+ @m.is_current?.should be_true
+ @dir = 'spec/files/interleaved_timestamped_migrations'
+ @m.is_current?.should be_false
+ end
+
specify "should apply all missing files when migrating up" do
@dir = 'spec/files/timestamped_migrations'
@m.apply(@db, @dir)
Please sign in to comment.
Something went wrong with that request. Please try again.