diff --git a/Dockerfile b/Dockerfile index ec4ef8a..f6ecefc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,4 +28,4 @@ ENV INFISICAL_SECRET_PATHS="/billing,/shared" EXPOSE 8000 -CMD ["sh", "-c", "node scripts/load-secrets.mjs && . ./.env.infisical && npx prisma migrate deploy && node dist/index.js"] +CMD ["sh", "-c", "node scripts/load-secrets.mjs && . ./.env.infisical && npx prisma migrate resolve --applied 0_init 2>/dev/null; npx prisma migrate deploy && node dist/index.js"] diff --git a/prisma/migrations/0_init/migration.sql b/prisma/migrations/0_init/migration.sql new file mode 100644 index 0000000..2b324e1 --- /dev/null +++ b/prisma/migrations/0_init/migration.sql @@ -0,0 +1,48 @@ +-- 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; +