CREATE TABLE IF NOT EXISTS cards (
    id INT AUTO_INCREMENT PRIMARY KEY,
    uid VARCHAR(32) NOT NULL UNIQUE,
    balance_cents INT NOT NULL DEFAULT 0,
    status ENUM('active','blocked') NOT NULL DEFAULT 'active',
    created_at DATETIME NOT NULL,
    updated_at DATETIME NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS transactions (
    id INT AUTO_INCREMENT PRIMARY KEY,
    uid VARCHAR(32) NOT NULL,
    type ENUM('topup','debit') NOT NULL,
    amount_cents INT NOT NULL,
    balance_after_cents INT NOT NULL,
    created_at DATETIME NOT NULL,
    INDEX idx_uid_created (uid, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
