feat(orders): issued_orders schema + migration
Pre-existing quotations.project_code + ai_chat_messages FK drift is captured in its own reconcile_quotations_aichat_fk migration; the issued_orders migration is purely additive. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE `ai_chat_messages` DROP FOREIGN KEY `fk_ai_chat_conv`;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE `quotations` MODIFY `project_code` VARCHAR(100) NULL;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `ai_chat_messages` ADD CONSTRAINT `ai_chat_messages_conversation_id_fkey` FOREIGN KEY (`conversation_id`) REFERENCES `ai_conversations`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
52
prisma/migrations/20260609085152_issued_orders/migration.sql
Normal file
52
prisma/migrations/20260609085152_issued_orders/migration.sql
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE `company_settings` ADD COLUMN `issued_order_number_pattern` VARCHAR(100) NULL,
|
||||||
|
ADD COLUMN `issued_order_type_code` VARCHAR(10) NULL;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `issued_orders` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`po_number` VARCHAR(50) NULL,
|
||||||
|
`customer_id` INTEGER NULL,
|
||||||
|
`status` ENUM('draft', 'sent', 'confirmed', 'completed', 'cancelled') NOT NULL DEFAULT 'draft',
|
||||||
|
`currency` VARCHAR(10) NULL DEFAULT 'CZK',
|
||||||
|
`vat_rate` DECIMAL(5, 2) NULL DEFAULT 21.00,
|
||||||
|
`apply_vat` BOOLEAN NULL DEFAULT true,
|
||||||
|
`exchange_rate` DECIMAL(10, 4) NULL DEFAULT 1.0000,
|
||||||
|
`order_date` DATE NULL,
|
||||||
|
`delivery_date` DATE NULL,
|
||||||
|
`language` VARCHAR(5) NULL DEFAULT 'cs',
|
||||||
|
`delivery_terms` VARCHAR(500) NULL,
|
||||||
|
`payment_terms` VARCHAR(500) NULL,
|
||||||
|
`issued_by` VARCHAR(255) NULL,
|
||||||
|
`notes` TEXT NULL,
|
||||||
|
`internal_notes` TEXT NULL,
|
||||||
|
`created_at` DATETIME(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||||
|
`modified_at` DATETIME(0) NULL,
|
||||||
|
|
||||||
|
UNIQUE INDEX `idx_issued_orders_number_unique`(`po_number`),
|
||||||
|
INDEX `issued_orders_customer_id`(`customer_id`),
|
||||||
|
INDEX `idx_issued_orders_status_date`(`status`, `order_date`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `issued_order_items` (
|
||||||
|
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||||
|
`issued_order_id` INTEGER NOT NULL,
|
||||||
|
`description` VARCHAR(500) NULL,
|
||||||
|
`item_description` TEXT NULL,
|
||||||
|
`quantity` DECIMAL(12, 3) NULL DEFAULT 1.000,
|
||||||
|
`unit` VARCHAR(20) NULL,
|
||||||
|
`unit_price` DECIMAL(12, 2) NULL DEFAULT 0.00,
|
||||||
|
`vat_rate` DECIMAL(5, 2) NULL DEFAULT 21.00,
|
||||||
|
`position` INTEGER NULL DEFAULT 0,
|
||||||
|
|
||||||
|
INDEX `issued_order_id`(`issued_order_id`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `issued_orders` ADD CONSTRAINT `issued_orders_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customers`(`id`) ON DELETE RESTRICT ON UPDATE NO ACTION;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `issued_order_items` ADD CONSTRAINT `issued_order_items_ibfk_1` FOREIGN KEY (`issued_order_id`) REFERENCES `issued_orders`(`id`) ON DELETE CASCADE ON UPDATE NO ACTION;
|
||||||
@@ -164,6 +164,8 @@ model company_settings {
|
|||||||
offer_number_pattern String? @db.VarChar(100)
|
offer_number_pattern String? @db.VarChar(100)
|
||||||
order_number_pattern String? @db.VarChar(100)
|
order_number_pattern String? @db.VarChar(100)
|
||||||
invoice_number_pattern String? @db.VarChar(100)
|
invoice_number_pattern String? @db.VarChar(100)
|
||||||
|
issued_order_number_pattern String? @db.VarChar(100)
|
||||||
|
issued_order_type_code String? @db.VarChar(10)
|
||||||
warehouse_receipt_prefix String? @db.VarChar(20)
|
warehouse_receipt_prefix String? @db.VarChar(20)
|
||||||
warehouse_receipt_number_pattern String? @db.VarChar(100)
|
warehouse_receipt_number_pattern String? @db.VarChar(100)
|
||||||
warehouse_issue_prefix String? @db.VarChar(20)
|
warehouse_issue_prefix String? @db.VarChar(20)
|
||||||
@@ -189,6 +191,7 @@ model customers {
|
|||||||
sync_version Int? @default(0)
|
sync_version Int? @default(0)
|
||||||
invoices invoices[]
|
invoices invoices[]
|
||||||
orders orders[]
|
orders orders[]
|
||||||
|
issued_orders issued_orders[]
|
||||||
projects projects[]
|
projects projects[]
|
||||||
quotations quotations[]
|
quotations quotations[]
|
||||||
}
|
}
|
||||||
@@ -362,6 +365,55 @@ model orders {
|
|||||||
@@index([quotation_id], map: "quotation_id")
|
@@index([quotation_id], map: "quotation_id")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model issued_orders {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
po_number String? @unique(map: "idx_issued_orders_number_unique") @db.VarChar(50)
|
||||||
|
customer_id Int?
|
||||||
|
status issued_orders_status @default(draft)
|
||||||
|
currency String? @default("CZK") @db.VarChar(10)
|
||||||
|
vat_rate Decimal? @default(21.00) @db.Decimal(5, 2)
|
||||||
|
apply_vat Boolean? @default(true)
|
||||||
|
exchange_rate Decimal? @default(1.0000) @db.Decimal(10, 4)
|
||||||
|
order_date DateTime? @db.Date
|
||||||
|
delivery_date DateTime? @db.Date
|
||||||
|
language String? @default("cs") @db.VarChar(5)
|
||||||
|
delivery_terms String? @db.VarChar(500)
|
||||||
|
payment_terms String? @db.VarChar(500)
|
||||||
|
issued_by String? @db.VarChar(255)
|
||||||
|
notes String? @db.Text
|
||||||
|
internal_notes String? @db.Text
|
||||||
|
created_at DateTime? @default(now()) @db.DateTime(0)
|
||||||
|
modified_at DateTime? @db.DateTime(0)
|
||||||
|
issued_order_items issued_order_items[]
|
||||||
|
customers customers? @relation(fields: [customer_id], references: [id], onDelete: Restrict, onUpdate: NoAction, map: "issued_orders_ibfk_1")
|
||||||
|
|
||||||
|
@@index([customer_id], map: "issued_orders_customer_id")
|
||||||
|
@@index([status, order_date], map: "idx_issued_orders_status_date")
|
||||||
|
}
|
||||||
|
|
||||||
|
model issued_order_items {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
issued_order_id Int
|
||||||
|
description String? @db.VarChar(500)
|
||||||
|
item_description String? @db.Text
|
||||||
|
quantity Decimal? @default(1.000) @db.Decimal(12, 3)
|
||||||
|
unit String? @db.VarChar(20)
|
||||||
|
unit_price Decimal? @default(0.00) @db.Decimal(12, 2)
|
||||||
|
vat_rate Decimal? @default(21.00) @db.Decimal(5, 2)
|
||||||
|
position Int? @default(0)
|
||||||
|
issued_orders issued_orders @relation(fields: [issued_order_id], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "issued_order_items_ibfk_1")
|
||||||
|
|
||||||
|
@@index([issued_order_id], map: "issued_order_id")
|
||||||
|
}
|
||||||
|
|
||||||
|
enum issued_orders_status {
|
||||||
|
draft
|
||||||
|
sent
|
||||||
|
confirmed
|
||||||
|
completed
|
||||||
|
cancelled
|
||||||
|
}
|
||||||
|
|
||||||
model permissions {
|
model permissions {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
name String @unique(map: "name") @db.VarChar(50)
|
name String @unique(map: "name") @db.VarChar(50)
|
||||||
|
|||||||
Reference in New Issue
Block a user