107 lines
3.2 KiB
Python
107 lines
3.2 KiB
Python
"""直接用 SQL 创建必要的表"""
|
|
import pymysql
|
|
|
|
SQL_STATEMENTS = """
|
|
CREATE TABLE IF NOT EXISTS `nf_lovers` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`user_id` bigint NOT NULL,
|
|
`name` varchar(64) DEFAULT NULL,
|
|
`gender` enum('male','female') NOT NULL,
|
|
`intro` text,
|
|
`story_background` text,
|
|
`personality_tag` int DEFAULT NULL,
|
|
`interest_tags` json DEFAULT NULL,
|
|
`opening_line` text,
|
|
`personality_prompt` text,
|
|
`appearance_prompt` text,
|
|
`appearance_params` json DEFAULT NULL,
|
|
`hair_style_id` int DEFAULT NULL,
|
|
`eye_color_id` int DEFAULT NULL,
|
|
`outfit_desc` varchar(50) DEFAULT NULL,
|
|
`outfit_top_id` bigint DEFAULT NULL,
|
|
`outfit_bottom_id` bigint DEFAULT NULL,
|
|
`outfit_dress_id` bigint DEFAULT NULL,
|
|
`voice_id` bigint DEFAULT NULL,
|
|
`image_url` varchar(255) DEFAULT NULL,
|
|
`last_image_task_id` bigint DEFAULT NULL,
|
|
`image_gen_used` int DEFAULT '0',
|
|
`image_gen_limit` int DEFAULT '10',
|
|
`image_gen_reset_date` date DEFAULT NULL,
|
|
`init_model` varchar(64) DEFAULT NULL,
|
|
`init_at` datetime DEFAULT NULL,
|
|
`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
|
|
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `user_id` (`user_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
CREATE TABLE IF NOT EXISTS `nf_voice_library` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`name` varchar(64) NOT NULL,
|
|
`gender` enum('male','female') NOT NULL,
|
|
`style_tag` varchar(32) DEFAULT NULL,
|
|
`avatar_url` varchar(255) DEFAULT NULL,
|
|
`sample_audio_url` varchar(255) DEFAULT NULL,
|
|
`tts_model_id` varchar(64) DEFAULT NULL,
|
|
`is_default` tinyint(1) DEFAULT '0',
|
|
`voice_code` varchar(64) NOT NULL,
|
|
`is_owned` tinyint(1) DEFAULT '1',
|
|
`price_gold` int DEFAULT '0',
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
CREATE TABLE IF NOT EXISTS `nf_girlfriend_mould` (
|
|
`id` int NOT NULL AUTO_INCREMENT,
|
|
`name` varchar(64) NOT NULL,
|
|
`gender` enum('male','female') DEFAULT NULL,
|
|
`weigh` int DEFAULT '0',
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
CREATE TABLE IF NOT EXISTS `nf_girlfriend_hobbies` (
|
|
`id` int NOT NULL AUTO_INCREMENT,
|
|
`name` varchar(64) NOT NULL,
|
|
`weigh` int DEFAULT '0',
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
CREATE TABLE IF NOT EXISTS `nf_girlfriend_hairstyles` (
|
|
`id` int NOT NULL AUTO_INCREMENT,
|
|
`name` varchar(64) NOT NULL,
|
|
`weigh` int DEFAULT '0',
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
CREATE TABLE IF NOT EXISTS `nf_girlfriend_eyecolor` (
|
|
`id` int NOT NULL AUTO_INCREMENT,
|
|
`name` varchar(64) NOT NULL,
|
|
`weigh` int DEFAULT '0',
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
"""
|
|
|
|
try:
|
|
conn = pymysql.connect(
|
|
host='127.0.0.1',
|
|
port=3306,
|
|
user='root',
|
|
password='root',
|
|
database='lover',
|
|
charset='utf8mb4'
|
|
)
|
|
print("✓ 连接数据库成功")
|
|
|
|
cursor = conn.cursor()
|
|
for statement in SQL_STATEMENTS.strip().split(';'):
|
|
statement = statement.strip()
|
|
if statement:
|
|
cursor.execute(statement)
|
|
print(f"✓ 执行成功")
|
|
|
|
conn.commit()
|
|
print("✓ 所有表创建完成!")
|
|
cursor.close()
|
|
conn.close()
|
|
except Exception as e:
|
|
print(f"✗ 失败: {e}")
|