delphi.market/db/schema.sql

67 lines
2.2 KiB
MySQL
Raw Normal View History

2024-07-12 11:26:27 +00:00
CREATE TABLE users(
id SERIAL PRIMARY KEY,
name TEXT UNIQUE NOT NULL DEFAULT LEFT(md5(random()::text), 8),
2024-07-12 11:26:27 +00:00
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
ln_pubkey TEXT UNIQUE,
nostr_pubkey TEXT UNIQUE,
msats BIGINT NOT NULL DEFAULT 0
);
CREATE TABLE sessions(
id VARCHAR(48) PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id),
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
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')
);
CREATE TABLE invoices(
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id),
msats BIGINT NOT NULL,
msats_received BIGINT,
hash TEXT NOT NULL UNIQUE,
bolt11 TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
2024-07-12 11:26:27 +00:00
expires_at TIMESTAMP WITH TIME ZONE NOT NULL,
confirmed_at TIMESTAMP WITH TIME ZONE,
held_since TIMESTAMP WITH TIME ZONE,
description TEXT
);
CREATE TABLE markets(
id SERIAL PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
question TEXT NOT NULL,
description TEXT,
2024-07-12 11:26:27 +00:00
end_date TIMESTAMP WITH TIME ZONE NOT NULL,
settled_at TIMESTAMP WITH TIME ZONE,
user_id INTEGER NOT NULL REFERENCES users(id),
2024-08-25 05:48:00 +00:00
invoice_id INTEGER NOT NULL UNIQUE REFERENCES invoices(id),
lmsr_b FLOAT NOT NULL
2024-07-12 11:26:27 +00:00
);
CREATE TABLE orders(
id SERIAL PRIMARY KEY,
2024-08-26 21:15:51 +00:00
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
2024-08-25 05:48:00 +00:00
market_id INTEGER NOT NULL REFERENCES markets(id),
2024-07-12 11:26:27 +00:00
user_id INTEGER NOT NULL REFERENCES users(id),
quantity BIGINT NOT NULL,
2024-08-25 05:48:00 +00:00
outcome INTEGER NOT NULL,
invoice_id INTEGER REFERENCES invoices(id)
2024-07-12 11:26:27 +00:00
);
CREATE TABLE withdrawals(
id SERIAL PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
canceled_at TIMESTAMP WITH TIME ZONE,
user_id INTEGER NOT NULL REFERENCES users(id),
bolt11 TEXT NOT NULL UNIQUE,
paid_at TIMESTAMP WITH TIME ZONE
);