CREATE TABLE "login_codes" (
	"id" serial PRIMARY KEY,
	"phone" text NOT NULL,
	"user_id" text,
	"code_hash" text,
	"attempts" integer DEFAULT 0 NOT NULL,
	"ip" text,
	"expires_at" timestamp with time zone NOT NULL,
	"used_at" timestamp with time zone,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "campaigns" ADD COLUMN "scheduled_for" timestamp with time zone;--> statement-breakpoint
ALTER TABLE "campaigns" ADD COLUMN "send_progress" integer DEFAULT 0 NOT NULL;--> statement-breakpoint
ALTER TABLE "campaigns" ADD COLUMN "sent_count" integer DEFAULT 0 NOT NULL;--> statement-breakpoint
ALTER TABLE "campaigns" ADD COLUMN "locked_until" timestamp with time zone;--> statement-breakpoint
ALTER TABLE "campaigns" ADD COLUMN "delivery" jsonb;--> statement-breakpoint
ALTER TABLE "campaigns" ADD COLUMN "delivery_checked_at" timestamp with time zone;--> statement-breakpoint
CREATE INDEX "campaigns_status_scheduled_idx" ON "campaigns" ("status","scheduled_for");--> statement-breakpoint
CREATE INDEX "login_codes_phone_created_idx" ON "login_codes" ("phone","created_at");--> statement-breakpoint
CREATE INDEX "login_codes_ip_created_idx" ON "login_codes" ("ip","created_at");--> statement-breakpoint
ALTER TABLE "login_codes" ADD CONSTRAINT "login_codes_user_id_accounts_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "accounts"("user_id");