初始化
This commit is contained in:
33
app/models/work_area.py
Normal file
33
app/models/work_area.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from sqlalchemy import Column, BigInteger, String
|
||||
|
||||
class WorkArea:
|
||||
"""工区表结构定义 - 动态分表"""
|
||||
|
||||
@staticmethod
|
||||
def get_table_name(account_id: int) -> str:
|
||||
return f"work_area_{account_id}"
|
||||
|
||||
@staticmethod
|
||||
def get_columns():
|
||||
return {
|
||||
"id": Column(BigInteger, primary_key=True, autoincrement=True),
|
||||
"department_id": Column(String(100), comment="标段/工区/工点id"),
|
||||
"parent_id": Column(String(100), comment="父id"),
|
||||
"type": Column(String(100), comment="类型"),
|
||||
"name": Column(String(100), comment="名称"),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def get_create_sql(account_id: int) -> str:
|
||||
table_name = WorkArea.get_table_name(account_id)
|
||||
return f"""
|
||||
CREATE TABLE IF NOT EXISTS `{table_name}` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`department_id` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '标段/工区/工点id',
|
||||
`parent_id` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '父id',
|
||||
`type` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '类型',
|
||||
`name` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '名称',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_department_id` (`department_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='标段/工区/工点信息表';
|
||||
"""
|
||||
Reference in New Issue
Block a user