18 lines
979 B
MySQL
18 lines
979 B
MySQL
|
|
-- 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.
|