feat: 初始化核心数据库表结构、Go模型并包含日期字段类型迁移脚本
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
-- Migration: Change transaction_date from DATE to DATETIME
|
||||
-- This migration updates the transaction_date column to store both date and time.
|
||||
-- Run this SQL on your MySQL database.
|
||||
|
||||
-- Step 1: Modify the column type (preserves existing data - dates will have 00:00:00 time)
|
||||
ALTER TABLE `transactions` MODIFY COLUMN `transaction_date` DATETIME NOT NULL;
|
||||
|
||||
-- Step 2 (Optional): Migrate existing transaction_time data into transaction_date
|
||||
-- This updates existing records to combine date + time into the transaction_date column
|
||||
-- Only run this if you have existing data that you want to preserve time info for
|
||||
UPDATE `transactions`
|
||||
SET `transaction_date` = TIMESTAMP(DATE(`transaction_date`), IFNULL(`transaction_time`, '00:00:00'))
|
||||
WHERE `transaction_time` IS NOT NULL;
|
||||
|
||||
-- Note: After running this migration, the transaction_time column is no longer used
|
||||
-- but is kept for backward compatibility. New transactions will store full datetime
|
||||
-- in the transaction_date column.
|
||||
@@ -123,7 +123,7 @@ CREATE TABLE IF NOT EXISTS `transactions` (
|
||||
`category_id` bigint(20) unsigned NOT NULL,
|
||||
`account_id` bigint(20) unsigned NOT NULL,
|
||||
`currency` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'CNY',
|
||||
`transaction_date` date NOT NULL,
|
||||
`transaction_date` datetime NOT NULL,
|
||||
`note` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`image_path` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`recurring_id` bigint(20) unsigned DEFAULT NULL,
|
||||
|
||||
Reference in New Issue
Block a user