CREATE TABLE IF NOT EXISTS `user` (
  `id` int NOT NULL AUTO_INCREMENT,
  `name` varchar(64) NOT NULL,
  `password` varchar(64) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_user_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `home` (
  `id` int NOT NULL AUTO_INCREMENT,
  `label` varchar(120) DEFAULT NULL,
  `custom` varchar(120) DEFAULT NULL,
  `count` decimal(10,2) DEFAULT 0,
  `comment` varchar(255) DEFAULT NULL,
  `type` varchar(64) DEFAULT NULL,
  `cusDate` date DEFAULT NULL,
  `pic` varchar(255) DEFAULT NULL,
  `used` tinyint(1) DEFAULT 1,
  PRIMARY KEY (`id`),
  KEY `idx_home_type` (`type`),
  KEY `idx_home_cusdate` (`cusDate`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `user` (`name`, `password`)
SELECT 'admin', '123456'
WHERE NOT EXISTS (SELECT 1 FROM `user` WHERE `name` = 'admin');

INSERT INTO `home` (`label`, `custom`, `count`, `comment`, `type`, `cusDate`, `pic`, `used`)
SELECT * FROM (
  SELECT '早餐', '食堂', 12.00, '工作日早餐', '餐饮', '2026-06-01', NULL, 1
  UNION ALL SELECT '午餐', '公司楼下', 28.00, '简餐', '餐饮', '2026-06-02', NULL, 1
  UNION ALL SELECT '地铁', '通勤', 7.00, '上下班交通', '交通', '2026-06-02', NULL, 1
  UNION ALL SELECT '咖啡', '便利店', 16.00, '下午咖啡', '饮品', '2026-06-03', NULL, 1
  UNION ALL SELECT '书籍', '网上书店', 68.00, '技术书', '学习', '2026-06-05', NULL, 1
  UNION ALL SELECT '电影票', '影院', 45.00, '周末观影', '娱乐', '2026-06-07', NULL, 1
  UNION ALL SELECT '超市采购', '社区超市', 136.50, '生活用品', '购物', '2026-06-08', NULL, 1
  UNION ALL SELECT '健身卡', '健身房', 199.00, '月卡', '运动', '2026-06-10', NULL, 0
) seed
WHERE NOT EXISTS (SELECT 1 FROM `home`);
