Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented task 8 #61

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/dist
/node_modules

.env

# Logs
logs
*.log
Expand Down
33 changes: 33 additions & 0 deletions cart.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
CREATE TYPE card_status AS ENUM ('OPEN', 'ORDERED');
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE TABLE carts (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
user_id uuid NOT NULL,
created_at DATE NOT NULL,
updated_at DATE NOT NULL,
status card_status,
FOREIGN KEY (user_id) REFERENCES users (id)
);

CREATE TABLE cart_items (
product_id uuid DEFAULT uuid_generate_v4(),
cart_id uuid,
count int,
FOREIGN KEY (cart_id) REFERENCES carts (id)
ON DELETE CASCADE ON UPDATE CASCADE
);

INSERT INTO carts (id, user_id, created_at, updated_at, status) VALUES
(uuid_generate_v4(), uuid_generate_v4(), CURRENT_DATE, CURRENT_DATE, 'OPEN'),
(uuid_generate_v4(), uuid_generate_v4(), CURRENT_DATE, CURRENT_DATE, 'ORDERED');

WITH inserted_carts AS (
SELECT id FROM carts ORDER BY created_at DESC LIMIT 2
)

INSERT INTO cart_items (product_id, cart_id, count) SELECT
uuid_generate_v4(),
inserted_carts.id,
CAST(RANDOM() * 10 + 1 AS INT)
FROM inserted_carts, generate_series(1,5);
Loading