refactor user accounts structure

This commit is contained in:
2026-03-16 00:33:40 +03:30
parent d2215b9f04
commit 0ad6a3200e
118 changed files with 18774 additions and 8764 deletions
@@ -1,155 +0,0 @@
-- CreateTable
CREATE TABLE `Goods` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`description` TEXT NULL,
`sku` VARCHAR(100) NOT NULL,
`localSku` VARCHAR(100) NOT NULL,
`barcode` VARCHAR(100) NULL,
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updatedAt` TIMESTAMP(0) NOT NULL,
`deletedAt` TIMESTAMP(0) NULL,
`categoryId` INTEGER NULL,
`baseSalePrice` DECIMAL(15, 0) NOT NULL DEFAULT 0.00,
UNIQUE INDEX `Goods_localSku_key`(`localSku`),
UNIQUE INDEX `Goods_barcode_key`(`barcode`),
INDEX `Goods_categoryId_idx`(`categoryId`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Good_categories` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) NOT NULL,
`description` TEXT NULL,
`imageUrl` VARCHAR(255) NULL,
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updatedAt` TIMESTAMP(0) NOT NULL,
`deletedAt` TIMESTAMP(0) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Customers` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`firstName` VARCHAR(255) NOT NULL,
`lastName` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NULL,
`mobileNumber` CHAR(11) NOT NULL,
`address` TEXT NULL,
`isActive` BOOLEAN NOT NULL DEFAULT true,
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updatedAt` TIMESTAMP(0) NOT NULL,
`deletedAt` TIMESTAMP(0) NULL,
UNIQUE INDEX `Customers_mobileNumber_key`(`mobileNumber`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Trigger_Logs` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`message` TEXT NOT NULL,
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`name` TEXT NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Sales_Invoices` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`code` VARCHAR(100) NOT NULL,
`totalAmount` DECIMAL(15, 2) NOT NULL,
`description` TEXT NULL,
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updatedAt` TIMESTAMP(0) NOT NULL,
`customerId` INTEGER NULL,
UNIQUE INDEX `Sales_Invoices_code_key`(`code`),
INDEX `Sales_Invoices_customerId_idx`(`customerId`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Sales_Invoice_Items` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`count` DECIMAL(10, 0) NOT NULL,
`unitPrice` DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
`totalAmount` DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`invoiceId` INTEGER NOT NULL,
`goodId` INTEGER NOT NULL,
`serviceId` INTEGER NOT NULL,
INDEX `Sales_Invoice_Items_invoiceId_goodId_idx`(`invoiceId`, `goodId`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Sales_Invoice_Payments` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`invoiceId` INTEGER NOT NULL,
`amount` DECIMAL(15, 2) NOT NULL,
`paymentMethod` ENUM('CASH', 'CARD', 'BANK', 'CHECK', 'OTHER') NOT NULL,
`paidAt` DATETIME(3) NOT NULL,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
INDEX `Sales_Invoice_Payments_invoiceId_idx`(`invoiceId`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Services` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`description` TEXT NULL,
`sku` VARCHAR(100) NOT NULL,
`barcode` VARCHAR(100) NULL,
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updatedAt` TIMESTAMP(0) NOT NULL,
`deletedAt` TIMESTAMP(0) NULL,
`categoryId` INTEGER NULL,
`baseSalePrice` DECIMAL(15, 0) NOT NULL DEFAULT 0.00,
UNIQUE INDEX `Services_sku_key`(`sku`),
UNIQUE INDEX `Services_barcode_key`(`barcode`),
INDEX `Services_categoryId_idx`(`categoryId`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Service_categories` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) NOT NULL,
`description` TEXT NULL,
`imageUrl` VARCHAR(255) NULL,
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updatedAt` TIMESTAMP(0) NOT NULL,
`deletedAt` TIMESTAMP(0) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `Goods` ADD CONSTRAINT `Goods_categoryId_fkey` FOREIGN KEY (`categoryId`) REFERENCES `Good_categories`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Sales_Invoices` ADD CONSTRAINT `Sales_Invoices_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customers`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Sales_Invoice_Items` ADD CONSTRAINT `Sales_Invoice_Items_invoiceId_fkey` FOREIGN KEY (`invoiceId`) REFERENCES `Sales_Invoices`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Sales_Invoice_Items` ADD CONSTRAINT `Sales_Invoice_Items_goodId_fkey` FOREIGN KEY (`goodId`) REFERENCES `Goods`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Sales_Invoice_Items` ADD CONSTRAINT `Sales_Invoice_Items_serviceId_fkey` FOREIGN KEY (`serviceId`) REFERENCES `Services`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Sales_Invoice_Payments` ADD CONSTRAINT `Sales_Invoice_Payments_invoiceId_fkey` FOREIGN KEY (`invoiceId`) REFERENCES `Sales_Invoices`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Services` ADD CONSTRAINT `Services_categoryId_fkey` FOREIGN KEY (`categoryId`) REFERENCES `Service_categories`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
@@ -1,245 +0,0 @@
/*
Warnings:
- The primary key for the `Sales_Invoice_Payments` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `createdAt` on the `Sales_Invoice_Payments` table. All the data in the column will be lost.
- You are about to drop the column `invoiceId` on the `Sales_Invoice_Payments` table. All the data in the column will be lost.
- You are about to drop the column `paidAt` on the `Sales_Invoice_Payments` table. All the data in the column will be lost.
- You are about to drop the column `paymentMethod` on the `Sales_Invoice_Payments` table. All the data in the column will be lost.
- You are about to drop the `Customers` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `Good_categories` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `Goods` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `Sales_Invoice_Items` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `Sales_Invoices` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `Service_categories` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `Services` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `Trigger_Logs` table. If the table is not empty, all the data it contains will be lost.
- Added the required column `invoice_id` to the `Sales_Invoice_Payments` table without a default value. This is not possible if the table is not empty.
- Added the required column `paid_at` to the `Sales_Invoice_Payments` table without a default value. This is not possible if the table is not empty.
- Added the required column `payment_method` to the `Sales_Invoice_Payments` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE `Goods` DROP FOREIGN KEY `Goods_categoryId_fkey`;
-- DropForeignKey
ALTER TABLE `Sales_Invoice_Items` DROP FOREIGN KEY `Sales_Invoice_Items_goodId_fkey`;
-- DropForeignKey
ALTER TABLE `Sales_Invoice_Items` DROP FOREIGN KEY `Sales_Invoice_Items_invoiceId_fkey`;
-- DropForeignKey
ALTER TABLE `Sales_Invoice_Items` DROP FOREIGN KEY `Sales_Invoice_Items_serviceId_fkey`;
-- DropForeignKey
ALTER TABLE `Sales_Invoice_Payments` DROP FOREIGN KEY `Sales_Invoice_Payments_invoiceId_fkey`;
-- DropForeignKey
ALTER TABLE `Sales_Invoices` DROP FOREIGN KEY `Sales_Invoices_customerId_fkey`;
-- DropForeignKey
ALTER TABLE `Services` DROP FOREIGN KEY `Services_categoryId_fkey`;
-- DropIndex
DROP INDEX `Sales_Invoice_Payments_invoiceId_idx` ON `Sales_Invoice_Payments`;
-- AlterTable
ALTER TABLE `Sales_Invoice_Payments` DROP PRIMARY KEY,
DROP COLUMN `createdAt`,
DROP COLUMN `invoiceId`,
DROP COLUMN `paidAt`,
DROP COLUMN `paymentMethod`,
ADD COLUMN `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
ADD COLUMN `invoice_id` VARCHAR(191) NOT NULL,
ADD COLUMN `paid_at` DATETIME(3) NOT NULL,
ADD COLUMN `payment_method` ENUM('CASH', 'CARD', 'BANK', 'CHECK', 'OTHER') NOT NULL,
MODIFY `id` VARCHAR(191) NOT NULL,
ADD PRIMARY KEY (`id`);
-- DropTable
DROP TABLE `Customers`;
-- DropTable
DROP TABLE `Good_categories`;
-- DropTable
DROP TABLE `Goods`;
-- DropTable
DROP TABLE `Sales_Invoice_Items`;
-- DropTable
DROP TABLE `Sales_Invoices`;
-- DropTable
DROP TABLE `Service_categories`;
-- DropTable
DROP TABLE `Services`;
-- DropTable
DROP TABLE `Trigger_Logs`;
-- CreateTable
CREATE TABLE `customers` (
`id` VARCHAR(191) NOT NULL,
`first_name` VARCHAR(255) NOT NULL,
`last_name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NULL,
`mobile_number` CHAR(11) NOT NULL,
`address` TEXT NULL,
`is_active` BOOLEAN NOT NULL DEFAULT true,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`deleted_at` TIMESTAMP(0) NULL,
UNIQUE INDEX `customers_mobile_number_key`(`mobile_number`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `devices` (
`account_id` VARCHAR(255) NULL,
`app_version` VARCHAR(20) NOT NULL,
`build_number` VARCHAR(20) NOT NULL,
`device_id` VARCHAR(255) NOT NULL,
`platform` VARCHAR(100) NOT NULL,
`brand` VARCHAR(100) NOT NULL,
`model` VARCHAR(100) NOT NULL,
`device` VARCHAR(100) NOT NULL,
`os_version` VARCHAR(20) NOT NULL,
`sdk_version` VARCHAR(20) NOT NULL,
`release_number` VARCHAR(20) NOT NULL,
`browser_name` VARCHAR(100) NULL,
PRIMARY KEY (`device_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `goods` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`description` TEXT NULL,
`sku` VARCHAR(100) NOT NULL,
`local_sku` VARCHAR(100) NOT NULL,
`barcode` VARCHAR(100) NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`deleted_at` TIMESTAMP(0) NULL,
`category_id` VARCHAR(191) NULL,
`base_sale_price` DECIMAL(15, 0) NOT NULL DEFAULT 0.00,
UNIQUE INDEX `goods_local_sku_key`(`local_sku`),
UNIQUE INDEX `goods_barcode_key`(`barcode`),
INDEX `goods_category_id_idx`(`category_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `good_categories` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(100) NOT NULL,
`description` TEXT NULL,
`image_url` VARCHAR(255) NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`deleted_at` TIMESTAMP(0) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `trigger_logs` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`message` TEXT NOT NULL,
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`name` TEXT NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `sales_invoices` (
`id` VARCHAR(191) NOT NULL,
`code` VARCHAR(100) NOT NULL,
`total_amount` DECIMAL(15, 2) NOT NULL,
`description` TEXT NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`customer_id` VARCHAR(191) NULL,
UNIQUE INDEX `sales_invoices_code_key`(`code`),
INDEX `sales_invoices_customer_id_idx`(`customer_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `sales_invoice_items` (
`id` VARCHAR(191) NOT NULL,
`count` DECIMAL(10, 0) NOT NULL,
`unit_price` DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
`total_amount` DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`invoice_id` VARCHAR(191) NOT NULL,
`good_id` VARCHAR(191) NOT NULL,
`service_id` VARCHAR(191) NOT NULL,
INDEX `sales_invoice_items_invoice_id_good_id_idx`(`invoice_id`, `good_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `services` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`description` TEXT NULL,
`sku` VARCHAR(100) NOT NULL,
`barcode` VARCHAR(100) NULL,
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updatedAt` TIMESTAMP(0) NOT NULL,
`deletedAt` TIMESTAMP(0) NULL,
`categoryId` VARCHAR(191) NULL,
`baseSalePrice` DECIMAL(15, 0) NOT NULL DEFAULT 0.00,
UNIQUE INDEX `services_sku_key`(`sku`),
UNIQUE INDEX `services_barcode_key`(`barcode`),
INDEX `services_categoryId_idx`(`categoryId`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `service_categories` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(100) NOT NULL,
`description` TEXT NULL,
`imageUrl` VARCHAR(255) NULL,
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updatedAt` TIMESTAMP(0) NOT NULL,
`deletedAt` TIMESTAMP(0) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateIndex
CREATE INDEX `Sales_Invoice_Payments_invoice_id_idx` ON `Sales_Invoice_Payments`(`invoice_id`);
-- AddForeignKey
ALTER TABLE `goods` ADD CONSTRAINT `goods_category_id_fkey` FOREIGN KEY (`category_id`) REFERENCES `good_categories`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `sales_invoices` ADD CONSTRAINT `sales_invoices_customer_id_fkey` FOREIGN KEY (`customer_id`) REFERENCES `customers`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `sales_invoice_items` ADD CONSTRAINT `sales_invoice_items_invoice_id_fkey` FOREIGN KEY (`invoice_id`) REFERENCES `sales_invoices`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `sales_invoice_items` ADD CONSTRAINT `sales_invoice_items_good_id_fkey` FOREIGN KEY (`good_id`) REFERENCES `goods`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `sales_invoice_items` ADD CONSTRAINT `sales_invoice_items_service_id_fkey` FOREIGN KEY (`service_id`) REFERENCES `services`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Sales_Invoice_Payments` ADD CONSTRAINT `Sales_Invoice_Payments_invoice_id_fkey` FOREIGN KEY (`invoice_id`) REFERENCES `sales_invoices`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `services` ADD CONSTRAINT `services_categoryId_fkey` FOREIGN KEY (`categoryId`) REFERENCES `service_categories`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
@@ -1,13 +0,0 @@
/*
Warnings:
- The primary key for the `devices` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `device_id` on the `devices` table. All the data in the column will be lost.
- Added the required column `uuid` to the `devices` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE `devices` DROP PRIMARY KEY,
DROP COLUMN `device_id`,
ADD COLUMN `uuid` VARCHAR(255) NOT NULL,
ADD PRIMARY KEY (`uuid`);
@@ -1,8 +0,0 @@
/*
Warnings:
- A unique constraint covering the columns `[uuid]` on the table `devices` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX `devices_uuid_key` ON `devices`(`uuid`);
@@ -1,2 +0,0 @@
-- AlterTable
ALTER TABLE `devices` ADD COLUMN `fcm_token` VARCHAR(100) NULL;
@@ -1,87 +0,0 @@
/*
Warnings:
- You are about to drop the column `createdAt` on the `service_categories` table. All the data in the column will be lost.
- You are about to drop the column `deletedAt` on the `service_categories` table. All the data in the column will be lost.
- You are about to drop the column `imageUrl` on the `service_categories` table. All the data in the column will be lost.
- You are about to drop the column `updatedAt` on the `service_categories` table. All the data in the column will be lost.
- You are about to drop the column `baseSalePrice` on the `services` table. All the data in the column will be lost.
- You are about to drop the column `categoryId` on the `services` table. All the data in the column will be lost.
- You are about to drop the column `createdAt` on the `services` table. All the data in the column will be lost.
- You are about to drop the column `deletedAt` on the `services` table. All the data in the column will be lost.
- You are about to drop the column `updatedAt` on the `services` table. All the data in the column will be lost.
- A unique constraint covering the columns `[local_sku]` on the table `services` will be added. If there are existing duplicate values, this will fail.
- Added the required column `account_id` to the `customers` table without a default value. This is not possible if the table is not empty.
- Added the required column `complex_id` to the `customers` table without a default value. This is not possible if the table is not empty.
- Added the required column `account_id` to the `good_categories` table without a default value. This is not possible if the table is not empty.
- Added the required column `complex_id` to the `good_categories` table without a default value. This is not possible if the table is not empty.
- Added the required column `account_id` to the `goods` table without a default value. This is not possible if the table is not empty.
- Added the required column `complex_id` to the `goods` table without a default value. This is not possible if the table is not empty.
- Added the required column `account_id` to the `sales_invoices` table without a default value. This is not possible if the table is not empty.
- Added the required column `complex_id` to the `sales_invoices` table without a default value. This is not possible if the table is not empty.
- Added the required column `account_id` to the `service_categories` table without a default value. This is not possible if the table is not empty.
- Added the required column `complex_id` to the `service_categories` table without a default value. This is not possible if the table is not empty.
- Added the required column `updated_at` to the `service_categories` table without a default value. This is not possible if the table is not empty.
- Added the required column `account_id` to the `services` table without a default value. This is not possible if the table is not empty.
- Added the required column `complex_id` to the `services` table without a default value. This is not possible if the table is not empty.
- Added the required column `updated_at` to the `services` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE `services` DROP FOREIGN KEY `services_categoryId_fkey`;
-- DropIndex
DROP INDEX `services_categoryId_idx` ON `services`;
-- AlterTable
ALTER TABLE `customers` ADD COLUMN `account_id` VARCHAR(191) NOT NULL,
ADD COLUMN `complex_id` VARCHAR(191) NOT NULL;
-- AlterTable
ALTER TABLE `good_categories` ADD COLUMN `account_id` VARCHAR(191) NOT NULL,
ADD COLUMN `complex_id` VARCHAR(191) NOT NULL;
-- AlterTable
ALTER TABLE `goods` ADD COLUMN `account_id` VARCHAR(191) NOT NULL,
ADD COLUMN `complex_id` VARCHAR(191) NOT NULL,
MODIFY `local_sku` VARCHAR(100) NULL;
-- AlterTable
ALTER TABLE `sales_invoices` ADD COLUMN `account_id` VARCHAR(191) NOT NULL,
ADD COLUMN `complex_id` VARCHAR(191) NOT NULL;
-- AlterTable
ALTER TABLE `service_categories` DROP COLUMN `createdAt`,
DROP COLUMN `deletedAt`,
DROP COLUMN `imageUrl`,
DROP COLUMN `updatedAt`,
ADD COLUMN `account_id` VARCHAR(191) NOT NULL,
ADD COLUMN `complex_id` VARCHAR(191) NOT NULL,
ADD COLUMN `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
ADD COLUMN `deleted_at` TIMESTAMP(0) NULL,
ADD COLUMN `image_url` VARCHAR(255) NULL,
ADD COLUMN `updated_at` TIMESTAMP(0) NOT NULL;
-- AlterTable
ALTER TABLE `services` DROP COLUMN `baseSalePrice`,
DROP COLUMN `categoryId`,
DROP COLUMN `createdAt`,
DROP COLUMN `deletedAt`,
DROP COLUMN `updatedAt`,
ADD COLUMN `account_id` VARCHAR(191) NOT NULL,
ADD COLUMN `base_sale_price` DECIMAL(15, 0) NOT NULL DEFAULT 0.00,
ADD COLUMN `category_id` VARCHAR(191) NULL,
ADD COLUMN `complex_id` VARCHAR(191) NOT NULL,
ADD COLUMN `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
ADD COLUMN `deleted_at` TIMESTAMP(0) NULL,
ADD COLUMN `local_sku` VARCHAR(100) NULL,
ADD COLUMN `updated_at` TIMESTAMP(0) NOT NULL;
-- CreateIndex
CREATE UNIQUE INDEX `services_local_sku_key` ON `services`(`local_sku`);
-- CreateIndex
CREATE INDEX `services_category_id_idx` ON `services`(`category_id`);
-- AddForeignKey
ALTER TABLE `services` ADD CONSTRAINT `services_category_id_fkey` FOREIGN KEY (`category_id`) REFERENCES `service_categories`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
@@ -1,27 +0,0 @@
/*
Warnings:
- You are about to drop the `Sales_Invoice_Payments` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE `Sales_Invoice_Payments` DROP FOREIGN KEY `Sales_Invoice_Payments_invoice_id_fkey`;
-- DropTable
DROP TABLE `Sales_Invoice_Payments`;
-- CreateTable
CREATE TABLE `sales_invoice_payments` (
`id` VARCHAR(191) NOT NULL,
`invoice_id` VARCHAR(191) NOT NULL,
`amount` DECIMAL(15, 2) NOT NULL,
`payment_method` ENUM('CASH', 'CARD', 'BANK', 'CHECK', 'OTHER') NOT NULL,
`paid_at` DATETIME(3) NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
INDEX `sales_invoice_payments_invoice_id_idx`(`invoice_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `sales_invoice_payments` ADD CONSTRAINT `sales_invoice_payments_invoice_id_fkey` FOREIGN KEY (`invoice_id`) REFERENCES `sales_invoices`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
@@ -1,2 +0,0 @@
-- AlterTable
ALTER TABLE `goods` ADD COLUMN `price_text` VARCHAR(100) NULL;
@@ -1,37 +0,0 @@
/*
Warnings:
- You are about to drop the column `price_text` on the `goods` table. All the data in the column will be lost.
- You are about to drop the column `count` on the `sales_invoice_items` table. All the data in the column will be lost.
- Added the required column `quantity` to the `sales_invoice_items` table without a default value. This is not possible if the table is not empty.
- Added the required column `unit_type` to the `sales_invoice_items` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE `sales_invoice_items` DROP FOREIGN KEY `sales_invoice_items_good_id_fkey`;
-- DropForeignKey
ALTER TABLE `sales_invoice_items` DROP FOREIGN KEY `sales_invoice_items_service_id_fkey`;
-- DropIndex
DROP INDEX `sales_invoice_items_good_id_fkey` ON `sales_invoice_items`;
-- DropIndex
DROP INDEX `sales_invoice_items_service_id_fkey` ON `sales_invoice_items`;
-- AlterTable
ALTER TABLE `goods` DROP COLUMN `price_text`;
-- AlterTable
ALTER TABLE `sales_invoice_items` DROP COLUMN `count`,
ADD COLUMN `payload` JSON NULL,
ADD COLUMN `quantity` DECIMAL(10, 0) NOT NULL,
ADD COLUMN `unit_type` ENUM('COUNT', 'GRAM', 'KILOGRAM', 'LITER', 'METER', 'HOUR') NOT NULL,
MODIFY `good_id` VARCHAR(191) NULL,
MODIFY `service_id` VARCHAR(191) NULL;
-- AddForeignKey
ALTER TABLE `sales_invoice_items` ADD CONSTRAINT `sales_invoice_items_good_id_fkey` FOREIGN KEY (`good_id`) REFERENCES `goods`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `sales_invoice_items` ADD CONSTRAINT `sales_invoice_items_service_id_fkey` FOREIGN KEY (`service_id`) REFERENCES `services`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
@@ -1,55 +0,0 @@
/*
Warnings:
- You are about to drop the column `account_id` on the `customers` table. All the data in the column will be lost.
- You are about to drop the column `address` on the `customers` table. All the data in the column will be lost.
- You are about to drop the column `email` on the `customers` table. All the data in the column will be lost.
- You are about to drop the column `first_name` on the `customers` table. All the data in the column will be lost.
- You are about to drop the column `is_active` on the `customers` table. All the data in the column will be lost.
- You are about to drop the column `last_name` on the `customers` table. All the data in the column will be lost.
- You are about to drop the column `mobile_number` on the `customers` table. All the data in the column will be lost.
- Added the required column `type` to the `customers` table without a default value. This is not possible if the table is not empty.
*/
-- DropIndex
DROP INDEX `customers_mobile_number_key` ON `customers`;
-- AlterTable
ALTER TABLE `customers` DROP COLUMN `account_id`,
DROP COLUMN `address`,
DROP COLUMN `email`,
DROP COLUMN `first_name`,
DROP COLUMN `is_active`,
DROP COLUMN `last_name`,
DROP COLUMN `mobile_number`,
ADD COLUMN `is_favorite` BOOLEAN NULL DEFAULT false,
ADD COLUMN `type` ENUM('INDIVIDUAL', 'LEGAL') NOT NULL;
-- CreateTable
CREATE TABLE `customer_individuals` (
`customer_id` VARCHAR(191) NOT NULL,
`first_name` VARCHAR(255) NOT NULL,
`last_name` VARCHAR(255) NOT NULL,
`national_id` CHAR(10) NOT NULL,
`postal_code` CHAR(10) NOT NULL,
`economic_code` CHAR(10) NULL,
PRIMARY KEY (`customer_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `customer_legal` (
`customer_id` VARCHAR(191) NOT NULL,
`company_name` VARCHAR(255) NOT NULL,
`economic_code` CHAR(10) NOT NULL,
`registration_number` CHAR(20) NOT NULL,
`postal_code` CHAR(10) NOT NULL,
PRIMARY KEY (`customer_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `customer_individuals` ADD CONSTRAINT `customer_individuals_customer_id_fkey` FOREIGN KEY (`customer_id`) REFERENCES `customers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `customer_legal` ADD CONSTRAINT `customer_legal_customer_id_fkey` FOREIGN KEY (`customer_id`) REFERENCES `customers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
@@ -1,3 +0,0 @@
-- AlterTable
ALTER TABLE `sales_invoice_items` ADD COLUMN `discount` DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
ADD COLUMN `pricingModel` ENUM('STANDARD', 'GOLD') NOT NULL DEFAULT 'STANDARD';
@@ -1,20 +0,0 @@
/*
Warnings:
- You are about to drop the column `description` on the `sales_invoices` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE `customers` MODIFY `type` ENUM('INDIVIDUAL', 'LEGAL', 'UNKNOWN') NOT NULL;
-- AlterTable
ALTER TABLE `sales_invoice_items` ADD COLUMN `notes` TEXT NULL;
-- AlterTable
ALTER TABLE `sales_invoice_payments` MODIFY `payment_method` ENUM('TERMINAL', 'CASH', 'SET_OFF', 'CARD', 'BANK', 'CHECK', 'OTHER') NOT NULL;
-- AlterTable
ALTER TABLE `sales_invoices` DROP COLUMN `description`,
ADD COLUMN `invoice_date` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
ADD COLUMN `notes` TEXT NULL,
ADD COLUMN `unknown_customer` JSON NULL;
@@ -1,272 +0,0 @@
/*
Warnings:
- The primary key for the `devices` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `account_id` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `app_version` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `brand` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `browser_name` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `build_number` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `device` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `fcm_token` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `model` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `platform` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `release_number` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `sdk_version` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `uuid` on the `devices` table. All the data in the column will be lost.
- A unique constraint covering the columns `[complex_id,national_id]` on the table `customer_individuals` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[complex_id,registration_number]` on the table `customer_legal` will be added. If there are existing duplicate values, this will fail.
- Added the required column `complex_id` to the `customer_individuals` table without a default value. This is not possible if the table is not empty.
- Added the required column `complex_id` to the `customer_legal` table without a default value. This is not possible if the table is not empty.
- Added the required column `brand_id` to the `devices` table without a default value. This is not possible if the table is not empty.
- The required column `id` was added to the `devices` table with a prisma-level default value. This is not possible if the table is not empty. Please add this column as optional, then populate it before making it required.
- Added the required column `name` to the `devices` table without a default value. This is not possible if the table is not empty.
- Added the required column `updated_at` to the `devices` table without a default value. This is not possible if the table is not empty.
*/
-- DropIndex
DROP INDEX `devices_uuid_key` ON `devices`;
-- AlterTable
ALTER TABLE `customer_individuals` ADD COLUMN `complex_id` VARCHAR(191) NOT NULL;
-- AlterTable
ALTER TABLE `customer_legal` ADD COLUMN `complex_id` VARCHAR(191) NOT NULL;
-- AlterTable
ALTER TABLE `devices` DROP PRIMARY KEY,
DROP COLUMN `account_id`,
DROP COLUMN `app_version`,
DROP COLUMN `brand`,
DROP COLUMN `browser_name`,
DROP COLUMN `build_number`,
DROP COLUMN `device`,
DROP COLUMN `fcm_token`,
DROP COLUMN `model`,
DROP COLUMN `platform`,
DROP COLUMN `release_number`,
DROP COLUMN `sdk_version`,
DROP COLUMN `uuid`,
ADD COLUMN `brand_id` VARCHAR(191) NOT NULL,
ADD COLUMN `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
ADD COLUMN `id` VARCHAR(191) NOT NULL,
ADD COLUMN `name` VARCHAR(191) NOT NULL,
ADD COLUMN `updated_at` DATETIME(3) NOT NULL,
MODIFY `os_version` VARCHAR(191) NULL,
ADD PRIMARY KEY (`id`);
-- CreateTable
CREATE TABLE `tokens` (
`id` VARCHAR(191) NOT NULL,
`token` VARCHAR(191) NOT NULL,
`type` ENUM('ACCESS', 'REFRESH') NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`expires_at` DATETIME(3) NOT NULL,
`account_id` VARCHAR(191) NOT NULL,
UNIQUE INDEX `tokens_token_key`(`token`),
UNIQUE INDEX `tokens_type_account_id_key`(`type`, `account_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `verification_codes` (
`id` VARCHAR(191) NOT NULL,
`code` VARCHAR(191) NOT NULL,
`is_used` BOOLEAN NOT NULL DEFAULT false,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`expires_at` DATETIME(3) NOT NULL,
`account_id` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `guilds` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`code` VARCHAR(191) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `business_activities` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`tax_id` VARCHAR(191) NULL,
`guild_id` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `complexes` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`address` VARCHAR(191) NULL,
`business_activity_id` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `poses` (
`id` VARCHAR(191) NOT NULL,
`serial` VARCHAR(191) NOT NULL,
`model` VARCHAR(191) NULL,
`status` ENUM('ACTIVE', 'DISABLED') NOT NULL DEFAULT 'ACTIVE',
`pos_type` ENUM('PSP', 'MOBILE', 'API') NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL,
`complex_id` VARCHAR(191) NOT NULL,
`device_id` VARCHAR(191) NOT NULL,
`provider_id` VARCHAR(191) NULL,
UNIQUE INDEX `poses_serial_key`(`serial`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `device_brands` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `licenses` (
`id` VARCHAR(191) NOT NULL,
`pos_id` VARCHAR(191) NOT NULL,
`partner_id` VARCHAR(191) NOT NULL,
`starts_at` DATETIME(3) NOT NULL,
`expires_at` DATETIME(3) NOT NULL,
`status` ENUM('ACTIVE', 'EXPIRED', 'SUSPENDED') NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `partners` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`code` VARCHAR(191) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `users` (
`id` VARCHAR(191) NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`mobile_number` VARCHAR(191) NOT NULL,
`national_code` VARCHAR(191) NULL,
`first_name` VARCHAR(191) NOT NULL,
`last_name` VARCHAR(191) NOT NULL,
UNIQUE INDEX `users_mobile_number_key`(`mobile_number`),
UNIQUE INDEX `users_national_code_key`(`national_code`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `accounts` (
`id` VARCHAR(191) NOT NULL,
`username` VARCHAR(191) NOT NULL,
`type` ENUM('PARTNER', 'BUSINESS', 'ADMIN', 'PROVIDER', 'POS') NOT NULL,
`status` ENUM('ACTIVE', 'SUSPENDED') NOT NULL,
`password` VARCHAR(191) NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`user_id` VARCHAR(191) NOT NULL,
`partner_id` VARCHAR(191) NULL,
`business_id` VARCHAR(191) NULL,
`provider_id` VARCHAR(191) NULL,
`pos_id` VARCHAR(191) NULL,
UNIQUE INDEX `accounts_username_key`(`username`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `providers` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`code` VARCHAR(191) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `user_devices` (
`account_id` VARCHAR(255) NULL,
`app_version` VARCHAR(20) NOT NULL,
`build_number` VARCHAR(20) NOT NULL,
`uuid` VARCHAR(255) NOT NULL,
`platform` VARCHAR(100) NOT NULL,
`brand` VARCHAR(100) NOT NULL,
`model` VARCHAR(100) NOT NULL,
`device` VARCHAR(100) NOT NULL,
`os_version` VARCHAR(20) NOT NULL,
`sdk_version` VARCHAR(20) NOT NULL,
`release_number` VARCHAR(20) NOT NULL,
`browser_name` VARCHAR(100) NULL,
`fcm_token` VARCHAR(100) NULL,
UNIQUE INDEX `user_devices_uuid_key`(`uuid`),
PRIMARY KEY (`uuid`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateIndex
CREATE UNIQUE INDEX `customer_individuals_complex_id_national_id_key` ON `customer_individuals`(`complex_id`, `national_id`);
-- CreateIndex
CREATE UNIQUE INDEX `customer_legal_complex_id_registration_number_key` ON `customer_legal`(`complex_id`, `registration_number`);
-- AddForeignKey
ALTER TABLE `tokens` ADD CONSTRAINT `tokens_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `verification_codes` ADD CONSTRAINT `verification_codes_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `business_activities` ADD CONSTRAINT `business_activities_guild_id_fkey` FOREIGN KEY (`guild_id`) REFERENCES `guilds`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `complexes` ADD CONSTRAINT `complexes_business_activity_id_fkey` FOREIGN KEY (`business_activity_id`) REFERENCES `business_activities`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `poses` ADD CONSTRAINT `poses_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `poses` ADD CONSTRAINT `poses_device_id_fkey` FOREIGN KEY (`device_id`) REFERENCES `devices`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `poses` ADD CONSTRAINT `poses_provider_id_fkey` FOREIGN KEY (`provider_id`) REFERENCES `providers`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `devices` ADD CONSTRAINT `devices_brand_id_fkey` FOREIGN KEY (`brand_id`) REFERENCES `device_brands`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `licenses` ADD CONSTRAINT `licenses_pos_id_fkey` FOREIGN KEY (`pos_id`) REFERENCES `poses`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `licenses` ADD CONSTRAINT `licenses_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_business_id_fkey` FOREIGN KEY (`business_id`) REFERENCES `business_activities`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_provider_id_fkey` FOREIGN KEY (`provider_id`) REFERENCES `providers`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_pos_id_fkey` FOREIGN KEY (`pos_id`) REFERENCES `poses`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
@@ -1,31 +0,0 @@
/*
Warnings:
- You are about to drop the column `account_id` on the `good_categories` table. All the data in the column will be lost.
- You are about to drop the column `account_id` on the `goods` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE `good_categories` DROP COLUMN `account_id`,
ADD COLUMN `guild_id` VARCHAR(191) NULL,
ADD COLUMN `is_default_guild_good` BOOLEAN NOT NULL DEFAULT false,
MODIFY `complex_id` VARCHAR(191) NULL;
-- AlterTable
ALTER TABLE `goods` DROP COLUMN `account_id`,
ADD COLUMN `guild_id` VARCHAR(191) NULL,
ADD COLUMN `is_default_guild_good` BOOLEAN NOT NULL DEFAULT false,
MODIFY `base_sale_price` DECIMAL(15, 0) NULL DEFAULT 0.00,
MODIFY `complex_id` VARCHAR(191) NULL;
-- AddForeignKey
ALTER TABLE `goods` ADD CONSTRAINT `goods_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `goods` ADD CONSTRAINT `goods_guild_id_fkey` FOREIGN KEY (`guild_id`) REFERENCES `guilds`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `good_categories` ADD CONSTRAINT `good_categories_guild_id_fkey` FOREIGN KEY (`guild_id`) REFERENCES `guilds`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `good_categories` ADD CONSTRAINT `good_categories_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
@@ -1,21 +0,0 @@
/*
Warnings:
- You are about to drop the column `tax_id` on the `business_activities` table. All the data in the column will be lost.
- You are about to drop the column `pricingModel` on the `sales_invoice_items` table. All the data in the column will be lost.
- Added the required column `owner_id` to the `business_activities` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE `business_activities` DROP COLUMN `tax_id`,
ADD COLUMN `owner_id` VARCHAR(191) NOT NULL;
-- AlterTable
ALTER TABLE `complexes` ADD COLUMN `tax_id` VARCHAR(191) NULL;
-- AlterTable
ALTER TABLE `sales_invoice_items` DROP COLUMN `pricingModel`,
MODIFY `unit_type` ENUM('COUNT', 'GRAM', 'KILOGRAM', 'MILLILITER', 'LITER', 'METER', 'HOUR') NOT NULL;
-- AddForeignKey
ALTER TABLE `business_activities` ADD CONSTRAINT `business_activities_owner_id_fkey` FOREIGN KEY (`owner_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
@@ -1,10 +0,0 @@
/*
Warnings:
- Added the required column `pricing_model` to the `goods` table without a default value. This is not possible if the table is not empty.
- Added the required column `unit_type` to the `goods` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE `goods` ADD COLUMN `pricing_model` ENUM('STANDARD', 'GOLD') NOT NULL,
ADD COLUMN `unit_type` ENUM('COUNT', 'GRAM', 'KILOGRAM', 'MILLILITER', 'LITER', 'METER', 'HOUR') NOT NULL;
@@ -1,2 +0,0 @@
-- AlterTable
ALTER TABLE `accounts` MODIFY `type` ENUM('PARTNER', 'BUSINESS', 'SUPER_ADMIN', 'ADMIN', 'PROVIDER', 'POS') NOT NULL;
@@ -1,2 +0,0 @@
-- AlterTable
ALTER TABLE `partners` ADD COLUMN `licenseQuota` INTEGER NULL DEFAULT 0;
@@ -1,58 +0,0 @@
/*
Warnings:
- You are about to drop the column `licenseQuota` on the `partners` table. All the data in the column will be lost.
- Added the required column `updated_at` to the `accounts` table without a default value. This is not possible if the table is not empty.
- Added the required column `updated_at` to the `business_activities` table without a default value. This is not possible if the table is not empty.
- Added the required column `updated_at` to the `complexes` table without a default value. This is not possible if the table is not empty.
- Added the required column `updated_at` to the `guilds` table without a default value. This is not possible if the table is not empty.
- Added the required column `updated_at` to the `licenses` table without a default value. This is not possible if the table is not empty.
- Added the required column `updated_at` to the `providers` table without a default value. This is not possible if the table is not empty.
- Added the required column `updated_at` to the `users` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE `accounts` ADD COLUMN `updated_at` TIMESTAMP(0) NOT NULL,
MODIFY `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0);
-- AlterTable
ALTER TABLE `business_activities` ADD COLUMN `updated_at` TIMESTAMP(0) NOT NULL,
MODIFY `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0);
-- AlterTable
ALTER TABLE `complexes` ADD COLUMN `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
ADD COLUMN `updated_at` TIMESTAMP(0) NOT NULL;
-- AlterTable
ALTER TABLE `device_brands` MODIFY `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
MODIFY `updated_at` TIMESTAMP(0) NOT NULL;
-- AlterTable
ALTER TABLE `devices` MODIFY `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
MODIFY `updated_at` TIMESTAMP(0) NOT NULL;
-- AlterTable
ALTER TABLE `guilds` ADD COLUMN `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
ADD COLUMN `updated_at` TIMESTAMP(0) NOT NULL;
-- AlterTable
ALTER TABLE `licenses` ADD COLUMN `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
ADD COLUMN `updated_at` TIMESTAMP(0) NOT NULL;
-- AlterTable
ALTER TABLE `partners` DROP COLUMN `licenseQuota`,
ADD COLUMN `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
ADD COLUMN `license_quota` INTEGER NULL DEFAULT 0,
ADD COLUMN `updated_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0);
-- AlterTable
ALTER TABLE `poses` MODIFY `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
MODIFY `updated_at` TIMESTAMP(0) NOT NULL;
-- AlterTable
ALTER TABLE `providers` ADD COLUMN `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
ADD COLUMN `updated_at` TIMESTAMP(0) NOT NULL;
-- AlterTable
ALTER TABLE `users` ADD COLUMN `updated_at` TIMESTAMP(0) NOT NULL,
MODIFY `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0);
@@ -1,20 +0,0 @@
/*
Warnings:
- A unique constraint covering the columns `[user_id,business_id]` on the table `accounts` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[user_id,provider_id]` on the table `accounts` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[user_id,pos_id]` on the table `accounts` will be added. If there are existing duplicate values, this will fail.
- Added the required column `name` to the `poses` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE `poses` ADD COLUMN `name` VARCHAR(191) NOT NULL;
-- CreateIndex
CREATE UNIQUE INDEX `accounts_user_id_business_id_key` ON `accounts`(`user_id`, `business_id`);
-- CreateIndex
CREATE UNIQUE INDEX `accounts_user_id_provider_id_key` ON `accounts`(`user_id`, `provider_id`);
-- CreateIndex
CREATE UNIQUE INDEX `accounts_user_id_pos_id_key` ON `accounts`(`user_id`, `pos_id`);
@@ -1,12 +0,0 @@
-- DropForeignKey
ALTER TABLE `poses` DROP FOREIGN KEY `poses_device_id_fkey`;
-- DropIndex
DROP INDEX `poses_device_id_fkey` ON `poses`;
-- AlterTable
ALTER TABLE `poses` MODIFY `pos_type` ENUM('PSP', 'MOBILE', 'WEB', 'API') NOT NULL,
MODIFY `device_id` VARCHAR(191) NULL;
-- AddForeignKey
ALTER TABLE `poses` ADD CONSTRAINT `poses_device_id_fkey` FOREIGN KEY (`device_id`) REFERENCES `devices`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
@@ -0,0 +1,557 @@
-- CreateTable
CREATE TABLE `admins` (
`id` VARCHAR(191) NOT NULL,
`mobile_number` VARCHAR(191) NOT NULL,
`national_code` VARCHAR(191) NULL,
`first_name` VARCHAR(191) NOT NULL,
`last_name` VARCHAR(191) NOT NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
UNIQUE INDEX `admins_mobile_number_key`(`mobile_number`),
UNIQUE INDEX `admins_national_code_key`(`national_code`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `admin_accounts` (
`id` VARCHAR(191) NOT NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`user_id` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Account` (
`id` VARCHAR(191) NOT NULL,
`username` VARCHAR(191) NOT NULL,
`password` VARCHAR(191) NOT NULL,
`status` ENUM('ACTIVE', 'SUSPENDED') NOT NULL,
`type` ENUM('ADMIN', 'PROVIDER', 'PARTNER', 'CONSUMER') NOT NULL,
`admin_account_id` VARCHAR(191) NULL,
`consumer_account_id` VARCHAR(191) NULL,
`provider_account_id` VARCHAR(191) NULL,
`partner_account_id` VARCHAR(191) NULL,
UNIQUE INDEX `Account_username_key`(`username`),
UNIQUE INDEX `Account_password_key`(`password`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `consumers` (
`id` VARCHAR(191) NOT NULL,
`mobile_number` VARCHAR(191) NOT NULL,
`first_name` VARCHAR(191) NOT NULL,
`last_name` VARCHAR(191) NOT NULL,
`status` ENUM('ACTIVE', 'SUSPENDED') NOT NULL DEFAULT 'ACTIVE',
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
UNIQUE INDEX `consumers_mobile_number_key`(`mobile_number`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `consumer_accounts` (
`id` VARCHAR(191) NOT NULL,
`role` ENUM('MANAGER', 'OPERATOR') NOT NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`user_id` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `business_activities` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`guild_id` VARCHAR(191) NOT NULL,
`user_id` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `complexes` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`address` VARCHAR(191) NULL,
`tax_id` VARCHAR(191) NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`business_activity_id` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `poses` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`serial` VARCHAR(191) NOT NULL,
`model` VARCHAR(191) NULL,
`status` ENUM('ACTIVE', 'DISABLED') NOT NULL DEFAULT 'ACTIVE',
`pos_type` ENUM('PSP', 'MOBILE', 'WEB', 'API') NOT NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`complex_id` VARCHAR(191) NOT NULL,
`device_id` VARCHAR(191) NULL,
`provider_id` VARCHAR(191) NULL,
UNIQUE INDEX `poses_serial_key`(`serial`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `device_brands` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `devices` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`os_version` VARCHAR(191) NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`brand_id` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `licenses` (
`id` VARCHAR(191) NOT NULL,
`starts_at` DATETIME(3) NOT NULL,
`expires_at` DATETIME(3) NOT NULL,
`status` ENUM('ACTIVE', 'EXPIRED', 'SUSPENDED') NOT NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`pos_id` VARCHAR(191) NOT NULL,
`partner_id` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `partners` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`code` VARCHAR(191) NOT NULL,
`license_quota` INTEGER NULL DEFAULT 0,
`status` ENUM('ACTIVE', 'SUSPENDED') NOT NULL DEFAULT 'ACTIVE',
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
UNIQUE INDEX `partners_code_key`(`code`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `partner_accounts` (
`id` VARCHAR(191) NOT NULL,
`role` ENUM('MANAGER', 'OPERATOR') NOT NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`user_id` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `permission_consumers` (
`id` VARCHAR(191) NOT NULL,
`account_id` VARCHAR(191) NOT NULL,
UNIQUE INDEX `permission_consumers_account_id_key`(`account_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `permission_poses` (
`id` VARCHAR(191) NOT NULL,
`role` ENUM('MANAGER', 'OPERATOR') NOT NULL,
`pos_id` VARCHAR(191) NOT NULL,
`permission_id` VARCHAR(191) NOT NULL,
UNIQUE INDEX `permission_poses_permission_id_pos_id_key`(`permission_id`, `pos_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `permission_complexes` (
`id` VARCHAR(191) NOT NULL,
`role` ENUM('MANAGER', 'OPERATOR') NOT NULL,
`complex_id` VARCHAR(191) NOT NULL,
`permission_id` VARCHAR(191) NOT NULL,
UNIQUE INDEX `permission_complexes_permission_id_complex_id_key`(`permission_id`, `complex_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `permission_business_activities` (
`id` VARCHAR(191) NOT NULL,
`role` ENUM('MANAGER', 'OPERATOR') NOT NULL,
`business_id` VARCHAR(191) NOT NULL,
`permission_id` VARCHAR(191) NOT NULL,
UNIQUE INDEX `permission_business_activities_permission_id_business_id_key`(`permission_id`, `business_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `providers` (
`id` VARCHAR(191) NOT NULL,
`code` VARCHAR(191) NOT NULL,
`status` ENUM('ACTIVE', 'SUSPENDED') NOT NULL DEFAULT 'ACTIVE',
`name` VARCHAR(191) NOT NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
UNIQUE INDEX `providers_code_key`(`code`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `provider_accounts` (
`id` VARCHAR(191) NOT NULL,
`role` ENUM('MANAGER', 'OPERATOR') NOT NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`user_id` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `trigger_logs` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`message` TEXT NOT NULL,
`createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`name` TEXT NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `user_devices` (
`account_id` VARCHAR(255) NULL,
`app_version` VARCHAR(20) NOT NULL,
`build_number` VARCHAR(20) NOT NULL,
`uuid` VARCHAR(255) NOT NULL,
`platform` VARCHAR(100) NOT NULL,
`brand` VARCHAR(100) NOT NULL,
`model` VARCHAR(100) NOT NULL,
`device` VARCHAR(100) NOT NULL,
`os_version` VARCHAR(20) NOT NULL,
`sdk_version` VARCHAR(20) NOT NULL,
`release_number` VARCHAR(20) NOT NULL,
`browser_name` VARCHAR(100) NULL,
`fcm_token` VARCHAR(100) NULL,
UNIQUE INDEX `user_devices_uuid_key`(`uuid`),
PRIMARY KEY (`uuid`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `customers` (
`id` VARCHAR(191) NOT NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`deleted_at` TIMESTAMP(0) NULL,
`type` ENUM('INDIVIDUAL', 'LEGAL', 'UNKNOWN') NOT NULL,
`complex_id` VARCHAR(191) NOT NULL,
`is_favorite` BOOLEAN NULL DEFAULT false,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `customer_individuals` (
`customer_id` VARCHAR(191) NOT NULL,
`first_name` VARCHAR(255) NOT NULL,
`last_name` VARCHAR(255) NOT NULL,
`national_id` CHAR(10) NOT NULL,
`postal_code` CHAR(10) NOT NULL,
`economic_code` CHAR(10) NULL,
`complex_id` VARCHAR(191) NOT NULL,
UNIQUE INDEX `customer_individuals_complex_id_national_id_key`(`complex_id`, `national_id`),
PRIMARY KEY (`customer_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `customer_legal` (
`customer_id` VARCHAR(191) NOT NULL,
`company_name` VARCHAR(255) NOT NULL,
`economic_code` CHAR(10) NOT NULL,
`registration_number` CHAR(20) NOT NULL,
`postal_code` CHAR(10) NOT NULL,
`complex_id` VARCHAR(191) NOT NULL,
UNIQUE INDEX `customer_legal_complex_id_registration_number_key`(`complex_id`, `registration_number`),
PRIMARY KEY (`customer_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `goods` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`is_default_guild_good` BOOLEAN NOT NULL DEFAULT false,
`sku` VARCHAR(100) NOT NULL,
`unit_type` ENUM('COUNT', 'GRAM', 'KILOGRAM', 'MILLILITER', 'LITER', 'METER', 'HOUR') NOT NULL,
`pricing_model` ENUM('STANDARD', 'GOLD') NOT NULL,
`description` TEXT NULL,
`local_sku` VARCHAR(100) NULL,
`barcode` VARCHAR(100) NULL,
`base_sale_price` DECIMAL(15, 0) NULL DEFAULT 0.00,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`deleted_at` TIMESTAMP(0) NULL,
`complex_id` VARCHAR(191) NULL,
`category_id` VARCHAR(191) NULL,
`guild_id` VARCHAR(191) NULL,
UNIQUE INDEX `goods_local_sku_key`(`local_sku`),
UNIQUE INDEX `goods_barcode_key`(`barcode`),
INDEX `goods_category_id_idx`(`category_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `good_categories` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(100) NOT NULL,
`description` TEXT NULL,
`image_url` VARCHAR(255) NULL,
`complex_id` VARCHAR(191) NULL,
`is_default_guild_good` BOOLEAN NOT NULL DEFAULT false,
`guild_id` VARCHAR(191) NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`deleted_at` TIMESTAMP(0) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `guilds` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`code` VARCHAR(191) NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `sales_invoices` (
`id` VARCHAR(191) NOT NULL,
`code` VARCHAR(100) NOT NULL,
`total_amount` DECIMAL(15, 2) NOT NULL,
`notes` TEXT NULL,
`unknown_customer` JSON NULL,
`invoice_date` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`customer_id` VARCHAR(191) NULL,
`account_id` VARCHAR(191) NOT NULL,
`complex_id` VARCHAR(191) NOT NULL,
UNIQUE INDEX `sales_invoices_code_key`(`code`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `sales_invoice_items` (
`id` VARCHAR(191) NOT NULL,
`quantity` DECIMAL(10, 0) NOT NULL,
`unit_type` ENUM('COUNT', 'GRAM', 'KILOGRAM', 'MILLILITER', 'LITER', 'METER', 'HOUR') NOT NULL,
`unit_price` DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
`total_amount` DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`discount` DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
`notes` TEXT NULL,
`invoice_id` VARCHAR(191) NOT NULL,
`good_id` VARCHAR(191) NULL,
`service_id` VARCHAR(191) NULL,
`payload` JSON NULL,
INDEX `sales_invoice_items_invoice_id_good_id_idx`(`invoice_id`, `good_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `sales_invoice_payments` (
`id` VARCHAR(191) NOT NULL,
`invoice_id` VARCHAR(191) NOT NULL,
`amount` DECIMAL(15, 2) NOT NULL,
`payment_method` ENUM('TERMINAL', 'CASH', 'SET_OFF', 'CARD', 'BANK', 'CHECK', 'OTHER') NOT NULL,
`paid_at` DATETIME(3) NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
INDEX `sales_invoice_payments_invoice_id_idx`(`invoice_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `services` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`description` TEXT NULL,
`sku` VARCHAR(100) NOT NULL,
`local_sku` VARCHAR(100) NULL,
`barcode` VARCHAR(100) NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`deleted_at` TIMESTAMP(0) NULL,
`category_id` VARCHAR(191) NULL,
`base_sale_price` DECIMAL(15, 0) NOT NULL DEFAULT 0.00,
`account_id` VARCHAR(191) NOT NULL,
`complex_id` VARCHAR(191) NOT NULL,
UNIQUE INDEX `services_sku_key`(`sku`),
UNIQUE INDEX `services_local_sku_key`(`local_sku`),
UNIQUE INDEX `services_barcode_key`(`barcode`),
INDEX `services_category_id_idx`(`category_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `service_categories` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(100) NOT NULL,
`description` TEXT NULL,
`image_url` VARCHAR(255) NULL,
`account_id` VARCHAR(191) NOT NULL,
`complex_id` VARCHAR(191) NOT NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`deleted_at` TIMESTAMP(0) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `admin_accounts` ADD CONSTRAINT `admin_accounts_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `admins`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Account` ADD CONSTRAINT `Account_admin_account_id_fkey` FOREIGN KEY (`admin_account_id`) REFERENCES `admin_accounts`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Account` ADD CONSTRAINT `Account_consumer_account_id_fkey` FOREIGN KEY (`consumer_account_id`) REFERENCES `consumer_accounts`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Account` ADD CONSTRAINT `Account_provider_account_id_fkey` FOREIGN KEY (`provider_account_id`) REFERENCES `provider_accounts`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Account` ADD CONSTRAINT `Account_partner_account_id_fkey` FOREIGN KEY (`partner_account_id`) REFERENCES `partner_accounts`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `consumer_accounts` ADD CONSTRAINT `consumer_accounts_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `consumers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `business_activities` ADD CONSTRAINT `business_activities_guild_id_fkey` FOREIGN KEY (`guild_id`) REFERENCES `guilds`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `business_activities` ADD CONSTRAINT `business_activities_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `consumers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `complexes` ADD CONSTRAINT `complexes_business_activity_id_fkey` FOREIGN KEY (`business_activity_id`) REFERENCES `business_activities`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `poses` ADD CONSTRAINT `poses_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `poses` ADD CONSTRAINT `poses_device_id_fkey` FOREIGN KEY (`device_id`) REFERENCES `devices`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `poses` ADD CONSTRAINT `poses_provider_id_fkey` FOREIGN KEY (`provider_id`) REFERENCES `providers`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `devices` ADD CONSTRAINT `devices_brand_id_fkey` FOREIGN KEY (`brand_id`) REFERENCES `device_brands`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `licenses` ADD CONSTRAINT `licenses_pos_id_fkey` FOREIGN KEY (`pos_id`) REFERENCES `poses`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `licenses` ADD CONSTRAINT `licenses_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `partner_accounts` ADD CONSTRAINT `partner_accounts_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `partners`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `permission_consumers` ADD CONSTRAINT `permission_consumers_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `consumer_accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `permission_poses` ADD CONSTRAINT `permission_poses_pos_id_fkey` FOREIGN KEY (`pos_id`) REFERENCES `poses`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `permission_poses` ADD CONSTRAINT `permission_poses_permission_id_fkey` FOREIGN KEY (`permission_id`) REFERENCES `permission_consumers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `permission_complexes` ADD CONSTRAINT `permission_complexes_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `permission_complexes` ADD CONSTRAINT `permission_complexes_permission_id_fkey` FOREIGN KEY (`permission_id`) REFERENCES `permission_consumers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `permission_business_activities` ADD CONSTRAINT `permission_business_activities_business_id_fkey` FOREIGN KEY (`business_id`) REFERENCES `business_activities`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `permission_business_activities` ADD CONSTRAINT `permission_business_activities_permission_id_fkey` FOREIGN KEY (`permission_id`) REFERENCES `permission_consumers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `provider_accounts` ADD CONSTRAINT `provider_accounts_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `providers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `customer_individuals` ADD CONSTRAINT `customer_individuals_customer_id_fkey` FOREIGN KEY (`customer_id`) REFERENCES `customers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `customer_legal` ADD CONSTRAINT `customer_legal_customer_id_fkey` FOREIGN KEY (`customer_id`) REFERENCES `customers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `goods` ADD CONSTRAINT `goods_category_id_fkey` FOREIGN KEY (`category_id`) REFERENCES `good_categories`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `goods` ADD CONSTRAINT `goods_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `goods` ADD CONSTRAINT `goods_guild_id_fkey` FOREIGN KEY (`guild_id`) REFERENCES `guilds`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `good_categories` ADD CONSTRAINT `good_categories_guild_id_fkey` FOREIGN KEY (`guild_id`) REFERENCES `guilds`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `good_categories` ADD CONSTRAINT `good_categories_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `sales_invoices` ADD CONSTRAINT `sales_invoices_customer_id_fkey` FOREIGN KEY (`customer_id`) REFERENCES `customers`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `sales_invoice_items` ADD CONSTRAINT `sales_invoice_items_invoice_id_fkey` FOREIGN KEY (`invoice_id`) REFERENCES `sales_invoices`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `sales_invoice_items` ADD CONSTRAINT `sales_invoice_items_good_id_fkey` FOREIGN KEY (`good_id`) REFERENCES `goods`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `sales_invoice_items` ADD CONSTRAINT `sales_invoice_items_service_id_fkey` FOREIGN KEY (`service_id`) REFERENCES `services`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `sales_invoice_payments` ADD CONSTRAINT `sales_invoice_payments_invoice_id_fkey` FOREIGN KEY (`invoice_id`) REFERENCES `sales_invoices`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `services` ADD CONSTRAINT `services_category_id_fkey` FOREIGN KEY (`category_id`) REFERENCES `service_categories`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
@@ -0,0 +1,49 @@
/*
Warnings:
- You are about to drop the `Account` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE `Account` DROP FOREIGN KEY `Account_admin_account_id_fkey`;
-- DropForeignKey
ALTER TABLE `Account` DROP FOREIGN KEY `Account_consumer_account_id_fkey`;
-- DropForeignKey
ALTER TABLE `Account` DROP FOREIGN KEY `Account_partner_account_id_fkey`;
-- DropForeignKey
ALTER TABLE `Account` DROP FOREIGN KEY `Account_provider_account_id_fkey`;
-- DropTable
DROP TABLE `Account`;
-- CreateTable
CREATE TABLE `accounts` (
`id` VARCHAR(191) NOT NULL,
`username` VARCHAR(191) NOT NULL,
`password` VARCHAR(191) NOT NULL,
`status` ENUM('ACTIVE', 'SUSPENDED') NOT NULL,
`type` ENUM('ADMIN', 'PROVIDER', 'PARTNER', 'CONSUMER') NOT NULL,
`admin_account_id` VARCHAR(191) NULL,
`consumer_account_id` VARCHAR(191) NULL,
`provider_account_id` VARCHAR(191) NULL,
`partner_account_id` VARCHAR(191) NULL,
UNIQUE INDEX `accounts_username_key`(`username`),
UNIQUE INDEX `accounts_password_key`(`password`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_admin_account_id_fkey` FOREIGN KEY (`admin_account_id`) REFERENCES `admin_accounts`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_consumer_account_id_fkey` FOREIGN KEY (`consumer_account_id`) REFERENCES `consumer_accounts`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_provider_account_id_fkey` FOREIGN KEY (`provider_account_id`) REFERENCES `provider_accounts`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_partner_account_id_fkey` FOREIGN KEY (`partner_account_id`) REFERENCES `partner_accounts`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
@@ -0,0 +1,85 @@
/*
Warnings:
- You are about to drop the column `admin_account_id` on the `accounts` table. All the data in the column will be lost.
- You are about to drop the column `consumer_account_id` on the `accounts` table. All the data in the column will be lost.
- You are about to drop the column `partner_account_id` on the `accounts` table. All the data in the column will be lost.
- You are about to drop the column `provider_account_id` on the `accounts` table. All the data in the column will be lost.
- A unique constraint covering the columns `[account_id]` on the table `admin_accounts` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[account_id]` on the table `consumer_accounts` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[account_id]` on the table `partner_accounts` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[account_id]` on the table `provider_accounts` will be added. If there are existing duplicate values, this will fail.
- Added the required column `account_id` to the `admin_accounts` table without a default value. This is not possible if the table is not empty.
- Added the required column `account_id` to the `consumer_accounts` table without a default value. This is not possible if the table is not empty.
- Added the required column `account_id` to the `partner_accounts` table without a default value. This is not possible if the table is not empty.
- Added the required column `account_id` to the `provider_accounts` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE `accounts` DROP FOREIGN KEY `accounts_admin_account_id_fkey`;
-- DropForeignKey
ALTER TABLE `accounts` DROP FOREIGN KEY `accounts_consumer_account_id_fkey`;
-- DropForeignKey
ALTER TABLE `accounts` DROP FOREIGN KEY `accounts_partner_account_id_fkey`;
-- DropForeignKey
ALTER TABLE `accounts` DROP FOREIGN KEY `accounts_provider_account_id_fkey`;
-- DropIndex
DROP INDEX `accounts_admin_account_id_fkey` ON `accounts`;
-- DropIndex
DROP INDEX `accounts_consumer_account_id_fkey` ON `accounts`;
-- DropIndex
DROP INDEX `accounts_partner_account_id_fkey` ON `accounts`;
-- DropIndex
DROP INDEX `accounts_provider_account_id_fkey` ON `accounts`;
-- AlterTable
ALTER TABLE `accounts` DROP COLUMN `admin_account_id`,
DROP COLUMN `consumer_account_id`,
DROP COLUMN `partner_account_id`,
DROP COLUMN `provider_account_id`;
-- AlterTable
ALTER TABLE `admin_accounts` ADD COLUMN `account_id` VARCHAR(191) NOT NULL;
-- AlterTable
ALTER TABLE `consumer_accounts` ADD COLUMN `account_id` VARCHAR(191) NOT NULL,
MODIFY `role` ENUM('OWNER', 'MANAGER', 'OPERATOR') NOT NULL;
-- AlterTable
ALTER TABLE `partner_accounts` ADD COLUMN `account_id` VARCHAR(191) NOT NULL,
MODIFY `role` ENUM('OWNER', 'MANAGER', 'OPERATOR') NOT NULL;
-- AlterTable
ALTER TABLE `provider_accounts` ADD COLUMN `account_id` VARCHAR(191) NOT NULL,
MODIFY `role` ENUM('OWNER', 'MANAGER', 'OPERATOR') NOT NULL;
-- CreateIndex
CREATE UNIQUE INDEX `admin_accounts_account_id_key` ON `admin_accounts`(`account_id`);
-- CreateIndex
CREATE UNIQUE INDEX `consumer_accounts_account_id_key` ON `consumer_accounts`(`account_id`);
-- CreateIndex
CREATE UNIQUE INDEX `partner_accounts_account_id_key` ON `partner_accounts`(`account_id`);
-- CreateIndex
CREATE UNIQUE INDEX `provider_accounts_account_id_key` ON `provider_accounts`(`account_id`);
-- AddForeignKey
ALTER TABLE `admin_accounts` ADD CONSTRAINT `admin_accounts_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `consumer_accounts` ADD CONSTRAINT `consumer_accounts_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `partner_accounts` ADD CONSTRAINT `partner_accounts_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `provider_accounts` ADD CONSTRAINT `provider_accounts_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
@@ -0,0 +1,14 @@
/*
Warnings:
- You are about to drop the column `guild_id` on the `goods` table. All the data in the column will be lost.
*/
-- DropForeignKey
ALTER TABLE `goods` DROP FOREIGN KEY `goods_guild_id_fkey`;
-- DropIndex
DROP INDEX `goods_guild_id_fkey` ON `goods`;
-- AlterTable
ALTER TABLE `goods` DROP COLUMN `guild_id`;
+53
View File
@@ -0,0 +1,53 @@
model Admin {
id String @id @default(uuid())
mobile_number String @unique()
national_code String? @unique()
first_name String
last_name String
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt() @db.Timestamp(0)
accounts AdminAccount[]
@@map("admins")
}
model AdminAccount {
id String @id @default(uuid())
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt() @db.Timestamp(0)
user_id String
user Admin @relation(fields: [user_id], references: [id])
account_id String @unique
account Account @relation(fields: [account_id], references: [id])
@@map("admin_accounts")
}
// model LegalProfile {
// user_id String @id
// company_name String
// register_no String @unique()
// representative_name String?
// representative_national_id String?
// // user User @relation(fields: [user_id], references: [id])
// @@map("legal_profiles")
// }
// model IndividualProfile {
// user_id String @id
// national_code String @unique()
// first_name String
// last_name String
// birth_date DateTime?
// mobile_number String
// // user User @relation(fields: [user_id], references: [id])
// @@map("individual_profiles")
// }
+38 -20
View File
@@ -1,26 +1,44 @@
model Token {
id String @id @default(uuid())
token String @unique
type TokenType
created_at DateTime @default(now())
expires_at DateTime
model Account {
id String @id @default(uuid())
username String @unique()
password String @unique()
status AccountStatus
type AccountType
account_id String
account Account @relation(fields: [account_id], references: [id])
admin_account AdminAccount?
provider_account ProviderAccount?
partner_account PartnerAccount?
consumer_account ConsumerAccount?
@@unique([type, account_id])
@@map("tokens")
// tokens Token[]
// refresh_tokens RefreshToken[]
@@map("accounts")
}
model VerificationCode {
id String @id @default(uuid())
code String
is_used Boolean @default(false)
created_at DateTime @default(now())
expires_at DateTime
// model Token {
// id String @id @d @uniqueefault(uuid())
// token String @unique
// type TokenType
// created_at DateTime @default(now())
// expires_at DateTime
account_id String
account Account @relation(fields: [account_id], references: [id])
// account_id String
// account Account @relation(fields: [account_id], references: [id])
@@map("verification_codes")
}
// @@unique([type, account_id])
// @@map("tokens")
// }
// model VerificationCode {
// id String @id @default(uuid())
// code String
// is_used Boolean @default(false)
// created_at DateTime @default(now())
// expires_at DateTime
// account_id String
// account Account @relation(fields: [account_id], references: [id])
// @@map("verification_codes")
// }
@@ -1,16 +1,35 @@
model Guild {
id String @id @default(uuid())
name String
code String?
model Consumer {
id String @id @default(uuid())
mobile_number String @unique()
first_name String
last_name String
status ConsumerStatus @default(ACTIVE)
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt() @db.Timestamp(0)
business_activities BusinessActivity[]
goods Good[]
good_categories GoodCategory[]
accounts ConsumerAccount[]
businessActivities BusinessActivity[]
@@map("guilds")
@@map("consumers")
}
model ConsumerAccount {
id String @id @default(uuid())
role ConsumerRole
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt() @db.Timestamp(0)
user_id String
user Consumer @relation(fields: [user_id], references: [id])
account_id String @unique
account Account @relation(fields: [account_id], references: [id])
permissions PermissionConsumer[]
@@map("consumer_accounts")
}
model BusinessActivity {
@@ -20,13 +39,13 @@ model BusinessActivity {
updated_at DateTime @updatedAt() @db.Timestamp(0)
guild_id String
owner_id String
user_id String
guild Guild @relation(fields: [guild_id], references: [id])
user User @relation(fields: [owner_id], references: [id])
guild Guild @relation(fields: [guild_id], references: [id])
user Consumer @relation(fields: [user_id], references: [id])
complexes Complex[]
accounts Account[]
complexes Complex[]
permissionBusinesses PermissionBusiness[]
@@map("business_activities")
}
@@ -44,9 +63,10 @@ model Complex {
business_activity BusinessActivity @relation(fields: [business_activity_id], references: [id])
pos_list Pos[]
goods Good[]
good_categories GoodCategory[]
pos_list Pos[]
goods Good[]
good_categories GoodCategory[]
permissionComplexes PermissionComplex[]
@@map("complexes")
}
@@ -61,16 +81,17 @@ model Pos {
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt() @db.Timestamp(0)
complex_id String
device_id String?
complex_id String
complex Complex @relation(fields: [complex_id], references: [id])
device_id String?
device Device? @relation(fields: [device_id], references: [id])
provider_id String?
provider Provider? @relation(fields: [provider_id], references: [id])
complex Complex @relation(fields: [complex_id], references: [id])
device Device? @relation(fields: [device_id], references: [id])
provider Provider? @relation(fields: [provider_id], references: [id])
licenses License[]
accounts Account[]
licenses License[]
permissionPos PermissionPos[]
@@map("poses")
}
+18 -16
View File
@@ -1,29 +1,31 @@
model Partner {
id String @id @default(uuid())
id String @id @default(uuid())
name String
code String?
license_quota Int? @default(0)
code String @unique()
license_quota Int? @default(0)
status PartnerStatus @default(ACTIVE)
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @default(now()) @updatedAt @db.Timestamp(0)
licenses License[]
account Account[]
accounts PartnerAccount[]
@@map("partners")
}
// model PartnerAccount {
// id String @id @default(uuid())
// role PartnerRole
// status AccountStatus @default(ACTIVE)
// created_at DateTime @default(now())
// partner_id String
// account_id String @unique
model PartnerAccount {
id String @id @default(uuid())
role PartnerRole
// partner Partner @relation(fields: [partner_id], references: [id])
// account Account @relation(fields: [account_id], references: [id])
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @default(now()) @updatedAt @db.Timestamp(0)
// @@unique([partner_id, account_id])
// @@map("partner_accounts")
// }
user_id String
user Partner @relation(fields: [user_id], references: [id])
account_id String @unique
account Account @relation(fields: [account_id], references: [id])
@@map("partner_accounts")
}
+55
View File
@@ -0,0 +1,55 @@
model PermissionConsumer {
id String @id @default(uuid())
account_id String @unique
account ConsumerAccount @relation(fields: [account_id], references: [id])
posPermissions PermissionPos[]
complexPermissions PermissionComplex[]
businessPermissions PermissionBusiness[]
@@map("permission_consumers")
}
model PermissionPos {
id String @id @default(uuid())
role POSRole
pos_id String
permission_id String
pos Pos @relation(fields: [pos_id], references: [id])
permission PermissionConsumer @relation(fields: [permission_id], references: [id])
@@unique([permission_id, pos_id])
@@map("permission_poses")
}
model PermissionComplex {
id String @id @default(uuid())
role ComplexRole
complex_id String
permission_id String
complex Complex @relation(fields: [complex_id], references: [id])
permission PermissionConsumer @relation(fields: [permission_id], references: [id])
@@unique([permission_id, complex_id])
@@map("permission_complexes")
}
model PermissionBusiness {
id String @id @default(uuid())
role BusinessRole
business_id String
permission_id String
business BusinessActivity @relation(fields: [business_id], references: [id])
permission PermissionConsumer @relation(fields: [permission_id], references: [id])
@@unique([permission_id, business_id])
@@map("permission_business_activities")
}
-77
View File
@@ -1,77 +0,0 @@
model User {
id String @id @default(uuid())
// user_type UserType
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt() @db.Timestamp(0)
// individual_profile IndividualProfile?
// legal_profile LegalProfile?
mobile_number String @unique()
national_code String? @unique()
first_name String
last_name String
// username String
accounts Account[]
businessActivities BusinessActivity[]
@@map("users")
}
// model LegalProfile {
// user_id String @id
// company_name String
// register_no String @unique()
// representative_name String?
// representative_national_id String?
// // user User @relation(fields: [user_id], references: [id])
// @@map("legal_profiles")
// }
// model IndividualProfile {
// user_id String @id
// national_code String @unique()
// first_name String
// last_name String
// birth_date DateTime?
// mobile_number String
// // user User @relation(fields: [user_id], references: [id])
// @@map("individual_profiles")
// }
model Account {
id String @id @default(uuid())
username String @unique()
// first_name String
// last_name String
type AccountType
status AccountStatus
password String
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt() @db.Timestamp(0)
user_id String
user User @relation(fields: [user_id], references: [id])
partner_id String?
partner Partner? @relation(fields: [partner_id], references: [id])
business_id String?
business BusinessActivity? @relation(fields: [business_id], references: [id])
provider_id String?
provider Provider? @relation(fields: [provider_id], references: [id])
pos_id String?
pos Pos? @relation(fields: [pos_id], references: [id])
verification_codes VerificationCode[]
tokens Token[]
@@unique([user_id, business_id])
@@unique([user_id, provider_id])
@@unique([user_id, pos_id])
@@map("accounts")
}
+18 -16
View File
@@ -1,28 +1,30 @@
model Provider {
id String @id @default(uuid())
name String
code String?
id String @id @default(uuid())
code String @unique()
status PartnerStatus @default(ACTIVE)
name String
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt @db.Timestamp(0)
pos_list Pos[]
accounts Account[]
accounts ProviderAccount[]
@@map("providers")
}
// model ProviderAccount {
// id String @id @default(uuid())
// role ProviderRole
// status AccountStatus @default(ACTIVE)
// created_at DateTime @default(now())
// provider_id String
// account_id String @unique
model ProviderAccount {
id String @id @default(uuid())
role ProviderRole
// provider Provider @relation(fields: [provider_id], references: [id])
// account Account @relation(fields: [account_id], references: [id])
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt() @db.Timestamp(0)
// @@unique([provider_id, account_id])
// @@map("provider_accounts")
// }
user_id String
user Provider @relation(fields: [user_id], references: [id])
account_id String @unique
account Account @relation(fields: [account_id], references: [id])
@@map("provider_accounts")
}
+51 -37
View File
@@ -8,17 +8,6 @@ enum PaymentMethodType {
OTHER
}
enum PurchaseReceiptStatus {
UNPAID
PARTIALLY_PAID
PAID
}
enum SalesInvoiceType {
GOOD
SERVICE
}
enum UnitType {
COUNT
GRAM
@@ -40,22 +29,6 @@ enum CustomerType {
UNKNOWN
}
enum UserStatus {
ACTIVE
INACTIVE
}
enum AccountRole {
OWNER
OPERATOR
ACCOUNTANT
}
enum AccountStatus {
ACTIVE
SUSPENDED
}
enum POSStatus {
ACTIVE
DISABLED
@@ -64,7 +37,16 @@ enum POSStatus {
enum POSRole {
MANAGER
OPERATOR
VIEWER
}
enum ComplexRole {
MANAGER
OPERATOR
}
enum BusinessRole {
MANAGER
OPERATOR
}
enum LicenseType {
@@ -92,29 +74,61 @@ enum UserType {
}
enum AccountType {
PARTNER
BUSINESS
SUPER_ADMIN
ADMIN
PROVIDER
POS
PARTNER
CONSUMER
}
enum UserStatus {
ACTIVE
INACTIVE
}
enum AccountRole {
OWNER
OPERATOR
ACCOUNTANT
}
enum AccountStatus {
ACTIVE
SUSPENDED
}
enum PartnerRole {
ADMIN
OWNER
MANAGER
OPERATOR
}
enum BusinessRole {
ADMIN
OPERATOR
enum PartnerStatus {
ACTIVE
SUSPENDED
}
enum ProviderRole {
ADMIN
OWNER
MANAGER
OPERATOR
}
enum ProviderStatus {
ACTIVE
SUSPENDED
}
enum ConsumerRole {
OWNER
MANAGER
OPERATOR
}
enum ConsumerStatus {
ACTIVE
SUSPENDED
}
enum TokenType {
ACCESS
REFRESH
-2
View File
@@ -15,11 +15,9 @@ model Good {
complex_id String?
category_id String?
guild_id String?
category GoodCategory? @relation(fields: [category_id], references: [id])
complex Complex? @relation(fields: [complex_id], references: [id])
guild Guild? @relation(fields: [guild_id], references: [id])
sales_invoice_items SalesInvoiceItem[]
@@index([category_id])
+13
View File
@@ -0,0 +1,13 @@
model Guild {
id String @id @default(uuid())
name String
code String?
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt() @db.Timestamp(0)
business_activities BusinessActivity[]
good_categories GoodCategory[]
@@map("guilds")
}
+52 -12
View File
@@ -3,25 +3,65 @@ import { prisma } from '../src/lib/prisma'
async function main() {
const password = await PasswordUtil.hash('123456')
const adminUser = await prisma.account.upsert({
where: { username: 'superAdmin' },
const adminUser = await prisma.admin.upsert({
where: {
mobile_number: '09120258156',
},
update: {},
create: {
username: 'superAdmin',
password,
type: 'ADMIN',
status: 'ACTIVE',
updated_at: new Date(),
user: {
first_name: 'عباس',
last_name: 'حسنی',
national_code: '0016022289',
mobile_number: '09120258156',
accounts: {
create: {
first_name: 'عباس',
last_name: 'حسنی',
national_code: '0016022289',
mobile_number: '09120258156',
account: {
create: {
username: 'superAdmin',
password,
type: 'ADMIN',
status: 'ACTIVE',
},
},
},
},
},
})
const guildsCount = prisma.guild.count()
if (!guildsCount) {
const guilds = await prisma.guild.createMany({
data: [
{
name: 'طلا',
code: 'Gold',
},
{
name: 'میوه و تره‌بار',
code: 'Fruit',
},
],
})
const goldGuildId = guilds[0].id
const categoryFactory = (name: string) => ({
name,
guild_id: goldGuildId,
is_default_guild_good: true,
})
await prisma.goodCategory.createMany({
data: [
categoryFactory('زیورآلات'),
categoryFactory('طلا'),
categoryFactory('سایر'),
categoryFactory('سکه'),
categoryFactory('شمش'),
categoryFactory('شمش'),
],
})
}
}
main()