- npc-dialogues gains priority + entryGate (flag key/op/amount) fields - contact page offers the highest-priority conversation whose gate passes (ungated = fallback, ties by oldest); only the winner's flow leaves the server so locked story content never reaches clients - extract shared flag reads (readFlag/evaluateCondition) to lib/npc-dialogue/flags and pure selection to lib/npc-dialogue/selection - migration 20261006_203217_add_dialogue_entry_gate; spec covers ordering, gating, fallback, and storage round-trip
19 lines
1 KiB
TypeScript
19 lines
1 KiB
TypeScript
import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
|
|
|
|
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
|
|
await db.execute(sql`
|
|
CREATE TYPE "public"."enum_npc_dialogues_entry_gate_op" AS ENUM('is_true', 'is_false', 'gte', 'lte', 'gt', 'lt', 'eq');
|
|
ALTER TABLE "npc_dialogues" ADD COLUMN "priority" numeric DEFAULT 0;
|
|
ALTER TABLE "npc_dialogues" ADD COLUMN "entry_gate_key" varchar;
|
|
ALTER TABLE "npc_dialogues" ADD COLUMN "entry_gate_op" "enum_npc_dialogues_entry_gate_op" DEFAULT 'is_true';
|
|
ALTER TABLE "npc_dialogues" ADD COLUMN "entry_gate_amount" numeric;`)
|
|
}
|
|
|
|
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
|
await db.execute(sql`
|
|
ALTER TABLE "npc_dialogues" DROP COLUMN "priority";
|
|
ALTER TABLE "npc_dialogues" DROP COLUMN "entry_gate_key";
|
|
ALTER TABLE "npc_dialogues" DROP COLUMN "entry_gate_op";
|
|
ALTER TABLE "npc_dialogues" DROP COLUMN "entry_gate_amount";
|
|
DROP TYPE "public"."enum_npc_dialogues_entry_gate_op";`)
|
|
}
|