This commit is contained in:
toom1996
2026-09-17 22:51:00 +08:00
parent 766c691eb3
commit f7ae917603
33 changed files with 8181 additions and 3094 deletions

View File

@ -1,7 +1,7 @@
// Command seed_users 预置内部账号(运营/编辑用,不开放公开注册)。
//
// 项目已移除 AutoMigrate,表结构由 scripts/sql/005_create_users.sql 托管;
// 本脚本用 CREATE TABLE IF NOT EXISTS 兜底建表,再 upsert 一个内部账号。
// 项目表结构由 GORM AutoMigrate 托管(服务启动时创建);
// 本脚本仅在独立运行、尚未跑过服务时兜底建表,再 upsert 一个内部账号。
//
// 用法:
// go run ./scripts/seed_users
@ -43,19 +43,19 @@ func main() {
}
}()
// 1. 兜底建表(与 scripts/sql/005_create_users.sql 完全一致)
// 1. 兜底建表(与 User 模型保持一致;正式结构由服务启动时 AutoMigrate 创建,此处仅作独立运行兜底)
createSQL := `CREATE TABLE IF NOT EXISTS users (
id int unsigned NOT NULL AUTO_INCREMENT,
created_at int unsigned NOT NULL DEFAULT 0,
updated_at int unsigned NOT NULL DEFAULT 0,
id bigserial PRIMARY KEY,
created_at bigint NOT NULL DEFAULT 0,
updated_at bigint NOT NULL DEFAULT 0,
username varchar(64) NOT NULL,
email varchar(191) NOT NULL,
password_hash varchar(255) NOT NULL DEFAULT '',
is_deleted tinyint unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (id),
UNIQUE KEY uk_username (username),
UNIQUE KEY uk_email (email)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`
is_deleted smallint NOT NULL DEFAULT 0,
tier varchar(16) NOT NULL DEFAULT 'free',
UNIQUE (username),
UNIQUE (email)
);`
if e := db.Exec(createSQL).Error; e != nil {
log.Fatalf("✗ 建表失败: %v", e)
}