新增 family_invite 家庭邀请码表(schema+0009迁移)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
jacobxu666
2026-08-19 15:17:38 +08:00
co-authored by Claude Haiku 4.5
parent 8c9d8ece1a
commit da7f7a6a19
3 changed files with 33 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
-- xuchao: 家庭邀请码——家长生成一次性邀请码,其他家长凭码注册加入家庭。幂等。
CREATE TABLE IF NOT EXISTS `family_invite` (
`id` bigint AUTO_INCREMENT NOT NULL,
`family_id` bigint NOT NULL,
`code_hash` varchar(64) NOT NULL,
`created_by` bigint NOT NULL,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`expires_at` datetime NOT NULL,
`used_at` datetime,
CONSTRAINT `family_invite_id` PRIMARY KEY(`id`)
);
+7
View File
@@ -64,6 +64,13 @@
"when": 1786233600000,
"tag": "0008_points",
"breakpoints": true
},
{
"idx": 9,
"version": "5",
"when": 1786320000000,
"tag": "0009_family-invite",
"breakpoints": true
}
]
}
+15
View File
@@ -78,6 +78,21 @@ export const activationCodes = mysqlTable("activation_code", {
usedAt: datetime("used_at"),
});
// ===== 家庭邀请码(家长生成,其他家长凭码注册加入;一次性,15 分钟)=====
export const familyInvites = mysqlTable("family_invite", {
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
familyId: bigint("family_id", { mode: "number" })
.notNull()
.references(() => families.id, { onDelete: "cascade" }),
codeHash: varchar("code_hash", { length: 64 }).notNull(),
createdBy: bigint("created_by", { mode: "number" })
.notNull()
.references(() => users.id),
createdAt: datetime("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
expiresAt: datetime("expires_at").notNull(),
usedAt: datetime("used_at"),
});
// ===== 周模板(每个孩子 × 每周几 × 每条任务)=====
export const taskTemplates = mysqlTable(
"task_template",