Split exchange into quotes service
All checks were successful
Build Docker Image / build (push) Successful in 2m0s
All checks were successful
Build Docker Image / build (push) Successful in 2m0s
This commit is contained in:
98
prisma/migrations/1_split_exchange_quotes/migration.sql
Normal file
98
prisma/migrations/1_split_exchange_quotes/migration.sql
Normal file
@@ -0,0 +1,98 @@
|
||||
-- DropTable
|
||||
DROP TABLE "offers";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "calculations";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "suppliers";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "exchange_quotes" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"uuid" TEXT NOT NULL,
|
||||
"supplier_id" INTEGER NOT NULL,
|
||||
"product_id" INTEGER NOT NULL,
|
||||
"status" VARCHAR(20) NOT NULL DEFAULT 'active',
|
||||
"quantity" DECIMAL(12,2) NOT NULL,
|
||||
"unit" VARCHAR(20) NOT NULL DEFAULT 'ton',
|
||||
"price_per_unit" DECIMAL(12,2) NOT NULL,
|
||||
"currency" VARCHAR(10) NOT NULL DEFAULT 'USD',
|
||||
"incoterms_code" VARCHAR(20),
|
||||
"origin_point_uuid" VARCHAR(100),
|
||||
"origin_name" VARCHAR(255),
|
||||
"valid_until" DATE,
|
||||
"notes" TEXT,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "exchange_quotes_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "exchange_suppliers" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"uuid" TEXT NOT NULL,
|
||||
"team_uuid" VARCHAR(100),
|
||||
"name" VARCHAR(255) NOT NULL,
|
||||
"description" TEXT,
|
||||
"country" VARCHAR(100) NOT NULL DEFAULT '',
|
||||
"country_code" VARCHAR(10) NOT NULL DEFAULT '',
|
||||
"logo_url" VARCHAR(500),
|
||||
"is_verified" BOOLEAN NOT NULL DEFAULT false,
|
||||
"is_active" BOOLEAN NOT NULL DEFAULT true,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "exchange_suppliers_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "exchange_products" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"uuid" TEXT NOT NULL,
|
||||
"sku" VARCHAR(100),
|
||||
"name" VARCHAR(255) NOT NULL,
|
||||
"category_name" VARCHAR(255) NOT NULL DEFAULT '',
|
||||
"unit" VARCHAR(20) NOT NULL DEFAULT 'ton',
|
||||
"description" TEXT,
|
||||
"is_active" BOOLEAN NOT NULL DEFAULT true,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "exchange_products_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "exchange_quotes_uuid_key" ON "exchange_quotes"("uuid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "exchange_quotes_status_product_id_created_at_idx" ON "exchange_quotes"("status", "product_id", "created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "exchange_quotes_supplier_id_created_at_idx" ON "exchange_quotes"("supplier_id", "created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "exchange_suppliers_uuid_key" ON "exchange_suppliers"("uuid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "exchange_suppliers_team_uuid_key" ON "exchange_suppliers"("team_uuid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "exchange_suppliers_country_code_is_active_idx" ON "exchange_suppliers"("country_code", "is_active");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "exchange_products_uuid_key" ON "exchange_products"("uuid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "exchange_products_sku_key" ON "exchange_products"("sku");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "exchange_products_category_name_is_active_idx" ON "exchange_products"("category_name", "is_active");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "exchange_quotes" ADD CONSTRAINT "exchange_quotes_supplier_id_fkey" FOREIGN KEY ("supplier_id") REFERENCES "exchange_suppliers"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "exchange_quotes" ADD CONSTRAINT "exchange_quotes_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "exchange_products"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
@@ -4,68 +4,67 @@ generator client {
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("EXCHANGE_DATABASE_URL")
|
||||
}
|
||||
|
||||
model Offer {
|
||||
id Int @id @default(autoincrement())
|
||||
uuid String @unique @default(uuid())
|
||||
teamUuid String @map("team_uuid") @db.VarChar(100)
|
||||
status String @default("active") @db.VarChar(20)
|
||||
workflowStatus String @default("pending") @map("workflow_status") @db.VarChar(20)
|
||||
workflowError String? @map("workflow_error")
|
||||
locationUuid String? @map("location_uuid") @db.VarChar(100)
|
||||
locationName String @default("") @map("location_name") @db.VarChar(255)
|
||||
locationCountry String @default("") @map("location_country") @db.VarChar(100)
|
||||
locationCountryCode String @default("") @map("location_country_code") @db.VarChar(10)
|
||||
locationLatitude Float? @map("location_latitude")
|
||||
locationLongitude Float? @map("location_longitude")
|
||||
productUuid String @map("product_uuid") @db.VarChar(100)
|
||||
productName String @map("product_name") @db.VarChar(255)
|
||||
categoryName String @default("") @map("category_name") @db.VarChar(255)
|
||||
quantity Decimal @db.Decimal(12, 2)
|
||||
unit String @default("ton") @db.VarChar(20)
|
||||
pricePerUnit Decimal @map("price_per_unit") @db.Decimal(12, 2)
|
||||
currency String @default("USD") @db.VarChar(10)
|
||||
terminusSchemaId String? @map("terminus_schema_id") @db.VarChar(255)
|
||||
terminusDocumentId String? @map("terminus_document_id") @db.VarChar(255)
|
||||
description String?
|
||||
validUntil DateTime? @map("valid_until") @db.Date
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
model Quote {
|
||||
id Int @id @default(autoincrement())
|
||||
uuid String @unique @default(uuid())
|
||||
supplierId Int @map("supplier_id")
|
||||
supplier Supplier @relation(fields: [supplierId], references: [id], onDelete: Cascade)
|
||||
productId Int @map("product_id")
|
||||
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
|
||||
status String @default("active") @db.VarChar(20)
|
||||
quantity Decimal @db.Decimal(12, 2)
|
||||
unit String @default("ton") @db.VarChar(20)
|
||||
pricePerUnit Decimal @map("price_per_unit") @db.Decimal(12, 2)
|
||||
currency String @default("USD") @db.VarChar(10)
|
||||
incotermsCode String? @map("incoterms_code") @db.VarChar(20)
|
||||
originPointUuid String? @map("origin_point_uuid") @db.VarChar(100)
|
||||
originName String? @map("origin_name") @db.VarChar(255)
|
||||
validUntil DateTime? @map("valid_until") @db.Date
|
||||
notes String?
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@map("offers")
|
||||
@@index([status, productId, createdAt])
|
||||
@@index([supplierId, createdAt])
|
||||
@@map("exchange_quotes")
|
||||
}
|
||||
|
||||
model Request {
|
||||
id Int @id @default(autoincrement())
|
||||
uuid String @unique @default(uuid())
|
||||
productUuid String @map("product_uuid") @db.VarChar(100)
|
||||
quantity Decimal @db.Decimal(12, 2)
|
||||
sourceLocationUuid String @map("source_location_uuid") @db.VarChar(100)
|
||||
userId String @map("user_id") @db.VarChar(255)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
model Supplier {
|
||||
id Int @id @default(autoincrement())
|
||||
uuid String @unique @default(uuid())
|
||||
teamUuid String? @unique @map("team_uuid") @db.VarChar(100)
|
||||
name String @db.VarChar(255)
|
||||
description String?
|
||||
country String @default("") @db.VarChar(100)
|
||||
countryCode String @default("") @map("country_code") @db.VarChar(10)
|
||||
logoUrl String? @map("logo_url") @db.VarChar(500)
|
||||
isVerified Boolean @default(false) @map("is_verified")
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@map("calculations")
|
||||
quotes Quote[]
|
||||
|
||||
@@index([countryCode, isActive])
|
||||
@@map("exchange_suppliers")
|
||||
}
|
||||
|
||||
model SupplierProfile {
|
||||
id Int @id @default(autoincrement())
|
||||
uuid String @unique @default(uuid())
|
||||
teamUuid String @unique @map("team_uuid") @db.VarChar(100)
|
||||
kycProfileUuid String? @map("kyc_profile_uuid") @db.VarChar(100)
|
||||
name String @db.VarChar(255)
|
||||
description String?
|
||||
country String @default("") @db.VarChar(100)
|
||||
countryCode String @default("") @map("country_code") @db.VarChar(10)
|
||||
logoUrl String? @map("logo_url") @db.VarChar(500)
|
||||
latitude Float?
|
||||
longitude Float?
|
||||
isVerified Boolean @default(false) @map("is_verified")
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
model Product {
|
||||
id Int @id @default(autoincrement())
|
||||
uuid String @unique @default(uuid())
|
||||
sku String? @unique @db.VarChar(100)
|
||||
name String @db.VarChar(255)
|
||||
categoryName String @default("") @map("category_name") @db.VarChar(255)
|
||||
unit String @default("ton") @db.VarChar(20)
|
||||
description String?
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@map("suppliers")
|
||||
quotes Quote[]
|
||||
|
||||
@@index([categoryName, isActive])
|
||||
@@map("exchange_products")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user