feat(database): initialize database schema and triggers
- Created initial database schema with tables for Users, Roles, Products, and related entities. - Added foreign key constraints to maintain data integrity across tables. - Implemented triggers for managing stock movements on insert, update, and delete operations. - Developed scripts to dump existing triggers and pull trigger definitions from the database.
This commit is contained in:
+18
-11
@@ -242,15 +242,16 @@ model PurchaseReceipt {
|
||||
}
|
||||
|
||||
model PurchaseReceiptItem {
|
||||
id Int @id @default(autoincrement())
|
||||
count Decimal @db.Decimal(10, 2)
|
||||
fee Decimal @db.Decimal(10, 2)
|
||||
total Decimal @db.Decimal(10, 2)
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
receiptId Int
|
||||
productId Int
|
||||
product Product @relation("Product_PurchaseReceiptItems", fields: [productId], references: [id])
|
||||
receipt PurchaseReceipt @relation("PurchaseReceipt_Items", fields: [receiptId], references: [id])
|
||||
id Int @id @default(autoincrement())
|
||||
count Decimal @db.Decimal(10, 2)
|
||||
fee Decimal @db.Decimal(10, 2)
|
||||
total Decimal @db.Decimal(10, 2)
|
||||
description String? @db.Text
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
receiptId Int
|
||||
productId Int
|
||||
product Product @relation("Product_PurchaseReceiptItems", fields: [productId], references: [id])
|
||||
receipt PurchaseReceipt @relation("PurchaseReceipt_Items", fields: [receiptId], references: [id])
|
||||
|
||||
@@index([productId], map: "Purchase_Receipt_Items_productId_fkey")
|
||||
@@index([receiptId], map: "Purchase_Receipt_Items_receiptId_fkey")
|
||||
@@ -315,7 +316,7 @@ model StockBalance {
|
||||
ProductId Int @id
|
||||
avgCost Decimal
|
||||
|
||||
@@map("stock_balance")
|
||||
@@map("Stock_Balance")
|
||||
}
|
||||
|
||||
model InventoryTransfer {
|
||||
@@ -374,7 +375,7 @@ view StockMovements_View {
|
||||
current_stock Decimal?
|
||||
current_avg_cost Decimal?
|
||||
|
||||
@@map("stock_movements_view")
|
||||
@@map("Stock_Movements_View")
|
||||
@@ignore
|
||||
}
|
||||
|
||||
@@ -384,6 +385,8 @@ view inventory_overview {
|
||||
avgCost Decimal
|
||||
totalCost Decimal
|
||||
updatedAt DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
@@map("Inventory_Overview")
|
||||
}
|
||||
|
||||
view stock_cardex {
|
||||
@@ -396,12 +399,16 @@ view stock_cardex {
|
||||
balance_quantity Decimal?
|
||||
balance_avg_cost Decimal?
|
||||
createdAt DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
@@map("Stock_Cardex")
|
||||
}
|
||||
|
||||
view stock_view {
|
||||
productId Int
|
||||
inventoryId Int
|
||||
stock Decimal? @db.Decimal(32, 2)
|
||||
|
||||
@@map("Stock_View")
|
||||
}
|
||||
|
||||
enum OrderStatus {
|
||||
|
||||
Reference in New Issue
Block a user