DROP DATABASE IF EXISTS qa_demo;
CREATE DATABASE qa_demo CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON qa_demo.* TO 'dbtool'@'%';
FLUSH PRIVILEGES;
USE qa_demo;

CREATE TABLE accounts (
  id BIGINT PRIMARY KEY,
  email VARCHAR(255) NOT NULL UNIQUE,
  display_name VARCHAR(255) NULL,
  is_active BOOLEAN NOT NULL,
  created_at TIMESTAMP NOT NULL
);

CREATE TABLE tickets (
  id BIGINT PRIMARY KEY,
  account_id BIGINT NOT NULL,
  title VARCHAR(255) NOT NULL,
  status VARCHAR(32) NOT NULL,
  notes TEXT NULL,
  amount_cents INT NOT NULL,
  created_at TIMESTAMP NOT NULL,
  CONSTRAINT fk_tickets_account FOREIGN KEY (account_id) REFERENCES accounts(id)
);

INSERT INTO accounts (id, email, display_name, is_active, created_at) VALUES
  (1, 'alice@example.com', 'Alice', TRUE, '2026-03-01 08:30:00'),
  (2, 'maria@example.com', 'Máría', FALSE, '2026-03-10 09:45:00'),
  (3, 'zhang@example.com', '张敏', TRUE, '2026-03-15 12:00:00');

INSERT INTO tickets (id, account_id, title, status, notes, amount_cents, created_at) VALUES
  (101, 1, 'login timeout', 'open', NULL, 0, '2026-03-20 10:00:00'),
  (102, 1, 'csv export mismatch', 'closed', 'fixed after re-run', 1500, '2026-03-21 11:15:00'),
  (103, 2, '权限验证', 'open', 'needs DBA review', 300, '2026-03-22 15:30:00'),
  (104, 3, 'emoji smoke 😀', 'open', NULL, 42, '2026-03-23 07:05:00');
