From bb365d918de5e8c6611a6cb5a0f34aa89587e92c Mon Sep 17 00:00:00 2001 From: Jake Kasper Date: Fri, 22 Aug 2025 08:29:48 -0400 Subject: [PATCH] update db --- database/init.sql | 4 +++- .../add_updated_at_to_user_products.sql | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 database/migrations/add_updated_at_to_user_products.sql diff --git a/database/init.sql b/database/init.sql index 344accc..513fd67 100644 --- a/database/init.sql +++ b/database/init.sql @@ -103,7 +103,8 @@ CREATE TABLE user_products ( custom_rate_amount DECIMAL(8, 4), custom_rate_unit VARCHAR(50), notes TEXT, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Application plans (what user plans to apply) @@ -242,4 +243,5 @@ CREATE TRIGGER update_users_updated_at BEFORE UPDATE ON users FOR EACH ROW EXECU CREATE TRIGGER update_properties_updated_at BEFORE UPDATE ON properties FOR EACH ROW EXECUTE FUNCTION update_updated_at_column(); CREATE TRIGGER update_lawn_sections_updated_at BEFORE UPDATE ON lawn_sections FOR EACH ROW EXECUTE FUNCTION update_updated_at_column(); CREATE TRIGGER update_user_equipment_updated_at BEFORE UPDATE ON user_equipment FOR EACH ROW EXECUTE FUNCTION update_updated_at_column(); +CREATE TRIGGER update_user_products_updated_at BEFORE UPDATE ON user_products FOR EACH ROW EXECUTE FUNCTION update_updated_at_column(); CREATE TRIGGER update_application_plans_updated_at BEFORE UPDATE ON application_plans FOR EACH ROW EXECUTE FUNCTION update_updated_at_column(); \ No newline at end of file diff --git a/database/migrations/add_updated_at_to_user_products.sql b/database/migrations/add_updated_at_to_user_products.sql new file mode 100644 index 0000000..21a0f9e --- /dev/null +++ b/database/migrations/add_updated_at_to_user_products.sql @@ -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(); \ No newline at end of file