Skip to content

Commit

Permalink
Initial sql schema drafts (#49)
Browse files Browse the repository at this point in the history
## Summary

Description:
Added SQL schemas to support the volunteer management system, including
tables for:

Event Log: Tracks changes to profiles, teams, and roles.
Profile: Stores volunteer details like name, email, and description.
Team: Stores team information, including name and description.
Role: Defines roles for profiles within teams, with foreign key
relationships to profile and team tables.
This setup ensures data integrity and supports tracking of
volunteer-related events.

## Tests


## Additional information

#48

Previous work: #21 

Closes: #43
  • Loading branch information
kbventures authored Dec 17, 2024
2 parents ebfb816 + a710017 commit 587218c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/db/drop_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Drop existing tables if they exist
DROP TABLE IF EXISTS event_log;
DROP TABLE IF EXISTS profile;
DROP TABLE IF EXISTS role;
DROP TABLE IF EXISTS team;
12 changes: 12 additions & 0 deletions src/db/event_log.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Event Log Schema
CREATE TABLE IF NOT EXISTS event_log (
id TEXT PRIMARY KEY NOT NULL UNIQUE COLLATE BINARY, -- UUID stored as TEXT
schemaVersion INTEGER NOT NULL,
subject TEXT NOT NULL UNIQUE COLLATE BINARY, -- UUID stored as TEXT (could be user or entity performing the action)
subjectSource TEXT NOT NULL DEFAULT 'profile' CHECK("subjectSource" IN ('profile', 'team', 'role', 'special'))
verb TEXT NOT NULL, -- Action (e.g., 'join', 'leave', 'assigned to')
object TEXT NOT NULL UNIQUE COLLATE BINARY, -- UUID stored as TEXT (the affected entity, e.g., profile, team)
objectSource TEXT NOT NULL DEFAULT 'special' CHECK("objectSource" IN ('profile', 'team', 'role', 'special'))
happenedAt TEXT NOT NULL, -- The time the event occurred
insertedAt TEXT NOT NULL, -- When the event log was inserted
);
11 changes: 11 additions & 0 deletions src/db/profile.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Volunteer Profile Schema
CREATE TABLE IF NOT EXISTS profile (
id TEXT PRIMARY KEY NOT NULL UNIQUE COLLATE BINARY, -- UUID stored as TEXT
email TEXT NOT NULL UNIQUE,
schemaVersion INTEGER NOT NULL,
name TEXT NOT NULL,
description TEXT,
happenedAt TEXT NOT NULL,
insertedAt TEXT NOT NULL,
links TEXT -- Store markup for social links
);
13 changes: 13 additions & 0 deletions src/db/role.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Role Schema
CREATE TABLE IF NOT EXISTS role (
id TEXT PRIMARY KEY NOT NULL UNIQUE COLLATE BINARY, -- UUID stored as TEXT
schemaVersion INTEGER NOT NULL,
role TEXT NOT NULL,
description TEXT,
teamId TEXT NOT NULL UNIQUE COLLATE BINARY, -- UUID stored as TEXT
profileId TEXT NOT NULL UNIQUE COLLATE BINARY, -- UUID stored as TEXT
happenedAt TEXT NOT NULL,
insertedAt TEXT NOT NULL,
FOREIGN KEY (teamId) REFERENCES team(id),
FOREIGN KEY (profileId) REFERENCES profile(id)
);
9 changes: 9 additions & 0 deletions src/db/team.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Team Schema
CREATE TABLE IF NOT EXISTS team (
id TEXT PRIMARY KEY NOT NULL UNIQUE COLLATE BINARY, -- UUID stored as TEXT
schemaVersion INTEGER NOT NULL,
name TEXT NOT NULL,
description TEXT,
happenedAt TEXT NOT NULL,
insertedAt TEXT NOT NULL
);

0 comments on commit 587218c

Please sign in to comment.