From 08a282e72291a3936919e3a77ed2305dea70080b Mon Sep 17 00:00:00 2001 From: sophon Date: Tue, 11 Nov 2025 14:55:13 +0800 Subject: [PATCH] modify scripts --- .../my_sqlalchemy/migrations/resources/env.py | 48 +++++++++---------- ...cbcd23e2815_auto_update_from_resources.py} | 23 +++++++-- 2 files changed, 44 insertions(+), 27 deletions(-) rename scrapy_proj/my_sqlalchemy/migrations/resources/versions/{0b2c66f54410_auto_update_from_resources.py => 3cbcd23e2815_auto_update_from_resources.py} (72%) diff --git a/scrapy_proj/my_sqlalchemy/migrations/resources/env.py b/scrapy_proj/my_sqlalchemy/migrations/resources/env.py index f922a18..d099b1c 100644 --- a/scrapy_proj/my_sqlalchemy/migrations/resources/env.py +++ b/scrapy_proj/my_sqlalchemy/migrations/resources/env.py @@ -25,30 +25,6 @@ target_metadata = None # my_important_option = config.get_main_option("my_important_option") # ... 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 from alembic import context from sqlalchemy import create_engine @@ -65,6 +41,30 @@ def get_mysql_url(): else: 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: """Run migrations in 'online' mode. diff --git a/scrapy_proj/my_sqlalchemy/migrations/resources/versions/0b2c66f54410_auto_update_from_resources.py b/scrapy_proj/my_sqlalchemy/migrations/resources/versions/3cbcd23e2815_auto_update_from_resources.py similarity index 72% rename from scrapy_proj/my_sqlalchemy/migrations/resources/versions/0b2c66f54410_auto_update_from_resources.py rename to scrapy_proj/my_sqlalchemy/migrations/resources/versions/3cbcd23e2815_auto_update_from_resources.py index 5f8f2fd..6853bbe 100644 --- a/scrapy_proj/my_sqlalchemy/migrations/resources/versions/0b2c66f54410_auto_update_from_resources.py +++ b/scrapy_proj/my_sqlalchemy/migrations/resources/versions/3cbcd23e2815_auto_update_from_resources.py @@ -1,8 +1,8 @@ """Auto update from resources -Revision ID: 0b2c66f54410 +Revision ID: 3cbcd23e2815 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 @@ -12,7 +12,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision: str = '0b2c66f54410' +revision: str = '3cbcd23e2815' down_revision: Union[str, Sequence[str], None] = '758b3971a51e' branch_labels: 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: """Upgrade schema.""" # ### 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', sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='主键ID'), 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('sis') op.drop_table('clm_keywords') + op.drop_table('clm_index') # ### end Alembic commands ###