Članci s tagom #mysql
-
Duplicate invoice number handling in production: graceful recovery without data loss
fiskalizacija_invoices UNIQUE KEY uq_company_invoice_number_year (company_id, invoice_number, issue_year GENERATED). generateInvoiceNumber MAX over all types including proformas (prevents proforma gap). PDOException catch on constraint name → 409 + 'invoice may already exist' (double-submit defence, no data loss). issue_year GENERATED ALWAYS AS YEAR(issue_date) STORED — same invoice number legal in different years.
-
Soft delete in PHP: why it matters for GDPR and how to implement it correctly
Model soft delete: opt-in $softDelete = true adds automatic WHERE deleted_at IS NULL to query(), withTrashed() / onlyTrashed() for admin bypass, trash(deletedBy) vs delete(), GdprRetentionJob atomic transaction (DELETE + auditLogger in one commit), GDPR_RETENTION sentinel, 2-year audit log cleanup.
-
Statistical query regression detection in PHP: Cohen's d on MySQL timing baselines
QueryBaselineComparator: MIN_BASELINE_SAMPLES=14, 7-day hourly median baseline from monitoring_luka_query_baselines, Cohen's d reused from KIKA TrendAnalyzer (single source of truth), directional gate (positive d only = regression), NULL-safe tenant_id <=> operator, confidence tiers (high≥100/medium≥24/low<24 samples).
-
PHP cron scheduler: self-hosted, zero dependencies, per-minute resolution
Shinobi Apps framework Scheduler: queue_scheduled_tasks table, registerIfNeeded (file cache → DB upsert, hash of jobClass+expression+jobData), ONCE marker for one-time tasks, runDue optimistic atomic claim (UPDATE WHERE old next_run_at → affected_rows=1 wins, prevents duplicate dispatch), INSERT ON DUPLICATE KEY UPDATE with is_active omitted (preserves user toggle). Scheduler::ONCE for delayed post-deploy tasks. Expression: cron 5-field or dailyAt HH:MM.
-
PHP job queue on a shared host: no Redis, no RabbitMQ, just MySQL and cron
Shinobi Apps framework queue: DatabaseDriver (MySQL-backed, no Redis). QueueManager priority queue list (default, emails, alerts, webhooks, ai-analysis, maintenance, notifications) + auto-discovery of unknown queues from storage (new addon queue Just Works). processMany round-robin, processManyUntil(deadline) for time-bounded critical-path drain. Exponential backoff (60s × 2^attempts). Dynamic class whitelist for unserialize (PHP Object Injection defence). Queue lifecycle events via EventDispatcher.
-
PHP migration system: forward-only, one file per change, shared-host compatible
SQL-only migrations, no PHP interface. Forward-only with no down() method. One logical change per file. Checksum verification on re-run. Shared-host compatible: no information_schema access needed, MySQL 5.5+ syntax only. Works across multiple databases in one command.
-
One PHP codebase, three MySQL servers: per-domain database routing without code changes
How to route a single PHP codebase to different MySQL databases based on HTTP_HOST — without code changes in any model or controller. The full implementation: ConnectionRouter, strict host validation, TLS to remote DBs, and CLI --connection flag.
-
Multi-tenant SaaS in PHP without a multi-tenant framework
Row-level tenancy in PHP using one database, one codebase, and a korisnici_companies table. How currentTenantId() and allowed_modules replaced per-tenant databases and per-tenant codebases — and the two contexts that can never be mixed up.