Skip to content

Commit 2b19745

Browse files
committed
Clear all cached schema information when using Database#drop_schema on PostgreSQL
1 parent 2670b8c commit 2b19745

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
=== master
22

3+
* Clear all cached schema information when using Database#drop_schema on PostgreSQL (jeremyevans)
4+
35
* Add Database#rename_schema on PostgreSQL (jeremyevans)
46

57
=== 5.96.0 (2025-09-01)

lib/sequel/adapters/shared/postgres.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ def drop_language(name, opts=OPTS)
571571
# :if_exists :: Don't raise an error if the schema doesn't exist.
572572
def drop_schema(name, opts=OPTS)
573573
self << drop_schema_sql(name, opts)
574+
remove_all_cached_schemas
574575
end
575576

576577
# Drops a trigger from the database. Arguments:

spec/adapters/postgres_spec.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,13 +2824,18 @@ def @Member.name; :Member; end
28242824
end
28252825

28262826
it "#create_schema and #drop_schema should create and drop schemas" do
2827-
@d.create_schema(:sequel)
2828-
@d.create_schema(:sequel, :if_not_exists=>true) if @d.server_version >= 90300
2829-
@d.create_table(Sequel[:sequel][:test]){Integer :a}
2830-
@d.tables(:schema=>:sequel).must_equal [:test]
2831-
@d.tables(:schema=>'sequel').must_equal [:test]
2832-
@d.tables(:schema=>Sequel[:sequel]).must_equal [:test]
2833-
@d.drop_schema(:sequel, :if_exists=>true, :cascade=>true)
2827+
begin
2828+
@d.create_schema(:sequel)
2829+
@d.create_schema(:sequel, :if_not_exists=>true) if @d.server_version >= 90300
2830+
@d.create_table(Sequel[:sequel][:test]){Integer :a}
2831+
@d.tables(:schema=>:sequel).must_equal [:test]
2832+
@d.tables(:schema=>'sequel').must_equal [:test]
2833+
@d.tables(:schema=>Sequel[:sequel]).must_equal [:test]
2834+
@d.schema(Sequel[:sequel][:test]).map(&:first).must_equal [:a]
2835+
ensure
2836+
@d.drop_schema(:sequel, :if_exists=>true, :cascade=>true)
2837+
proc{@d.schema(Sequel[:sequel][:test])}.must_raise Sequel::DatabaseError
2838+
end
28342839
end
28352840

28362841
it "#rename_schema should rename schema" do

0 commit comments

Comments
 (0)