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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user