sqlalchemy / sqlalchemy/alembic
IF (NOT) EXISTS for ALTER TABLE sub-commands like constraints etc
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 375
- PR merge metrics
- No merged PRs in 30d
Description
Hello, forgive me if an issue already exists for this, I have seen a related one here but that is several years old and status is unclear.
There doesn't seem to be an option to add IF (NOT) EXISTS or CASCADE flags to queries generated by e.g. op.create_unique_constraint or op.drop_index. Here are some raw queries I've added and directly executed lately:
DROP INDEX ix_host_ip
CASCADE;
or
ALTER TABLE host
DROP CONSTRAINT IF EXISTS vuln_occurrence_unique_constraint
CASCADE;
I would like to be able to create these with alembic, for example:
op.drop_index('ix_host_ip', table_name='host', cascade=True)
op.drop_constraint_if_exists('vuln_occurrence_host_ip_fkey', 'vuln_occurrence', type_='foreignkey', cascade=True)
(The syntax could be different to better fit the style of existing commands, if needed.)
I haven't contributed yet but I might be able to work on this issue if it is deemed a worthwhile change to the project.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing op.create_unique_constraint and op.drop_index operation APIs and how they generate ALTER TABLE and DROP INDEX SQL. Check the related issue and current dialect behavior; done means a consistent API for the requested IF (NOT) EXISTS and CASCADE options, with coverage for the affected operations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sql, sqlalchemy
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100