-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Another bunch of fixes to correctly delete users (#918)
* Another bunch of fixes to correctly delete users * Additional test * oops * Fix bug in tests
- Loading branch information
Showing
5 changed files
with
69 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
mwdb/model/migrations/versions/1a46a79d9108_set_nullable_fk_to_correctly_delete_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Set nullable FK to correctly delete users | ||
Revision ID: 1a46a79d9108 | ||
Revises: a81513c2a4bf | ||
Create Date: 2024-02-23 16:13:48.780670 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "1a46a79d9108" | ||
down_revision = "a81513c2a4bf" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column("api_key", "issued_by", existing_type=sa.INTEGER(), nullable=True) | ||
op.drop_constraint("api_key_issued_by_fkey", "api_key", type_="foreignkey") | ||
op.create_foreign_key( | ||
None, "api_key", "user", ["issued_by"], ["id"], ondelete="SET NULL" | ||
) | ||
op.drop_constraint("user_registered_by_fkey", "user", type_="foreignkey") | ||
op.create_foreign_key( | ||
None, "user", "user", ["registered_by"], ["id"], ondelete="SET NULL" | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_constraint(None, "user", type_="foreignkey") | ||
op.create_foreign_key( | ||
"user_registered_by_fkey", "user", "user", ["registered_by"], ["id"] | ||
) | ||
op.drop_constraint(None, "api_key", type_="foreignkey") | ||
op.create_foreign_key( | ||
"api_key_issued_by_fkey", "api_key", "user", ["issued_by"], ["id"] | ||
) | ||
op.alter_column("api_key", "issued_by", existing_type=sa.INTEGER(), nullable=False) | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters