Skip to content

Commit

Permalink
feat: improve seeder
Browse files Browse the repository at this point in the history
  • Loading branch information
arrdix committed Jul 18, 2024
1 parent 7cc94de commit 288c381
Show file tree
Hide file tree
Showing 4 changed files with 454 additions and 41 deletions.
366 changes: 366 additions & 0 deletions prisma/migrations/20240718082749_create_prisma_schema/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,366 @@
-- CreateTable
CREATE TABLE "Users" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"email" TEXT NOT NULL,
"phone" TEXT,
"password" TEXT NOT NULL,
"role" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "Roles" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "Profile" (
"id" SERIAL NOT NULL,
"userId" INTEGER,

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

-- CreateTable
CREATE TABLE "Carts" (
"id" SERIAL NOT NULL,
"price" INTEGER NOT NULL,
"discount" INTEGER NOT NULL,
"userId" INTEGER,
"storeId" INTEGER,

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

-- CreateTable
CREATE TABLE "CartItems" (
"id" SERIAL NOT NULL,
"qty" INTEGER NOT NULL,
"price" INTEGER NOT NULL,
"cartId" INTEGER,
"userId" INTEGER,
"storeId" INTEGER,
"variantOptionValueId" INTEGER,

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

-- CreateTable
CREATE TABLE "Invoices" (
"id" SERIAL NOT NULL,
"price" INTEGER NOT NULL,
"serviceCharge" INTEGER NOT NULL,
"status" TEXT NOT NULL,
"receiverLatitude" DOUBLE PRECISION NOT NULL,
"receiverLongtitude" DOUBLE PRECISION NOT NULL,
"receiverDistrict" TEXT NOT NULL,
"receiverVillage" TEXT NOT NULL,
"receiverPhone" TEXT,
"receiverAddress" TEXT NOT NULL,
"receiverName" TEXT NOT NULL,
"invoiceNumber" TEXT NOT NULL,
"notes" TEXT,
"cartId" INTEGER,
"userId" INTEGER,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "ConfirmationPayment" (
"id" SERIAL NOT NULL,
"amount" INTEGER NOT NULL,
"bank" TEXT NOT NULL,
"invoiceId" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "InvoiceHistories" (
"id" SERIAL NOT NULL,
"status" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"invoiceId" INTEGER,

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

-- CreateTable
CREATE TABLE "Payments" (
"id" SERIAL NOT NULL,
"bank" TEXT NOT NULL,
"amount" INTEGER NOT NULL,
"status" TEXT NOT NULL,
"mootaTransactionId" INTEGER NOT NULL,
"invoiceId" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "Couriers" (
"id" SERIAL NOT NULL,
"courierCode" TEXT NOT NULL,
"courierServiceName" TEXT NOT NULL,
"courierServiceCode" TEXT NOT NULL,
"price" INTEGER NOT NULL,
"orderId" INTEGER NOT NULL,
"invoiceId" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "Stores" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"slogan" TEXT NOT NULL,
"description" TEXT NOT NULL,
"domain" TEXT NOT NULL,
"logoAttachment" TEXT NOT NULL,
"bannerAttachment" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "StoreOnDecorations" (
"id" SERIAL NOT NULL,
"decorationId" INTEGER,
"storeId" INTEGER,

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

-- CreateTable
CREATE TABLE "Decorations" (
"id" SERIAL NOT NULL,

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

-- CreateTable
CREATE TABLE "OperationHours" (
"id" SERIAL NOT NULL,
"day" TEXT NOT NULL,
"openAt" INTEGER NOT NULL,
"closeAt" INTEGER NOT NULL,
"isOff" BOOLEAN NOT NULL,
"storeId" INTEGER,

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

-- CreateTable
CREATE TABLE "MessageTemplate" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"content" TEXT NOT NULL,
"storeId" INTEGER,

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

-- CreateTable
CREATE TABLE "Locations" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"address" TEXT NOT NULL,
"postalCode" INTEGER NOT NULL,
"cityDistrict" TEXT NOT NULL,
"latitude" DOUBLE PRECISION NOT NULL,
"longtitude" DOUBLE PRECISION NOT NULL,
"isMainLocation" BOOLEAN NOT NULL,
"storeId" INTEGER,
"profileId" INTEGER,

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

-- CreateTable
CREATE TABLE "BankAccounts" (
"id" SERIAL NOT NULL,
"bank" TEXT NOT NULL,
"accNumber" INTEGER NOT NULL,
"accName" TEXT NOT NULL,
"storeId" INTEGER,

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

-- CreateTable
CREATE TABLE "Products" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT NOT NULL,
"attachments" TEXT[],
"isActive" BOOLEAN NOT NULL DEFAULT true,
"minimumOrder" INTEGER NOT NULL,
"url" TEXT NOT NULL,
"storeId" INTEGER,
"categoryId" INTEGER,

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

-- CreateTable
CREATE TABLE "Categories" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"subcategoryId" INTEGER,

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

-- CreateTable
CREATE TABLE "Variants" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"isActive" BOOLEAN NOT NULL DEFAULT true,
"productId" INTEGER,

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

-- CreateTable
CREATE TABLE "VariantOptions" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"variantId" INTEGER,
"variantOptionValuesId" INTEGER,

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

-- CreateTable
CREATE TABLE "VariantOptionValues" (
"id" SERIAL NOT NULL,
"sku" TEXT NOT NULL,
"weight" DOUBLE PRECISION NOT NULL,
"stock" INTEGER NOT NULL,
"price" DOUBLE PRECISION NOT NULL,
"isActive" BOOLEAN NOT NULL DEFAULT true,

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

-- CreateIndex
CREATE UNIQUE INDEX "Users_email_key" ON "Users"("email");

-- CreateIndex
CREATE UNIQUE INDEX "Roles_name_key" ON "Roles"("name");

-- CreateIndex
CREATE UNIQUE INDEX "Profile_userId_key" ON "Profile"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "ConfirmationPayment_invoiceId_key" ON "ConfirmationPayment"("invoiceId");

-- CreateIndex
CREATE UNIQUE INDEX "Payments_invoiceId_key" ON "Payments"("invoiceId");

-- CreateIndex
CREATE UNIQUE INDEX "Couriers_invoiceId_key" ON "Couriers"("invoiceId");

-- CreateIndex
CREATE UNIQUE INDEX "Products_url_key" ON "Products"("url");

-- CreateIndex
CREATE UNIQUE INDEX "Variants_productId_key" ON "Variants"("productId");

-- CreateIndex
CREATE UNIQUE INDEX "VariantOptions_variantOptionValuesId_key" ON "VariantOptions"("variantOptionValuesId");

-- CreateIndex
CREATE UNIQUE INDEX "VariantOptionValues_sku_key" ON "VariantOptionValues"("sku");

-- AddForeignKey
ALTER TABLE "Users" ADD CONSTRAINT "Users_role_fkey" FOREIGN KEY ("role") REFERENCES "Roles"("name") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Profile" ADD CONSTRAINT "Profile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Users"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Carts" ADD CONSTRAINT "Carts_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Users"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Carts" ADD CONSTRAINT "Carts_storeId_fkey" FOREIGN KEY ("storeId") REFERENCES "Stores"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CartItems" ADD CONSTRAINT "CartItems_cartId_fkey" FOREIGN KEY ("cartId") REFERENCES "Carts"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CartItems" ADD CONSTRAINT "CartItems_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Users"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CartItems" ADD CONSTRAINT "CartItems_storeId_fkey" FOREIGN KEY ("storeId") REFERENCES "Stores"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CartItems" ADD CONSTRAINT "CartItems_variantOptionValueId_fkey" FOREIGN KEY ("variantOptionValueId") REFERENCES "VariantOptionValues"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Invoices" ADD CONSTRAINT "Invoices_cartId_fkey" FOREIGN KEY ("cartId") REFERENCES "Carts"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Invoices" ADD CONSTRAINT "Invoices_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Users"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ConfirmationPayment" ADD CONSTRAINT "ConfirmationPayment_invoiceId_fkey" FOREIGN KEY ("invoiceId") REFERENCES "Invoices"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "InvoiceHistories" ADD CONSTRAINT "InvoiceHistories_invoiceId_fkey" FOREIGN KEY ("invoiceId") REFERENCES "Invoices"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Payments" ADD CONSTRAINT "Payments_invoiceId_fkey" FOREIGN KEY ("invoiceId") REFERENCES "Invoices"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Couriers" ADD CONSTRAINT "Couriers_invoiceId_fkey" FOREIGN KEY ("invoiceId") REFERENCES "Invoices"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "StoreOnDecorations" ADD CONSTRAINT "StoreOnDecorations_decorationId_fkey" FOREIGN KEY ("decorationId") REFERENCES "Decorations"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "StoreOnDecorations" ADD CONSTRAINT "StoreOnDecorations_storeId_fkey" FOREIGN KEY ("storeId") REFERENCES "Stores"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "OperationHours" ADD CONSTRAINT "OperationHours_storeId_fkey" FOREIGN KEY ("storeId") REFERENCES "Stores"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MessageTemplate" ADD CONSTRAINT "MessageTemplate_storeId_fkey" FOREIGN KEY ("storeId") REFERENCES "Stores"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Locations" ADD CONSTRAINT "Locations_storeId_fkey" FOREIGN KEY ("storeId") REFERENCES "Stores"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Locations" ADD CONSTRAINT "Locations_profileId_fkey" FOREIGN KEY ("profileId") REFERENCES "Profile"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "BankAccounts" ADD CONSTRAINT "BankAccounts_storeId_fkey" FOREIGN KEY ("storeId") REFERENCES "Stores"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Products" ADD CONSTRAINT "Products_storeId_fkey" FOREIGN KEY ("storeId") REFERENCES "Stores"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Products" ADD CONSTRAINT "Products_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "Categories"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Categories" ADD CONSTRAINT "Categories_subcategoryId_fkey" FOREIGN KEY ("subcategoryId") REFERENCES "Categories"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Variants" ADD CONSTRAINT "Variants_productId_fkey" FOREIGN KEY ("productId") REFERENCES "Products"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "VariantOptions" ADD CONSTRAINT "VariantOptions_variantId_fkey" FOREIGN KEY ("variantId") REFERENCES "Variants"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "VariantOptions" ADD CONSTRAINT "VariantOptions_variantOptionValuesId_fkey" FOREIGN KEY ("variantOptionValuesId") REFERENCES "VariantOptionValues"("id") ON DELETE CASCADE ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
Loading

0 comments on commit 288c381

Please sign in to comment.