Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip out any view schema prefix in populated?(name) #406

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading