Skip to content
Open
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
6 changes: 5 additions & 1 deletion lib/sequel/extensions/pg_comment/database_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ def create_view(*args)
super

if args.last.is_a?(Hash) && args.last[:comment]
comment_on(:view, args.first, args.last[:comment])
if args.last[:materialized]
comment_on(:materialized_view, args.first, args.last[:comment])
else
comment_on(:view, args.first, args.last[:comment])
end
end
end

Expand Down
13 changes: 12 additions & 1 deletion spec/create_view_comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Sequel.connect("mock://postgres").extension(:pg_comment)
end

it "sets a table comment" do
it "sets a table comment on a view" do
db.create_view(
:gold_albums,
db[:albums].where { copies_sold > 500_000 },
Expand All @@ -15,4 +15,15 @@
expect(db.sqls.last).
to eq("COMMENT ON VIEW \"gold_albums\" IS 'Rich!'")
end

it "sets a table comment on a materialized view" do
db.create_view(
:gold_albums_mv,
db[:albums].where { copies_sold > 500_000 },
:comment => "Rich!",
:materialized => true,
)
expect(db.sqls.last).
to eq("COMMENT ON MATERIALIZED VIEW \"gold_albums_mv\" IS 'Rich!'")
end
end