fisual structure
This commit is contained in:
723
DATABASE_VISUAL_STRUCTURE.md
Normal file
723
DATABASE_VISUAL_STRUCTURE.md
Normal file
@@ -0,0 +1,723 @@
|
||||
# Database Visual Structure - Trasabilitate Quality App
|
||||
|
||||
**Database**: `trasabilitate` (MariaDB 11.8.3)
|
||||
**Total Tables**: 17
|
||||
**Character Set**: utf8mb4
|
||||
**Date**: January 10, 2026
|
||||
|
||||
---
|
||||
|
||||
## 1. Database Schema Overview
|
||||
|
||||
```
|
||||
╔═══════════════════════════════════════════════════════════════════════════╗
|
||||
║ TRASABILITATE DATABASE ║
|
||||
╠═══════════════════════════════════════════════════════════════════════════╣
|
||||
║ ║
|
||||
║ ┌─────────────────────────────────────────────────────────────────────┐ ║
|
||||
║ │ USER MANAGEMENT & ACCESS CONTROL (6 tables) │ ║
|
||||
║ │ │ ║
|
||||
║ │ • users • roles │ ║
|
||||
║ │ • role_hierarchy • permissions │ ║
|
||||
║ │ • role_permissions • permission_audit_log │ ║
|
||||
║ └─────────────────────────────────────────────────────────────────────┘ ║
|
||||
║ ║
|
||||
║ ┌─────────────────────────────────────────────────────────────────────┐ ║
|
||||
║ │ QUALITY MANAGEMENT / PRODUCTION SCANNING (2 tables) │ ║
|
||||
║ │ │ ║
|
||||
║ │ • scan1_orders (Phase 1 - Quilting) │ ║
|
||||
║ │ • scanfg_orders (Final Goods Quality) │ ║
|
||||
║ └─────────────────────────────────────────────────────────────────────┘ ║
|
||||
║ ║
|
||||
║ ┌─────────────────────────────────────────────────────────────────────┐ ║
|
||||
║ │ DAILY MIRROR / BUSINESS INTELLIGENCE (7 tables) │ ║
|
||||
║ │ │ ║
|
||||
║ │ • dm_articles • dm_machines │ ║
|
||||
║ │ • dm_customers • dm_orders │ ║
|
||||
║ │ • dm_production_orders • dm_deliveries │ ║
|
||||
║ │ • dm_daily_summary │ ║
|
||||
║ └─────────────────────────────────────────────────────────────────────┘ ║
|
||||
║ ║
|
||||
║ ┌─────────────────────────────────────────────────────────────────────┐ ║
|
||||
║ │ LABELS & WAREHOUSE (2 tables) │ ║
|
||||
║ │ │ ║
|
||||
║ │ • order_for_labels • warehouse_locations │ ║
|
||||
║ └─────────────────────────────────────────────────────────────────────┘ ║
|
||||
║ ║
|
||||
╚═══════════════════════════════════════════════════════════════════════════╝
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. Entity Relationship Diagram (ERD)
|
||||
|
||||
```
|
||||
┌──────────────────────────────────────────────────────────────────────────────────┐
|
||||
│ USER MANAGEMENT HIERARCHY │
|
||||
└──────────────────────────────────────────────────────────────────────────────────┘
|
||||
|
||||
┌─────────────┐ ┌──────────────┐ ┌────────────────┐
|
||||
│ users │─────────│ roles │───────│ role_hierarchy │
|
||||
└─────────────┘ └──────────────┘ └────────────────┘
|
||||
(id) (id) (id)
|
||||
username name (referenced) role_name (PK)
|
||||
password access_level level (100-50)
|
||||
role ←─────────────────────┐ parent_role
|
||||
email │ description
|
||||
modules (JSON) │
|
||||
│
|
||||
└─── hierarchy level
|
||||
(100=superadmin)
|
||||
(90=admin)
|
||||
(70=manager)
|
||||
(50=worker)
|
||||
|
||||
┌────────────────┐ ┌──────────────┐ ┌─────────────────────┐
|
||||
│ permissions │ │ role_ │ │ permission_ │
|
||||
└────────────────┘ │ permissions │ │ audit_log │
|
||||
(id) ◄──────└──────────────┘──────►└─────────────────────┘
|
||||
permission_key (M:M mapping) (audit trail)
|
||||
page role_name ──┐
|
||||
section permission_ │
|
||||
action id │
|
||||
description granted_at │
|
||||
granted_by │
|
||||
│
|
||||
Tracks permission
|
||||
changes for security
|
||||
|
||||
|
||||
┌──────────────────────────────────────────────────────────────────────────────────┐
|
||||
│ BUSINESS INTELLIGENCE / DAILY MIRROR (DM) │
|
||||
└──────────────────────────────────────────────────────────────────────────────────┘
|
||||
|
||||
MASTER DATA (Reference Tables)
|
||||
|
||||
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
|
||||
│ dm_articles │ │ dm_customers │ │ dm_machines │
|
||||
├──────────────┤ ├──────────────┤ ├──────────────┤
|
||||
│ article_code │ │customer_code │ │machine_code │
|
||||
│ description │ │customer_name │ │machine_name │
|
||||
│ product_ │ │customer_group│ │machine_type │
|
||||
│ group │ │country │ │department │
|
||||
│ unit_of_ │ │currency │ │capacity_per_ │
|
||||
│ measure │ │credit_limit │ │ hour │
|
||||
└──────────────┘ └──────────────┘ └──────────────┘
|
||||
△ △ △
|
||||
│ │ │
|
||||
│ │ │
|
||||
┌──────┴──────────────────────┴──────────────────┬──────────┐
|
||||
│ │ │
|
||||
│ TRANSACTIONAL DATA │ │
|
||||
│ │ │
|
||||
│ ┌─────────────────────┐ ┌──────────────────┴────────┐ │
|
||||
│ │ dm_orders │ │ dm_production_orders │ │
|
||||
│ ├─────────────────────┤ ├───────────────────────────┤ │
|
||||
│ │ order_id │ │ production_order (PK) │ │
|
||||
│ │ order_line │ │ production_order_line │ │
|
||||
│ │ customer_code ◄─────┼────│ customer_code ◄──────────┤ │
|
||||
│ │ article_code ◄──────┼────│ article_code ◄────────────┤ │
|
||||
│ │ quantity_requested │ │ machine_code ◄────────────┤ │
|
||||
│ │ delivery_date │ │ quantity_requested │ │
|
||||
│ │ order_status │ │ opening_date │ │
|
||||
│ │ production_order │────│ closing_date │ │
|
||||
│ │ (links to PO) ────┘ │ production_status │ │
|
||||
│ │ production_status │ │ PHASE TRACKING: │ │
|
||||
│ │ created_at │ │ • phase_t1_prepared │ │
|
||||
│ └─────────────────────┘ │ • phase_t2_cut │ │
|
||||
│ │ • phase_t3_sewing │ │
|
||||
│ │ (with operator names & │ │
|
||||
│ │ registration dates) │ │
|
||||
│ │ created_at │ │
|
||||
│ └───────────────────────────┘ │
|
||||
│ │ │
|
||||
│ │ │
|
||||
│ ┌──────────────────┴────────┐ │
|
||||
│ │ │ │
|
||||
│ ┌──────────────────┴──┐ ┌───────────┴────────┐ │
|
||||
│ │ dm_deliveries │ │ QUALITY SCANS │ │
|
||||
│ ├─────────────────────┤ │ │ │
|
||||
│ │ shipment_id │ │ • scan1_orders │ │
|
||||
│ │ order_id ◄──────────┼───────────┤ (T1/Quilting) │ │
|
||||
│ │ customer_code ◄─────┼───────────┤ │ │
|
||||
│ │ article_code ◄──────┼───────────┤ • scanfg_orders │ │
|
||||
│ │ quantity_delivered │ │ (Final Goods) │ │
|
||||
│ │ shipment_date │ │ │ │
|
||||
│ │ delivery_date │ │ COMMON FIELDS: │ │
|
||||
│ │ delivery_status │ │ • operator_code │ │
|
||||
│ │ total_value │ │ • CP_full_code ───┼──┐
|
||||
│ │ created_at │ │ • quality_code │ │
|
||||
│ └─────────────────────┘ │ • approved_qty │ │
|
||||
│ │ • rejected_qty │ │
|
||||
│ │ • date, time │ │
|
||||
│ └───────────────────┘ │
|
||||
│ │
|
||||
│ AGGREGATED KPIs │
|
||||
│ │
|
||||
│ ┌──────────────────────────┐ │
|
||||
│ │ dm_daily_summary │ │
|
||||
│ ├──────────────────────────┤ │
|
||||
│ │ report_date (PK) │ │
|
||||
│ │ orders_received │ │
|
||||
│ │ production_launched │ │
|
||||
│ │ production_finished │ │
|
||||
│ │ t1_scans_total │ │
|
||||
│ │ t1_scans_approved │ │
|
||||
│ │ t1_approval_rate │ │
|
||||
│ │ t2_scans_total │ │
|
||||
│ │ t2_approval_rate │ │
|
||||
│ │ t3_scans_total │ │
|
||||
│ │ t3_approval_rate │ │
|
||||
│ │ orders_shipped │ │
|
||||
│ │ orders_delivered │ │
|
||||
│ │ on_time_deliveries │ │
|
||||
│ │ delivery_value │ │
|
||||
│ │ active_operators │ │
|
||||
│ │ (aggregated daily via │ │
|
||||
│ │ batch process) │ │
|
||||
│ └──────────────────────────┘ │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
|
||||
|
||||
┌──────────────────────────────────────────────────────────────────────────────────┐
|
||||
│ LABELS & WAREHOUSE MANAGEMENT │
|
||||
└──────────────────────────────────────────────────────────────────────────────────┘
|
||||
|
||||
┌──────────────────────┐
|
||||
│ order_for_labels │
|
||||
├──────────────────────┤
|
||||
│ id │
|
||||
│ comanda_productie │──────────────┐
|
||||
│ cod_articol │ │
|
||||
│ descr_com_prod │ │
|
||||
│ cantitate │ │
|
||||
│ com_achiz_client │ │ Links to
|
||||
│ nr_linie_com_client │ │ dm_production_orders
|
||||
│ customer_name │ │ (production_order)
|
||||
│ customer_article_num │ │
|
||||
│ open_for_order │ │
|
||||
│ printed_labels (0/1) │ │
|
||||
│ data_livrare │ │
|
||||
│ dimensiune │ │
|
||||
│ created_at │ │
|
||||
│ updated_at │ │
|
||||
└──────────────────────┘ │
|
||||
│
|
||||
▼
|
||||
┌──────────────────────────┐
|
||||
│ dm_production_orders │
|
||||
│ (production_order field) │
|
||||
└──────────────────────────┘
|
||||
|
||||
┌──────────────────────┐
|
||||
│warehouse_locations │
|
||||
├──────────────────────┤
|
||||
│ id │
|
||||
│ location_code │
|
||||
│ size │
|
||||
│ description │
|
||||
└──────────────────────┘
|
||||
(standalone)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Table Summary by Category
|
||||
|
||||
### 📋 User Management & Access Control (6 tables)
|
||||
|
||||
| Table | Records | Purpose | Key Field |
|
||||
|-------|---------|---------|-----------|
|
||||
| **users** | ~50-100 | User accounts & authentication | `id`, `username` |
|
||||
| **roles** | 4 | Role definitions | `id`, `name` |
|
||||
| **role_hierarchy** | 4 | Hierarchical role structure | `role_name` |
|
||||
| **permissions** | 50-100+ | Granular permission definitions | `id`, `permission_key` |
|
||||
| **role_permissions** | 100-200 | Role→Permission mapping | `role_name`, `permission_id` |
|
||||
| **permission_audit_log** | 1000+ | Permission change audit trail | `id` |
|
||||
|
||||
**Access Levels**:
|
||||
- 100 = superadmin (Full access)
|
||||
- 90 = admin (Administrative)
|
||||
- 70 = manager (Module management)
|
||||
- 50 = worker (Basic operations)
|
||||
|
||||
---
|
||||
|
||||
### 🔍 Quality Management / Production Scanning (2 tables)
|
||||
|
||||
| Table | Records | Purpose | Key Field |
|
||||
|-------|---------|---------|-----------|
|
||||
| **scan1_orders** | 10,000+ | Phase 1 quality scans (T1/Quilting) | `Id` (PK), `CP_full_code` (FK) |
|
||||
| **scanfg_orders** | 5,000+ | Final goods quality scans | `Id` (PK), `CP_full_code` (FK) |
|
||||
|
||||
**Common Fields** (both tables):
|
||||
- `operator_code` - Worker identifier (4 char)
|
||||
- `CP_full_code` - Production order reference
|
||||
- `quality_code` - 0=Rejected, 1=Approved
|
||||
- `date`, `time` - Scan timestamp
|
||||
- `approved_quantity`, `rejected_quantity` - Count
|
||||
|
||||
**Production Phases**:
|
||||
- T1 = Quilting preparation
|
||||
- T2 = Cutting
|
||||
- T3 = Sewing/Assembly
|
||||
|
||||
---
|
||||
|
||||
### 📊 Business Intelligence / Daily Mirror (7 tables)
|
||||
|
||||
#### Master Data Tables (Reference/Lookup)
|
||||
|
||||
| Table | Records | Purpose | Unique Key |
|
||||
|-------|---------|---------|------------|
|
||||
| **dm_articles** | 500-2000 | Product catalog | `article_code` |
|
||||
| **dm_customers** | 100-500 | Customer master data | `customer_code` |
|
||||
| **dm_machines** | 20-50 | Production equipment | `machine_code` |
|
||||
|
||||
#### Transactional Data Tables
|
||||
|
||||
| Table | Records | Purpose | Unique Key |
|
||||
|-------|---------|---------|------------|
|
||||
| **dm_orders** | 5,000+ | Sales orders & line items | `order_line` |
|
||||
| **dm_production_orders** | 3,000+ | Manufacturing orders | `production_order_line` |
|
||||
| **dm_deliveries** | 5,000+ | Shipment & delivery tracking | `shipment_id` |
|
||||
|
||||
#### Aggregated Data Table
|
||||
|
||||
| Table | Records | Purpose | Unique Key |
|
||||
|-------|---------|---------|------------|
|
||||
| **dm_daily_summary** | 365+ | Daily KPI aggregations | `report_date` |
|
||||
|
||||
**Daily Metrics Tracked**:
|
||||
- Orders (received, quantity, value)
|
||||
- Production (launched, finished, in-progress)
|
||||
- Quality (T1/T2/T3 scans & approval rates)
|
||||
- Deliveries (shipped, delivered, late)
|
||||
- Operations (active operators)
|
||||
|
||||
---
|
||||
|
||||
### 🏷️ Labels & Warehouse (2 tables)
|
||||
|
||||
| Table | Records | Purpose | Key Field |
|
||||
|-------|---------|---------|-----------|
|
||||
| **order_for_labels** | 2,000+ | Label printing queue | `id`, `comanda_productie` (FK) |
|
||||
| **warehouse_locations** | 50-200 | Storage location definitions | `location_code` |
|
||||
|
||||
---
|
||||
|
||||
## 4. Data Flow & Relationships
|
||||
|
||||
```
|
||||
USER INTERACTION
|
||||
│
|
||||
▼
|
||||
┌──────────────────┐
|
||||
│ QUALITY SCANS │
|
||||
│ (scan1_orders, │
|
||||
│ scanfg_orders) │
|
||||
└────────┬─────────┘
|
||||
│
|
||||
│ Uses
|
||||
▼
|
||||
┌────────────────────────────────┐
|
||||
│ dm_production_orders (T1 data) │
|
||||
│ │
|
||||
│ Links to: │
|
||||
│ • dm_articles │
|
||||
│ • dm_customers │
|
||||
│ • dm_machines │
|
||||
└────────┬───────────────────────┘
|
||||
│
|
||||
├─────────────────────────────────┐
|
||||
│ │
|
||||
▼ ▼
|
||||
┌─────────────────┐ ┌──────────────────┐
|
||||
│ dm_orders │ │ order_for_labels │
|
||||
│ (sales orders) │ │ (label printing) │
|
||||
└────────┬────────┘ └──────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────┐
|
||||
│ dm_deliveries │
|
||||
│ (shipments) │
|
||||
└─────────────────┘
|
||||
│
|
||||
└─ Aggregates into
|
||||
▼
|
||||
┌──────────────────┐
|
||||
│ dm_daily_summary │
|
||||
│ (KPI Dashboard) │
|
||||
└──────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Key Relationships Matrix
|
||||
|
||||
### Foreign Key References
|
||||
|
||||
```
|
||||
dm_orders
|
||||
├─→ dm_customers.customer_code
|
||||
├─→ dm_articles.article_code
|
||||
└─→ dm_production_orders.production_order
|
||||
|
||||
dm_production_orders
|
||||
├─→ dm_customers.customer_code
|
||||
├─→ dm_articles.article_code
|
||||
└─→ dm_machines.machine_code
|
||||
|
||||
dm_deliveries
|
||||
├─→ dm_orders.order_id
|
||||
├─→ dm_customers.customer_code
|
||||
└─→ dm_articles.article_code
|
||||
|
||||
scan1_orders & scanfg_orders
|
||||
└─→ dm_production_orders.production_order (via CP_full_code)
|
||||
|
||||
order_for_labels
|
||||
└─→ dm_production_orders.production_order (via comanda_productie)
|
||||
|
||||
role_permissions
|
||||
├─→ role_hierarchy.role_name
|
||||
└─→ permissions.id
|
||||
|
||||
users
|
||||
└─→ roles.name (via role field)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. Database Statistics
|
||||
|
||||
### Table Size Estimation
|
||||
|
||||
| Category | Count | Est. Records | Est. Size |
|
||||
|----------|-------|--------------|-----------|
|
||||
| User Management | 6 | ~5,000 | ~50 MB |
|
||||
| Quality Scans | 2 | ~15,000 | ~150 MB |
|
||||
| Daily Mirror (Master) | 3 | ~3,000 | ~30 MB |
|
||||
| Daily Mirror (Transactional) | 3 | ~13,000 | ~350 MB |
|
||||
| Daily Mirror (Aggregated) | 1 | ~365 | ~5 MB |
|
||||
| Labels & Warehouse | 2 | ~2,250 | ~50 MB |
|
||||
| **TOTAL** | **17** | **~38,000+** | **~635 MB** |
|
||||
|
||||
---
|
||||
|
||||
## 7. Critical Indexes
|
||||
|
||||
### Primary Keys (All Tables)
|
||||
- Every table has `id` or equivalent as PRIMARY KEY
|
||||
|
||||
### Unique Constraints
|
||||
```
|
||||
users.username
|
||||
dm_articles.article_code
|
||||
dm_customers.customer_code
|
||||
dm_machines.machine_code
|
||||
dm_orders.order_line
|
||||
dm_production_orders.production_order_line
|
||||
warehouse_locations.location_code
|
||||
permissions.permission_key
|
||||
role_hierarchy.role_name
|
||||
dm_daily_summary.report_date
|
||||
```
|
||||
|
||||
### Foreign Key Indexes
|
||||
```
|
||||
dm_orders
|
||||
├─ customer_code
|
||||
├─ article_code
|
||||
├─ delivery_date
|
||||
└─ order_status
|
||||
|
||||
dm_production_orders
|
||||
├─ customer_code
|
||||
├─ article_code
|
||||
├─ delivery_date
|
||||
└─ production_status
|
||||
|
||||
dm_deliveries
|
||||
├─ order_id
|
||||
├─ customer_code
|
||||
├─ article_code
|
||||
├─ shipment_date
|
||||
├─ delivery_date
|
||||
└─ delivery_status
|
||||
|
||||
dm_articles
|
||||
├─ product_group
|
||||
└─ classification
|
||||
|
||||
dm_customers
|
||||
├─ customer_name
|
||||
└─ customer_group
|
||||
|
||||
dm_machines
|
||||
├─ machine_type
|
||||
└─ department
|
||||
|
||||
role_permissions
|
||||
├─ role_name
|
||||
└─ permission_id
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 8. Data Types Summary
|
||||
|
||||
### Numeric Types
|
||||
- `INT(11)` - IDs, counts, priorities
|
||||
- `BIGINT(20)` - Large IDs (order_for_labels)
|
||||
- `DECIMAL(10,2)` - Prices, measurements
|
||||
- `DECIMAL(15,2)` - Large values, order totals
|
||||
- `TINYINT(1)` - Boolean flags (0/1)
|
||||
|
||||
### String Types
|
||||
- `VARCHAR(4)` - Operator codes
|
||||
- `VARCHAR(15)` - Production codes
|
||||
- `VARCHAR(50)` - Article/customer/machine codes
|
||||
- `VARCHAR(100)` - Names, descriptions
|
||||
- `VARCHAR(255)` - Long fields (email, descriptions)
|
||||
- `TEXT` - Large text (descriptions, JSON arrays)
|
||||
|
||||
### Date/Time Types
|
||||
- `DATE` - Calendar dates
|
||||
- `TIME` - Time-of-day
|
||||
- `TIMESTAMP` - Creation/update timestamps
|
||||
- `DATETIME` - Precise date+time values
|
||||
|
||||
---
|
||||
|
||||
## 9. Application Modules & Table Usage
|
||||
|
||||
```
|
||||
LOGIN PAGE (/)
|
||||
└─→ users
|
||||
|
||||
DASHBOARD (/dashboard)
|
||||
├─→ users
|
||||
├─→ scan1_orders (statistics)
|
||||
├─→ scanfg_orders (statistics)
|
||||
├─→ dm_production_orders (status)
|
||||
└─→ dm_orders (metrics)
|
||||
|
||||
SETTINGS (/settings)
|
||||
├─→ users
|
||||
├─→ roles
|
||||
├─→ role_hierarchy
|
||||
├─→ permissions
|
||||
└─→ role_permissions
|
||||
|
||||
QUALITY SCANNING
|
||||
├─ Quality Scan 1 (/scan1)
|
||||
│ ├─→ scan1_orders (insert/read)
|
||||
│ └─→ dm_production_orders (lookup)
|
||||
│
|
||||
├─ Quality Scan FG (/scanfg)
|
||||
│ ├─→ scanfg_orders (insert/read)
|
||||
│ └─→ dm_production_orders (lookup)
|
||||
│
|
||||
├─ Quality Reports (/reports_for_quality)
|
||||
│ └─→ scan1_orders (analytics)
|
||||
│
|
||||
└─ Quality Reports FG (/reports_for_quality_fg)
|
||||
└─→ scanfg_orders (analytics)
|
||||
|
||||
LABEL PRINTING (/print)
|
||||
├─→ order_for_labels (manage queue)
|
||||
└─→ dm_production_orders (lookup)
|
||||
|
||||
WAREHOUSE (/warehouse)
|
||||
└─→ warehouse_locations (locations)
|
||||
|
||||
DAILY MIRROR / BI (/daily_mirror)
|
||||
├─ Dashboard
|
||||
│ └─→ dm_daily_summary (KPIs)
|
||||
│
|
||||
├─ Articles (/daily_mirror/articles)
|
||||
│ └─→ dm_articles
|
||||
│
|
||||
├─ Customers (/daily_mirror/customers)
|
||||
│ └─→ dm_customers
|
||||
│
|
||||
├─ Machines (/daily_mirror/machines)
|
||||
│ └─→ dm_machines
|
||||
│
|
||||
├─ Orders (/daily_mirror/orders)
|
||||
│ ├─→ dm_orders
|
||||
│ ├─→ dm_customers (lookup)
|
||||
│ └─→ dm_articles (lookup)
|
||||
│
|
||||
├─ Production Orders (/daily_mirror/production_orders)
|
||||
│ ├─→ dm_production_orders
|
||||
│ ├─→ dm_customers (lookup)
|
||||
│ ├─→ dm_articles (lookup)
|
||||
│ └─→ dm_machines (lookup)
|
||||
│
|
||||
└─ Deliveries (/daily_mirror/deliveries)
|
||||
├─→ dm_deliveries
|
||||
├─→ dm_customers (lookup)
|
||||
└─→ dm_articles (lookup)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 10. Data Maintenance & Optimization
|
||||
|
||||
### Performance Optimization
|
||||
1. **Regular Index Analysis**: Monitor slow queries
|
||||
2. **Table Optimization**: `OPTIMIZE TABLE` for tables > 100MB
|
||||
3. **Partition Strategy**: Consider date-based partitioning for scan tables
|
||||
4. **Archiving**: Archive quality scans older than 2 years
|
||||
|
||||
### Backup Strategy
|
||||
- **Daily automated backups** → `/srv/quality_app/backups/`
|
||||
- **Retention**: 30 days (configurable)
|
||||
- **Backup types**: Full + data-only incremental backups
|
||||
|
||||
### Data Cleanup Recommendations
|
||||
```
|
||||
scan1_orders, scanfg_orders
|
||||
└─→ Archive data older than 2 years
|
||||
|
||||
permission_audit_log
|
||||
└─→ Archive quarterly
|
||||
|
||||
dm_daily_summary
|
||||
└─→ Keep all historical data
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 11. Production Phases Tracking
|
||||
|
||||
The system tracks three phases of production:
|
||||
|
||||
### Phase T1: Quilting Preparation
|
||||
- Table: `scan1_orders`
|
||||
- Fields in `dm_production_orders`:
|
||||
- `phase_t1_prepared` (status)
|
||||
- `t1_operator_name` (who performed)
|
||||
- `t1_registration_date` (when scanned)
|
||||
- `end_of_quilting` (completion date)
|
||||
|
||||
### Phase T2: Cutting
|
||||
- Fields in `dm_production_orders`:
|
||||
- `phase_t2_cut` (status)
|
||||
- `t2_operator_name`
|
||||
- `t2_registration_date`
|
||||
|
||||
### Phase T3: Sewing/Assembly
|
||||
- Fields in `dm_production_orders`:
|
||||
- `phase_t3_sewing` (status)
|
||||
- `t3_operator_name`
|
||||
- `t3_registration_date`
|
||||
- `end_of_sewing` (completion date)
|
||||
|
||||
### Final Goods (FG) Quality
|
||||
- Table: `scanfg_orders`
|
||||
- After all phases complete
|
||||
|
||||
---
|
||||
|
||||
## 12. Key Metrics & KPIs
|
||||
|
||||
Tracked in `dm_daily_summary`:
|
||||
|
||||
```
|
||||
PRODUCTION METRICS
|
||||
├─ Orders Received
|
||||
├─ Production Launched
|
||||
├─ Production Finished
|
||||
├─ Production In-Progress
|
||||
└─ Active Operators
|
||||
|
||||
QUALITY METRICS (by phase)
|
||||
├─ T1 (Quilting)
|
||||
│ ├─ Total Scans
|
||||
│ ├─ Approved Count
|
||||
│ └─ Approval Rate (%)
|
||||
│
|
||||
├─ T2 (Cutting)
|
||||
│ ├─ Total Scans
|
||||
│ ├─ Approved Count
|
||||
│ └─ Approval Rate (%)
|
||||
│
|
||||
└─ T3 (Sewing)
|
||||
├─ Total Scans
|
||||
├─ Approved Count
|
||||
└─ Approval Rate (%)
|
||||
|
||||
DELIVERY METRICS
|
||||
├─ Orders Shipped
|
||||
├─ Orders Delivered
|
||||
├─ Orders Returned
|
||||
├─ On-Time Deliveries
|
||||
├─ Late Deliveries
|
||||
└─ Delivery Value
|
||||
|
||||
ORDER METRICS
|
||||
├─ Orders Quantity
|
||||
├─ Orders Value
|
||||
├─ Unique Customers
|
||||
└─ Quilting Completed
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 13. Future Enhancements
|
||||
|
||||
### Planned Tables
|
||||
1. **production_schedule** - Production planning calendar
|
||||
2. **quality_issues** - Defect tracking & analysis
|
||||
3. **inventory_movements** - Stock tracking
|
||||
4. **operator_performance** - Worker productivity
|
||||
|
||||
### Planned Improvements
|
||||
- Composite indexes for frequent joins
|
||||
- Table partitioning by date (scan tables)
|
||||
- Materialized views for complex reports
|
||||
- Full-text search indexes
|
||||
|
||||
---
|
||||
|
||||
## Database Health Check Query
|
||||
|
||||
```sql
|
||||
-- View database size
|
||||
SELECT
|
||||
table_name,
|
||||
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS 'Size (MB)'
|
||||
FROM information_schema.TABLES
|
||||
WHERE table_schema = 'trasabilitate'
|
||||
ORDER BY (data_length + index_length) DESC;
|
||||
|
||||
-- Check row counts
|
||||
SELECT
|
||||
table_name,
|
||||
table_rows
|
||||
FROM information_schema.TABLES
|
||||
WHERE table_schema = 'trasabilitate'
|
||||
ORDER BY table_rows DESC;
|
||||
|
||||
-- List all indexes
|
||||
SELECT
|
||||
table_name,
|
||||
index_name,
|
||||
seq_in_index,
|
||||
column_name
|
||||
FROM information_schema.STATISTICS
|
||||
WHERE table_schema = 'trasabilitate'
|
||||
ORDER BY table_name, index_name, seq_in_index;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**Last Updated**: January 10, 2026
|
||||
**Database Version**: MariaDB 11.8.3
|
||||
**Total Tables**: 17
|
||||
**Total Estimated Records**: 38,000+
|
||||
**Total Estimated Size**: ~635 MB
|
||||
Reference in New Issue
Block a user