update db

This commit is contained in:
Jake Kasper
2025-08-22 08:29:48 -04:00
parent a0a9ec5411
commit bb365d918d
2 changed files with 18 additions and 1 deletions

View File

@@ -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();

View 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();