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

fixtures: use unlogged tables for PostgreSQL #106

Merged
merged 1 commit into from
Jan 29, 2024
Merged
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
13 changes: 13 additions & 0 deletions pytest_invenio/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,19 @@ def database(appctx):

if not database_exists(str(db_.engine.url)):
create_database(str(db_.engine.url))

# Use unlogged tables for PostgreSQL (see https://github.com/sqlalchemy/alembic/discussions/1108)
if db_.engine.name == "postgresql":
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.schema import CreateTable

@compiles(CreateTable)
def _compile_unlogged(element, compiler, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment with linking to the alembic discussion for context?

return compiler.visit_create_table(element).replace(
"CREATE TABLE ",
"CREATE UNLOGGED TABLE ",
)

db_.create_all()

yield db_
Expand Down
Loading