-- Techvai Billing — Licensing server database schema
-- Import this once into your MySQL database (phpMyAdmin -> Import, or `mysql -u user -p dbname < schema.sql`)

CREATE TABLE IF NOT EXISTS licenses (
    id                 INT AUTO_INCREMENT PRIMARY KEY,
    license_key        VARCHAR(64) NOT NULL UNIQUE,
    customer_name      VARCHAR(191) NOT NULL DEFAULT '',
    customer_email     VARCHAR(191) NOT NULL DEFAULT '',
    status             ENUM('unused', 'active', 'revoked') NOT NULL DEFAULT 'unused',
    device_fingerprint VARCHAR(191) NULL DEFAULT NULL,
    max_devices        INT NOT NULL DEFAULT 1,
    created_at         DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    activated_at       DATETIME NULL DEFAULT NULL,
    last_checked_at    DATETIME NULL DEFAULT NULL,
    notes              VARCHAR(255) NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE INDEX idx_licenses_status ON licenses(status);
