Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support default_schema when reseting primary key sequences on Postgre…

…SQL (Fixes #596)
  • Loading branch information...
commit 52ad6b0b7b325a031238f9f2f6193163f3563349 1 parent b31e8f6
@jeremyevans authored
View
2  CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD
+* Support default_schema when reseting primary key sequences on PostgreSQL (jeremyevans) (#596)
+
* Allow treating tinyint(1) unsigned columns as booleans in the mysql adapters (jeremyevans)
* Support the jdbc-hsqldb gem in the jdbc adapter, since it has been updated to 2.2.9 (jeremyevans)
View
2  lib/sequel/adapters/shared/postgres.rb
@@ -429,6 +429,8 @@ def reset_primary_key_sequence(table)
pk = SQL::Identifier.new(primary_key(table))
db = self
seq_ds = db.from(LiteralString.new(seq))
+ s, t = schema_and_table(table)
+ table = Sequel.qualify(s, t) if s
get{setval(seq, db[table].select{coalesce(max(pk)+seq_ds.select{:increment_by}, seq_ds.select(:min_value))}, false)}
end
View
19 spec/adapters/postgres_spec.rb
@@ -539,6 +539,25 @@ def logger.method_missing(m, msg)
@db[:posts].insert.should == 21
@db[:posts].order(:a).map(:a).should == [1, 2, 10, 20, 21]
end
+
+ specify "should support resetting the primary key sequence with default_schema" do
+ begin
+ @db.run("DROP SCHEMA p") rescue nil
+ @db.run("CREATE SCHEMA p")
+ @db.default_schema = :p
+ @db.create_table(:posts){primary_key :a}
+ @db[:p__posts].insert(:a=>20).should == 20
+ @db[:p__posts].insert.should == 1
+ @db[:p__posts].insert.should == 2
+ @db[:p__posts].insert(:a=>10).should == 10
+ @db.reset_primary_key_sequence(:posts).should == 21
+ @db[:p__posts].insert.should == 21
+ @db[:p__posts].order(:a).map(:a).should == [1, 2, 10, 20, 21]
+ ensure
+ @db.default_schema = nil
+ @db.run("DROP SCHEMA p CASCADE")
+ end
+ end
specify "should support specifying Integer/Bignum/Fixnum types in primary keys and have them be auto incrementing" do
@db.create_table(:posts){primary_key :a, :type=>Integer}
Please sign in to comment.
Something went wrong with that request. Please try again.