feat: Update monetary column data types to DOUBLE PRECISION, add IF NOT EXISTS to column additions, and introduce a timestamp trigger function.

This commit is contained in:
2026-02-15 14:43:31 -03:00
parent bb4cd01d99
commit 2a16a18676
2 changed files with 16 additions and 7 deletions
@@ -1,6 +1,15 @@
-- Add price and currency to courses table in LMS
ALTER TABLE courses ADD COLUMN price NUMERIC(10, 2) DEFAULT 0.00;
ALTER TABLE courses ADD COLUMN currency VARCHAR(10) DEFAULT 'USD';
ALTER TABLE courses ADD COLUMN IF NOT EXISTS price DOUBLE PRECISION DEFAULT 0.0;
ALTER TABLE courses ADD COLUMN IF NOT EXISTS currency VARCHAR(10) DEFAULT 'USD';
-- Create general trigger function if not exists
CREATE OR REPLACE FUNCTION trigger_set_timestamp()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- Create transactions table
CREATE TABLE transactions (
@@ -8,7 +17,7 @@ CREATE TABLE transactions (
organization_id UUID NOT NULL REFERENCES organizations(id),
user_id UUID NOT NULL REFERENCES users(id),
course_id UUID NOT NULL REFERENCES courses(id),
amount NUMERIC(10, 2) NOT NULL,
amount DOUBLE PRECISION NOT NULL,
currency VARCHAR(10) NOT NULL,
status TEXT NOT NULL DEFAULT 'pending', -- 'pending', 'success', 'failure'
provider_reference TEXT,