PCv5/migrations/versions/72df33816b21_switched_attac...

35 lines
1.1 KiB
Python

"""Switched attachment id to UUID
Revision ID: 72df33816b21
Revises: d2227d2479e2
Create Date: 2022-04-26 21:50:05.466388
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = '72df33816b21'
down_revision = 'd2227d2479e2'
branch_labels = None
depends_on = None
def upgrade():
# Create uuid-ossp extension, required to use uuid_generate_v4()
op.execute('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";')
# /!\ This operation will break all attachments /!\
op.execute("""ALTER TABLE attachment ALTER COLUMN id DROP DEFAULT,
ALTER COLUMN id SET DATA TYPE UUID USING (uuid_generate_v4()),
ALTER COLUMN id SET DEFAULT uuid_generate_v4();""")
# ### end Alembic commands ###
def downgrade():
# /!\ This operation will break all attachments /!\
op.execute("""ALTER TABLE attachment ALTER COLUMN id DROP DEFAULT,
ALTER COLUMN id SET DATA TYPE integer USING nextval('attachment_id_seq'::regclass),
ALTER COLUMN id SET DEFAULT nextval('attachment_id_seq'::regclass);""")
# ### end Alembic commands ###