Migrate remaining encrypted-column lookups to the blind index

Completes the set of queries that matched a freshly encrypted value against a
stored one, which only works while encryption is deterministic. Each keeps its
original comparison and adds an index comparison in the same WHERE, so nothing
changes today.

- passenger sign-in by email, service-staff sign-in, Firebase token lookup
- driver lookup by phone and by national number
- admin ride lookup and ride monitor (both tables)
- nabeh: driver status, user resolution, ride history, complaint submission

transit_org_admins lives in the transit database and has no index column, so
login there falls back to decrypting the small set of active admins and
comparing normalised numbers.

Schema: adds users.email_bidx/phone_bidx and driver.national_bidx with their
indexes.

Verified that every :*_bidx placeholder introduced is actually bound — an
unbound one is a fatal error at request time, not a silent miss.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Hamza-Ayed
2026-07-25 16:36:32 +03:00
co-authored by Claude Opus 5
parent 39b5a7fc7f
commit 8d7e3118b5
14 changed files with 109 additions and 28 deletions
+8
View File
@@ -84,6 +84,11 @@ $columns = [
['token_verification', 'phone_enc', "TEXT NULL DEFAULT NULL COMMENT 'الهاتف مشفّراً للاسترجاع'"],
['token_verification_driver', 'phone_enc', "TEXT NULL DEFAULT NULL COMMENT 'الهاتف مشفّراً للاسترجاع'"],
// بقية الجداول التي يُبحث فيها بحقل مشفّر
['users', 'email_bidx', "CHAR(64) NULL DEFAULT NULL COMMENT 'HMAC لبريد موظف الخدمة'"],
['users', 'phone_bidx', "CHAR(64) NULL DEFAULT NULL COMMENT 'HMAC لهاتف موظف الخدمة'"],
['driver', 'national_bidx', "CHAR(64) NULL DEFAULT NULL COMMENT 'HMAC للرقم الوطني'"],
// أعمدة موافقات المشرفين المفقودة في هذا النشر
['adminUser', 'status', "VARCHAR(20) NOT NULL DEFAULT 'active' COMMENT 'active | pending | suspended | rejected'"],
['adminUser', 'approved_by', "VARCHAR(32) NULL DEFAULT NULL"],
@@ -99,6 +104,9 @@ $indexes = [
['passengers', 'idx_passengers_name_bidx', 'name_bidx'],
['adminUser', 'idx_adminuser_phone_bidx', 'phone_bidx'],
['adminUser', 'idx_adminuser_email_bidx', 'email_bidx'],
['users', 'idx_users_email_bidx', 'email_bidx'],
['users', 'idx_users_phone_bidx', 'phone_bidx'],
['driver', 'idx_driver_national_bidx', 'national_bidx'],
];
$applied = 0;