fed8b2eed7
Build and push multi-arch DocsGPT Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Has been cancelled
Backend release / release (push) Has been cancelled
Bandit Security Scan / bandit_scan (push) Has been cancelled
Build and push multi-arch DocsGPT Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Has been cancelled
Build and push multi-arch DocsGPT Docker image / manifest (push) Has been cancelled
Build and push DocsGPT FE Docker image for development / build (linux/amd64, ubuntu-latest, amd64) (push) Has been cancelled
Build and push DocsGPT FE Docker image for development / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Has been cancelled
Build and push DocsGPT FE Docker image for development / manifest (push) Has been cancelled
Python linting / ruff (push) Has been cancelled
Run python tests with pytest / Run tests and count coverage (3.12) (push) Has been cancelled
React Widget Build / build (push) Has been cancelled
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
"""0013 devices approval modes — collapse to ask/full.
|
|
|
|
Drops the ``writes-only`` mode and renames ``never`` to ``full``. Existing
|
|
rows are converted (``writes-only`` -> ``ask``, ``never`` -> ``full``) and
|
|
the CHECK constraint is rewritten to allow only ``ask`` / ``full``.
|
|
|
|
Revision ID: 0013_devices_approval_modes
|
|
Revises: 0012_remote_devices
|
|
"""
|
|
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
|
|
|
|
revision: str = "0013_devices_approval_modes"
|
|
down_revision: Union[str, None] = "0012_remote_devices"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Drop the old constraint before rewriting values so the conversion
|
|
# never trips the stale CHECK.
|
|
op.execute(
|
|
"ALTER TABLE devices DROP CONSTRAINT IF EXISTS devices_approval_mode_chk;"
|
|
)
|
|
op.execute(
|
|
"UPDATE devices SET approval_mode = 'ask' WHERE approval_mode = 'writes-only';"
|
|
)
|
|
op.execute(
|
|
"UPDATE devices SET approval_mode = 'full' WHERE approval_mode = 'never';"
|
|
)
|
|
op.execute(
|
|
"ALTER TABLE devices ADD CONSTRAINT devices_approval_mode_chk "
|
|
"CHECK (approval_mode IN ('ask', 'full'));"
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
# ``never`` is restored from ``full``. ``writes-only`` is gone — rows
|
|
# that were converted to ``ask`` stay ``ask`` (no reverse mapping).
|
|
op.execute(
|
|
"ALTER TABLE devices DROP CONSTRAINT IF EXISTS devices_approval_mode_chk;"
|
|
)
|
|
op.execute(
|
|
"UPDATE devices SET approval_mode = 'never' WHERE approval_mode = 'full';"
|
|
)
|
|
op.execute(
|
|
"ALTER TABLE devices ADD CONSTRAINT devices_approval_mode_chk "
|
|
"CHECK (approval_mode IN ('ask', 'writes-only', 'never'));"
|
|
)
|