Add drop="if_exists" support to todb()#695
Conversation
Review Summary by QodoAdd drop='if_exists' support to todb() for idempotent operations
WalkthroughsDescription• Add drop='if_exists' mode to todb() for idempotent table recreation • Allow table drops without raising errors if table missing • Preserve existing drop=True behavior with normal DROP TABLE • Add comprehensive tests and documentation for new feature Diagramflowchart LR
A["todb() with drop parameter"] -->|drop=True| B["DROP TABLE"]
A -->|drop='if_exists'| C["DROP TABLE IF EXISTS"]
A -->|drop=False| D["Skip drop"]
B --> E["Create table"]
C --> E
D --> E
E --> F["Load data"]
File Changes1. petl/io/db.py
|
Code Review by Qodo
Context used✅ Tickets:
🎫 Feature Request: Drop table if exists 1. Unvalidated drop string
|
Coverage Report for CI Build 26760053583Coverage increased (+0.03%) to 90.992%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
|
Thanks for taking a look. I noticed the
This appears to happen after the Codacy analysis step completes, during The local DB tests for this PR passed:
Result:
The warnings are existing sqlite generator cleanup warnings from Please let me know if you would like any changes to the PR itself. |
Closes #666.
This PR has the objective of adding an idempotent drop mode to
todb()so ETL jobs can recreate target tables whether or not the table already exists.Changes
drop="if_exists"when usingtodb(..., create=True).todb()to calldrop_table(..., if_exists=True)before creating the table.drop=Truebehavior, which still issues a normalDROP TABLEand raises if the table does not exist.DROP TABLE IF EXISTSonly for the newif_existsmode.drop="if_exists"behavior.docs/changes.rst.Testing
.venv/bin/python -m pytest petl/test/io/test_db.py petl/test/io/test_db_create.pyResult:
12 passed, 2 skipped, 2 warningsThe warnings are existing sqlite generator cleanup warnings from
test_fromdb.Checklist
Use this checklist to ensure the quality of pull requests that include new code and/or make changes to existing code.
tox/pytestmasterbranch and tested before sending the PR