-- ============================================================
-- migration_app_config.sql
-- ============================================================
-- FIX: the `app_config` table is read by api/v1/index.php's
-- `app_version` action (used for the mobile "update available" popup)
-- but was never actually created anywhere in config/database.sql —
-- same bug pattern as notifications before migration_notifications.sql.
-- That means every version check has been silently failing.
--
-- Run this once against your existing database:
--   mysql -u <user> -p <database_name> < migration_app_config.sql
-- ============================================================

CREATE TABLE IF NOT EXISTS app_config (
    config_key   VARCHAR(50) PRIMARY KEY,
    config_value VARCHAR(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Seed with the current app version. Bump `latest_version_code` (and
-- `latest_version_name` for display) every time you release a new APK —
-- the mobile app checks this on every launch and shows an "Update
-- Available" popup (with an Update Now button) if the installed
-- version is older. See modules/companies/index.php ("Push App
-- Version Update" card) to update these values from the vendor console
-- instead of editing the database by hand.
INSERT INTO app_config (config_key, config_value) VALUES
    ('latest_version_code', '1'),
    ('latest_version_name', '1.0'),
    ('update_message', 'A new version of the app is available.'),
    ('update_url', 'http://192.168.1.113/hr_system/downloads/app-latest.apk')
ON DUPLICATE KEY UPDATE config_value = config_value;
