-- CreateSchema CREATE SCHEMA IF NOT EXISTS "public"; -- CreateEnum CREATE TYPE "AccountType" AS ENUM ('USER', 'SERVICE'); -- CreateTable CREATE TABLE "billing_app_account" ( "uuid" UUID NOT NULL, "name" VARCHAR(255) NOT NULL, "account_type" "AccountType" NOT NULL DEFAULT 'USER', "description" TEXT, "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "billing_app_account_pkey" PRIMARY KEY ("uuid") ); -- CreateTable CREATE TABLE "billing_app_operationcode" ( "id" SERIAL NOT NULL, "code" INTEGER NOT NULL, "name" VARCHAR(255) NOT NULL, "description" TEXT, "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "billing_app_operationcode_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "billing_app_serviceaccount" ( "account_id" UUID NOT NULL, "slug" VARCHAR(50) NOT NULL, CONSTRAINT "billing_app_serviceaccount_pkey" PRIMARY KEY ("account_id") ); -- CreateIndex CREATE UNIQUE INDEX "billing_app_operationcode_code_key" ON "billing_app_operationcode"("code"); -- CreateIndex CREATE UNIQUE INDEX "billing_app_operationcode_name_key" ON "billing_app_operationcode"("name"); -- CreateIndex CREATE UNIQUE INDEX "billing_app_serviceaccount_slug_key" ON "billing_app_serviceaccount"("slug"); -- AddForeignKey ALTER TABLE "billing_app_serviceaccount" ADD CONSTRAINT "billing_app_serviceaccount_account_id_fkey" FOREIGN KEY ("account_id") REFERENCES "billing_app_account"("uuid") ON DELETE CASCADE ON UPDATE CASCADE;