-
Notifications
You must be signed in to change notification settings - Fork 18
Add D1 migrations and migrate.sh for notifications tables #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/bin/bash | ||
| set -euo pipefail | ||
| echo "Applying D1 migrations to education_db..." | ||
| npx --yes wrangler d1 migrations apply education_db --remote | ||
| echo "Done." | ||
|
Ananya44444 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| -- Migration 0001: Initial schema | ||
|
|
||
| CREATE TABLE IF NOT EXISTS users ( | ||
| id TEXT PRIMARY KEY, | ||
| username_hash TEXT NOT NULL UNIQUE, | ||
| email_hash TEXT NOT NULL UNIQUE, | ||
| name TEXT NOT NULL, | ||
| username TEXT NOT NULL, | ||
| email TEXT NOT NULL, | ||
| password_hash TEXT NOT NULL, | ||
| role TEXT NOT NULL, | ||
| created_at TEXT NOT NULL DEFAULT (datetime('now')) | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS activities ( | ||
| id TEXT PRIMARY KEY, | ||
| title TEXT NOT NULL, | ||
| description TEXT, | ||
| type TEXT NOT NULL DEFAULT 'course', | ||
| format TEXT NOT NULL DEFAULT 'self_paced', | ||
| schedule_type TEXT NOT NULL DEFAULT 'ongoing', | ||
| host_id TEXT NOT NULL, | ||
| created_at TEXT NOT NULL DEFAULT (datetime('now')), | ||
| FOREIGN KEY (host_id) REFERENCES users(id) | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS sessions ( | ||
| id TEXT PRIMARY KEY, | ||
| activity_id TEXT NOT NULL, | ||
| title TEXT, | ||
| description TEXT, | ||
| start_time TEXT, | ||
| end_time TEXT, | ||
| location TEXT, | ||
| created_at TEXT NOT NULL DEFAULT (datetime('now')), | ||
| FOREIGN KEY (activity_id) REFERENCES activities(id) | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS enrollments ( | ||
| id TEXT PRIMARY KEY, | ||
| activity_id TEXT NOT NULL, | ||
| user_id TEXT NOT NULL, | ||
| role TEXT NOT NULL DEFAULT 'participant', | ||
| status TEXT NOT NULL DEFAULT 'active', | ||
| created_at TEXT NOT NULL DEFAULT (datetime('now')), | ||
| UNIQUE (activity_id, user_id), | ||
| FOREIGN KEY (activity_id) REFERENCES activities(id), | ||
| FOREIGN KEY (user_id) REFERENCES users(id) | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS session_attendance ( | ||
| id TEXT PRIMARY KEY, | ||
| session_id TEXT NOT NULL, | ||
| user_id TEXT NOT NULL, | ||
| status TEXT NOT NULL DEFAULT 'registered', | ||
| created_at TEXT NOT NULL DEFAULT (datetime('now')), | ||
| UNIQUE (session_id, user_id), | ||
| FOREIGN KEY (session_id) REFERENCES sessions(id), | ||
| FOREIGN KEY (user_id) REFERENCES users(id) | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS tags ( | ||
| id TEXT PRIMARY KEY, | ||
| name TEXT UNIQUE NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS activity_tags ( | ||
| activity_id TEXT NOT NULL, | ||
| tag_id TEXT NOT NULL, | ||
| PRIMARY KEY (activity_id, tag_id), | ||
| FOREIGN KEY (activity_id) REFERENCES activities(id), | ||
| FOREIGN KEY (tag_id) REFERENCES tags(id) | ||
| ); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_activities_host ON activities(host_id); | ||
| CREATE INDEX IF NOT EXISTS idx_enrollments_activity ON enrollments(activity_id); | ||
| CREATE INDEX IF NOT EXISTS idx_enrollments_user ON enrollments(user_id); | ||
| CREATE INDEX IF NOT EXISTS idx_sessions_activity ON sessions(activity_id); | ||
| CREATE INDEX IF NOT EXISTS idx_sa_session ON session_attendance(session_id); | ||
| CREATE INDEX IF NOT EXISTS idx_sa_user ON session_attendance(user_id); | ||
| CREATE INDEX IF NOT EXISTS idx_at_activity ON activity_tags(activity_id); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| -- Migration 0002: Add notifications and notification_preferences tables | ||
|
|
||
| CREATE TABLE IF NOT EXISTS notifications ( | ||
| id TEXT PRIMARY KEY, | ||
| user_id TEXT NOT NULL, | ||
| type TEXT NOT NULL, | ||
| title TEXT NOT NULL, | ||
| message TEXT NOT NULL, | ||
| is_read INTEGER NOT NULL DEFAULT 0, | ||
| related_id TEXT, | ||
| created_at TEXT NOT NULL DEFAULT (datetime('now')), | ||
| FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE | ||
| ); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_notif_user ON notifications(user_id); | ||
| CREATE INDEX IF NOT EXISTS idx_notif_unread ON notifications(user_id, is_read); | ||
| CREATE INDEX IF NOT EXISTS idx_notif_created ON notifications(user_id, created_at DESC); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS notification_preferences ( | ||
| user_id TEXT PRIMARY KEY, | ||
| enrollment_notify INTEGER NOT NULL DEFAULT 1, | ||
| session_notify INTEGER NOT NULL DEFAULT 1, | ||
| system_notify INTEGER NOT NULL DEFAULT 1, | ||
| updated_at TEXT NOT NULL DEFAULT (datetime('now')), | ||
| FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE | ||
| ); | ||
|
Ananya44444 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.