183 lines
5.9 KiB
SQL
183 lines
5.9 KiB
SQL
/*
|
|
Warnings:
|
|
|
|
- You are about to drop the `AuthSession` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `Invoice` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `Notification` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `Operator` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `Partner` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `Payment` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `Plan` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `Refund` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `Subscription` table. If the table is not empty, all the data it contains will be lost.
|
|
- You are about to drop the `Webhook` table. If the table is not empty, all the data it contains will be lost.
|
|
|
|
*/
|
|
-- CreateEnum
|
|
CREATE TYPE "TransactionStatus" AS ENUM ('SUCCES', 'FAILED', 'PENDING');
|
|
|
|
-- CreateEnum
|
|
CREATE TYPE "Periodicity" AS ENUM ('Daily', 'Weekly', 'Monthly', 'OneTime');
|
|
|
|
-- CreateEnum
|
|
CREATE TYPE "PaymentType" AS ENUM ('MM', 'BANK', 'CHEQUE');
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."AuthSession" DROP CONSTRAINT "AuthSession_partnerId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."Invoice" DROP CONSTRAINT "Invoice_partnerId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."Invoice" DROP CONSTRAINT "Invoice_paymentId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."Invoice" DROP CONSTRAINT "Invoice_subscriptionId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."Invoice" DROP CONSTRAINT "Invoice_userId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."Notification" DROP CONSTRAINT "Notification_partnerId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."Notification" DROP CONSTRAINT "Notification_userId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."Payment" DROP CONSTRAINT "Payment_partnerId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."Payment" DROP CONSTRAINT "Payment_subscriptionId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."Payment" DROP CONSTRAINT "Payment_userId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."Plan" DROP CONSTRAINT "Plan_partnerId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."Refund" DROP CONSTRAINT "Refund_paymentId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."Subscription" DROP CONSTRAINT "Subscription_partnerId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."Subscription" DROP CONSTRAINT "Subscription_planId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."Subscription" DROP CONSTRAINT "Subscription_userId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."User" DROP CONSTRAINT "User_operatorId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."User" DROP CONSTRAINT "User_partnerId_fkey";
|
|
|
|
-- DropForeignKey
|
|
ALTER TABLE "public"."Webhook" DROP CONSTRAINT "Webhook_partnerId_fkey";
|
|
|
|
-- DropTable
|
|
DROP TABLE "public"."AuthSession";
|
|
|
|
-- DropTable
|
|
DROP TABLE "public"."Invoice";
|
|
|
|
-- DropTable
|
|
DROP TABLE "public"."Notification";
|
|
|
|
-- DropTable
|
|
DROP TABLE "public"."Operator";
|
|
|
|
-- DropTable
|
|
DROP TABLE "public"."Partner";
|
|
|
|
-- DropTable
|
|
DROP TABLE "public"."Payment";
|
|
|
|
-- DropTable
|
|
DROP TABLE "public"."Plan";
|
|
|
|
-- DropTable
|
|
DROP TABLE "public"."Refund";
|
|
|
|
-- DropTable
|
|
DROP TABLE "public"."Subscription";
|
|
|
|
-- DropTable
|
|
DROP TABLE "public"."Webhook";
|
|
|
|
-- DropEnum
|
|
DROP TYPE "public"."OperatorCode";
|
|
|
|
-- DropEnum
|
|
DROP TYPE "public"."PaymentStatus";
|
|
|
|
-- DropEnum
|
|
DROP TYPE "public"."SubscriptionStatus";
|
|
|
|
-- CreateTable
|
|
CREATE TABLE "transactions" (
|
|
"id" SERIAL NOT NULL,
|
|
"date" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"amount" DOUBLE PRECISION NOT NULL,
|
|
"tax" DOUBLE PRECISION NOT NULL,
|
|
"status" "TransactionStatus" NOT NULL,
|
|
"merchantPartnerId" INTEGER NOT NULL,
|
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
|
|
CONSTRAINT "transactions_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
-- CreateTable
|
|
CREATE TABLE "subscriptions" (
|
|
"id" SERIAL NOT NULL,
|
|
"periodicity" "Periodicity" NOT NULL,
|
|
"startDate" TIMESTAMP(3) NOT NULL,
|
|
"endDate" TIMESTAMP(3),
|
|
"amount" DOUBLE PRECISION NOT NULL,
|
|
"currency" TEXT NOT NULL,
|
|
"token" TEXT NOT NULL,
|
|
"nextPaymentDate" TIMESTAMP(3) NOT NULL,
|
|
"merchantPartnerId" INTEGER NOT NULL,
|
|
"customerId" INTEGER NOT NULL,
|
|
"serviceId" INTEGER NOT NULL,
|
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
|
|
CONSTRAINT "subscriptions_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
-- CreateTable
|
|
CREATE TABLE "reversement_requests" (
|
|
"id" SERIAL NOT NULL,
|
|
"startDate" TIMESTAMP(3) NOT NULL,
|
|
"endDate" TIMESTAMP(3) NOT NULL,
|
|
"amount" DOUBLE PRECISION NOT NULL,
|
|
"tax" DOUBLE PRECISION NOT NULL,
|
|
"status" "TransactionStatus" NOT NULL,
|
|
"transactionId" INTEGER NOT NULL,
|
|
"paymentId" INTEGER,
|
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
|
|
CONSTRAINT "reversement_requests_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
-- CreateTable
|
|
CREATE TABLE "payments" (
|
|
"id" SERIAL NOT NULL,
|
|
"type" "PaymentType" NOT NULL,
|
|
"status" "TransactionStatus" NOT NULL,
|
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
|
|
CONSTRAINT "payments_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "reversement_requests" ADD CONSTRAINT "reversement_requests_transactionId_fkey" FOREIGN KEY ("transactionId") REFERENCES "transactions"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "reversement_requests" ADD CONSTRAINT "reversement_requests_paymentId_fkey" FOREIGN KEY ("paymentId") REFERENCES "payments"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|