mirror of
https://github.com/rommapp/romm.git
synced 2026-12-02 10:08:40 +01:00
Prevents errors when migrations are re-run against a database that already has (or has already dropped) the target indexes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
"""update to 2.0.0
|
|
|
|
Revision ID: 2.0.0
|
|
Revises: 1.8.3
|
|
Create Date: 2023-08-10 22:18:24.012779
|
|
|
|
"""
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
from sqlalchemy.dialects.postgresql import ENUM
|
|
|
|
from utils.database import is_postgresql
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = "2.0.0"
|
|
down_revision = "1.8.3"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"users",
|
|
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column("username", sa.String(length=255), nullable=True),
|
|
sa.Column("hashed_password", sa.String(length=255), nullable=True),
|
|
sa.Column("enabled", sa.Boolean(), nullable=True),
|
|
sa.Column(
|
|
"role", sa.Enum("VIEWER", "EDITOR", "ADMIN", name="role"), nullable=True
|
|
),
|
|
sa.Column("avatar_path", sa.String(length=255), nullable=True),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
if_not_exists=True,
|
|
)
|
|
with op.batch_alter_table("users", schema=None) as batch_op:
|
|
batch_op.create_index(
|
|
batch_op.f("ix_users_username"),
|
|
["username"],
|
|
unique=True,
|
|
if_not_exists=True,
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
connection = op.get_bind()
|
|
|
|
with op.batch_alter_table("users", schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f("ix_users_username"), if_exists=True)
|
|
|
|
op.drop_table("users", if_exists=True)
|
|
|
|
if is_postgresql(connection):
|
|
ENUM(name="role").drop(connection, checkfirst=False)
|