# Database Structure Documentation ## Overview This document provides a comprehensive overview of the **trasabilitate** database structure, including all tables, their fields, purposes, and which application pages/modules use them. **Database**: `trasabilitate` **Type**: MariaDB 11.8.3 **Character Set**: utf8mb4 **Collation**: utf8mb4_uca1400_ai_ci ## Table Categories ### 1. User Management & Access Control - [users](#users) - User accounts and authentication - [roles](#roles) - User role definitions - [role_hierarchy](#role_hierarchy) - Role levels and inheritance - [permissions](#permissions) - Granular permission definitions - [role_permissions](#role_permissions) - Permission assignments to roles - [permission_audit_log](#permission_audit_log) - Audit trail for permission changes ### 2. Quality Management (Production Scanning) - [scan1_orders](#scan1_orders) - Phase 1 quality scans (quilting preparation) - [scanfg_orders](#scanfg_orders) - Final goods quality scans ### 3. Daily Mirror (Business Intelligence) - [dm_articles](#dm_articles) - Product catalog - [dm_customers](#dm_customers) - Customer master data - [dm_machines](#dm_machines) - Production equipment - [dm_orders](#dm_orders) - Sales orders - [dm_production_orders](#dm_production_orders) - Manufacturing orders - [dm_deliveries](#dm_deliveries) - Shipment tracking - [dm_daily_summary](#dm_daily_summary) - Daily KPI aggregations ### 4. Labels & Warehouse - [order_for_labels](#order_for_labels) - Label printing queue - [warehouse_locations](#warehouse_locations) - Storage location master --- ## Detailed Table Descriptions ### users **Purpose**: Stores user accounts, credentials, and access permissions **Structure**: | Field | Type | Null | Key | Description | |----------|--------------|------|-----|-------------| | id | int(11) | NO | PRI | Unique user ID | | username | varchar(50) | NO | UNI | Login username | | password | varchar(255) | NO | | Password (hashed) | | role | varchar(50) | NO | | User role (superadmin, admin, manager, worker) | | email | varchar(255) | YES | | Email address | | modules | text | YES | | Accessible modules (JSON array) | **Access Levels**: - **superadmin** (Level 100): Full system access - **admin** (Level 90): Administrative access - **manager** (Level 70): Module management - **worker** (Level 50): Basic operations **Used By**: - **Pages**: Login (`/`), Dashboard (`/dashboard`), Settings (`/settings`) - **Routes**: `login()`, `dashboard()`, `get_users()`, `create_user()`, `edit_user()`, `delete_user()` - **Access Control**: All pages via `@login_required`, role checks **Relationships**: - **role** references **roles.name** - **modules** contains JSON array of accessible modules --- ### roles **Purpose**: Defines available user roles and their access levels **Structure**: | Field | Type | Null | Key | Description | |--------------|--------------|------|-----|-------------| | id | int(11) | NO | PRI | Unique role ID | | name | varchar(100) | NO | UNI | Role name | | access_level | varchar(50) | NO | | Access level description | | description | text | YES | | Role description | | created_at | timestamp | YES | | Creation timestamp | **Default Roles**: 1. **superadmin**: Full system access, all permissions 2. **admin**: Can manage users and settings 3. **manager**: Can oversee production and quality 4. **worker**: Can perform scans and basic operations **Used By**: - **Pages**: Settings (`/settings`) - **Routes**: Role management, user creation --- ### role_hierarchy **Purpose**: Defines hierarchical role structure with levels and inheritance **Structure**: | Field | Type | Null | Key | Description | |-------------------|--------------|------|-----|-------------| | id | int(11) | NO | PRI | Unique ID | | role_name | varchar(100) | NO | UNI | Role identifier | | role_display_name | varchar(255) | NO | | Display name | | level | int(11) | NO | | Hierarchy level (100=highest) | | parent_role | varchar(100) | YES | | Parent role in hierarchy | | description | text | YES | | Role description | | is_active | tinyint(1) | YES | | Active status | | created_at | timestamp | YES | | Creation timestamp | **Hierarchy Levels**: - **100**: superadmin (root) - **90**: admin - **70**: manager - **50**: worker **Used By**: - **Pages**: Settings (`/settings`), Role Management - **Routes**: Permission management, role assignment --- ### permissions **Purpose**: Defines granular permissions for pages, sections, and actions **Structure**: | Field | Type | Null | Key | Description | |----------------|--------------|------|-----|-------------| | id | int(11) | NO | PRI | Unique permission ID | | permission_key | varchar(255) | NO | UNI | Unique key (page.section.action) | | page | varchar(100) | NO | | Page identifier | | page_name | varchar(255) | NO | | Display page name | | section | varchar(100) | NO | | Section identifier | | section_name | varchar(255) | NO | | Display section name | | action | varchar(50) | NO | | Action (view, create, edit, delete) | | action_name | varchar(255) | NO | | Display action name | | description | text | YES | | Permission description | | created_at | timestamp | YES | | Creation timestamp | **Permission Structure**: `page.section.action` - Example: `quality.scan1.view`, `daily_mirror.orders.edit` **Used By**: - **Pages**: Settings (`/settings`), Permission Management - **Routes**: Permission checks via decorators --- ### role_permissions **Purpose**: Maps permissions to roles (many-to-many relationship) **Structure**: | Field | Type | Null | Key | Description | |---------------|--------------|------|-----|-------------| | id | int(11) | NO | PRI | Unique mapping ID | | role_name | varchar(100) | NO | MUL | Role identifier | | permission_id | int(11) | NO | MUL | Permission ID | | granted_at | timestamp | YES | | Grant timestamp | | granted_by | varchar(100) | YES | | User who granted | **Used By**: - **Pages**: Settings (`/settings`), Permission Management - **Routes**: `check_permission()`, permission decorators - **Access Control**: All protected pages --- ### permission_audit_log **Purpose**: Tracks all permission changes for security auditing **Structure**: | Field | Type | Null | Key | Description | |----------------|--------------|------|-----|-------------| | id | int(11) | NO | PRI | Unique log ID | | action | varchar(50) | NO | | Action (grant, revoke, modify) | | role_name | varchar(100) | YES | | Affected role | | permission_key | varchar(255) | YES | | Affected permission | | user_id | varchar(100) | YES | | User who performed action | | timestamp | timestamp | YES | | Action timestamp | | details | text | YES | | Additional details (JSON) | | ip_address | varchar(45) | YES | | IP address of user | **Used By**: - **Pages**: Audit logs (future feature) - **Routes**: Automatically logged by permission management functions --- ### scan1_orders **Purpose**: Stores Phase 1 (T1) quality scan data for quilting preparation **Structure**: | Field | Type | Null | Key | Description | |-------------------|-------------|------|-----|-------------| | Id | int(11) | NO | PRI | Unique scan ID | | operator_code | varchar(4) | NO | | Worker identifier | | CP_full_code | varchar(15) | NO | | Full production order code | | OC1_code | varchar(4) | NO | | Customer order code 1 | | OC2_code | varchar(4) | NO | | Customer order code 2 | | CP_base_code | varchar(10) | YES | | Base production code (generated) | | quality_code | int(3) | NO | | Quality check result | | date | date | NO | | Scan date | | time | time | NO | | Scan time | | approved_quantity | int(11) | YES | | Approved items | | rejected_quantity | int(11) | YES | | Rejected items | **Quality Codes**: - **0**: Rejected - **1**: Approved **Used By**: - **Pages**: - Quality Scan 1 (`/scan1`) - Quality Reports (`/reports_for_quality`) - Daily Reports (`/daily_scan`) - Production Scan 1 (`/productie_scan_1`) - **Routes**: `scan1()`, `insert_scan1()`, `reports_for_quality()`, `daily_scan()`, `productie_scan_1()` - **Dashboard**: Phase 1 statistics widget **Related Tables**: - Linked to **dm_production_orders** via **CP_full_code** --- ### scanfg_orders **Purpose**: Stores final goods (FG) quality scan data **Structure**: | Field | Type | Null | Key | Description | |-------------------|-------------|------|-----|-------------| | Id | int(11) | NO | PRI | Unique scan ID | | operator_code | varchar(4) | NO | | Worker identifier | | CP_full_code | varchar(15) | NO | | Full production order code | | OC1_code | varchar(4) | NO | | Customer order code 1 | | OC2_code | varchar(4) | NO | | Customer order code 2 | | CP_base_code | varchar(10) | YES | | Base production code (generated) | | quality_code | int(3) | NO | | Quality check result | | date | date | NO | | Scan date | | time | time | NO | | Scan time | | approved_quantity | int(11) | YES | | Approved items | | rejected_quantity | int(11) | YES | | Rejected items | **Used By**: - **Pages**: - Quality Scan FG (`/scanfg`) - Quality Reports FG (`/reports_for_quality_fg`) - Daily Scan FG (`/daily_scan_fg`) - Production Scan FG (`/productie_scan_fg`) - **Routes**: `scanfg()`, `insert_scanfg()`, `reports_for_quality_fg()`, `daily_scan_fg()`, `productie_scan_fg()` - **Dashboard**: Final goods statistics widget **Related Tables**: - Linked to **dm_production_orders** via **CP_full_code** --- ### order_for_labels **Purpose**: Manages label printing queue for production orders **Structure**: | Field | Type | Null | Key | Description | |-------------------------|-------------|------|-----|-------------| | id | bigint(20) | NO | PRI | Unique ID | | comanda_productie | varchar(15) | NO | | Production order | | cod_articol | varchar(15) | YES | | Article code | | descr_com_prod | varchar(50) | NO | | Description | | cantitate | int(3) | NO | | Quantity | | com_achiz_client | varchar(25) | YES | | Customer order | | nr_linie_com_client | int(3) | YES | | Order line number | | customer_name | varchar(50) | YES | | Customer name | | customer_article_number | varchar(25) | YES | | Customer article # | | open_for_order | varchar(25) | YES | | Open order reference | | line_number | int(3) | YES | | Line number | | created_at | timestamp | YES | | Creation timestamp | | updated_at | timestamp | YES | | Update timestamp | | printed_labels | int(1) | YES | | Print status (0/1) | | data_livrare | date | YES | | Delivery date | | dimensiune | varchar(20) | YES | | Dimensions | **Print Status**: - **0**: Not printed - **1**: Printed **Used By**: - **Pages**: - Label Printing (`/print`) - Print All Labels (`/print_all`) - **Routes**: `print_module()`, `print_all()`, `get_available_labels()` - **Module**: Labels Module **Related Tables**: - **comanda_productie** references **dm_production_orders.production_order** --- ### warehouse_locations **Purpose**: Stores warehouse storage location definitions **Structure**: | Field | Type | Null | Key | Description | |---------------|--------------|------|-----|-------------| | id | bigint(20) | NO | PRI | Unique location ID | | location_code | varchar(12) | NO | UNI | Location identifier | | size | int(11) | YES | | Storage capacity | | description | varchar(250) | YES | | Location description | **Used By**: - **Pages**: Warehouse Management (`/warehouse`) - **Module**: Warehouse Module - **Routes**: Warehouse location management --- ### dm_articles **Purpose**: Product catalog and article master data **Structure**: | Field | Type | Null | Key | Description | |---------------------|---------------|------|-----|-------------| | id | int(11) | NO | PRI | Unique article ID | | article_code | varchar(50) | NO | UNI | Article code | | article_description | text | NO | | Full description | | product_group | varchar(100) | YES | MUL | Product group | | classification | varchar(100) | YES | MUL | Classification | | unit_of_measure | varchar(20) | YES | | Unit (PC, KG, M) | | standard_price | decimal(10,2) | YES | | Standard price | | standard_time | decimal(8,2) | YES | | Production time | | active | tinyint(1) | YES | | Active status | | created_at | timestamp | YES | | Creation timestamp | | updated_at | timestamp | YES | | Update timestamp | **Used By**: - **Pages**: Daily Mirror - Articles (`/daily_mirror/articles`) - **Module**: Daily Mirror BI Module - **Routes**: Article management, reporting - **Dashboard**: Product statistics **Related Tables**: - Referenced by **dm_orders**, **dm_production_orders**, **dm_deliveries** --- ### dm_customers **Purpose**: Customer master data and relationship management **Structure**: | Field | Type | Null | Key | Description | |----------------|---------------|------|-----|-------------| | id | int(11) | NO | PRI | Unique customer ID | | customer_code | varchar(50) | NO | UNI | Customer code | | customer_name | varchar(255) | NO | MUL | Customer name | | customer_group | varchar(100) | YES | MUL | Customer group | | country | varchar(50) | YES | | Country | | currency | varchar(3) | YES | | Currency (RON, EUR) | | payment_terms | varchar(100) | YES | | Payment terms | | credit_limit | decimal(15,2) | YES | | Credit limit | | active | tinyint(1) | YES | | Active status | | created_at | timestamp | YES | | Creation timestamp | | updated_at | timestamp | YES | | Update timestamp | **Used By**: - **Pages**: Daily Mirror - Customers (`/daily_mirror/customers`) - **Module**: Daily Mirror BI Module - **Routes**: Customer management, reporting - **Dashboard**: Customer statistics **Related Tables**: - Referenced by **dm_orders**, **dm_production_orders**, **dm_deliveries** --- ### dm_machines **Purpose**: Production equipment and machine master data **Structure**: | Field | Type | Null | Key | Description | |-------------------|--------------|------|-----|-------------| | id | int(11) | NO | PRI | Unique machine ID | | machine_code | varchar(50) | NO | UNI | Machine code | | machine_name | varchar(255) | YES | | Machine name | | machine_type | varchar(50) | YES | MUL | Type (Quilting, Sewing) | | machine_number | varchar(20) | YES | | Machine number | | department | varchar(100) | YES | MUL | Department | | capacity_per_hour | decimal(8,2) | YES | | Hourly capacity | | active | tinyint(1) | YES | | Active status | | created_at | timestamp | YES | | Creation timestamp | | updated_at | timestamp | YES | | Update timestamp | **Machine Types**: - **Quilting**: Quilting machines - **Sewing**: Sewing machines - **Cutting**: Cutting equipment **Used By**: - **Pages**: Daily Mirror - Machines (`/daily_mirror/machines`) - **Module**: Daily Mirror BI Module - **Routes**: Machine management, production planning **Related Tables**: - Referenced by **dm_production_orders** --- ### dm_orders **Purpose**: Sales orders and order line management **Structure**: | Field | Type | Null | Key | Description | |---------------------|--------------|------|-----|-------------| | id | int(11) | NO | PRI | Unique ID | | order_id | varchar(50) | NO | MUL | Order number | | order_line | varchar(120) | NO | UNI | Unique order line | | line_number | varchar(20) | YES | | Line number | | client_order_line | varchar(100) | YES | | Customer line ref | | customer_code | varchar(50) | YES | MUL | Customer code | | customer_name | varchar(255) | YES | | Customer name | | article_code | varchar(50) | YES | MUL | Article code | | article_description | text | YES | | Article description | | quantity_requested | int(11) | YES | | Ordered quantity | | balance | int(11) | YES | | Remaining quantity | | unit_of_measure | varchar(20) | YES | | Unit | | delivery_date | date | YES | MUL | Delivery date | | order_date | date | YES | | Order date | | order_status | varchar(50) | YES | MUL | Order status | | article_status | varchar(50) | YES | | Article status | | priority | varchar(20) | YES | | Priority level | | product_group | varchar(100) | YES | | Product group | | production_order | varchar(50) | YES | | Linked prod order | | production_status | varchar(50) | YES | | Production status | | model | varchar(100) | YES | | Model/design | | closed | varchar(10) | YES | | Closed status | | created_at | timestamp | YES | | Creation timestamp | | updated_at | timestamp | YES | | Update timestamp | **Order Status Values**: - **Open**: Active order - **In Production**: Manufacturing started - **Completed**: Finished - **Shipped**: Delivered **Used By**: - **Pages**: Daily Mirror - Orders (`/daily_mirror/orders`) - **Module**: Daily Mirror BI Module - **Routes**: Order management, reporting, dashboard - **Dashboard**: Order statistics and KPIs **Related Tables**: - **customer_code** references **dm_customers.customer_code** - **article_code** references **dm_articles.article_code** - **production_order** references **dm_production_orders.production_order** --- ### dm_production_orders **Purpose**: Manufacturing orders and production tracking **Structure**: | Field | Type | Null | Key | Description | |-----------------------|---------------|------|-----|-------------| | id | int(11) | NO | PRI | Unique ID | | production_order | varchar(50) | NO | MUL | Production order # | | production_order_line | varchar(120) | NO | UNI | Unique line | | line_number | varchar(20) | YES | | Line number | | open_for_order_line | varchar(100) | YES | | Sales order line | | client_order_line | varchar(100) | YES | | Customer line ref | | customer_code | varchar(50) | YES | MUL | Customer code | | customer_name | varchar(200) | YES | | Customer name | | article_code | varchar(50) | YES | MUL | Article code | | article_description | varchar(255) | YES | | Description | | quantity_requested | int(11) | YES | | Quantity to produce | | unit_of_measure | varchar(20) | YES | | Unit | | delivery_date | date | YES | MUL | Delivery date | | opening_date | date | YES | | Start date | | closing_date | date | YES | | Completion date | | data_planificare | date | YES | | Planning date | | production_status | varchar(50) | YES | MUL | Status | | machine_code | varchar(50) | YES | | Assigned machine | | machine_type | varchar(50) | YES | | Machine type | | machine_number | varchar(50) | YES | | Machine number | | end_of_quilting | date | YES | | Quilting end date | | end_of_sewing | date | YES | | Sewing end date | | phase_t1_prepared | varchar(50) | YES | | T1 phase status | | t1_operator_name | varchar(100) | YES | | T1 operator | | t1_registration_date | datetime | YES | | T1 scan date | | phase_t2_cut | varchar(50) | YES | | T2 phase status | | t2_operator_name | varchar(100) | YES | | T2 operator | | t2_registration_date | datetime | YES | | T2 scan date | | phase_t3_sewing | varchar(50) | YES | | T3 phase status | | t3_operator_name | varchar(100) | YES | | T3 operator | | t3_registration_date | datetime | YES | | T3 scan date | | design_number | int(11) | YES | | Design reference | | classification | varchar(50) | YES | | Classification | | model_description | varchar(255) | YES | | Model description | | model_lb2 | varchar(100) | YES | | LB2 model | | needle_position | decimal(10,2) | YES | | Needle position | | needle_row | varchar(50) | YES | | Needle row | | priority | int(11) | YES | | Priority (0-10) | | created_at | timestamp | YES | | Creation timestamp | | updated_at | timestamp | YES | | Update timestamp | **Production Status Values**: - **Planned**: Scheduled - **In Progress**: Manufacturing - **T1 Complete**: Phase 1 done - **T2 Complete**: Phase 2 done - **T3 Complete**: Phase 3 done - **Finished**: Completed **Production Phases**: - **T1**: Quilting preparation - **T2**: Cutting - **T3**: Sewing/Assembly **Used By**: - **Pages**: - Daily Mirror - Production Orders (`/daily_mirror/production_orders`) - Quality Scan pages (linked via production_order) - Label printing (comanda_productie) - **Module**: Daily Mirror BI Module - **Routes**: Production management, quality scans, reporting - **Dashboard**: Production statistics and phase tracking **Related Tables**: - **customer_code** references **dm_customers.customer_code** - **article_code** references **dm_articles.article_code** - **machine_code** references **dm_machines.machine_code** - Referenced by **scan1_orders**, **scanfg_orders**, **order_for_labels** --- ### dm_deliveries **Purpose**: Shipment and delivery tracking **Structure**: | Field | Type | Null | Key | Description | |---------------------|---------------|------|-----|-------------| | id | int(11) | NO | PRI | Unique ID | | shipment_id | varchar(50) | NO | | Shipment number | | order_id | varchar(50) | YES | MUL | Order reference | | client_order_line | varchar(100) | YES | | Customer line ref | | customer_code | varchar(50) | YES | MUL | Customer code | | customer_name | varchar(255) | YES | | Customer name | | article_code | varchar(50) | YES | MUL | Article code | | article_description | text | YES | | Description | | quantity_delivered | int(11) | YES | | Delivered quantity | | shipment_date | date | YES | MUL | Shipment date | | delivery_date | date | YES | MUL | Delivery date | | delivery_status | varchar(50) | YES | MUL | Status | | total_value | decimal(12,2) | YES | | Shipment value | | created_at | timestamp | YES | | Creation timestamp | | updated_at | timestamp | YES | | Update timestamp | **Delivery Status Values**: - **Pending**: Awaiting shipment - **Shipped**: In transit - **Delivered**: Completed - **Returned**: Returned by customer **Used By**: - **Pages**: Daily Mirror - Deliveries (`/daily_mirror/deliveries`) - **Module**: Daily Mirror BI Module - **Routes**: Delivery tracking, reporting - **Dashboard**: Delivery statistics **Related Tables**: - **order_id** references **dm_orders.order_id** - **customer_code** references **dm_customers.customer_code** - **article_code** references **dm_articles.article_code** --- ### dm_daily_summary **Purpose**: Daily aggregated KPIs and performance metrics **Structure**: | Field | Type | Null | Key | Description | |------------------------|---------------|------|-----|-------------| | id | int(11) | NO | PRI | Unique ID | | report_date | date | NO | UNI | Summary date | | orders_received | int(11) | YES | | New orders | | orders_quantity | int(11) | YES | | Total quantity | | orders_value | decimal(15,2) | YES | | Total value | | unique_customers | int(11) | YES | | Customer count | | production_launched | int(11) | YES | | Started orders | | production_finished | int(11) | YES | | Completed orders | | production_in_progress | int(11) | YES | | Active orders | | quilting_completed | int(11) | YES | | Quilting done | | sewing_completed | int(11) | YES | | Sewing done | | t1_scans_total | int(11) | YES | | T1 total scans | | t1_scans_approved | int(11) | YES | | T1 approved | | t1_approval_rate | decimal(5,2) | YES | | T1 rate (%) | | t2_scans_total | int(11) | YES | | T2 total scans | | t2_scans_approved | int(11) | YES | | T2 approved | | t2_approval_rate | decimal(5,2) | YES | | T2 rate (%) | | t3_scans_total | int(11) | YES | | T3 total scans | | t3_scans_approved | int(11) | YES | | T3 approved | | t3_approval_rate | decimal(5,2) | YES | | T3 rate (%) | | orders_shipped | int(11) | YES | | Shipped orders | | orders_delivered | int(11) | YES | | Delivered orders | | orders_returned | int(11) | YES | | Returns | | delivery_value | decimal(15,2) | YES | | Delivery value | | on_time_deliveries | int(11) | YES | | On-time count | | late_deliveries | int(11) | YES | | Late count | | active_operators | int(11) | YES | | Active workers | | created_at | timestamp | YES | | Creation timestamp | | updated_at | timestamp | YES | | Update timestamp | **Calculation**: Automatically updated daily via batch process **Used By**: - **Pages**: Daily Mirror - Dashboard (`/daily_mirror`) - **Module**: Daily Mirror BI Module - **Routes**: Daily reporting, KPI dashboard - **Dashboard**: Main KPI widgets **Data Source**: Aggregated from all other tables --- ## Table Relationships ### Entity Relationship Diagram (Text) ``` users ├── role → roles.name └── modules (JSON array) roles └── Used by: users, role_hierarchy role_hierarchy ├── role_name → roles.name └── parent_role → role_hierarchy.role_name permissions └── Used by: role_permissions role_permissions ├── role_name → role_hierarchy.role_name └── permission_id → permissions.id dm_articles ├── Used by: dm_orders.article_code ├── Used by: dm_production_orders.article_code └── Used by: dm_deliveries.article_code dm_customers ├── Used by: dm_orders.customer_code ├── Used by: dm_production_orders.customer_code └── Used by: dm_deliveries.customer_code dm_machines └── Used by: dm_production_orders.machine_code dm_orders ├── customer_code → dm_customers.customer_code ├── article_code → dm_articles.article_code └── production_order → dm_production_orders.production_order dm_production_orders ├── customer_code → dm_customers.customer_code ├── article_code → dm_articles.article_code ├── machine_code → dm_machines.machine_code ├── Used by: scan1_orders.CP_full_code ├── Used by: scanfg_orders.CP_full_code └── Used by: order_for_labels.comanda_productie dm_deliveries ├── order_id → dm_orders.order_id ├── customer_code → dm_customers.customer_code └── article_code → dm_articles.article_code scan1_orders └── CP_full_code → dm_production_orders.production_order scanfg_orders └── CP_full_code → dm_production_orders.production_order order_for_labels └── comanda_productie → dm_production_orders.production_order dm_daily_summary └── Aggregated from: all other tables ``` --- ## Pages and Table Usage Matrix | Page/Module | Tables Used | |-------------|-------------| | **Login** (`/`) | users | | **Dashboard** (`/dashboard`) | users, scan1_orders, scanfg_orders, dm_production_orders, dm_orders | | **Settings** (`/settings`) | users, roles, role_hierarchy, permissions, role_permissions | | **Quality Scan 1** (`/scan1`) | scan1_orders, dm_production_orders | | **Quality Scan FG** (`/scanfg`) | scanfg_orders, dm_production_orders | | **Quality Reports** (`/reports_for_quality`) | scan1_orders | | **Quality Reports FG** (`/reports_for_quality_fg`) | scanfg_orders | | **Label Printing** (`/print`) | order_for_labels, dm_production_orders | | **Warehouse** (`/warehouse`) | warehouse_locations | | **Daily Mirror** (`/daily_mirror`) | dm_daily_summary, dm_orders, dm_production_orders, dm_customers | | **DM - Articles** | dm_articles | | **DM - Customers** | dm_customers | | **DM - Machines** | dm_machines | | **DM - Orders** | dm_orders, dm_customers, dm_articles | | **DM - Production** | dm_production_orders, dm_customers, dm_articles, dm_machines | | **DM - Deliveries** | dm_deliveries, dm_customers, dm_articles | --- ## Indexes and Performance ### Primary Indexes - All tables have **PRIMARY KEY** on `id` field ### Unique Indexes - **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 --- ## Database Maintenance ### Backup Strategy - **Manual Backups**: Via Settings page → Database Backup Management - **Automatic Backups**: Scheduled daily backups (configurable) - **Backup Location**: `/srv/quality_app/backups/` - **Retention**: 30 days (configurable) See: [DATABASE_BACKUP_GUIDE.md](DATABASE_BACKUP_GUIDE.md) ### Data Cleanup - **scan1_orders, scanfg_orders**: Consider archiving data older than 2 years - **permission_audit_log**: Archive quarterly - **dm_daily_summary**: Keep all historical data ### Performance Optimization 1. Regularly analyze slow queries 2. Keep indexes updated: `OPTIMIZE TABLE table_name` 3. Monitor table sizes: `SELECT table_name, ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)" FROM information_schema.TABLES WHERE table_schema = "trasabilitate"` --- ## Future Enhancements ### Planned Tables - **production_schedule**: Production planning calendar - **quality_issues**: Defect tracking and analysis - **inventory_movements**: Stock movement tracking - **operator_performance**: Worker productivity metrics ### Planned Improvements - Add more composite indexes for frequently joined tables - Implement table partitioning for scan tables (by date) - Create materialized views for complex reports - Add full-text search indexes for descriptions --- ## Related Documentation - [PRODUCTION_STARTUP_GUIDE.md](PRODUCTION_STARTUP_GUIDE.md) - Application management - [DATABASE_BACKUP_GUIDE.md](DATABASE_BACKUP_GUIDE.md) - Backup procedures - [DATABASE_RESTORE_GUIDE.md](DATABASE_RESTORE_GUIDE.md) - Restore and migration - [DOCKER_DEPLOYMENT.md](../old%20code/DOCKER_DEPLOYMENT.md) - Deployment guide --- **Last Updated**: November 3, 2025 **Database Version**: MariaDB 11.8.3 **Application Version**: 1.0.0 **Total Tables**: 17