update models and create consumer domain accounts permissions
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
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;
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
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;
|
||||
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
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`;
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `complex_id` on the `customers` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `complex_id` on the `sales_invoices` table. All the data in the column will be lost.
|
||||
- Added the required column `pos_id` to the `sales_invoices` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE `customers` DROP COLUMN `complex_id`;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `sales_invoices` DROP COLUMN `complex_id`,
|
||||
ADD COLUMN `pos_id` VARCHAR(191) NOT NULL;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `customer_individuals` ADD CONSTRAINT `customer_individuals_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `customer_legal` ADD CONSTRAINT `customer_legal_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `sales_invoices` ADD CONSTRAINT `sales_invoices_pos_id_fkey` FOREIGN KEY (`pos_id`) REFERENCES `poses`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `sales_invoices` ADD CONSTRAINT `sales_invoices_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `consumer_accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@@ -1,2 +0,0 @@
|
||||
-- DropIndex
|
||||
DROP INDEX `accounts_password_key` ON `accounts`;
|
||||
@@ -1,17 +0,0 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `licenses` DROP FOREIGN KEY `licenses_partner_id_fkey`;
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX `licenses_partner_id_fkey` ON `licenses`;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `consumers` ADD COLUMN `license_id` VARCHAR(191) NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `licenses` MODIFY `partner_id` VARCHAR(191) NULL;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `consumers` ADD CONSTRAINT `consumers_license_id_fkey` FOREIGN KEY (`license_id`) REFERENCES `licenses`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `licenses` ADD CONSTRAINT `licenses_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `pos_id` on the `licenses` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `licenses` DROP FOREIGN KEY `licenses_pos_id_fkey`;
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX `licenses_pos_id_fkey` ON `licenses`;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `licenses` DROP COLUMN `pos_id`;
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[license_id]` on the table `consumers` will be added. If there are existing duplicate values, this will fail.
|
||||
- A unique constraint covering the columns `[consumer_id]` on the table `licenses` will be added. If there are existing duplicate values, this will fail.
|
||||
- Added the required column `consumer_id` to the `licenses` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `consumers` DROP FOREIGN KEY `consumers_license_id_fkey`;
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX `consumers_license_id_fkey` ON `consumers`;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `licenses` ADD COLUMN `consumer_id` VARCHAR(191) NOT NULL;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX `consumers_license_id_key` ON `consumers`(`license_id`);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX `licenses_consumer_id_key` ON `licenses`(`consumer_id`);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `licenses` ADD CONSTRAINT `licenses_consumer_id_fkey` FOREIGN KEY (`consumer_id`) REFERENCES `consumers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@@ -1,20 +0,0 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `customer_individuals` DROP FOREIGN KEY `customer_individuals_customer_id_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `customer_legal` DROP FOREIGN KEY `customer_legal_customer_id_fkey`;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `customers` ADD COLUMN `unknown_customer` JSON NULL;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX `customer_individuals_complex_id_idx` ON `customer_individuals`(`complex_id`);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX `customer_legal_complex_id_idx` ON `customer_legal`(`complex_id`);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `customer_individuals` ADD CONSTRAINT `customer_individuals_customer_id_fkey` FOREIGN KEY (`customer_id`) REFERENCES `customers`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `customer_legal` ADD CONSTRAINT `customer_legal_customer_id_fkey` FOREIGN KEY (`customer_id`) REFERENCES `customers`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
+96
-82
@@ -1,3 +1,15 @@
|
||||
-- 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,
|
||||
`admin_id` VARCHAR(191) NOT NULL,
|
||||
`account_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `admin_accounts_account_id_key`(`account_id`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `admins` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
@@ -14,29 +26,27 @@ CREATE TABLE `admins` (
|
||||
) 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` (
|
||||
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 `Account_username_key`(`username`),
|
||||
UNIQUE INDEX `Account_password_key`(`password`),
|
||||
UNIQUE INDEX `accounts_username_key`(`username`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `consumer_accounts` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`role` ENUM('OWNER', 'MANAGER', 'OPERATOR') NOT NULL,
|
||||
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updated_at` TIMESTAMP(0) NOT NULL,
|
||||
`consumer_id` VARCHAR(191) NOT NULL,
|
||||
`account_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `consumer_accounts_account_id_key`(`account_id`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
@@ -54,17 +64,6 @@ CREATE TABLE `consumers` (
|
||||
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,
|
||||
@@ -72,7 +71,7 @@ CREATE TABLE `business_activities` (
|
||||
`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,
|
||||
`consumer_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
@@ -138,9 +137,23 @@ CREATE TABLE `licenses` (
|
||||
`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,
|
||||
`partner_id` VARCHAR(191) NULL,
|
||||
`consumer_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `licenses_consumer_id_key`(`consumer_id`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `partner_accounts` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`role` ENUM('OWNER', 'MANAGER', 'OPERATOR') NOT NULL,
|
||||
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updated_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`partner_id` VARCHAR(191) NOT NULL,
|
||||
`account_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `partner_accounts_account_id_key`(`account_id`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
@@ -158,23 +171,12 @@ CREATE TABLE `partners` (
|
||||
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,
|
||||
`consumer_account_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `permission_consumers_account_id_key`(`account_id`),
|
||||
UNIQUE INDEX `permission_consumers_consumer_account_id_key`(`consumer_account_id`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
@@ -211,6 +213,19 @@ CREATE TABLE `permission_business_activities` (
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `provider_accounts` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`role` ENUM('OWNER', 'MANAGER', 'OPERATOR') NOT NULL,
|
||||
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updated_at` TIMESTAMP(0) NOT NULL,
|
||||
`provider_id` VARCHAR(191) NOT NULL,
|
||||
`account_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `provider_accounts_account_id_key`(`account_id`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `providers` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
@@ -224,17 +239,6 @@ CREATE TABLE `providers` (
|
||||
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,
|
||||
@@ -268,39 +272,41 @@ CREATE TABLE `user_devices` (
|
||||
-- CreateTable
|
||||
CREATE TABLE `customers` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`is_favorite` BOOLEAN NULL DEFAULT false,
|
||||
`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,
|
||||
`unknown_customer` JSON NULL,
|
||||
|
||||
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,
|
||||
`customer_id` VARCHAR(191) NOT NULL,
|
||||
`complex_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
INDEX `customer_individuals_complex_id_idx`(`complex_id`),
|
||||
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,
|
||||
`customer_id` VARCHAR(191) NOT NULL,
|
||||
`complex_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
INDEX `customer_legal_complex_id_idx`(`complex_id`),
|
||||
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;
|
||||
@@ -322,7 +328,6 @@ CREATE TABLE `goods` (
|
||||
`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`),
|
||||
@@ -369,7 +374,7 @@ CREATE TABLE `sales_invoices` (
|
||||
`updated_at` TIMESTAMP(0) NOT NULL,
|
||||
`customer_id` VARCHAR(191) NULL,
|
||||
`account_id` VARCHAR(191) NOT NULL,
|
||||
`complex_id` VARCHAR(191) NOT NULL,
|
||||
`pos_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `sales_invoices_code_key`(`code`),
|
||||
PRIMARY KEY (`id`)
|
||||
@@ -446,28 +451,22 @@ CREATE TABLE `service_categories` (
|
||||
) 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;
|
||||
ALTER TABLE `admin_accounts` ADD CONSTRAINT `admin_accounts_admin_id_fkey` FOREIGN KEY (`admin_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;
|
||||
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 `Account` ADD CONSTRAINT `Account_consumer_account_id_fkey` FOREIGN KEY (`consumer_account_id`) REFERENCES `consumer_accounts`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
ALTER TABLE `consumer_accounts` ADD CONSTRAINT `consumer_accounts_consumer_id_fkey` FOREIGN KEY (`consumer_id`) REFERENCES `consumers`(`id`) ON DELETE RESTRICT 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;
|
||||
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 `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;
|
||||
ALTER TABLE `business_activities` ADD CONSTRAINT `business_activities_consumer_id_fkey` FOREIGN KEY (`consumer_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;
|
||||
@@ -485,16 +484,19 @@ ALTER TABLE `poses` ADD CONSTRAINT `poses_provider_id_fkey` FOREIGN KEY (`provid
|
||||
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;
|
||||
ALTER TABLE `licenses` ADD CONSTRAINT `licenses_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners`(`id`) ON DELETE SET NULL 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;
|
||||
ALTER TABLE `licenses` ADD CONSTRAINT `licenses_consumer_id_fkey` FOREIGN KEY (`consumer_id`) REFERENCES `consumers`(`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;
|
||||
ALTER TABLE `partner_accounts` ADD CONSTRAINT `partner_accounts_partner_id_fkey` FOREIGN KEY (`partner_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;
|
||||
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 `permission_consumers` ADD CONSTRAINT `permission_consumers_consumer_account_id_fkey` FOREIGN KEY (`consumer_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;
|
||||
@@ -515,13 +517,22 @@ ALTER TABLE `permission_business_activities` ADD CONSTRAINT `permission_business
|
||||
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;
|
||||
ALTER TABLE `provider_accounts` ADD CONSTRAINT `provider_accounts_provider_id_fkey` FOREIGN KEY (`provider_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;
|
||||
ALTER TABLE `provider_accounts` ADD CONSTRAINT `provider_accounts_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`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;
|
||||
ALTER TABLE `customer_individuals` ADD CONSTRAINT `customer_individuals_customer_id_fkey` FOREIGN KEY (`customer_id`) REFERENCES `customers`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `customer_individuals` ADD CONSTRAINT `customer_individuals_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes`(`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 CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `customer_legal` ADD CONSTRAINT `customer_legal_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes`(`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;
|
||||
@@ -529,9 +540,6 @@ ALTER TABLE `goods` ADD CONSTRAINT `goods_category_id_fkey` FOREIGN KEY (`catego
|
||||
-- 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;
|
||||
|
||||
@@ -541,6 +549,12 @@ ALTER TABLE `good_categories` ADD CONSTRAINT `good_categories_complex_id_fkey` F
|
||||
-- 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_invoices` ADD CONSTRAINT `sales_invoices_pos_id_fkey` FOREIGN KEY (`pos_id`) REFERENCES `poses`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `sales_invoices` ADD CONSTRAINT `sales_invoices_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `consumer_accounts`(`id`) ON DELETE RESTRICT 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;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `permission_business_activities` DROP FOREIGN KEY `permission_business_activities_business_id_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `permission_business_activities` DROP FOREIGN KEY `permission_business_activities_permission_id_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `permission_complexes` DROP FOREIGN KEY `permission_complexes_complex_id_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `permission_complexes` DROP FOREIGN KEY `permission_complexes_permission_id_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `permission_consumers` DROP FOREIGN KEY `permission_consumers_consumer_account_id_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `permission_poses` DROP FOREIGN KEY `permission_poses_permission_id_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `permission_poses` DROP FOREIGN KEY `permission_poses_pos_id_fkey`;
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX `permission_business_activities_business_id_fkey` ON `permission_business_activities`;
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX `permission_complexes_complex_id_fkey` ON `permission_complexes`;
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX `permission_poses_pos_id_fkey` ON `permission_poses`;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `permission_consumers` ADD CONSTRAINT `permission_consumers_consumer_account_id_fkey` FOREIGN KEY (`consumer_account_id`) REFERENCES `consumer_accounts`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `permission_poses` ADD CONSTRAINT `permission_poses_pos_id_fkey` FOREIGN KEY (`pos_id`) REFERENCES `poses`(`id`) ON DELETE CASCADE 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 CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `permission_complexes` ADD CONSTRAINT `permission_complexes_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes`(`id`) ON DELETE CASCADE 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 CASCADE 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 CASCADE 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 CASCADE ON UPDATE CASCADE;
|
||||
@@ -1,3 +1,18 @@
|
||||
model AdminAccount {
|
||||
id String @id @default(uuid())
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
admin_id String
|
||||
admin Admin @relation(fields: [admin_id], references: [id])
|
||||
|
||||
account_id String @unique
|
||||
account Account @relation(fields: [account_id], references: [id])
|
||||
|
||||
@@map("admin_accounts")
|
||||
}
|
||||
|
||||
model Admin {
|
||||
id String @id @default(uuid())
|
||||
mobile_number String @unique()
|
||||
@@ -8,26 +23,11 @@ model Admin {
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
accounts AdminAccount[]
|
||||
adminAccounts 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
|
||||
|
||||
@@ -1,22 +1,3 @@
|
||||
model Consumer {
|
||||
id String @id @default(uuid())
|
||||
mobile_number String @unique()
|
||||
first_name String
|
||||
last_name String
|
||||
status ConsumerStatus @default(ACTIVE)
|
||||
license_id String? @unique()
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
accounts ConsumerAccount[]
|
||||
businessActivities BusinessActivity[]
|
||||
|
||||
license License?
|
||||
|
||||
@@map("consumers")
|
||||
}
|
||||
|
||||
model ConsumerAccount {
|
||||
id String @id @default(uuid())
|
||||
role ConsumerRole
|
||||
@@ -24,18 +5,36 @@ model ConsumerAccount {
|
||||
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])
|
||||
consumer_id String
|
||||
consumer Consumer @relation(fields: [consumer_id], references: [id])
|
||||
|
||||
account_id String @unique
|
||||
account Account @relation(fields: [account_id], references: [id])
|
||||
|
||||
permissions PermissionConsumer[]
|
||||
salesInvoices SalesInvoice[]
|
||||
permission PermissionConsumer?
|
||||
sales_invoices SalesInvoice[]
|
||||
|
||||
@@map("consumer_accounts")
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
consumer_accounts ConsumerAccount[]
|
||||
business_activities BusinessActivity[]
|
||||
|
||||
license License? @relation()
|
||||
|
||||
@@map("consumers")
|
||||
}
|
||||
|
||||
model BusinessActivity {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
@@ -43,13 +42,13 @@ model BusinessActivity {
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
guild_id String
|
||||
user_id String
|
||||
guild Guild @relation(fields: [guild_id], references: [id])
|
||||
|
||||
guild Guild @relation(fields: [guild_id], references: [id])
|
||||
user Consumer @relation(fields: [user_id], references: [id])
|
||||
consumer_id String
|
||||
consumer Consumer @relation(fields: [consumer_id], references: [id])
|
||||
|
||||
complexes Complex[]
|
||||
permissionBusinesses PermissionBusiness[]
|
||||
complexes Complex[]
|
||||
permission_businesses PermissionBusiness[]
|
||||
|
||||
@@map("business_activities")
|
||||
}
|
||||
@@ -67,12 +66,12 @@ model Complex {
|
||||
|
||||
business_activity BusinessActivity @relation(fields: [business_activity_id], references: [id])
|
||||
|
||||
pos_list Pos[]
|
||||
goods Good[]
|
||||
good_categories GoodCategory[]
|
||||
permissionComplexes PermissionComplex[]
|
||||
customerIndividuals CustomerIndividual[]
|
||||
customerLegals CustomerLegal[]
|
||||
pos_list Pos[]
|
||||
goods Good[]
|
||||
good_categories GoodCategory[]
|
||||
permission_complexes PermissionComplex[]
|
||||
customer_individuals CustomerIndividual[]
|
||||
customer_legals CustomerLegal[]
|
||||
|
||||
@@map("complexes")
|
||||
}
|
||||
@@ -96,37 +95,8 @@ model Pos {
|
||||
provider_id String?
|
||||
provider Provider? @relation(fields: [provider_id], references: [id])
|
||||
|
||||
permissionPos PermissionPos[]
|
||||
salesInvoices SalesInvoice[]
|
||||
permission_pos PermissionPos[]
|
||||
sales_invoices SalesInvoice[]
|
||||
|
||||
@@map("poses")
|
||||
}
|
||||
|
||||
// model BusinessAccount {
|
||||
// id String @id @default(uuid())
|
||||
// role BusinessRole
|
||||
// status AccountStatus @default(ACTIVE)
|
||||
// created_at DateTime @default(now())
|
||||
// business_activity_id String
|
||||
// account_id String @unique
|
||||
|
||||
// account Account @relation(fields: [account_id], references: [id])
|
||||
// owned_activities BusinessActivity[] @relation("business_owner")
|
||||
|
||||
// @@unique([business_activity_id, account_id])
|
||||
// @@map("business_accounts")
|
||||
// }
|
||||
|
||||
// model PosAccount {
|
||||
// id String @id @default(uuid())
|
||||
// pos_id String
|
||||
// account_id String
|
||||
// role POSRole
|
||||
// created_at DateTime @default(now())
|
||||
|
||||
// pos Pos @relation(fields: [pos_id], references: [id])
|
||||
// account Account @relation(fields: [account_id], references: [id])
|
||||
|
||||
// @@unique([pos_id, account_id])
|
||||
// @@map("pos_accounts")
|
||||
// }
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
model PartnerAccount {
|
||||
id String @id @default(uuid())
|
||||
role PartnerRole
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @default(now()) @updatedAt @db.Timestamp(0)
|
||||
|
||||
partner_id String
|
||||
partner Partner @relation(fields: [partner_id], references: [id])
|
||||
|
||||
account_id String @unique
|
||||
account Account @relation(fields: [account_id], references: [id])
|
||||
|
||||
@@map("partner_accounts")
|
||||
}
|
||||
|
||||
model Partner {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
@@ -8,24 +24,8 @@ model Partner {
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @default(now()) @updatedAt @db.Timestamp(0)
|
||||
|
||||
licenses License[]
|
||||
accounts PartnerAccount[]
|
||||
licenses License[]
|
||||
partner_accounts PartnerAccount[]
|
||||
|
||||
@@map("partners")
|
||||
}
|
||||
|
||||
model PartnerAccount {
|
||||
id String @id @default(uuid())
|
||||
role PartnerRole
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @default(now()) @updatedAt @db.Timestamp(0)
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
model PermissionConsumer {
|
||||
id String @id @default(uuid())
|
||||
|
||||
account_id String @unique
|
||||
consumer_account_id String @unique
|
||||
consumer_account ConsumerAccount @relation(fields: [consumer_account_id], references: [id], onDelete: Cascade)
|
||||
|
||||
account ConsumerAccount @relation(fields: [account_id], references: [id])
|
||||
|
||||
posPermissions PermissionPos[]
|
||||
complexPermissions PermissionComplex[]
|
||||
businessPermissions PermissionBusiness[]
|
||||
pos_permissions PermissionPos[]
|
||||
complex_permissions PermissionComplex[]
|
||||
business_permissions PermissionBusiness[]
|
||||
|
||||
@@map("permission_consumers")
|
||||
}
|
||||
@@ -19,8 +18,8 @@ model PermissionPos {
|
||||
pos_id String
|
||||
permission_id String
|
||||
|
||||
pos Pos @relation(fields: [pos_id], references: [id])
|
||||
permission PermissionConsumer @relation(fields: [permission_id], references: [id])
|
||||
pos Pos @relation(fields: [pos_id], references: [id], onDelete: Cascade)
|
||||
permission PermissionConsumer @relation(fields: [permission_id], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([permission_id, pos_id])
|
||||
@@map("permission_poses")
|
||||
@@ -33,8 +32,8 @@ model PermissionComplex {
|
||||
complex_id String
|
||||
permission_id String
|
||||
|
||||
complex Complex @relation(fields: [complex_id], references: [id])
|
||||
permission PermissionConsumer @relation(fields: [permission_id], references: [id])
|
||||
complex Complex @relation(fields: [complex_id], references: [id], onDelete: Cascade)
|
||||
permission PermissionConsumer @relation(fields: [permission_id], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([permission_id, complex_id])
|
||||
@@map("permission_complexes")
|
||||
@@ -47,8 +46,8 @@ model PermissionBusiness {
|
||||
business_id String
|
||||
permission_id String
|
||||
|
||||
business BusinessActivity @relation(fields: [business_id], references: [id])
|
||||
permission PermissionConsumer @relation(fields: [permission_id], references: [id])
|
||||
business BusinessActivity @relation(fields: [business_id], references: [id], onDelete: Cascade)
|
||||
permission PermissionConsumer @relation(fields: [permission_id], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([permission_id, business_id])
|
||||
@@map("permission_business_activities")
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
model ProviderAccount {
|
||||
id String @id @default(uuid())
|
||||
role ProviderRole
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
provider_id String
|
||||
provider Provider @relation(fields: [provider_id], references: [id])
|
||||
|
||||
account_id String @unique
|
||||
account Account @relation(fields: [account_id], references: [id])
|
||||
|
||||
@@map("provider_accounts")
|
||||
}
|
||||
|
||||
model Provider {
|
||||
id String @id @default(uuid())
|
||||
code String @unique()
|
||||
@@ -7,24 +23,8 @@ model Provider {
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt @db.Timestamp(0)
|
||||
|
||||
pos_list Pos[]
|
||||
accounts ProviderAccount[]
|
||||
pos_list Pos[]
|
||||
provider_accounts ProviderAccount[]
|
||||
|
||||
@@map("providers")
|
||||
}
|
||||
|
||||
model ProviderAccount {
|
||||
id String @id @default(uuid())
|
||||
role ProviderRole
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
+16
-8
@@ -15,7 +15,7 @@ async function main() {
|
||||
last_name: 'حسنی',
|
||||
national_code: '0016022289',
|
||||
mobile_number: '09120258156',
|
||||
accounts: {
|
||||
adminAccounts: {
|
||||
create: {
|
||||
account: {
|
||||
create: {
|
||||
@@ -33,7 +33,7 @@ async function main() {
|
||||
// ****************** GUILD Start ****************** //
|
||||
const guilds = await prisma.guild.findMany()
|
||||
if (!guilds.length) {
|
||||
const guilds = await prisma.guild.createMany({
|
||||
await prisma.guild.createMany({
|
||||
data: [
|
||||
{
|
||||
name: 'طلا',
|
||||
@@ -48,14 +48,22 @@ async function main() {
|
||||
}
|
||||
|
||||
// ****************** GUILD Good Categories Start ****************** //
|
||||
const goldGuildId = guilds[0].id
|
||||
|
||||
const goldGuild = await prisma.guild.findFirst({
|
||||
where: {
|
||||
name: 'طلا',
|
||||
},
|
||||
})
|
||||
|
||||
const goldGuildId = goldGuild?.id
|
||||
const goldGuildGoodCategories = await prisma.goodCategory.findMany({
|
||||
where: {
|
||||
guild_id: goldGuildId,
|
||||
is_default_guild_good: true,
|
||||
},
|
||||
})
|
||||
if (!goldGuildGoodCategories) {
|
||||
|
||||
if (!goldGuildGoodCategories?.length) {
|
||||
const categoryFactory = (name: string) => ({
|
||||
name,
|
||||
guild_id: goldGuildId,
|
||||
@@ -239,12 +247,12 @@ async function main() {
|
||||
await prisma.businessActivity.create({
|
||||
data: {
|
||||
name: 'طلا فروشی',
|
||||
user: {
|
||||
consumer: {
|
||||
create: {
|
||||
first_name: 'محمد',
|
||||
last_name: 'زرگر',
|
||||
mobile_number: '09120258155',
|
||||
accounts: {
|
||||
consumer_accounts: {
|
||||
create: {
|
||||
role: 'OWNER',
|
||||
account: {
|
||||
@@ -293,7 +301,7 @@ async function main() {
|
||||
code: 'TIS',
|
||||
license_quota: 5,
|
||||
status: 'ACTIVE',
|
||||
accounts: {
|
||||
partner_accounts: {
|
||||
create: {
|
||||
role: 'OWNER',
|
||||
account: {
|
||||
@@ -318,7 +326,7 @@ async function main() {
|
||||
name: 'توسن',
|
||||
code: 'Tosan',
|
||||
status: 'ACTIVE',
|
||||
accounts: {
|
||||
provider_accounts: {
|
||||
create: {
|
||||
role: 'OWNER',
|
||||
account: {
|
||||
|
||||
Reference in New Issue
Block a user