CREATE TABLE IF NOT EXISTS SystemErrorLogs (
  ID BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  AppName VARCHAR(100) NOT NULL DEFAULT 'miaoguo_system_server',
  Env VARCHAR(32) NULL,
  Host VARCHAR(128) NULL,
  PM2Process VARCHAR(128) NULL,
  PID INT NULL,
  Level VARCHAR(32) NOT NULL DEFAULT 'error',
  Source VARCHAR(64) NOT NULL DEFAULT 'application',
  Message VARCHAR(1024) NOT NULL,
  Stack MEDIUMTEXT NULL,
  FilePath VARCHAR(512) NULL,
  LineNumber INT NULL,
  ColumnNumber INT NULL,
  RequestMethod VARCHAR(16) NULL,
  RequestUrl VARCHAR(2048) NULL,
  RequestQuery MEDIUMTEXT NULL,
  RequestBody MEDIUMTEXT NULL,
  UserID VARCHAR(64) NULL,
  NodeVersion VARCHAR(32) NULL,
  GitCommit VARCHAR(64) NULL,
  Fingerprint CHAR(64) NOT NULL,
  Count INT UNSIGNED NOT NULL DEFAULT 1,
  Status VARCHAR(32) NOT NULL DEFAULT 'open',
  Extra MEDIUMTEXT NULL,
  FirstSeenAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  LastSeenAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  CreateTime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  UpdateTime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (ID),
  UNIQUE KEY uk_SystemErrorLogs_Fingerprint (Fingerprint),
  KEY idx_SystemErrorLogs_Status_LastSeenAt (Status, LastSeenAt),
  KEY idx_SystemErrorLogs_LastSeenAt (LastSeenAt),
  KEY idx_SystemErrorLogs_Source (Source),
  KEY idx_SystemErrorLogs_FilePath (FilePath(191))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
