diff --git a/scripts/migrate_phase3_mobile.php b/scripts/migrate_phase3_mobile.php index fb9e086..5a26e0c 100644 --- a/scripts/migrate_phase3_mobile.php +++ b/scripts/migrate_phase3_mobile.php @@ -22,13 +22,23 @@ echo " مُصادَق — Phase 3 Migration\n"; echo " Mobile App + Batch Processing Support\n"; echo "═══════════════════════════════════════════\n\n"; +// --- Fetch Parent Collation dynamically --- +$stmt = $db->query("SHOW FULL COLUMNS FROM users WHERE Field = 'id'"); +$userCol = $stmt->fetch(PDO::FETCH_ASSOC); +$charsetCollation = ""; +if ($userCol && !empty($userCol['Collation'])) { + $collation = $userCol['Collation']; + list($charset) = explode('_', $collation); + $charsetCollation = "CHARACTER SET {$charset} COLLATE {$collation}"; +} + $migrations = [ // ─── 1. User Device Management ───────────────────────── 'create_user_devices' => " CREATE TABLE IF NOT EXISTS user_devices ( - id CHAR(36) PRIMARY KEY DEFAULT (UUID()), - user_id CHAR(36) NOT NULL, + id CHAR(36) {$charsetCollation} PRIMARY KEY DEFAULT (UUID()), + user_id CHAR(36) {$charsetCollation} NOT NULL, device_fingerprint VARCHAR(64) NOT NULL, device_name VARCHAR(100) NULL, platform ENUM('android','ios','web') NOT NULL DEFAULT 'android', @@ -55,10 +65,10 @@ $migrations = [ // ─── 3. Invoice Batches (Mobile Scanner) ─────────────── 'create_invoice_batches' => " CREATE TABLE IF NOT EXISTS invoice_batches ( - id CHAR(36) PRIMARY KEY, - tenant_id CHAR(36) NOT NULL, - company_id CHAR(36) NOT NULL, - uploaded_by CHAR(36) NOT NULL, + id CHAR(36) {$charsetCollation} PRIMARY KEY, + tenant_id CHAR(36) {$charsetCollation} NOT NULL, + company_id CHAR(36) {$charsetCollation} NOT NULL, + uploaded_by CHAR(36) {$charsetCollation} NOT NULL, total_images INT NOT NULL DEFAULT 0, processed_images INT NOT NULL DEFAULT 0, failed_images INT NOT NULL DEFAULT 0, @@ -81,10 +91,10 @@ $migrations = [ 'create_processing_queue' => " CREATE TABLE IF NOT EXISTS invoice_processing_queue ( id INT AUTO_INCREMENT PRIMARY KEY, - batch_id CHAR(36) NOT NULL, - invoice_id CHAR(36) NULL, - tenant_id CHAR(36) NOT NULL, - company_id CHAR(36) NOT NULL, + batch_id CHAR(36) {$charsetCollation} NOT NULL, + invoice_id CHAR(36) {$charsetCollation} NULL, + tenant_id CHAR(36) {$charsetCollation} NOT NULL, + company_id CHAR(36) {$charsetCollation} NOT NULL, image_path VARCHAR(500) NOT NULL, image_order INT NOT NULL DEFAULT 0, status ENUM('pending','processing','done','failed') DEFAULT 'pending', @@ -106,9 +116,9 @@ $migrations = [ // ─── 6. Notifications Table ──────────────────────────── 'create_notifications' => " CREATE TABLE IF NOT EXISTS notifications ( - id CHAR(36) PRIMARY KEY DEFAULT (UUID()), - tenant_id CHAR(36) NOT NULL, - user_id CHAR(36) NULL, + id CHAR(36) {$charsetCollation} PRIMARY KEY DEFAULT (UUID()), + tenant_id CHAR(36) {$charsetCollation} NOT NULL, + user_id CHAR(36) {$charsetCollation} NULL, type VARCHAR(50) NOT NULL, title VARCHAR(255) NOT NULL, body TEXT NULL,