Skip to content

Commit

Permalink
Separate table schema and environment-specific products
Browse files Browse the repository at this point in the history
  • Loading branch information
zackproser committed Feb 2, 2024
1 parent 369063f commit 4c914ca
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 102 deletions.
51 changes: 0 additions & 51 deletions schema/dev_and_staging.sql → schema/dev_and_staging_products.sql
Original file line number Diff line number Diff line change
@@ -1,54 +1,3 @@
-- Drop tables if they exist
DROP TABLE IF EXISTS Students, Courses, CourseEnrollments, StripePayments, Logins;

-- Create ENUM type for course status
CREATE TYPE course_status AS ENUM (
'coming-soon',
'in-progress',
'available'
);

CREATE TABLE Students (
student_id SERIAL PRIMARY KEY,
github_username VARCHAR(255),
full_name VARCHAR(255),
email VARCHAR(255) UNIQUE,
avatar_url TEXT,
followers_count INTEGER
);

CREATE TABLE Courses (
course_id SERIAL PRIMARY KEY,
title VARCHAR(255),
description TEXT,
slug VARCHAR(255) UNIQUE,
status course_status, -- Using ENUM type
price_id VARCHAR(255)
);

CREATE TABLE CourseEnrollments (
enrollment_id SERIAL PRIMARY KEY,
student_id INTEGER REFERENCES Students(student_id),
course_id INTEGER REFERENCES Courses(course_id),
enrollment_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(student_id, course_id)
);

CREATE TABLE StripePayments (
payment_id SERIAL PRIMARY KEY,
student_id INTEGER REFERENCES Students(student_id),
stripe_payment_id VARCHAR(255),
amount DECIMAL(10, 2),
payment_status VARCHAR(50),
payment_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE Logins (
login_id SERIAL PRIMARY KEY,
student_id INTEGER REFERENCES Students(student_id),
login_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Populate test (dev/staging) courses
INSERT INTO Courses (title, description, slug, status, price_id)
VALUES
Expand Down
51 changes: 0 additions & 51 deletions schema/production.sql → schema/production_products.sql
Original file line number Diff line number Diff line change
@@ -1,54 +1,3 @@
-- Drop tables if they exist
DROP TABLE IF EXISTS Students, Courses, CourseEnrollments, StripePayments, Logins;

-- Create ENUM type for course status
CREATE TYPE course_status AS ENUM (
'coming-soon',
'in-progress',
'available'
);

CREATE TABLE Students (
student_id SERIAL PRIMARY KEY,
github_username VARCHAR(255),
full_name VARCHAR(255),
email VARCHAR(255) UNIQUE,
avatar_url TEXT,
followers_count INTEGER
);

CREATE TABLE Courses (
course_id SERIAL PRIMARY KEY,
title VARCHAR(255),
description TEXT,
slug VARCHAR(255) UNIQUE,
status course_status, -- Using ENUM type
price_id VARCHAR(255)
);

CREATE TABLE CourseEnrollments (
enrollment_id SERIAL PRIMARY KEY,
student_id INTEGER REFERENCES Students(student_id),
course_id INTEGER REFERENCES Courses(course_id),
enrollment_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(student_id, course_id)
);

CREATE TABLE StripePayments (
payment_id SERIAL PRIMARY KEY,
student_id INTEGER REFERENCES Students(student_id),
stripe_payment_id VARCHAR(255),
amount DECIMAL(10, 2),
payment_status VARCHAR(50),
payment_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE Logins (
login_id SERIAL PRIMARY KEY,
student_id INTEGER REFERENCES Students(student_id),
login_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Populate Production courses
INSERT INTO Courses (title, description, slug, status, price_id)
VALUES
Expand Down
49 changes: 49 additions & 0 deletions schema/tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

-- Create ENUM type for course status
CREATE TYPE course_status AS ENUM (
'coming-soon',
'in-progress',
'available'
);

CREATE TABLE Students (
student_id SERIAL PRIMARY KEY,
github_username VARCHAR(255),
full_name VARCHAR(255),
email VARCHAR(255) UNIQUE,
avatar_url TEXT,
followers_count INTEGER
);

CREATE TABLE Courses (
course_id SERIAL PRIMARY KEY,
title VARCHAR(255),
description TEXT,
slug VARCHAR(255) UNIQUE,
status course_status, -- Using ENUM type
price_id VARCHAR(255)
);

CREATE TABLE CourseEnrollments (
enrollment_id SERIAL PRIMARY KEY,
student_id INTEGER REFERENCES Students(student_id),
course_id INTEGER REFERENCES Courses(course_id),
enrollment_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(student_id, course_id)
);

CREATE TABLE StripePayments (
payment_id SERIAL PRIMARY KEY,
student_id INTEGER REFERENCES Students(student_id),
stripe_payment_id VARCHAR(255),
amount DECIMAL(10, 2),
payment_status VARCHAR(50),
payment_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE Logins (
login_id SERIAL PRIMARY KEY,
student_id INTEGER REFERENCES Students(student_id),
login_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

0 comments on commit 4c914ca

Please sign in to comment.