fix pb migration

This commit is contained in:
JCEEE
2026-08-10 15:56:03 +01:00
parent e1fb046afd
commit 3085934fb9
7 changed files with 59 additions and 8 deletions
+5 -3
View File
@@ -7,8 +7,10 @@
// so SERVER_IP is unset → loopback below.
const SERVER_IP = process.env.SERVER_IP;
export const PB_ENDPOINT = SERVER_IP
? `http://${SERVER_IP}:8090`
: `http://127.0.0.1:8090`;
// PB_ENDPOINT can be overridden explicitly (used for migration step-through
// against a throwaway PB on another port). Defaults to the dev/prod split.
export const PB_ENDPOINT =
process.env.PB_ENDPOINT ||
(SERVER_IP ? `http://${SERVER_IP}:8090` : `http://127.0.0.1:8090`);
export const PB_EMAIL = process.env.PB_EMAIL || "debug@famchamp.dev";
export const PB_PASSWORD = process.env.PB_PASSWORD || "debug123";
+21 -1
View File
@@ -1455,7 +1455,27 @@ export async function migrate(): Promise<void> {
});
} else {
console.log(` ↳ messages already exists`);
await updateCollection("messages", { listRule: "", viewRule: "" });
// PB 0.39 doesn't auto-add createdAt to API-created collections, and
// older stores may predate it. Chat filters/sorts on createdAt, so
// ensure the field exists even if the collection was created without it.
const msgsFields = msgsCol.fields?.map((f: any) => f.name) || [];
if (!msgsFields.includes("createdAt")) {
console.log(" ↳ adding missing createdAt field to messages...");
msgsCol.fields.push({
name: "createdAt",
type: "date",
required: false,
min: "",
max: "",
});
await updateCollection("messages", {
listRule: "",
viewRule: "",
fields: msgsCol.fields,
});
} else {
await updateCollection("messages", { listRule: "", viewRule: "" });
}
}
// 9b. chat_typing (transient presence rows, one per actor)