-- PPanel Database Schema
-- Migration: 001_init
-- Description: Initial database schema

-- ============================================================
-- User Domain
-- ============================================================

CREATE TABLE IF NOT EXISTS `user` (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `email` varchar(255) DEFAULT NULL,
    `telephone` varchar(32) DEFAULT NULL,
    `password` varchar(255) NOT NULL DEFAULT '',
    `refer_code` varchar(32) DEFAULT NULL,
    `refer_id` bigint unsigned DEFAULT 0,
    `avatar` varchar(512) DEFAULT '',
    `balance` bigint DEFAULT 0,
    `commission` bigint DEFAULT 0,
    `gift_amount` bigint DEFAULT 0,
    `is_admin` tinyint(1) NOT NULL DEFAULT 0,
    `is_staff` tinyint(1) NOT NULL DEFAULT 0,
    `enable` tinyint(1) NOT NULL DEFAULT 1,
    `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `idx_email` (`email`),
    UNIQUE KEY `idx_telephone` (`telephone`),
    UNIQUE KEY `idx_refer_code` (`refer_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- TODO: Add remaining tables
-- user_auth_methods, user_device, user_subscribe, user_balance_log,
-- user_commission_log, user_subscribe_log, user_login_log,
-- user_device_online_record, user_gift_amount_log, user_reset_subscribe_log
-- order, coupon, ticket, ticket_follow
-- payment, announcement, document
-- system, server, server_group, server_rule_group
-- subscribe, subscribe_group, subscribe_type, subscribe_application
-- ads, application, application_config, application_version
-- traffic_log, system_logs
