Skip to content

Commit

Permalink
clean up db schema
Browse files Browse the repository at this point in the history
  • Loading branch information
nbari committed Aug 21, 2024
1 parent a5dbf50 commit 7b69cfa
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions sql/schema.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
-- psql -U <user> -d genesis -f schema.sql

-- Ensure necessary extensions are enabled
-- CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

-- https://github.com/pksunkara/pgx_ulid
-- CREATE EXTENSION ulid;
-- CREATE EXTENSION IF NOT EXISTS ulid;

-- Create the table for clients
DROP TABLE IF EXISTS clients CASCADE;
CREATE TABLE clients (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
id SMALLINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
name text NOT NULL,
uuid UUID DEFAULT uuid_generate_v4() UNIQUE
);

INSERT INTO clients (id, name, uuid) VALUES (0, 'unknown', '00000000-0000-0000-0000-000000000000');
INSERT INTO clients (id, name, uuid) OVERRIDING SYSTEM VALUE VALUES (0, 'unknown', '00000000-0000-0000-0000-000000000000');

-- Create the table for the tokens
DROP TABLE IF EXISTS tokens CASCADE;
CREATE TABLE tokens (
id ulid NOT NULL DEFAULT gen_ulid() PRIMARY KEY,
client_id INTEGER DEFAULT 0 REFERENCES clients(id)
client_id SMALLINT DEFAULT 0 REFERENCES clients(id)
);

-- Create the table for the metadata
Expand All @@ -26,7 +29,7 @@ CREATE TABLE metadata (
id ulid PRIMARY KEY REFERENCES tokens(id) ON DELETE CASCADE,
ip_address INET,
country CHAR(2),
user_agent VARCHAR(255),
user_agent text,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

Expand Down

0 comments on commit 7b69cfa

Please sign in to comment.