ALTER TABLE "users"
ADD COLUMN "approval_permissions" "ApprovalType"[] NOT NULL DEFAULT ARRAY[]::"ApprovalType"[];

UPDATE "users"
SET "approval_permissions" = CASE
  WHEN "approval_preference" IS NOT NULL THEN ARRAY["approval_preference"]::"ApprovalType"[]
  WHEN "role" = 'FINANCE' THEN ARRAY['FINANCE']::"ApprovalType"[]
  ELSE ARRAY[]::"ApprovalType"[]
END;

CREATE TABLE "app_settings" (
    "id" TEXT NOT NULL,
    "approval_threshold" DECIMAL(10,2) NOT NULL DEFAULT 50.00,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "app_settings_pkey" PRIMARY KEY ("id")
);

INSERT INTO "app_settings" ("id", "approval_threshold", "updated_at")
VALUES ('global', 50.00, CURRENT_TIMESTAMP)
ON CONFLICT ("id") DO NOTHING;
