-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration to include the full "us.lms.org" in Organization.public_id
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
lms/migrations/versions/b512a5cf64ed_public_id_migration.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,33 @@ | ||
"""Public ID migration. | ||
Revision ID: b512a5cf64ed | ||
Revises: 329313b38de1 | ||
""" | ||
|
||
import os | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
revision = "b512a5cf64ed" | ||
down_revision = "329313b38de1" | ||
|
||
|
||
def upgrade() -> None: | ||
region = os.environ["REGION_CODE"] | ||
conn = op.get_bind() | ||
conn.execute( | ||
sa.text( | ||
f"""UPDATE "organization" set public_id = '{region}.lms.org.' || "public_id";""" | ||
) | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
conn = op.get_bind() | ||
conn.execute( | ||
sa.text( | ||
"""UPDATE "organization" set public_id = split_part("public_id", '.', 4);""" | ||
) | ||
) |