-- Print API keys for remote printing authentication CREATE TABLE IF NOT EXISTS print_api_keys ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(128) NOT NULL, key_hash VARCHAR(128) NOT NULL, key_prefix VARCHAR(8) NOT NULL, is_active TINYINT(1) NOT NULL DEFAULT 1, last_used_at DATETIME NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, UNIQUE INDEX print_api_keys_hash_unique (key_hash), INDEX print_api_keys_active_idx (is_active) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- Print jobs queue for remote label printing -- No FK constraints: order_id/package_id types may vary across environments CREATE TABLE IF NOT EXISTS print_jobs ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, order_id BIGINT UNSIGNED NOT NULL, package_id BIGINT UNSIGNED NOT NULL, label_path VARCHAR(255) NOT NULL, status ENUM('pending', 'printing', 'completed', 'failed') NOT NULL DEFAULT 'pending', created_by INT UNSIGNED NOT NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, completed_at DATETIME NULL, INDEX print_jobs_status_idx (status), INDEX print_jobs_order_idx (order_id), INDEX print_jobs_package_idx (package_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;