magicwallet/db/schema.sql
ekzyis 92876c5011 users, sessions and wallets w/o authentication
* if a request has no session cookie, a new user, session and wallet is created and session cookie is set
* if a request has a session cookie and session exists in db, we will fetch user and wallet from db
* this means that we have a user and wallet during each render without any login required
2024-12-15 21:56:26 +01:00

22 lines
689 B
SQL

CREATE TABLE users(
id SERIAL PRIMARY KEY,
name TEXT UNIQUE NOT NULL DEFAULT LEFT(md5(random()::text), 8),
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
ln_pubkey TEXT UNIQUE,
nostr_pubkey TEXT UNIQUE
);
CREATE TABLE sessions(
id VARCHAR(48) PRIMARY KEY DEFAULT encode(gen_random_uuid()::text::bytea, 'base64'),
user_id INTEGER NOT NULL REFERENCES users(id),
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE wallets(
id SERIAL PRIMARY KEY,
wallet_pubkey CHAR(66) NOT NULL,
secret CHAR(66) NOT NULL,
msats BIGINT NOT NULL DEFAULT 0,
user_id SERIAL REFERENCES users(id)
);