Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hpaul/7f311a1edf5ddf44a35536824dbb49fd to your computer and use it in GitHub Desktop.
Save hpaul/7f311a1edf5ddf44a35536824dbb49fd to your computer and use it in GitHub Desktop.
"""2023-10-25_FY-34010_add-source-to-class-resource
/home/paulh/apps/finetune/service-fym/submodules/ft-core/migrations/versions/2023_10_25_fy_34010_add_source_to_class__2be8a742c105.py
Revision ID: 2be8a742c105
Revises: 6088d1b424e3
Create Date: 2023-10-25 15:10:40.516490
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '2be8a742c105'
down_revision = '6088d1b424e3'
branch_labels = None
depends_on = None
def upgrade():
with op.get_context().autocommit_block():
op.execute("ALTER TYPE shared_resource_to_class_resource_type ADD VALUE 'SourceResourse'")
def downgrade():
# Inspired by https://makimo.com/blog/upgrading-postgresqls-enum-type-with-sqlalchemy-using-alembic-migration/
op.execute("ALTER TYPE shared_resource_to_class_resource_type RENAME TO shared_resource_to_class_resource_type_old")
op.execute("CREATE TYPE shared_resource_to_class_resource_type AS ENUM('URLResource', 'EmbeddedVideoResource')")
op.execute((
"ALTER TABLE shared_resource_to_class ALTER COLUMN resource_type TYPE shared_resource_to_class_resource_type USING "
"resource_type::text::shared_resource_to_class_resource_type"
))
op.execute("DROP TYPE shared_resource_to_class_resource_type_old")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment