Files
quality_recticel/DATABASE_SETUP_README.md
Quality System Admin d264bcdca9 feat: Major system improvements and production deployment
 New Features:
- Added view_orders route with proper table display
- Implemented CSV upload with preview workflow and date parsing
- Added production WSGI server configuration with Gunicorn
- Created comprehensive production management scripts

🔧 Bug Fixes:
- Fixed upload_data route column mapping for actual CSV structure
- Resolved print module database queries and template rendering
- Fixed view orders navigation routing (was pointing to JSON API)
- Corrected barcode display width constraints in print module
- Added proper date format parsing for MySQL compatibility

🎨 UI/UX Improvements:
- Updated view_orders template with theme-compliant styling
- Hidden barcode text in print module preview for cleaner display
- Enhanced CSV upload with two-step preview-then-save workflow
- Improved error handling and debugging throughout upload process

🚀 Production Infrastructure:
- Added Gunicorn WSGI server with proper configuration
- Created systemd service for production deployment
- Implemented production management scripts (start/stop/status)
- Added comprehensive logging setup
- Updated requirements.txt with production dependencies

📊 Database & Data:
- Enhanced order_for_labels table compatibility
- Fixed column mappings for real CSV data structure
- Added proper date parsing and validation
- Improved error handling with detailed debugging

🔧 Technical Debt:
- Reorganized database setup documentation
- Added proper error handling throughout upload workflow
- Enhanced debugging capabilities for troubleshooting
- Improved code organization and documentation
2025-10-11 23:31:32 +03:00

4.1 KiB

Quick Database Setup for Trasabilitate Application

This script provides a complete one-step database setup for quick deployment of the Trasabilitate application.

Prerequisites

Before running the setup script, ensure:

  1. MariaDB is installed and running
  2. Database and user are created:
    CREATE DATABASE trasabilitate;
    CREATE USER 'trasabilitate'@'localhost' IDENTIFIED BY 'Initial01!';
    GRANT ALL PRIVILEGES ON trasabilitate.* TO 'trasabilitate'@'localhost';
    FLUSH PRIVILEGES;
    
  3. Python virtual environment is activated:
    source ../recticel/bin/activate
    
  4. Python dependencies are installed:
    pip install -r requirements.txt
    

Usage

cd /srv/quality_recticel/py_app
source ../recticel/bin/activate
python3 app/db_create_scripts/setup_complete_database.py

What the script creates:

MariaDB Tables:

  • scan1_orders - Quality scanning data for process 1
  • scanfg_orders - Quality scanning data for finished goods
  • order_for_labels - Label printing orders
  • warehouse_locations - Warehouse location management
  • permissions - System permissions
  • role_permissions - Role-permission mappings
  • role_hierarchy - User role hierarchy
  • permission_audit_log - Permission change audit trail

Database Triggers:

  • Auto-increment approved/rejected quantities based on quality codes
  • Triggers for both scan1_orders and scanfg_orders tables

SQLite Tables:

  • users - User authentication (in instance/users.db)
  • roles - User roles (in instance/users.db)

Configuration:

  • Updates instance/external_server.conf with correct database settings
  • Creates default superadmin user (username: superadmin, password: superadmin123)

Permission System:

  • 7 user roles (superadmin, admin, manager, quality_manager, warehouse_manager, quality_worker, warehouse_worker)
  • 25+ granular permissions for different application areas
  • Complete role hierarchy with inheritance

After Setup

  1. Start the application:

    python3 run.py
    
  2. Access the application:

  3. Login with superadmin:

    • Username: superadmin
    • Password: superadmin123

Troubleshooting

Common Issues:

  1. Database connection failed:

    • Check if MariaDB is running: sudo systemctl status mariadb
    • Verify database exists: sudo mysql -e "SHOW DATABASES;"
    • Check user privileges: sudo mysql -e "SHOW GRANTS FOR 'trasabilitate'@'localhost';"
  2. Import errors:

    • Ensure virtual environment is activated
    • Install missing dependencies: pip install -r requirements.txt
  3. Permission denied:

    • Make script executable: chmod +x app/db_create_scripts/setup_complete_database.py
    • Check file ownership: ls -la app/db_create_scripts/

Manual Database Recreation:

If you need to completely reset the database:

# Drop and recreate database
sudo mysql -e "DROP DATABASE IF EXISTS trasabilitate; CREATE DATABASE trasabilitate; GRANT ALL PRIVILEGES ON trasabilitate.* TO 'trasabilitate'@'localhost'; FLUSH PRIVILEGES;"

# Remove SQLite database
rm -f instance/users.db

# Run setup script
python3 app/db_create_scripts/setup_complete_database.py

Script Features

  • Comprehensive: Creates all necessary database structure
  • Safe: Uses IF NOT EXISTS clauses to prevent conflicts
  • Verified: Includes verification step to confirm setup
  • Informative: Detailed output showing each step
  • Error handling: Clear error messages and troubleshooting hints
  • Idempotent: Can be run multiple times safely

Development Notes

The script combines functionality from these individual scripts:

  • create_scan_1db.py
  • create_scanfg_orders.py
  • create_order_for_labels_table.py
  • create_warehouse_locations_table.py
  • create_permissions_tables.py
  • create_roles_table.py
  • create_triggers.py
  • create_triggers_fg.py
  • populate_permissions.py

For development or debugging, you can still run individual scripts if needed.