diff --git a/backend/app/api/v1/module_example/demo/model.py b/backend/app/api/v1/module_example/demo/model.py index 5c2d5eaf..1ed81920 100644 --- a/backend/app/api/v1/module_example/demo/model.py +++ b/backend/app/api/v1/module_example/demo/model.py @@ -9,8 +9,7 @@ from app.core.base_model import CreatorMixin class DemoModel(CreatorMixin): """ - 示例表 - SQLAlchemy 2.0 语法 - 兼容 MySQL 和 PostgreSQL + 示例表 """ __tablename__ = 'example_demo' __table_args__ = ({'comment': '示例表'}) diff --git a/backend/app/api/v1/module_generator/gencode/model.py b/backend/app/api/v1/module_generator/gencode/model.py index cbfd7880..2d25b1e7 100644 --- a/backend/app/api/v1/module_generator/gencode/model.py +++ b/backend/app/api/v1/module_generator/gencode/model.py @@ -2,8 +2,8 @@ from datetime import datetime from typing import Optional, List -from sqlalchemy import String, Integer, Text, DateTime, Boolean, ForeignKey, text -from sqlalchemy.orm import Mapped, mapped_column, relationship, declared_attr +from sqlalchemy import String, Integer, ForeignKey +from sqlalchemy.orm import Mapped, mapped_column, relationship from app.core.base_model import CreatorMixin @@ -12,14 +12,8 @@ class GenTableModel(CreatorMixin): """ 代码生成表 """ - - @declared_attr.directive - def __tablename__(cls) -> str: - return 'gen_table' - - @declared_attr.directive - def __table_args__(cls) -> dict: - return {'comment': '代码生成表'} + __tablename__ = 'gen_table' + __table_args__ = ({'comment': '代码生成表'}) table_name: Mapped[Optional[str]] = mapped_column(String(200), nullable=True, default='', comment='表名称') table_comment: Mapped[Optional[str]] = mapped_column(String(500), nullable=True, default='', comment='表描述') @@ -37,13 +31,6 @@ class GenTableModel(CreatorMixin): gen_path: Mapped[Optional[str]] = mapped_column(String(200), nullable=True, default='/', comment='生成路径(不填默认项目路径)') options: Mapped[Optional[str]] = mapped_column(String(1000), nullable=True, comment='其它生成选项') - del_flag: Mapped[str] = mapped_column(String(1), nullable=False, default='0', server_default=text("'0'"), comment='删除标志(0代表存在 2代表删除)') - create_by: Mapped[Optional[str]] = mapped_column(String(64), default='', comment='创建者') - create_time: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True, default=None, comment='创建时间') - update_by: Mapped[Optional[str]] = mapped_column(String(64), default='', comment='更新者') - update_time: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True, default=None, comment='更新时间') - remark: Mapped[Optional[str]] = mapped_column(Text, nullable=True, default=None, comment='备注') - columns: Mapped[List['GenTableColumnModel']] = relationship('GenTableColumnModel', order_by='GenTableColumnModel.sort', back_populates='table') @@ -51,16 +38,9 @@ class GenTableColumnModel(CreatorMixin): """ 代码生成表字段 """ - - @declared_attr.directive - def __tablename__(cls) -> str: - return 'gen_table_column' - - @declared_attr.directive - def __table_args__(cls) -> dict: - return {'comment': '代码生成表字段'} + __tablename__ = 'gen_table_column' + __table_args__ = ({'comment': '代码生成表字段'}) - table_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey('gen_table.id'), nullable=True, comment='归属表编号') column_name: Mapped[Optional[str]] = mapped_column(String(200), nullable=True, comment='列名称') column_comment: Mapped[Optional[str]] = mapped_column(String(500), nullable=True, comment='列描述') column_type: Mapped[Optional[str]] = mapped_column(String(100), nullable=True, comment='列类型') @@ -79,4 +59,5 @@ class GenTableColumnModel(CreatorMixin): dict_type: Mapped[Optional[str]] = mapped_column(String(200), nullable=True, default='', comment='字典类型') sort: Mapped[Optional[int]] = mapped_column(Integer, nullable=True, comment='排序') + table_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey('gen_table.id'), nullable=True, comment='归属表编号') table: Mapped['GenTableModel'] = relationship('GenTableModel', back_populates='columns') \ No newline at end of file diff --git a/backend/app/api/v1/module_generator/gencode/schema.py b/backend/app/api/v1/module_generator/gencode/schema.py index 92bb066e..1d3c507f 100644 --- a/backend/app/api/v1/module_generator/gencode/schema.py +++ b/backend/app/api/v1/module_generator/gencode/schema.py @@ -165,6 +165,7 @@ class GenTableColumnBaseSchema(BaseModel): html_type: str = Field(default=..., description='显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)') dict_type: str = Field(default=..., description='字典类型') sort: Optional[int] = Field(default=None, description='排序') + create_by: Optional[str] = Field(default=None, description='创建者') create_time: Optional[datetime] = Field(default=None, description='创建时间') update_by: Optional[str] = Field(default=None, description='更新者')