"""2.0.6

Revision ID: a295e41830a6
Revises: ecf3c693fdf3
Create Date: 2024-11-14 12:49:13.838120

"""

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = 'a295e41830a6'
down_revision = 'ecf3c693fdf3'
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    # 初始化AList存储
    systemconfig = sa.table(
        "systemconfig",
        sa.column("key", sa.String()),
        sa.column("value", sa.JSON()),
    )
    connection = op.get_bind()
    key = "Storages"
    row = connection.execute(
        sa.select(systemconfig.c.value).where(systemconfig.c.key == key)
    ).first()
    _storages = row[0] if row else None
    if _storages and "alist" not in [storage["type"] for storage in _storages]:
        _storages.append({
                "type": "alist",
                "name": "AList",
                "config": {}
            })
        connection.execute(
            systemconfig.update().where(systemconfig.c.key == key).values(
                value=_storages
            )
        )

    # ### end Alembic commands ###


def downgrade() -> None:
    pass
