Skip to content

Commit

Permalink
Use unprivileged PostgreSQL role for testing
Browse files Browse the repository at this point in the history
In your test environment config, put something like
config.test_role = :your_frontend_db_role

crashtech/torque-postgresql#33
  • Loading branch information
mlt committed Jul 14, 2019
1 parent ae145f8 commit caa081e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def disable_referential_integrity # :nodoc:
original_exception = nil

begin
execute('reset role')
transaction(requires_new: true) do
execute(tables_with_schema_all.collect { |name| "ALTER TABLE #{name} DISABLE TRIGGER ALL" }.join(";"))
end
Expand All @@ -34,6 +35,10 @@ def disable_referential_integrity # :nodoc:
transaction(requires_new: true) do
execute(tables_with_schema_all.collect { |name| "ALTER TABLE #{name} ENABLE TRIGGER ALL" }.join(";"))
end
r = Rails.configuration.test_role
if r.present?
execute("set role #{r}")
end
rescue ActiveRecord::ActiveRecordError
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,12 @@ def reset_pk_sequence!(table, pk = nil, sequence = nil) #:nodoc:
end
end

execute('reset role')
query_value("SELECT setval(#{quote(quoted_sequence)}, #{max_pk ? max_pk : minvalue}, #{max_pk ? true : false})", "SCHEMA")
r = Rails.configuration.test_role
if r.present?
execute("set role #{r}")
end
end
end

Expand Down

0 comments on commit caa081e

Please sign in to comment.