完全跑通1.0版本

This commit is contained in:
2026-05-26 12:56:03 +08:00
parent 2ece5174a7
commit 93c714a93b
11557 changed files with 1648225 additions and 36 deletions

55
backend/alembic/env.py Normal file
View File

@@ -0,0 +1,55 @@
import asyncio
from logging.config import fileConfig
from sqlalchemy import pool
from sqlalchemy.ext.asyncio import async_engine_from_config
from alembic import context
config = context.config
if config.config_file_name is not None:
fileConfig(config.config_file_name)
# Import all models so Alembic can detect schema changes
from app.models.news import Base # noqa: E402
target_metadata = Base.metadata
def run_migrations_offline() -> None:
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()
def do_run_migrations(connection):
context.configure(connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
async def run_async_migrations() -> None:
connectable = async_engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
async with connectable.connect() as connection:
await connection.run_sync(do_run_migrations)
await connectable.dispose()
def run_migrations_online() -> None:
asyncio.run(run_async_migrations())
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

View File

@@ -0,0 +1,25 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
revision: str = ${repr(up_revision)}
down_revision: Union[str, None] = ${repr(down_revision)}
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
def upgrade() -> None:
${upgrades if upgrades else "pass"}
def downgrade() -> None:
${downgrades if downgrades else "pass"}

View File

@@ -0,0 +1,95 @@
"""initial schema
Revision ID: 0001
Revises:
Create Date: 2026-05-26
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision: str = "0001"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table(
"news_sources",
sa.Column("id", sa.Integer(), primary_key=True),
sa.Column("name", sa.String(100), nullable=False),
sa.Column("url", sa.String(500), nullable=False),
sa.Column("source_type", sa.String(20), nullable=False, server_default="rss"),
sa.Column("language", sa.String(5), nullable=False, server_default="zh"),
sa.Column("category", sa.String(50), nullable=True),
sa.Column("is_active", sa.Boolean(), nullable=False, server_default="true"),
sa.Column("created_at", sa.DateTime(), nullable=False),
)
op.create_table(
"raw_news",
sa.Column("id", sa.Integer(), primary_key=True),
sa.Column("source_id", sa.Integer(), sa.ForeignKey("news_sources.id"), nullable=True),
sa.Column("title", sa.String(500), nullable=False),
sa.Column("url", sa.String(1000), nullable=False, unique=True),
sa.Column("raw_content", sa.Text(), nullable=True),
sa.Column("published_at", sa.DateTime(), nullable=True),
sa.Column("crawled_at", sa.DateTime(), nullable=False),
sa.Column("status", sa.String(20), nullable=False, server_default="pending"),
)
op.create_table(
"processed_news",
sa.Column("id", sa.Integer(), primary_key=True),
sa.Column("raw_news_id", sa.Integer(), sa.ForeignKey("raw_news.id"), nullable=False),
sa.Column("title_zh", sa.String(500), nullable=False),
sa.Column("summary", sa.Text(), nullable=False),
sa.Column("opinion", sa.Text(), nullable=True),
sa.Column("keywords", postgresql.ARRAY(sa.String()), nullable=True),
sa.Column("importance_score", sa.Float(), nullable=False, server_default="5.0"),
sa.Column("importance_reason", sa.Text(), nullable=True),
sa.Column("category", sa.String(50), nullable=False, server_default="行业动态"),
sa.Column("is_featured", sa.Boolean(), nullable=False, server_default="false"),
sa.Column("featured_rank", sa.Integer(), nullable=True),
sa.Column("source_name", sa.String(200), nullable=True),
sa.Column("source_url", sa.String(1000), nullable=True),
sa.Column("published_at", sa.DateTime(), nullable=True),
sa.Column("processed_at", sa.DateTime(), nullable=False),
)
op.create_table(
"llm_config",
sa.Column("id", sa.Integer(), primary_key=True),
sa.Column("name", sa.String(100), nullable=False),
sa.Column("provider", sa.String(50), nullable=False),
sa.Column("api_key", sa.String(500), nullable=False),
sa.Column("base_url", sa.String(500), nullable=False),
sa.Column("model_name", sa.String(200), nullable=False),
sa.Column("is_active", sa.Boolean(), nullable=False, server_default="true"),
sa.Column("created_at", sa.DateTime(), nullable=False),
)
op.create_table(
"system_logs",
sa.Column("id", sa.Integer(), primary_key=True),
sa.Column("event_type", sa.String(50), nullable=False),
sa.Column("message", sa.Text(), nullable=False),
sa.Column("level", sa.String(20), nullable=False, server_default="INFO"),
sa.Column("created_at", sa.DateTime(), nullable=False),
)
op.create_index("ix_raw_news_status", "raw_news", ["status"])
op.create_index("ix_processed_news_processed_at", "processed_news", ["processed_at"])
op.create_index("ix_processed_news_is_featured", "processed_news", ["is_featured"])
def downgrade() -> None:
op.drop_table("system_logs")
op.drop_table("llm_config")
op.drop_table("processed_news")
op.drop_table("raw_news")
op.drop_table("news_sources")