db: add table article
This commit is contained in:
@ -7,6 +7,7 @@ from alembic import context
|
||||
|
||||
from models.base import Base
|
||||
import models.source_content # 导入模型以注册到 Base.metadata
|
||||
import models.article # 导入模型以注册到 Base.metadata
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
|
||||
42
migrations/versions/7de2da2e824b_add_table_article.py
Normal file
42
migrations/versions/7de2da2e824b_add_table_article.py
Normal file
@ -0,0 +1,42 @@
|
||||
"""add table article
|
||||
|
||||
Revision ID: 7de2da2e824b
|
||||
Revises: dfad2ce9d3b7
|
||||
Create Date: 2026-02-15 15:11:54.662014
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '7de2da2e824b'
|
||||
down_revision: Union[str, Sequence[str], None] = 'dfad2ce9d3b7'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('t_article',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='自动递增的唯一内容ID'),
|
||||
sa.Column('title', sa.String(length=256), nullable=False, comment='标题'),
|
||||
sa.Column('keywords', sa.Text(), nullable=True, comment='关键词'),
|
||||
sa.Column('content', sa.Text(), nullable=True, comment='内容'),
|
||||
sa.Column('create_time', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False, comment='创建时间'),
|
||||
sa.Column('used', sa.Boolean(), nullable=False, comment='是否已被使用'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_t_article_title'), 't_article', ['title'], unique=False)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index(op.f('ix_t_article_title'), table_name='t_article')
|
||||
op.drop_table('t_article')
|
||||
# ### end Alembic commands ###
|
||||
32
migrations/versions/dfad2ce9d3b7_add_table_article.py
Normal file
32
migrations/versions/dfad2ce9d3b7_add_table_article.py
Normal file
@ -0,0 +1,32 @@
|
||||
"""add table article
|
||||
|
||||
Revision ID: dfad2ce9d3b7
|
||||
Revises: fc8b7693c66b
|
||||
Create Date: 2026-02-15 15:09:51.788382
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'dfad2ce9d3b7'
|
||||
down_revision: Union[str, Sequence[str], None] = 'fc8b7693c66b'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
50
models/article.py
Normal file
50
models/article.py
Normal file
@ -0,0 +1,50 @@
|
||||
from datetime import datetime
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy import String, Text, Integer, DateTime, func
|
||||
from models.base import Base
|
||||
|
||||
|
||||
class Article(Base):
|
||||
__tablename__ = "t_article"
|
||||
|
||||
id: Mapped[int] = mapped_column(
|
||||
Integer,
|
||||
primary_key=True,
|
||||
autoincrement=True,
|
||||
comment="自动递增的唯一内容ID"
|
||||
)
|
||||
|
||||
title: Mapped[str] = mapped_column(
|
||||
String(256),
|
||||
nullable=False,
|
||||
index=True,
|
||||
comment="标题"
|
||||
)
|
||||
|
||||
keywords: Mapped[str | None] = mapped_column(
|
||||
Text,
|
||||
nullable=True,
|
||||
comment="关键词"
|
||||
)
|
||||
|
||||
content: Mapped[str | None] = mapped_column(
|
||||
Text,
|
||||
nullable=True,
|
||||
comment="内容"
|
||||
)
|
||||
|
||||
create_time: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
server_default=func.now(),
|
||||
nullable=False,
|
||||
comment="创建时间"
|
||||
)
|
||||
|
||||
used: Mapped[bool] = mapped_column(
|
||||
default=False,
|
||||
nullable=False,
|
||||
comment="是否已被使用"
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Article id={self.id} title={self.title!r} used={self.used!r}>"
|
||||
Reference in New Issue
Block a user