-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🗃️ changed UUID to String(36) for IDs
- Loading branch information
Showing
2 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
alembic/versions/1df6ff5028e4_change_uuid_to_str_for_pks.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,83 @@ | ||
"""change UUID to Str for PKs | ||
Revision ID: 1df6ff5028e4 | ||
Revises: b77bb559f678 | ||
Create Date: 2023-11-18 12:02:17.505398 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "1df6ff5028e4" | ||
down_revision = "b77bb559f678" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
|
||
# Drop the constraint | ||
op.execute('ALTER TABLE message DROP CONSTRAINT message_interaction_id_fkey') | ||
|
||
# Change the type of 'id' in 'interaction' table | ||
op.alter_column( | ||
"interaction", | ||
"id", | ||
existing_type=postgresql.UUID(), | ||
type_=sa.String(length=36), | ||
existing_nullable=False, | ||
) | ||
|
||
# Change the type of 'id' and 'interaction_id' in 'message' table | ||
op.alter_column( | ||
"message", | ||
"id", | ||
existing_type=postgresql.UUID(), | ||
type_=sa.String(length=36), | ||
existing_nullable=False, | ||
) | ||
op.alter_column( | ||
"message", | ||
"interaction_id", | ||
existing_type=postgresql.UUID(), | ||
type_=sa.String(), | ||
existing_nullable=True, | ||
) | ||
|
||
# Add the constraints back | ||
op.create_unique_constraint(None, "interaction", ["id"]) | ||
op.create_unique_constraint(None, "message", ["id"]) | ||
op.execute('ALTER TABLE message ADD CONSTRAINT message_interaction_id_fkey FOREIGN KEY(interaction_id) REFERENCES interaction(id)') | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_constraint(None, "message", type_="unique") | ||
op.alter_column( | ||
"message", | ||
"interaction_id", | ||
existing_type=sa.String(), | ||
type_=postgresql.UUID(), | ||
existing_nullable=True, | ||
) | ||
op.alter_column( | ||
"message", | ||
"id", | ||
existing_type=sa.String(length=36), | ||
type_=postgresql.UUID(), | ||
existing_nullable=False, | ||
) | ||
op.drop_constraint(None, "interaction", type_="unique") | ||
op.alter_column( | ||
"interaction", | ||
"id", | ||
existing_type=sa.String(length=36), | ||
type_=postgresql.UUID(), | ||
existing_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