update compose to be coolifyable
This commit is contained in:
+11
-202
@@ -1,3 +1,4 @@
|
||||
import { SCHEMA_PLAN } from "@shared/pb/schema.ts";
|
||||
import { PB_ENDPOINT, PB_EMAIL, PB_PASSWORD } from "./env.ts";
|
||||
|
||||
let token: string | null = null;
|
||||
@@ -63,53 +64,9 @@ async function updateCollection(id: string, col: any): Promise<void> {
|
||||
console.log(` ✓ Updated collection: ${col.name || id}`);
|
||||
}
|
||||
|
||||
// ── Field helpers (mirror proxy/scripts/seed.ts) ──
|
||||
function text(name: string, required = false) {
|
||||
return { name, type: "text", required };
|
||||
}
|
||||
function uniqueText(name: string) {
|
||||
return { name, type: "text", required: true, unique: true };
|
||||
}
|
||||
function number(name: string, required = false) {
|
||||
return { name, type: "number", required };
|
||||
}
|
||||
function bool(name: string) {
|
||||
return { name, type: "bool" };
|
||||
}
|
||||
function date(name: string) {
|
||||
return { name, type: "date" };
|
||||
}
|
||||
function jsonField(name: string) {
|
||||
return { name, type: "json" };
|
||||
}
|
||||
function select(name: string, values: string[], required = false) {
|
||||
return { name, type: "select", required, values, maxSelect: 1 };
|
||||
}
|
||||
function rel(name: string, collectionId: string, required = false) {
|
||||
return {
|
||||
name,
|
||||
type: "relation",
|
||||
required,
|
||||
collectionId,
|
||||
maxSelect: 1,
|
||||
cascadeDelete: false,
|
||||
};
|
||||
}
|
||||
function colDef(name: string, fields: any[]): any {
|
||||
return {
|
||||
name,
|
||||
type: "base",
|
||||
listRule: "",
|
||||
viewRule: "",
|
||||
createRule: null,
|
||||
updateRule: null,
|
||||
deleteRule: null,
|
||||
fields,
|
||||
};
|
||||
}
|
||||
|
||||
// Bootstrap the full base schema on a fresh PocketBase (docker first boot).
|
||||
// Idempotent — skips collections that already exist.
|
||||
// Idempotent — skips collections that already exist. Schema is shared with
|
||||
// seed.ts via shared/pb/schema.ts.
|
||||
async function ensureSchema(): Promise<void> {
|
||||
if (await getCollection("fams")) {
|
||||
console.log("[migrate] Base schema already present — skipping bootstrap.");
|
||||
@@ -117,163 +74,15 @@ async function ensureSchema(): Promise<void> {
|
||||
}
|
||||
console.log("[migrate] Bootstrapping base schema on fresh PocketBase...");
|
||||
|
||||
// Pass 1: independent
|
||||
const famsId = (await createCollection(
|
||||
colDef("fams", [
|
||||
text("name", true),
|
||||
uniqueText("slug"),
|
||||
text("inviteCode"),
|
||||
text("stripeCustomerId"),
|
||||
jsonField("featureFlags"),
|
||||
jsonField("seasons"),
|
||||
]),
|
||||
))!;
|
||||
const ids: Record<string, string> = {};
|
||||
for (const entry of SCHEMA_PLAN) {
|
||||
const createdId = await createCollection(entry.build(ids));
|
||||
if (createdId) ids[entry.name] = createdId;
|
||||
}
|
||||
|
||||
// fams is sensitive → superadmin-only (proxy/server reads). Not public.
|
||||
await updateCollection(famsId, { viewRule: null, listRule: null });
|
||||
await createCollection(
|
||||
colDef("bonus_templates", [
|
||||
rel("famId", famsId, true),
|
||||
text("name", true),
|
||||
text("description"),
|
||||
select("target", ["individual", "competitive", "collaborative"], true),
|
||||
select("type", ["threshold", "count", "manual"], true),
|
||||
select("occurrence", ["recurring", "once"], true),
|
||||
select("rewardType", ["points", "cash", "prize"], true),
|
||||
text("rewardValue", true),
|
||||
number("criteriaValue"),
|
||||
select("period", ["schedule", "daily", "weekly", "monthly"]),
|
||||
]),
|
||||
);
|
||||
|
||||
// Pass 2: reference fams
|
||||
await createCollection(
|
||||
colDef("settings", [rel("famId", famsId, true), text("webhookUrl")]),
|
||||
);
|
||||
const membersId = (await createCollection(
|
||||
colDef("members", [
|
||||
rel("famId", famsId, true),
|
||||
text("name", true),
|
||||
text("color"),
|
||||
text("deviceToken"),
|
||||
text("deviceTokenHint"),
|
||||
]),
|
||||
))!;
|
||||
const choreTemplatesId = (await createCollection(
|
||||
colDef("chore_templates", [
|
||||
rel("famId", famsId, true),
|
||||
text("name", true),
|
||||
text("description"),
|
||||
select("defaultFrequency", ["daily", "weekly"], true),
|
||||
select("defaultType", ["points", "money"], true),
|
||||
number("defaultValue", true),
|
||||
]),
|
||||
))!;
|
||||
await createCollection(
|
||||
colDef("fam_admins", [
|
||||
rel("famId", famsId, true),
|
||||
text("userId", true),
|
||||
text("email", true),
|
||||
text("name"),
|
||||
text("color"),
|
||||
]),
|
||||
);
|
||||
const bonusConfigsId = (await createCollection(
|
||||
colDef("bonus_configs", [
|
||||
rel("famId", famsId, true),
|
||||
text("name", true),
|
||||
text("description"),
|
||||
select("target", ["individual", "competitive", "collaborative"], true),
|
||||
select("type", ["threshold", "count", "manual"], true),
|
||||
select("occurrence", ["recurring", "once"], true),
|
||||
select("rewardType", ["points", "cash", "prize"], true),
|
||||
text("rewardValue", true),
|
||||
number("criteriaValue"),
|
||||
rel("memberId", membersId),
|
||||
select("period", ["schedule", "daily", "weekly", "monthly"]),
|
||||
select("status", ["active", "completed"], true),
|
||||
]),
|
||||
))!;
|
||||
|
||||
// Pass 3: nested deps
|
||||
await createCollection(
|
||||
colDef("weekly_history", [
|
||||
rel("famId", famsId, true),
|
||||
rel("memberId", membersId, true),
|
||||
date("weekStart"),
|
||||
number("pointsEarned"),
|
||||
number("moneyEarned"),
|
||||
number("choresCompleted"),
|
||||
number("bonusEarned"),
|
||||
]),
|
||||
);
|
||||
await createCollection(
|
||||
colDef("rewards", [
|
||||
rel("famId", famsId, true),
|
||||
rel("memberId", membersId, true),
|
||||
rel("bonusConfigId", bonusConfigsId),
|
||||
text("label", true),
|
||||
number("value", true),
|
||||
select("rewardType", ["cash", "prize", "points"], true),
|
||||
select("status", ["unclaimed", "requested", "claimed"], true),
|
||||
select("claimable", ["immediate", "payday"], true),
|
||||
text("settleDate"),
|
||||
date("claimedAt"),
|
||||
date("requestedAt"),
|
||||
text("date"),
|
||||
]),
|
||||
);
|
||||
const assignedChoresId = (await createCollection(
|
||||
colDef("assigned_chores", [
|
||||
rel("famId", famsId, true),
|
||||
rel("memberId", membersId, true),
|
||||
rel("templateId", choreTemplatesId, true),
|
||||
select("frequency", ["daily", "weekly"], true),
|
||||
select("type", ["points", "money"], true),
|
||||
number("value", true),
|
||||
text("customName"),
|
||||
jsonField("seasonIds"),
|
||||
]),
|
||||
))!;
|
||||
await createCollection(
|
||||
colDef("seasons", [
|
||||
rel("famId", famsId, true),
|
||||
text("name", true),
|
||||
text("color"),
|
||||
bool("active"),
|
||||
date("autoDisable"),
|
||||
date("autoStart"),
|
||||
]),
|
||||
);
|
||||
await createCollection(
|
||||
colDef("completions", [
|
||||
rel("famId", famsId, true),
|
||||
rel("memberId", membersId, true),
|
||||
rel("assignedChoreId", assignedChoresId, true),
|
||||
date("date"),
|
||||
date("completedAt"),
|
||||
]),
|
||||
);
|
||||
await createCollection(
|
||||
colDef("messages", [
|
||||
rel("famId", famsId, true),
|
||||
select("authorType", ["admin", "member"], true),
|
||||
text("authorId", true),
|
||||
text("authorName", true),
|
||||
text("authorColor"),
|
||||
text("content", true),
|
||||
date("createdAt"),
|
||||
]),
|
||||
);
|
||||
await createCollection(
|
||||
colDef("chat_typing", [
|
||||
rel("famId", famsId, true),
|
||||
text("actorId", true),
|
||||
select("actorType", ["admin", "member"], true),
|
||||
text("authorName", true),
|
||||
text("authorColor"),
|
||||
bool("typing"),
|
||||
]),
|
||||
);
|
||||
const famsId = ids.fams;
|
||||
if (famsId) await updateCollection(famsId, { viewRule: null, listRule: null });
|
||||
console.log("[migrate] Base schema bootstrapped.");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user