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

Run delete_everything inside a transaction #2273

Closed
simonw opened this issue Feb 16, 2024 · 1 comment
Closed

Run delete_everything inside a transaction #2273

simonw opened this issue Feb 16, 2024 · 1 comment
Labels

Comments

@simonw
Copy link
Owner

simonw commented Feb 16, 2024

This should use an explicit transaction to avoid "database locked" errors:

async def populate_schema_tables(internal_db, db):
database_name = db.name
def delete_everything(conn):
conn.execute(
"DELETE FROM catalog_tables WHERE database_name = ?", [database_name]
)
conn.execute(
"DELETE FROM catalog_columns WHERE database_name = ?", [database_name]
)
conn.execute(
"DELETE FROM catalog_foreign_keys WHERE database_name = ?", [database_name]
)
conn.execute(
"DELETE FROM catalog_indexes WHERE database_name = ?", [database_name]
)
await internal_db.execute_write_fn(delete_everything)

@simonw simonw added the bug label Feb 16, 2024
@simonw
Copy link
Owner Author

simonw commented Feb 16, 2024

This keeps on coming up with datasette.execute_write_fn() - I think it should automatically wrap a transaction around the function that gets executed.

@simonw simonw closed this as completed in 97de4d6 Feb 16, 2024
@simonw simonw added this to the Datasette 1.0a9 milestone Feb 16, 2024
simonw added a commit that referenced this issue Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant