from datetime import datetime from sqlalchemy import ( Column, Integer, BigInteger, SmallInteger, String, DateTime, JSON, UniqueConstraint, Index, ) from app.core.database import Base class BookerEntry(Base): __tablename__ = "booker_entries" __ddl__ = """ CREATE TABLE IF NOT EXISTS `booker_entries` ( `id` BIGINT NOT NULL AUTO_INCREMENT, `node_id` VARCHAR(64) NOT NULL, `identifier` VARCHAR(64) NOT NULL, `enable` SMALLINT NOT NULL DEFAULT 0, `debug` SMALLINT NOT NULL DEFAULT 0, `need_account` SMALLINT NOT NULL DEFAULT 1, `need_proxy` SMALLINT NOT NULL DEFAULT 1, `proxy_pool` JSON NOT NULL, `proxy_cd` INT NOT NULL DEFAULT 300, `session_max_life` INT NOT NULL DEFAULT 1800, `active_time_start` VARCHAR(5) NOT NULL DEFAULT '00:00', `active_time_end` VARCHAR(5) NOT NULL DEFAULT '23:59', `website` VARCHAR(512) NOT NULL DEFAULT '', `booker` JSON NOT NULL, `plugin_config` JSON NOT NULL, `appointment_types` JSON NOT NULL, `free_config` JSON NOT NULL, `version` INT NOT NULL DEFAULT 0, `updated_by` VARCHAR(64) NULL DEFAULT 'system', `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `uk_booker_node_identifier` (`node_id`,`identifier`), KEY `idx_booker_identifier` (`identifier`), KEY `idx_booker_updated_at` (`updated_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Booker节点配置表'; """ id = Column(BigInteger, primary_key=True, autoincrement=True) node_id = Column(String(64), nullable=False) identifier = Column(String(64), nullable=False) enable = Column(SmallInteger, nullable=False, default=0) debug = Column(SmallInteger, nullable=False, default=0) need_account = Column(SmallInteger, nullable=False, default=1) need_proxy = Column(SmallInteger, nullable=False, default=1) proxy_pool = Column(JSON, nullable=False, default=list) proxy_cd = Column(Integer, nullable=False, default=300) session_max_life = Column(Integer, nullable=False, default=1800) active_time_start = Column(String(5), nullable=False, default="00:00") active_time_end = Column(String(5), nullable=False, default="23:59") website = Column(String(512), nullable=False, default="") booker = Column(JSON, nullable=False, default=dict) plugin_config = Column(JSON, nullable=False, default=dict) appointment_types = Column(JSON, nullable=False, default=list) free_config = Column(JSON, nullable=False, default=dict) version = Column(Integer, nullable=False, default=0) updated_by = Column(String(64), nullable=True, default="system") created_at = Column(DateTime, default=datetime.utcnow, nullable=False) updated_at = Column( DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False ) __table_args__ = ( UniqueConstraint("node_id", "identifier", name="uk_booker_node_identifier"), Index("idx_booker_identifier", "identifier"), Index("idx_booker_updated_at", "updated_at"), ) class SentinelEntry(Base): __tablename__ = "sentinel_entries" __ddl__ = """ CREATE TABLE IF NOT EXISTS `sentinel_entries` ( `id` BIGINT NOT NULL AUTO_INCREMENT, `node_id` VARCHAR(64) NOT NULL, `identifier` VARCHAR(64) NOT NULL, `enable` SMALLINT NOT NULL DEFAULT 0, `debug` SMALLINT NOT NULL DEFAULT 0, `need_account` SMALLINT NOT NULL DEFAULT 1, `need_proxy` SMALLINT NOT NULL DEFAULT 1, `proxy_pool` JSON NOT NULL, `proxy_cd` INT NOT NULL DEFAULT 300, `session_max_life` INT NOT NULL DEFAULT 1800, `active_time_start` VARCHAR(5) NOT NULL DEFAULT '00:00', `active_time_end` VARCHAR(5) NOT NULL DEFAULT '23:59', `website` VARCHAR(512) NOT NULL DEFAULT '', `sentinel` JSON NOT NULL, `plugin_config` JSON NOT NULL, `appointment_types` JSON NOT NULL, `free_config` JSON NOT NULL, `version` INT NOT NULL DEFAULT 0, `updated_by` VARCHAR(64) NULL DEFAULT 'system', `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `uk_sentinel_node_identifier` (`node_id`,`identifier`), KEY `idx_sentinel_identifier` (`identifier`), KEY `idx_sentinel_updated_at` (`updated_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Sentinel监听节点配置表'; """ id = Column(BigInteger, primary_key=True, autoincrement=True) node_id = Column(String(64), nullable=False) identifier = Column(String(64), nullable=False) enable = Column(SmallInteger, nullable=False, default=0) debug = Column(SmallInteger, nullable=False, default=0) need_account = Column(SmallInteger, nullable=False, default=1) need_proxy = Column(SmallInteger, nullable=False, default=1) proxy_pool = Column(JSON, nullable=False, default=list) proxy_cd = Column(Integer, nullable=False, default=300) session_max_life = Column(Integer, nullable=False, default=1800) active_time_start = Column(String(5), nullable=False, default="00:00") active_time_end = Column(String(5), nullable=False, default="23:59") website = Column(String(512), nullable=False, default="") sentinel = Column(JSON, nullable=False, default=dict) plugin_config = Column(JSON, nullable=False, default=dict) appointment_types = Column(JSON, nullable=False, default=list) free_config = Column(JSON, nullable=False, default=dict) version = Column(Integer, nullable=False, default=0) updated_by = Column(String(64), nullable=True, default="system") created_at = Column(DateTime, default=datetime.utcnow, nullable=False) updated_at = Column( DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False ) __table_args__ = ( UniqueConstraint("node_id", "identifier", name="uk_sentinel_node_identifier"), Index("idx_sentinel_identifier", "identifier"), Index("idx_sentinel_updated_at", "updated_at"), ) class StandaloneEntry(Base): __tablename__ = "standalone_entries" __ddl__ = """ CREATE TABLE IF NOT EXISTS `standalone_entries` ( `id` BIGINT NOT NULL AUTO_INCREMENT, `node_id` VARCHAR(64) NOT NULL, `order_id` VARCHAR(64) NULL, `identifier` VARCHAR(64) NOT NULL, `enable` SMALLINT NOT NULL DEFAULT 1, `debug` SMALLINT NOT NULL DEFAULT 0, `plugin_config` JSON NOT NULL, `account` JSON NOT NULL, `proxy_pool` JSON NOT NULL, `query_wait` JSON NOT NULL, `login_interval` INT NOT NULL DEFAULT 1800, `session_max_life` INT NOT NULL DEFAULT 1800, `active_time_start` VARCHAR(5) NOT NULL DEFAULT '00:00', `active_time_end` VARCHAR(5) NOT NULL DEFAULT '23:59', `appointment_types` JSON NOT NULL, `user_preferences` JSON NOT NULL, `free_config` JSON NOT NULL, `version` INT NOT NULL DEFAULT 0, `updated_by` VARCHAR(64) NULL DEFAULT 'system', `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `uk_standalone_node_identifier` (`node_id`,`identifier`), KEY `idx_standalone_identifier` (`identifier`), KEY `idx_standalone_order_id` (`order_id`), KEY `idx_standalone_updated_at` (`updated_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='独立节点配置表'; """ id = Column(BigInteger, primary_key=True, autoincrement=True) node_id = Column(String(64), nullable=False) order_id = Column(String(64), nullable=True) identifier = Column(String(64), nullable=False) enable = Column(SmallInteger, nullable=False, default=1) debug = Column(SmallInteger, nullable=False, default=0) plugin_config = Column(JSON, nullable=False, default=dict) account = Column(JSON, nullable=False, default=dict) proxy_pool = Column(JSON, nullable=False, default=list) query_wait = Column(JSON, nullable=False, default=dict) login_interval = Column(Integer, nullable=False, default=1800) session_max_life = Column(Integer, nullable=False, default=1800) active_time_start = Column(String(5), nullable=False, default="00:00") active_time_end = Column(String(5), nullable=False, default="23:59") appointment_types = Column(JSON, nullable=False, default=list) user_preferences = Column(JSON, nullable=False, default=dict) free_config = Column(JSON, nullable=False, default=dict) version = Column(Integer, nullable=False, default=0) updated_by = Column(String(64), nullable=True, default="system") created_at = Column(DateTime, default=datetime.utcnow, nullable=False) updated_at = Column( DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False ) __table_args__ = ( UniqueConstraint("node_id", "identifier", name="uk_standalone_node_identifier"), Index("idx_standalone_identifier", "identifier"), Index("idx_standalone_order_id", "order_id"), Index("idx_standalone_updated_at", "updated_at"), ) class NodeConfigurationRevision(Base): __tablename__ = "node_configuration_revisions" __ddl__ = """ CREATE TABLE IF NOT EXISTS `node_configuration_revisions` ( `id` BIGINT NOT NULL AUTO_INCREMENT, `entry_type` VARCHAR(32) NOT NULL, `entry_id` BIGINT NOT NULL, `version` INT NOT NULL DEFAULT 0, `action` VARCHAR(32) NOT NULL DEFAULT 'update', `snapshot` JSON NOT NULL, `updated_by` VARCHAR(64) NULL DEFAULT 'system', `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `idx_node_config_rev_type_id` (`entry_type`,`entry_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='节点配置版本历史表'; """ id = Column(BigInteger, primary_key=True, autoincrement=True) entry_type = Column(String(32), nullable=False, index=True) entry_id = Column(BigInteger, nullable=False, index=True) version = Column(Integer, nullable=False, default=0) action = Column(String(32), nullable=False, default="update") snapshot = Column(JSON, nullable=False, default=dict) updated_by = Column(String(64), nullable=True, default="system") created_at = Column(DateTime, default=datetime.utcnow, nullable=False) __table_args__ = ( Index("idx_node_config_rev_type_id", "entry_type", "entry_id"), ) class ClusterNodeEntry(Base): __tablename__ = "cluster_nodes" __ddl__ = """ CREATE TABLE IF NOT EXISTS `cluster_nodes` ( `id` BIGINT NOT NULL AUTO_INCREMENT, `node_id` VARCHAR(64) NOT NULL, `name` VARCHAR(128) NOT NULL, `ip_address` VARCHAR(64) NULL, `region` VARCHAR(64) NULL, `status` SMALLINT NOT NULL DEFAULT 1 COMMENT '1:启用, 0:停用', `notes` VARCHAR(512) NULL, `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `uk_cluster_node_id` (`node_id`), KEY `idx_cluster_node_status` (`status`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='集群节点注册档案表'; """ id = Column(BigInteger, primary_key=True, autoincrement=True) node_id = Column(String(64), nullable=False) name = Column(String(128), nullable=False) ip_address = Column(String(64), nullable=True) region = Column(String(64), nullable=True) status = Column(SmallInteger, nullable=False, default=1) notes = Column(String(512), nullable=True) created_at = Column(DateTime, default=datetime.utcnow, nullable=False) updated_at = Column( DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False ) __table_args__ = ( UniqueConstraint("node_id", name="uk_cluster_node_id"), Index("idx_cluster_node_status", "status"), )