Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make migrator work when a default_schema is set

  • Loading branch information...
commit 40879f1ad2f37ac0e79e60b10c73ead8463838fd 1 parent 0d79af5
@jeremyevans authored
View
4 CHANGELOG
@@ -1,3 +1,7 @@
+=== HEAD
+
+* Make migrator work correctly when a default_schema is set (jeremyevans) (#331)
+
=== 3.21.0 (2011-03-01)
* Make symbol splitting (:table__column___alias) work correctly for identifiers that are not in the \w character class (authorNari)
View
3  lib/sequel/extensions/migration.rb
@@ -375,7 +375,8 @@ def initialize(db, directory, opts={})
@db = db
@directory = directory
@files = get_migration_files
- @table = opts[:table] || self.class.const_get(:DEFAULT_SCHEMA_TABLE)
+ schema, table = @db.send(:schema_and_table, opts[:table] || self.class.const_get(:DEFAULT_SCHEMA_TABLE))
+ @table = schema ? Sequel::SQL::QualifiedIdentifier.new(schema, table) : table
@column = opts[:column] || self.class.const_get(:DEFAULT_SCHEMA_COLUMN)
@ds = schema_dataset
end
View
34 spec/extensions/migration_spec.rb
@@ -202,7 +202,7 @@ def initialize(*args)
@drops = []
@tables_created = []
@columns_created = []
- @versions = {}
+ @versions = Hash.new{|h,k| h[k.to_sym]}
end
def version; versions.values.first || 0; end
@@ -212,7 +212,7 @@ def drop_table(*a); super; @drops.concat(a.map{|x| y = x.to_s; y !~ /\Asm(\d+)/;
def create_table(name, opts={}, &block)
super
@columns_created << / \(?(\w+) integer.*\)?\z/.match(sqls.last)[1].to_sym
- @tables_created << name
+ @tables_created << name.to_sym
end
def dataset(opts={})
@@ -228,7 +228,7 @@ def fetch_rows(sql); db.execute(sql); yield(db.versions) unless db.versions.empt
end
def table_exists?(name)
- @tables_created.include?(name)
+ @tables_created.include?(name.to_sym)
end
end
@db = dbc.new
@@ -250,7 +250,7 @@ def table_exists?(name)
specify "should add a column name if it doesn't already exist in the schema_info table" do
@db.create_table(:schema_info){Integer :v}
- @db.should_receive(:alter_table).with(:schema_info)
+ @db.should_receive(:alter_table).with('schema_info')
Sequel::Migrator.apply(@db, @dirname)
end
@@ -320,45 +320,45 @@ def table_exists?(name)
@dsc = dsc = Class.new(MockDataset) do
def columns
case opts[:from].first
- when :schema_info
+ when :schema_info, 'schema_info'
[:version]
- when :schema_migrations
+ when :schema_migrations, 'schema_migrations'
[:filename]
- when :sm
+ when :sm, 'sm'
[:fn]
end
end
def fetch_rows(sql)
case opts[:from].first
- when :schema_info
+ when :schema_info, 'schema_info'
yield({:version=>$sequel_migration_version})
- when :schema_migrations
+ when :schema_migrations, 'schema_migrations'
$sequel_migration_files.sort.each{|f| yield(:filename=>f)}
- when :sm
+ when :sm, 'sm'
$sequel_migration_files.sort.each{|f| yield(:fn=>f)}
end
end
def insert(h={})
case opts[:from].first
- when :schema_info
+ when :schema_info, 'schema_info'
$sequel_migration_version = h.values.first
- when :schema_migrations, :sm
+ when :schema_migrations, :sm, 'schema_migrations', 'sm'
$sequel_migration_files << h.values.first
end
end
def update(h={})
case opts[:from].first
- when :schema_info
+ when :schema_info, 'schema_info'
$sequel_migration_version = h.values.first
end
end
def delete
case opts[:from].first
- when :schema_migrations, :sm
+ when :schema_migrations, :sm, 'schema_migrations', 'sm'
$sequel_migration_files.delete(opts[:where].args.last)
end
end
@@ -366,9 +366,9 @@ def delete
dbc = Class.new(MockDatabase) do
tables = {}
define_method(:dataset){|*a| dsc.new(self, *a)}
- define_method(:create_table){|name, *args| tables[name] = true}
- define_method(:drop_table){|*names| names.each{|n| tables.delete(n)}}
- define_method(:table_exists?){|name| tables.has_key?(name)}
+ define_method(:create_table){|name, *args| tables[name.to_sym] = true}
+ define_method(:drop_table){|*names| names.each{|n| tables.delete(n.to_sym)}}
+ define_method(:table_exists?){|name| tables.has_key?(name.to_sym)}
end
@db = dbc.new
@m = Sequel::Migrator
Please sign in to comment.
Something went wrong with that request. Please try again.