Merge pull request #1547 from MODSetter/dev

feat(hotpatch): fix migration 168
This commit is contained in:
Rohan Verma 2026-06-26 11:31:50 -07:00 committed by GitHub
commit cdc7c8ff7f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -17,35 +17,49 @@ depends_on: str | Sequence[str] | None = None
def upgrade() -> None: def upgrade() -> None:
op.add_column( op.execute(
"refresh_tokens", "ALTER TABLE refresh_tokens ADD COLUMN IF NOT EXISTS "
sa.Column("revoked_at", sa.TIMESTAMP(timezone=True), nullable=True), "revoked_at TIMESTAMP WITH TIME ZONE"
) )
op.add_column( op.execute(
"refresh_tokens", "ALTER TABLE refresh_tokens ADD COLUMN IF NOT EXISTS "
sa.Column("absolute_expiry", sa.TIMESTAMP(timezone=True), nullable=True), "absolute_expiry TIMESTAMP WITH TIME ZONE"
) )
bind = op.get_bind()
is_revoked_exists = bind.execute(
sa.text(
"""
SELECT EXISTS (
SELECT FROM information_schema.columns
WHERE table_schema = current_schema()
AND table_name = 'refresh_tokens'
AND column_name = 'is_revoked'
)
"""
)
).scalar()
if is_revoked_exists:
op.execute( op.execute(
""" """
UPDATE refresh_tokens UPDATE refresh_tokens
SET revoked_at = NOW() SET revoked_at = NOW()
WHERE is_revoked = TRUE WHERE is_revoked = TRUE
AND revoked_at IS NULL
""" """
) )
op.alter_column(
"refresh_tokens", op.execute(
"token_hash", "ALTER TABLE refresh_tokens ALTER COLUMN token_hash TYPE VARCHAR(64)"
existing_type=sa.String(length=256),
type_=sa.String(length=64),
existing_nullable=False,
) )
op.drop_column("refresh_tokens", "is_revoked") op.execute("ALTER TABLE refresh_tokens DROP COLUMN IF EXISTS is_revoked")
def downgrade() -> None: def downgrade() -> None:
op.add_column( op.execute(
"refresh_tokens", "ALTER TABLE refresh_tokens ADD COLUMN IF NOT EXISTS "
sa.Column("is_revoked", sa.Boolean(), nullable=False, server_default="false"), "is_revoked BOOLEAN NOT NULL DEFAULT false"
) )
op.execute( op.execute(
""" """
@ -54,13 +68,9 @@ def downgrade() -> None:
WHERE revoked_at IS NOT NULL WHERE revoked_at IS NOT NULL
""" """
) )
op.alter_column("refresh_tokens", "is_revoked", server_default=None) op.execute("ALTER TABLE refresh_tokens ALTER COLUMN is_revoked DROP DEFAULT")
op.alter_column( op.execute(
"refresh_tokens", "ALTER TABLE refresh_tokens ALTER COLUMN token_hash TYPE VARCHAR(256)"
"token_hash",
existing_type=sa.String(length=64),
type_=sa.String(length=256),
existing_nullable=False,
) )
op.drop_column("refresh_tokens", "absolute_expiry") op.execute("ALTER TABLE refresh_tokens DROP COLUMN IF EXISTS absolute_expiry")
op.drop_column("refresh_tokens", "revoked_at") op.execute("ALTER TABLE refresh_tokens DROP COLUMN IF EXISTS revoked_at")