modify scripts

This commit is contained in:
2025-11-11 14:55:13 +08:00
parent bd6e1b6ed8
commit 08a282e722
2 changed files with 44 additions and 27 deletions

View File

@ -25,30 +25,6 @@ target_metadata = None
# my_important_option = config.get_main_option("my_important_option") # my_important_option = config.get_main_option("my_important_option")
# ... etc. # ... etc.
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
import os import os
from alembic import context from alembic import context
from sqlalchemy import create_engine from sqlalchemy import create_engine
@ -65,6 +41,30 @@ def get_mysql_url():
else: else:
return "mysql+pymysql://root:mysqlpw@testdb:3306/resources" return "mysql+pymysql://root:mysqlpw@testdb:3306/resources"
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = get_mysql_url()
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online() -> None: def run_migrations_online() -> None:
"""Run migrations in 'online' mode. """Run migrations in 'online' mode.

View File

@ -1,8 +1,8 @@
"""Auto update from resources """Auto update from resources
Revision ID: 0b2c66f54410 Revision ID: 3cbcd23e2815
Revises: 758b3971a51e Revises: 758b3971a51e
Create Date: 2025-11-10 15:21:58.323573 Create Date: 2025-11-11 12:06:44.924577
""" """
from typing import Sequence, Union from typing import Sequence, Union
@ -12,7 +12,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision: str = '0b2c66f54410' revision: str = '3cbcd23e2815'
down_revision: Union[str, Sequence[str], None] = '758b3971a51e' down_revision: Union[str, Sequence[str], None] = '758b3971a51e'
branch_labels: Union[str, Sequence[str], None] = None branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None
@ -21,6 +21,22 @@ depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None: def upgrade() -> None:
"""Upgrade schema.""" """Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('clm_index',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='主键ID'),
sa.Column('category', sa.Text(), nullable=True, comment='分类'),
sa.Column('title', sa.Text(), nullable=True, comment='标题'),
sa.Column('href', sa.String(length=512), nullable=True, comment='资源链接(唯一)'),
sa.Column('magnet_href', sa.Text(), nullable=True, comment='磁力链接'),
sa.Column('size_text', sa.Text(), nullable=True, comment='大小文本描述'),
sa.Column('size_gb', sa.Float(), nullable=True, comment='大小GB'),
sa.Column('heat', sa.Integer(), nullable=True, comment='热度'),
sa.Column('add_date', sa.Text(), nullable=True, comment='添加日期'),
sa.Column('last_down_date', sa.Text(), nullable=True, comment='最后下载日期'),
sa.Column('created_at', sa.DateTime(), nullable=True, comment='创建时间(本地时间)'),
sa.Column('updated_at', sa.DateTime(), nullable=True, comment='更新时间(本地时间)'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('href')
)
op.create_table('clm_keywords', op.create_table('clm_keywords',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='主键ID'), sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='主键ID'),
sa.Column('words', sa.String(length=512), nullable=True, comment='关键词(唯一)'), sa.Column('words', sa.String(length=512), nullable=True, comment='关键词(唯一)'),
@ -67,4 +83,5 @@ def downgrade() -> None:
op.drop_table('clm_keywords_index') op.drop_table('clm_keywords_index')
op.drop_table('sis') op.drop_table('sis')
op.drop_table('clm_keywords') op.drop_table('clm_keywords')
op.drop_table('clm_index')
# ### end Alembic commands ### # ### end Alembic commands ###