Files
psp_api/prisma/migrations/20260304125039_init/migration.sql
T

273 lines
12 KiB
SQL

/*
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;