Skip to content

Commit

Permalink
Do not pass schema in view name as pg_class stores relname without sc…
Browse files Browse the repository at this point in the history
…hema prefix
  • Loading branch information
drnic authored and derekprior committed Mar 28, 2024
1 parent b371800 commit 618c517
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/scenic/adapters/postgres.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ def refresh_materialized_view(name, concurrently: false, cascade: false)
def populated?(name)
raise_unless_materialized_views_supported

sql = "SELECT relispopulated FROM pg_class WHERE relname = '#{name}'"
schemaless_name = name.split(".").last

sql = "SELECT relispopulated FROM pg_class WHERE relname = '#{schemaless_name}'"
relations = execute(sql)

if relations.count.positive?
Expand Down
12 changes: 12 additions & 0 deletions spec/scenic/adapters/postgres_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,18 @@ module Adapters
expect(adapter.populated?("greetings")).to be true
end

it "strips out the schema from table_name" do
adapter = Postgres.new

ActiveRecord::Base.connection.execute <<-SQL
CREATE MATERIALIZED VIEW greetings AS
SELECT text 'hi' AS greeting
WITH NO DATA
SQL

expect(adapter.populated?("public.greetings")).to be false
end

it "raises an exception if the version of PostgreSQL is too old" do
connection = double("Connection", supports_materialized_views?: false)
connectable = double("Connectable", connection: connection)
Expand Down

0 comments on commit 618c517

Please sign in to comment.