33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
"""账号自选学时判断依据,并增加公告。"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
revision = "0015_account_source_and_notices"
|
|
down_revision = "0014_official_month_hours"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
with op.batch_alter_table("accounts") as batch:
|
|
batch.add_column(sa.Column("hours_source", sa.String(length=16), server_default="api", nullable=False))
|
|
op.execute(
|
|
"UPDATE accounts SET hours_source = COALESCE("
|
|
"(SELECT hours_source FROM system_config ORDER BY id LIMIT 1), 'api')"
|
|
)
|
|
op.create_table(
|
|
"announcements",
|
|
sa.Column("id", sa.Integer(), primary_key=True),
|
|
sa.Column("title", sa.String(length=80), nullable=False),
|
|
sa.Column("body", sa.Text(), nullable=False),
|
|
sa.Column("link_url", sa.String(length=300), server_default="", nullable=False),
|
|
sa.Column("published_at", sa.DateTime(timezone=True), nullable=False),
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_table("announcements")
|
|
with op.batch_alter_table("accounts") as batch:
|
|
batch.drop_column("hours_source")
|