2023-09-09 20:52:50 +00:00
|
|
|
CREATE TABLE users(
|
2024-07-11 03:48:50 +00:00
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
ln_pubkey TEXT,
|
|
|
|
nostr_pubkey TEXT,
|
2023-12-02 21:08:01 +00:00
|
|
|
msats BIGINT NOT NULL DEFAULT 0
|
2023-09-09 20:52:50 +00:00
|
|
|
);
|
2024-07-11 03:48:50 +00:00
|
|
|
|
2023-09-09 20:52:50 +00:00
|
|
|
CREATE TABLE sessions(
|
2024-07-11 03:48:50 +00:00
|
|
|
user_id INTEGER NOT NULL REFERENCES users(id),
|
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
2023-09-09 20:52:50 +00:00
|
|
|
session_id VARCHAR(48)
|
|
|
|
);
|
2024-07-11 03:48:50 +00:00
|
|
|
|
|
|
|
CREATE TABLE lnauth(
|
|
|
|
k1 VARCHAR(64) PRIMARY KEY,
|
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
lnurl TEXT NOT NULL,
|
|
|
|
session_id VARCHAR(48) NOT NULL DEFAULT encode(gen_random_uuid()::text::bytea, 'base64')
|
|
|
|
);
|
|
|
|
|
2023-09-09 20:52:51 +00:00
|
|
|
CREATE TABLE invoices(
|
2024-07-11 03:48:50 +00:00
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
user_id INTEGER NOT NULL REFERENCES users(id),
|
2023-09-09 20:52:51 +00:00
|
|
|
msats BIGINT NOT NULL,
|
|
|
|
msats_received BIGINT,
|
|
|
|
preimage TEXT NOT NULL UNIQUE,
|
|
|
|
hash TEXT NOT NULL UNIQUE,
|
|
|
|
bolt11 TEXT NOT NULL,
|
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
|
|
expires_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
|
|
confirmed_at TIMESTAMP WITH TIME ZONE,
|
2023-11-09 02:47:24 +00:00
|
|
|
held_since TIMESTAMP WITH TIME ZONE,
|
|
|
|
description TEXT
|
2023-09-09 20:52:51 +00:00
|
|
|
);
|
2024-07-11 03:48:50 +00:00
|
|
|
|
2023-11-20 13:18:50 +00:00
|
|
|
CREATE TABLE markets(
|
|
|
|
id SERIAL PRIMARY KEY,
|
2024-07-11 03:48:50 +00:00
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
2023-11-20 13:18:50 +00:00
|
|
|
description TEXT NOT NULL,
|
|
|
|
end_date TIMESTAMP WITH TIME ZONE NOT NULL,
|
2023-12-03 22:52:24 +00:00
|
|
|
settled_at TIMESTAMP WITH TIME ZONE,
|
2024-07-11 03:48:50 +00:00
|
|
|
user_id INTEGER NOT NULL REFERENCES users(id),
|
|
|
|
invoice_id INTEGER NOT NULL UNIQUE REFERENCES invoices(id)
|
2023-11-20 13:18:50 +00:00
|
|
|
);
|
2024-07-11 03:48:50 +00:00
|
|
|
|
2023-11-20 13:18:50 +00:00
|
|
|
CREATE TABLE shares(
|
2024-07-11 03:48:50 +00:00
|
|
|
id SERIAL PRIMARY KEY,
|
2023-12-04 03:56:01 +00:00
|
|
|
market_id INTEGER NOT NULL REFERENCES markets(id),
|
2024-07-11 03:48:50 +00:00
|
|
|
description TEXT NOT NULL,
|
|
|
|
win BOOLEAN
|
2023-11-20 13:18:50 +00:00
|
|
|
);
|
2024-07-11 03:48:50 +00:00
|
|
|
|
2023-09-09 20:52:50 +00:00
|
|
|
CREATE TYPE order_side AS ENUM ('BUY', 'SELL');
|
2024-07-11 03:48:50 +00:00
|
|
|
|
2023-09-09 20:52:50 +00:00
|
|
|
CREATE TABLE orders(
|
2024-07-11 03:48:50 +00:00
|
|
|
id SERIAL PRIMARY KEY,
|
2023-09-09 20:52:51 +00:00
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
2023-12-02 21:08:01 +00:00
|
|
|
deleted_at TIMESTAMP WITH TIME ZONE,
|
2024-07-11 03:48:50 +00:00
|
|
|
share_id INTEGER NOT NULL REFERENCES shares(id),
|
|
|
|
user_id INTEGER NOT NULL REFERENCES users(id),
|
2023-09-09 20:52:50 +00:00
|
|
|
side ORDER_SIDE NOT NULL,
|
2023-09-09 20:52:50 +00:00
|
|
|
quantity BIGINT NOT NULL,
|
2023-09-09 20:52:51 +00:00
|
|
|
price BIGINT NOT NULL,
|
2024-07-11 03:48:50 +00:00
|
|
|
invoice_id INTEGER REFERENCES invoices(id),
|
|
|
|
order_id INTEGER REFERENCES orders(id)
|
2023-09-09 20:52:50 +00:00
|
|
|
);
|
2024-07-11 03:48:50 +00:00
|
|
|
|
2023-09-09 20:52:51 +00:00
|
|
|
ALTER TABLE orders ADD CONSTRAINT order_price CHECK(price > 0 AND price < 100);
|
2023-11-26 17:31:22 +00:00
|
|
|
ALTER TABLE orders ADD CONSTRAINT order_quantity CHECK(quantity > 0);
|
2024-07-11 03:48:50 +00:00
|
|
|
|
2023-12-03 05:21:57 +00:00
|
|
|
CREATE TABLE withdrawals(
|
2024-07-11 03:48:50 +00:00
|
|
|
id SERIAL PRIMARY KEY,
|
2023-12-03 05:21:57 +00:00
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
2024-07-11 03:48:50 +00:00
|
|
|
canceled_at TIMESTAMP WITH TIME ZONE,
|
|
|
|
user_id INTEGER NOT NULL REFERENCES users(id),
|
2023-12-03 05:21:57 +00:00
|
|
|
bolt11 TEXT NOT NULL UNIQUE,
|
|
|
|
paid_at TIMESTAMP WITH TIME ZONE
|
|
|
|
);
|