update db
This commit is contained in:
15
database/migrations/add_updated_at_to_user_products.sql
Normal file
15
database/migrations/add_updated_at_to_user_products.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
-- Migration: Add updated_at column to user_products table
|
||||
-- This fixes the error: column "updated_at" of relation "user_products" does not exist
|
||||
|
||||
-- Add the updated_at column
|
||||
ALTER TABLE user_products
|
||||
ADD COLUMN updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
||||
|
||||
-- Update existing rows to have the current timestamp
|
||||
UPDATE user_products SET updated_at = created_at WHERE updated_at IS NULL;
|
||||
|
||||
-- Create trigger to automatically update the timestamp
|
||||
CREATE TRIGGER update_user_products_updated_at
|
||||
BEFORE UPDATE ON user_products
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION update_updated_at_column();
|
||||
Reference in New Issue
Block a user