diff --git a/lms/migrations/versions/b512a5cf64ed_public_id_migration.py b/lms/migrations/versions/b512a5cf64ed_public_id_migration.py new file mode 100644 index 0000000000..d16d6b3cb0 --- /dev/null +++ b/lms/migrations/versions/b512a5cf64ed_public_id_migration.py @@ -0,0 +1,29 @@ +"""Public ID migration + +Revision ID: b512a5cf64ed +Revises: 329313b38de1 +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +revision = "b512a5cf64ed" +down_revision = "329313b38de1" + + +def upgrade() -> None: + conn = op.get_bind() + conn.execute( + sa.text( + """UPDATE "organization" set public_id = 'us.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);""" + ) + )