ALTER TABLE "calls" ADD COLUMN IF NOT EXISTS "livekit_room" text;
--> statement-breakpoint
ALTER TABLE "calls" ADD COLUMN IF NOT EXISTS "recording_status" text DEFAULT 'idle' NOT NULL;
--> statement-breakpoint
ALTER TABLE "calls" ADD COLUMN IF NOT EXISTS "recording_egress_id" text;
--> statement-breakpoint
ALTER TABLE "calls" ADD COLUMN IF NOT EXISTS "recording_object_key" text;
--> statement-breakpoint
ALTER TABLE "calls" ADD COLUMN IF NOT EXISTS "transcript_status" text DEFAULT 'idle' NOT NULL;
--> statement-breakpoint
ALTER TABLE "calls" ADD COLUMN IF NOT EXISTS "transcript" text;
--> statement-breakpoint
ALTER TABLE "calls" ADD COLUMN IF NOT EXISTS "summary" text;
--> statement-breakpoint
-- One live Connect per channel is created after this transaction commits
-- (see migrate.ts). Postgres will not use a new enum label until ADD VALUE
-- in 0020 is committed, and drizzle runs pending files in one transaction.
CREATE TABLE IF NOT EXISTS "workspace_phone_numbers" (
  "id" integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
  "workspace_id" integer NOT NULL,
  "e164" text NOT NULL,
  "label" text,
  "created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
DO $$ BEGIN
 ALTER TABLE "workspace_phone_numbers" ADD CONSTRAINT "workspace_phone_numbers_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "workspace_phone_numbers_e164_idx" ON "workspace_phone_numbers" USING btree ("e164");
--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "workspace_phone_numbers_workspace_idx" ON "workspace_phone_numbers" USING btree ("workspace_id");
--> statement-breakpoint
DO $$ BEGIN
  IF EXISTS (SELECT FROM pg_roles WHERE rolname = 'slackwsh_app') THEN
    GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE workspace_phone_numbers TO slackwsh_app;
    GRANT USAGE, SELECT ON SEQUENCE workspace_phone_numbers_id_seq TO slackwsh_app;
  END IF;
END $$;
