summaryrefslogtreecommitdiff
path: root/prisma
diff options
context:
space:
mode:
Diffstat (limited to 'prisma')
-rw-r--r--prisma/client.ts15
-rw-r--r--prisma/migrations/20231101073315_initial/migration.sql80
-rw-r--r--prisma/migrations/migration_lock.toml3
-rw-r--r--prisma/schema.prisma70
4 files changed, 168 insertions, 0 deletions
diff --git a/prisma/client.ts b/prisma/client.ts
new file mode 100644
index 0000000..16df655
--- /dev/null
+++ b/prisma/client.ts
@@ -0,0 +1,15 @@
+import { PrismaClient } from "@prisma/client";
+
+const prismaClientSingleton = () => {
+ return new PrismaClient();
+};
+
+type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;
+
+const globalForPrisma = globalThis as unknown as {
+ prisma: PrismaClientSingleton | undefined;
+};
+
+export const prisma = globalForPrisma.prisma ?? prismaClientSingleton();
+
+if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
diff --git a/prisma/migrations/20231101073315_initial/migration.sql b/prisma/migrations/20231101073315_initial/migration.sql
new file mode 100644
index 0000000..e559eb2
--- /dev/null
+++ b/prisma/migrations/20231101073315_initial/migration.sql
@@ -0,0 +1,80 @@
+-- CreateTable
+CREATE TABLE `Company` (
+ `id` INTEGER NOT NULL AUTO_INCREMENT,
+ `name` VARCHAR(191) NOT NULL,
+
+ PRIMARY KEY (`id`)
+) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
+
+-- CreateTable
+CREATE TABLE `User` (
+ `id` INTEGER NOT NULL AUTO_INCREMENT,
+ `name` VARCHAR(191) NOT NULL,
+ `companyId` INTEGER NOT NULL,
+ `username` VARCHAR(191) NOT NULL,
+ `password` VARCHAR(191) NOT NULL,
+ `team` ENUM('COUNT1', 'COUNT2', 'VERIFICATION') NOT NULL,
+
+ UNIQUE INDEX `User_username_key`(`username`),
+ PRIMARY KEY (`id`)
+) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
+
+-- CreateTable
+CREATE TABLE `Location` (
+ `id` INTEGER NOT NULL AUTO_INCREMENT,
+ `name` VARCHAR(191) NOT NULL,
+ `companyId` INTEGER NOT NULL,
+
+ PRIMARY KEY (`id`)
+) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
+
+-- CreateTable
+CREATE TABLE `Product` (
+ `id` INTEGER NOT NULL AUTO_INCREMENT,
+ `barcode` VARCHAR(191) NOT NULL,
+ `itemCode` VARCHAR(191) NOT NULL,
+ `name` VARCHAR(191) NOT NULL,
+ `onhandQty` INTEGER NOT NULL,
+ `differenceQty` INTEGER NOT NULL,
+ `isDifferent` BOOLEAN NOT NULL,
+ `companyId` INTEGER NOT NULL,
+ `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
+ `updatedAt` DATETIME(3) NULL,
+
+ PRIMARY KEY (`id`)
+) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
+
+-- CreateTable
+CREATE TABLE `StockOpname` (
+ `id` INTEGER NOT NULL AUTO_INCREMENT,
+ `productId` INTEGER NOT NULL,
+ `locationId` INTEGER NOT NULL,
+ `companyId` INTEGER NOT NULL,
+ `userId` INTEGER NOT NULL,
+ `team` ENUM('COUNT1', 'COUNT2', 'VERIFICATION') NOT NULL,
+ `quantity` INTEGER NOT NULL,
+ `isDifferent` BOOLEAN NOT NULL,
+
+ PRIMARY KEY (`id`)
+) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
+
+-- AddForeignKey
+ALTER TABLE `User` ADD CONSTRAINT `User_companyId_fkey` FOREIGN KEY (`companyId`) REFERENCES `Company`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE `Location` ADD CONSTRAINT `Location_companyId_fkey` FOREIGN KEY (`companyId`) REFERENCES `Company`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE `Product` ADD CONSTRAINT `Product_companyId_fkey` FOREIGN KEY (`companyId`) REFERENCES `Company`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE `StockOpname` ADD CONSTRAINT `StockOpname_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Product`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE `StockOpname` ADD CONSTRAINT `StockOpname_locationId_fkey` FOREIGN KEY (`locationId`) REFERENCES `Location`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE `StockOpname` ADD CONSTRAINT `StockOpname_companyId_fkey` FOREIGN KEY (`companyId`) REFERENCES `Company`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE `StockOpname` ADD CONSTRAINT `StockOpname_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml
new file mode 100644
index 0000000..e5a788a
--- /dev/null
+++ b/prisma/migrations/migration_lock.toml
@@ -0,0 +1,3 @@
+# Please do not edit this file manually
+# It should be added in your version-control system (i.e. Git)
+provider = "mysql" \ No newline at end of file
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
new file mode 100644
index 0000000..a37f63c
--- /dev/null
+++ b/prisma/schema.prisma
@@ -0,0 +1,70 @@
+generator client {
+ provider = "prisma-client-js"
+}
+
+datasource db {
+ provider = "mysql"
+ url = env("DATABASE_URL")
+}
+
+model Company {
+ id Int @id @default(autoincrement())
+ name String
+ users User[]
+ locations Location[]
+ products Product[]
+ stockOpnames StockOpname[]
+}
+
+model User {
+ id Int @id @default(autoincrement())
+ name String
+ company Company @relation(fields: [companyId], references: [id])
+ companyId Int
+ username String @unique
+ password String
+ stockOpnames StockOpname[]
+ team Team
+}
+
+model Location {
+ id Int @id @default(autoincrement())
+ name String
+ company Company @relation(fields: [companyId], references: [id])
+ companyId Int
+ stockOpnames StockOpname[]
+}
+
+model Product {
+ id Int @id @default(autoincrement())
+ barcode String
+ itemCode String
+ name String
+ onhandQty Int
+ differenceQty Int
+ isDifferent Boolean
+ company Company @relation(fields: [companyId], references: [id])
+ companyId Int
+ stockOpnames StockOpname[]
+}
+
+model StockOpname {
+ id Int @id @default(autoincrement())
+ product Product @relation(fields: [productId], references: [id])
+ productId Int
+ location Location @relation(fields: [locationId], references: [id])
+ locationId Int
+ company Company @relation(fields: [companyId], references: [id])
+ companyId Int
+ user User @relation(fields: [userId], references: [id])
+ userId Int
+ team Team
+ quantity Int
+ isDifferent Boolean
+}
+
+enum Team {
+ COUNT1
+ COUNT2
+ VERIFICATION
+}