Update db schema
This commit is contained in:
parent
94d1f6c1d8
commit
4ba568951d
63
db/init.sql
63
db/init.sql
|
@ -1,23 +1,27 @@
|
||||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
||||||
|
|
||||||
CREATE TABLE lnauth(
|
|
||||||
k1 VARCHAR(64) NOT NULL PRIMARY KEY,
|
|
||||||
lnurl TEXT NOT NULL,
|
|
||||||
created TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
session_id VARCHAR(48) NOT NULL DEFAULT encode(gen_random_uuid()::text::bytea, 'base64')
|
|
||||||
);
|
|
||||||
CREATE TABLE users(
|
CREATE TABLE users(
|
||||||
pubkey TEXT PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
last_seen TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
ln_pubkey TEXT,
|
||||||
|
nostr_pubkey TEXT,
|
||||||
msats BIGINT NOT NULL DEFAULT 0
|
msats BIGINT NOT NULL DEFAULT 0
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE sessions(
|
CREATE TABLE sessions(
|
||||||
pubkey TEXT NOT NULL REFERENCES users(pubkey),
|
user_id INTEGER NOT NULL REFERENCES users(id),
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
session_id VARCHAR(48)
|
session_id VARCHAR(48)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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(
|
CREATE TABLE invoices(
|
||||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
id SERIAL PRIMARY KEY,
|
||||||
pubkey TEXT NOT NULL REFERENCES users(pubkey),
|
user_id INTEGER NOT NULL REFERENCES users(id),
|
||||||
msats BIGINT NOT NULL,
|
msats BIGINT NOT NULL,
|
||||||
msats_received BIGINT,
|
msats_received BIGINT,
|
||||||
preimage TEXT NOT NULL UNIQUE,
|
preimage TEXT NOT NULL UNIQUE,
|
||||||
|
@ -29,40 +33,47 @@ CREATE TABLE invoices(
|
||||||
held_since TIMESTAMP WITH TIME ZONE,
|
held_since TIMESTAMP WITH TIME ZONE,
|
||||||
description TEXT
|
description TEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE markets(
|
CREATE TABLE markets(
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
description TEXT NOT NULL,
|
description TEXT NOT NULL,
|
||||||
end_date TIMESTAMP WITH TIME ZONE NOT NULL,
|
end_date TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||||
settled_at TIMESTAMP WITH TIME ZONE,
|
settled_at TIMESTAMP WITH TIME ZONE,
|
||||||
pubkey TEXT NOT NULL REFERENCES users(pubkey),
|
user_id INTEGER NOT NULL REFERENCES users(id),
|
||||||
invoice_id UUID NOT NULL UNIQUE REFERENCES invoices(id)
|
invoice_id INTEGER NOT NULL UNIQUE REFERENCES invoices(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE shares(
|
CREATE TABLE shares(
|
||||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
id SERIAL PRIMARY KEY,
|
||||||
market_id INTEGER NOT NULL REFERENCES markets(id),
|
market_id INTEGER NOT NULL REFERENCES markets(id),
|
||||||
win BOOLEAN,
|
description TEXT NOT NULL,
|
||||||
description TEXT NOT NULL
|
win BOOLEAN
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TYPE order_side AS ENUM ('BUY', 'SELL');
|
CREATE TYPE order_side AS ENUM ('BUY', 'SELL');
|
||||||
|
|
||||||
CREATE TABLE orders(
|
CREATE TABLE orders(
|
||||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
id SERIAL PRIMARY KEY,
|
||||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
deleted_at TIMESTAMP WITH TIME ZONE,
|
deleted_at TIMESTAMP WITH TIME ZONE,
|
||||||
share_id UUID NOT NULL REFERENCES shares(id),
|
share_id INTEGER NOT NULL REFERENCES shares(id),
|
||||||
pubkey TEXT NOT NULL REFERENCES users(pubkey),
|
user_id INTEGER NOT NULL REFERENCES users(id),
|
||||||
side ORDER_SIDE NOT NULL,
|
side ORDER_SIDE NOT NULL,
|
||||||
quantity BIGINT NOT NULL,
|
quantity BIGINT NOT NULL,
|
||||||
price BIGINT NOT NULL,
|
price BIGINT NOT NULL,
|
||||||
invoice_id UUID REFERENCES invoices(id),
|
invoice_id INTEGER REFERENCES invoices(id),
|
||||||
order_id UUID REFERENCES orders(id)
|
order_id INTEGER REFERENCES orders(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
ALTER TABLE orders ADD CONSTRAINT order_price CHECK(price > 0 AND price < 100);
|
ALTER TABLE orders ADD CONSTRAINT order_price CHECK(price > 0 AND price < 100);
|
||||||
ALTER TABLE orders ADD CONSTRAINT order_quantity CHECK(quantity > 0);
|
ALTER TABLE orders ADD CONSTRAINT order_quantity CHECK(quantity > 0);
|
||||||
|
|
||||||
CREATE TABLE withdrawals(
|
CREATE TABLE withdrawals(
|
||||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
id SERIAL PRIMARY KEY,
|
||||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
deleted_at TIMESTAMP WITH TIME ZONE,
|
canceled_at TIMESTAMP WITH TIME ZONE,
|
||||||
pubkey TEXT NOT NULL REFERENCES users(pubkey),
|
user_id INTEGER NOT NULL REFERENCES users(id),
|
||||||
bolt11 TEXT NOT NULL UNIQUE,
|
bolt11 TEXT NOT NULL UNIQUE,
|
||||||
paid_at TIMESTAMP WITH TIME ZONE
|
paid_at TIMESTAMP WITH TIME ZONE
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue