update license structures and setup file storage services

This commit is contained in:
2026-04-16 22:19:20 +03:30
parent d098ef10e1
commit ca494ee82a
75 changed files with 4550 additions and 1255 deletions
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `goods` ADD COLUMN `image_url` VARCHAR(255) NULL;
@@ -0,0 +1,78 @@
/*
Warnings:
- You are about to drop the column `consumer_id` on the `licenses` table. All the data in the column will be lost.
- You are about to drop the column `expires_at` on the `licenses` table. All the data in the column will be lost.
- You are about to drop the column `starts_at` on the `licenses` table. All the data in the column will be lost.
- You are about to drop the column `status` on the `licenses` table. All the data in the column will be lost.
- A unique constraint covering the columns `[activated_license_id]` on the table `consumers` will be added. If there are existing duplicate values, this will fail.
- Added the required column `activation_expires_at` to the `licenses` table without a default value. This is not possible if the table is not empty.
- Added the required column `charged_license_transaction_id` to the `licenses` table without a default value. This is not possible if the table is not empty.
- Made the column `partner_id` on table `licenses` required. This step will fail if there are existing NULL values in that column.
*/
-- DropForeignKey
ALTER TABLE `licenses` DROP FOREIGN KEY `licenses_consumer_id_fkey`;
-- DropForeignKey
ALTER TABLE `licenses` DROP FOREIGN KEY `licenses_partner_id_fkey`;
-- DropIndex
DROP INDEX `licenses_consumer_id_key` ON `licenses`;
-- DropIndex
DROP INDEX `licenses_partner_id_fkey` ON `licenses`;
-- AlterTable
ALTER TABLE `consumers` ADD COLUMN `activated_license_id` VARCHAR(191) NULL;
-- AlterTable
ALTER TABLE `licenses` DROP COLUMN `consumer_id`,
DROP COLUMN `expires_at`,
DROP COLUMN `starts_at`,
DROP COLUMN `status`,
ADD COLUMN `activation_expires_at` DATETIME(3) NOT NULL,
ADD COLUMN `charged_license_transaction_id` VARCHAR(191) NOT NULL,
MODIFY `partner_id` VARCHAR(191) NOT NULL;
-- CreateTable
CREATE TABLE `activated_licenses` (
`id` VARCHAR(191) NOT NULL,
`starts_at` DATETIME(3) NOT NULL,
`expires_at` DATETIME(3) NOT NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`license_id` VARCHAR(191) NOT NULL,
UNIQUE INDEX `activated_licenses_id_key`(`id`),
UNIQUE INDEX `activated_licenses_license_id_key`(`license_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `charged_license_transactions` (
`id` VARCHAR(191) NOT NULL,
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
`updated_at` TIMESTAMP(0) NOT NULL,
`partner_id` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateIndex
CREATE UNIQUE INDEX `consumers_activated_license_id_key` ON `consumers`(`activated_license_id`);
-- AddForeignKey
ALTER TABLE `consumers` ADD CONSTRAINT `consumers_activated_license_id_fkey` FOREIGN KEY (`activated_license_id`) REFERENCES `activated_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 RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `licenses` ADD CONSTRAINT `licenses_charged_license_transaction_id_fkey` FOREIGN KEY (`charged_license_transaction_id`) REFERENCES `charged_license_transactions`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `activated_licenses` ADD CONSTRAINT `activated_licenses_license_id_fkey` FOREIGN KEY (`license_id`) REFERENCES `licenses`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `charged_license_transactions` ADD CONSTRAINT `charged_license_transactions_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
@@ -0,0 +1,41 @@
/*
Warnings:
- You are about to drop the column `activated_license_id` on the `consumers` table. All the data in the column will be lost.
- You are about to drop the column `activation_expires_at` on the `licenses` table. All the data in the column will be lost.
- You are about to drop the column `partner_id` on the `licenses` table. All the data in the column will be lost.
- You are about to drop the column `license_quota` on the `partners` table. All the data in the column will be lost.
- Added the required column `consumer_id` to the `activated_licenses` table without a default value. This is not possible if the table is not empty.
- Added the required column `activation_expires_at` to the `charged_license_transactions` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE `consumers` DROP FOREIGN KEY `consumers_activated_license_id_fkey`;
-- DropForeignKey
ALTER TABLE `licenses` DROP FOREIGN KEY `licenses_partner_id_fkey`;
-- DropIndex
DROP INDEX `consumers_activated_license_id_key` ON `consumers`;
-- DropIndex
DROP INDEX `licenses_partner_id_fkey` ON `licenses`;
-- AlterTable
ALTER TABLE `activated_licenses` ADD COLUMN `consumer_id` VARCHAR(191) NOT NULL;
-- AlterTable
ALTER TABLE `charged_license_transactions` ADD COLUMN `activation_expires_at` DATETIME(3) NOT NULL;
-- AlterTable
ALTER TABLE `consumers` DROP COLUMN `activated_license_id`;
-- AlterTable
ALTER TABLE `licenses` DROP COLUMN `activation_expires_at`,
DROP COLUMN `partner_id`;
-- AlterTable
ALTER TABLE `partners` DROP COLUMN `license_quota`;
-- AddForeignKey
ALTER TABLE `activated_licenses` ADD CONSTRAINT `activated_licenses_consumer_id_fkey` FOREIGN KEY (`consumer_id`) REFERENCES `consumers`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
+1 -2
View File
@@ -29,8 +29,7 @@ model Consumer {
consumer_accounts ConsumerAccount[]
business_activities BusinessActivity[]
license License? @relation()
activated_licenses ActivatedLicense[]
@@map("consumers")
}
+36 -8
View File
@@ -1,17 +1,45 @@
model License {
id String @id @default(uuid())
starts_at DateTime
expires_at DateTime
status LicenseStatus
id String @id @default(uuid())
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt() @db.Timestamp(0)
partner_id String?
partner Partner? @relation(fields: [partner_id], references: [id])
charged_license_transaction_id String
charged_license_transaction ChargedLicenseTransactions @relation(fields: [charged_license_transaction_id], references: [id])
consumer_id String @unique
consumer Consumer @relation(fields: [consumer_id], references: [id])
activated_license ActivatedLicense?
@@map("licenses")
}
model ActivatedLicense {
id String @id @unique() @default(uuid())
starts_at DateTime
expires_at DateTime
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt() @db.Timestamp(0)
license_id String @unique
license License @relation(fields: [license_id], references: [id])
consumer_id String
consumer Consumer @relation(fields: [consumer_id], references: [id])
@@map("activated_licenses")
}
model ChargedLicenseTransactions {
id String @id @default(uuid())
activation_expires_at DateTime
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt() @db.Timestamp(0)
partner_id String
partner Partner @relation(fields: [partner_id], references: [id])
licenses License[]
@@map("charged_license_transactions")
}
+6 -7
View File
@@ -15,17 +15,16 @@ model PartnerAccount {
}
model Partner {
id String @id @default(uuid())
name String
code String @unique()
license_quota Int? @default(0)
status PartnerStatus @default(ACTIVE)
id String @id @default(uuid())
name String
code String @unique()
status PartnerStatus @default(ACTIVE)
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @default(now()) @updatedAt @db.Timestamp(0)
licenses License[]
partner_accounts PartnerAccount[]
partner_accounts PartnerAccount[]
chargedLicenseTransactions ChargedLicenseTransactions[]
@@map("partners")
}
+5 -3
View File
@@ -9,9 +9,11 @@ model Good {
local_sku String? @unique() @db.VarChar(100)
barcode String? @unique() @db.VarChar(100)
base_sale_price Decimal? @default(0.00) @db.Decimal(15, 0)
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt @db.Timestamp(0)
deleted_at DateTime? @db.Timestamp(0)
image_url String? @db.VarChar(255)
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt @db.Timestamp(0)
deleted_at DateTime? @db.Timestamp(0)
complex_id String?
category_id String?
+43 -3
View File
@@ -293,13 +293,12 @@ async function main() {
// ****************** BA Start ****************** //
// ****************** partner Start ****************** //
const partner = await prisma.partner.count()
let partner = await prisma.partner.findFirst()
if (!partner) {
await prisma.partner.create({
partner = await prisma.partner.create({
data: {
name: 'تیس',
code: 'TIS',
license_quota: 5,
status: 'ACTIVE',
partner_accounts: {
create: {
@@ -317,6 +316,47 @@ async function main() {
},
})
}
if (partner) {
await prisma.$transaction(async tx => {
const startOfToday = new Date()
startOfToday.setHours(0, 0, 0, 0)
const month = startOfToday.getMonth()
let year = startOfToday.getFullYear()
let expMonth = month + 3
if (expMonth > 11) {
expMonth = expMonth - 11
year = year + 1
}
startOfToday.setFullYear(year)
startOfToday.setMonth(expMonth)
const transaction = await tx.chargedLicenseTransactions.create({
data: {
activation_expires_at: startOfToday,
partner: {
connect: {
id: partner.id,
},
},
},
select: {
id: true,
},
})
if (transaction)
await tx.license.create({
data: {
charged_license_transaction: {
connect: {
id: transaction.id,
},
},
},
})
})
}
// ****************** provider Start ****************** //
const provider = await prisma.provider.count()