CREATE TABLE "settings" ( "key" text PRIMARY KEY NOT NULL, "value" jsonb NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "telegram_outbox" ( "id" serial PRIMARY KEY NOT NULL, "dedupe_key" text NOT NULL, "method" text NOT NULL, "params" jsonb NOT NULL, "question_id" integer, "status" text DEFAULT 'pending' NOT NULL, "attempts" integer DEFAULT 0 NOT NULL, "next_attempt_at" timestamp with time zone DEFAULT now() NOT NULL, "telegram_message_id" integer, "error" text, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "sent_at" timestamp with time zone, CONSTRAINT "telegram_outbox_dedupe_key_unique" UNIQUE("dedupe_key") ); --> statement-breakpoint CREATE TABLE "telegram_updates" ( "update_id" integer PRIMARY KEY NOT NULL, "status" text NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint ALTER TABLE "telegram_outbox" ADD CONSTRAINT "telegram_outbox_question_id_questions_id_fk" FOREIGN KEY ("question_id") REFERENCES "public"."questions"("id") ON DELETE set null ON UPDATE no action;