CREATE TABLE "app_state" (
	"owner_id" uuid NOT NULL,
	"key" text NOT NULL,
	"value" jsonb,
	"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "app_state_owner_id_key_pk" PRIMARY KEY("owner_id","key")
);
--> statement-breakpoint
ALTER TABLE "app_state" ADD CONSTRAINT "app_state_owner_id_users_id_fk" FOREIGN KEY ("owner_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
-- Seed the fixed default owner used by /state until auth is wired in (the
-- conceptual "user 1"; see DEFAULT_USER_ID in src/modules/state/state.controller.ts).
-- Password hash is a non-login placeholder; this account cannot authenticate.
INSERT INTO "users" ("id", "email", "password_hash", "display_name", "role", "is_active")
VALUES ('00000000-0000-0000-0000-000000000001', 'default@local.ck-terminal', 'disabled', 'Default User', 'USER', false)
ON CONFLICT ("id") DO NOTHING;