chore: initial commit

This commit is contained in:
2024-04-16 22:27:52 +01:00
commit 531b5dabe2
194 changed files with 27071 additions and 0 deletions

View File

@@ -0,0 +1 @@
DROP TABLE IF EXISTS auth_methods CASCADE;

View File

@@ -0,0 +1,4 @@
CREATE TABLE auth_methods (
user_id varchar(64) PRIMARY KEY,
hashed_password varchar(128) NOT NULL
);

View File

@@ -0,0 +1,3 @@
DROP TABLE IF EXISTS orders CASCADE;
DROP TABLE IF EXISTS order_items CASCADE;
DROP TABLE IF EXISTS event_outbox CASCADE;

View File

@@ -0,0 +1,32 @@
CREATE TABLE orders (
id bigserial PRIMARY KEY,
status smallint NOT NULL,
customer_id varchar(64) NOT NULL,
shipment_id varchar(64),
transaction_id varchar(64),
items_price money,
total_price money,
created_at timestamp NOT NULL DEFAULT timezone('utc', now()),
updated_at timestamp
);
CREATE TABLE order_items (
order_id bigserial,
product_id varchar(64),
quantity integer NOT NULL,
PRIMARY KEY (order_id, product_id),
FOREIGN KEY (order_id) REFERENCES orders (id) ON DELETE CASCADE
);
CREATE TABLE event_outbox (
id bigserial PRIMARY KEY,
aggregateid varchar(128) NOT NULL,
aggregatetype varchar(128) NOT NULL,
payload bytea NOT NULL
);

View File

@@ -0,0 +1,3 @@
DROP TABLE IF EXISTS transactions CASCADE;
DROP TABLE IF EXISTS customer_balances CASCADE;
DROP TABLE IF EXISTS event_outbox CASCADE;

View File

@@ -0,0 +1,24 @@
CREATE TABLE transactions (
id bigserial PRIMARY KEY,
order_id varchar(64),
customer_id varchar(64) NOT NULL,
amount money NOT NULL,
reversed_at timestamp,
processed_at timestamp NOT NULL DEFAULT timezone('utc', now())
);
CREATE TABLE customer_balances (
customer_id varchar(64) PRIMARY KEY,
balance money NOT NULL
);
CREATE TABLE event_outbox (
id bigserial PRIMARY KEY,
aggregateid varchar(128) NOT NULL,
aggregatetype varchar(128) NOT NULL,
payload bytea NOT NULL
);

View File

@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS products CASCADE;
DROP TABLE IF EXISTS event_outbox CASCADE;

View File

@@ -0,0 +1,18 @@
CREATE TABLE products (
id bigserial PRIMARY KEY,
name varchar(128) NOT NULL,
description varchar(256) NOT NULL,
price money NOT NULL,
created_at timestamp NOT NULL DEFAULT timezone('utc', now()),
updated_at timestamp
);
CREATE TABLE event_outbox (
id bigserial PRIMARY KEY,
aggregateid varchar(128) NOT NULL,
aggregatetype varchar(128) NOT NULL,
payload bytea NOT NULL
);

View File

@@ -0,0 +1,3 @@
DROP TABLE IF EXISTS shipments CASCADE;
DROP TABLE IF EXISTS shipment_items CASCADE;
DROP TABLE IF EXISTS event_outbox CASCADE;

View File

@@ -0,0 +1,26 @@
CREATE TABLE shipments (
id bigserial PRIMARY KEY,
order_id varchar(64) NOT NULL,
dispatched boolean DEFAULT FALSE,
created_at timestamp NOT NULL DEFAULT timezone('utc', now())
);
CREATE TABLE shipment_items (
shipment_id bigserial,
product_id varchar(64),
quantity integer NOT NULL,
PRIMARY KEY (shipment_id, product_id),
FOREIGN KEY (shipment_id) REFERENCES shipments (id) ON DELETE CASCADE
);
CREATE TABLE event_outbox (
id bigserial PRIMARY KEY,
aggregateid varchar(128) NOT NULL,
aggregatetype varchar(128) NOT NULL,
payload bytea NOT NULL
);

View File

@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS users CASCADE;
DROP TABLE IF EXISTS event_outbox CASCADE;

View File

@@ -0,0 +1,19 @@
CREATE TABLE users (
id bigserial PRIMARY KEY,
first_name varchar(64) NOT NULL,
last_name varchar(64) NOT NULL,
email varchar NOT NULL UNIQUE,
created_at timestamp NOT NULL DEFAULT timezone('utc', now()),
updated_at timestamp
);
CREATE TABLE event_outbox (
id bigserial PRIMARY KEY,
aggregateid varchar(128) NOT NULL,
aggregatetype varchar(128) NOT NULL,
payload bytea NOT NULL
);

View File

@@ -0,0 +1,4 @@
DROP TABLE IF EXISTS product_stock CASCADE;
DROP TABLE IF EXISTS reservations CASCADE;
DROP TABLE IF EXISTS reservation_items CASCADE;
DROP TABLE IF EXISTS event_outbox CASCADE;

View File

@@ -0,0 +1,30 @@
CREATE TABLE product_stock (
product_id varchar(64) PRIMARY KEY,
quantity integer NOT NULL
);
CREATE TABLE reservations (
id bigserial PRIMARY KEY,
order_id varchar(64) NOT NULL,
created_at timestamp NOT NULL DEFAULT timezone('utc', now())
);
CREATE TABLE reservation_items (
reservation_id bigserial,
product_id varchar(64),
quantity integer NOT NULL,
PRIMARY KEY (reservation_id, product_id),
FOREIGN KEY (reservation_id) REFERENCES reservations (id) ON DELETE CASCADE
);
CREATE TABLE event_outbox (
id bigserial PRIMARY KEY,
aggregateid varchar(128) NOT NULL,
aggregatetype varchar(128) NOT NULL,
payload bytea NOT NULL
);