From aad9fec4614823d50ec2b78e97e5eed07c75c215 Mon Sep 17 00:00:00 2001 From: 12975 <1297598740@qq.com> Date: Wed, 28 Jan 2026 23:30:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9D=E5=A7=8B=E5=8C=96=E6=A0=B8?= =?UTF-8?q?=E5=BF=83=E6=95=B0=E6=8D=AE=E5=BA=93=E8=A1=A8=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E3=80=81Go=E6=A8=A1=E5=9E=8B=E5=B9=B6=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E5=AD=97=E6=AE=B5=E7=B1=BB=E5=9E=8B=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20260128_transaction_date_to_datetime.sql | 17 +++++++++++++++++ database/sql/schema.sql | 2 +- internal/models/models.go | 7 +++---- 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 database/sql/migrations/20260128_transaction_date_to_datetime.sql diff --git a/database/sql/migrations/20260128_transaction_date_to_datetime.sql b/database/sql/migrations/20260128_transaction_date_to_datetime.sql new file mode 100644 index 0000000..e3fd468 --- /dev/null +++ b/database/sql/migrations/20260128_transaction_date_to_datetime.sql @@ -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. diff --git a/database/sql/schema.sql b/database/sql/schema.sql index 88332d5..93e038a 100644 --- a/database/sql/schema.sql +++ b/database/sql/schema.sql @@ -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, diff --git a/internal/models/models.go b/internal/models/models.go index ff940d0..35f415d 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -348,7 +348,7 @@ type Transaction struct { CategoryID uint `gorm:"not null;index" json:"category_id"` AccountID uint `gorm:"not null;index" json:"account_id"` Currency Currency `gorm:"size:10;not null;default:'CNY'" json:"currency"` - TransactionDate time.Time `gorm:"type:date;not null;index" json:"transaction_date"` + TransactionDate time.Time `gorm:"type:datetime;not null;index" json:"transaction_date"` Note string `gorm:"size:500" json:"note,omitempty"` ImagePath string `gorm:"size:255" json:"image_path,omitempty"` RecurringID *uint `gorm:"index" json:"recurring_id,omitempty"` @@ -361,9 +361,8 @@ type Transaction struct { // Validates: Requirements 3.10 LedgerID *uint `gorm:"index" json:"ledger_id,omitempty"` - // Precise time recording - // Feature: accounting-feature-upgrade - // Validates: Requirements 5.2 + // TransactionTime is deprecated - time is now stored in TransactionDate (DATETIME) + // Kept for backward compatibility with existing data TransactionTime *time.Time `gorm:"type:time" json:"transaction_time,omitempty"` // Transaction sub-type for special transactions