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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user