add database schema and update docker-compose for initialization

This commit is contained in:
2026-01-11 14:22:46 +00:00
parent 550bba62f7
commit c12e1f7623
2 changed files with 17 additions and 1 deletions

15
db/sql/01_schema.sql Normal file
View File

@@ -0,0 +1,15 @@
CREATE SCHEMA IF NOT EXISTS ethnograph;
CREATE TABLE IF NOT EXISTS ethnograph.users (
id SERIAL PRIMARY KEY,
username VARCHAR(255) UNIQUE NOT NULL,
created_utc TIMESTAMP NOT NULL,
karma INTEGER
);
CREATE TABLE IF NOT EXISTS ethnograph.posts (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES ethnograph.users(id),
content TEXT NOT NULL,
created_utc TIMESTAMP NOT NULL
);

View File

@@ -1,7 +1,7 @@
services: services:
postgres: postgres:
image: postgres:16 image: postgres:16
container_name: ethnograph-postgres container_name: ethnograph-db
restart: unless-stopped restart: unless-stopped
environment: environment:
POSTGRES_DB: ethnograph POSTGRES_DB: ethnograph
@@ -11,6 +11,7 @@ services:
- "5432:5432" - "5432:5432"
volumes: volumes:
- pgdata:/var/lib/postgresql/data - pgdata:/var/lib/postgresql/data
- ./db/sql:/docker-entrypoint-initdb.d
volumes: volumes:
pgdata: pgdata: