-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from MathisBurger/feature/scaling
- Loading branch information
Showing
42 changed files
with
691 additions
and
226 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
-- There should be no way back here |
This file contains 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,14 @@ | ||
CREATE TABLE group_members ( | ||
group_id INTEGER NOT NULL, | ||
member_id INTEGER NOT NULL, | ||
PRIMARY KEY (group_id, member_id) | ||
); | ||
|
||
INSERT INTO group_members (group_id, member_id) | ||
SELECT | ||
g.id AS group_id, | ||
unnest(g.members) AS member_id | ||
FROM | ||
groups g; | ||
|
||
ALTER TABLE groups DROP COLUMN members; |
This file contains 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 @@ | ||
-- This file should undo anything in `up.sql` |
This file contains 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 @@ | ||
ALTER TABLE group_members | ||
ADD CONSTRAINT fk_group_id | ||
FOREIGN KEY (group_id) | ||
REFERENCES groups(id) | ||
ON DELETE CASCADE; |
1 change: 1 addition & 0 deletions
1
tasky/migrations/2024-11-19-174343_scaling_assignments/down.sql
This file contains 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 @@ | ||
-- This file should undo anything in `up.sql` |
14 changes: 14 additions & 0 deletions
14
tasky/migrations/2024-11-19-174343_scaling_assignments/up.sql
This file contains 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,14 @@ | ||
CREATE TABLE assignment_completions ( | ||
assignment_id INTEGER REFERENCES assignments(id) ON DELETE CASCADE, | ||
member_id INTEGER NOT NULL, | ||
PRIMARY KEY (assignment_Id, member_id) | ||
); | ||
|
||
INSERT INTO assignment_completions (assignment_id, member_id) | ||
SELECT | ||
a.id AS assignment_id, | ||
unnest(a.completed_by) AS member_id | ||
FROM | ||
assignments a; | ||
|
||
ALTER TABLE assignments DROP COLUMN completed_by; |
1 change: 1 addition & 0 deletions
1
tasky/migrations/2024-11-19-211502_scalable_notifications/down.sql
This file contains 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 @@ | ||
-- This file should undo anything in `up.sql` |
14 changes: 14 additions & 0 deletions
14
tasky/migrations/2024-11-19-211502_scalable_notifications/up.sql
This file contains 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,14 @@ | ||
CREATE TABLE notification_targets ( | ||
notification_id INTEGER NOT NULL REFERENCES notifications(id), | ||
user_id INTEGER NOT NULL, | ||
PRIMARY KEY (notification_id, user_id) | ||
); | ||
|
||
INSERT INTO notification_targets (notification_id, user_id) | ||
SELECT | ||
n.id AS notification_id, | ||
unnest(n.targeted_users) AS user_id | ||
FROM | ||
notifications n; | ||
|
||
ALTER TABLE notifications DROP COLUMN targeted_users; |
This file contains 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
This file contains 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,58 @@ | ||
use diesel::prelude::*; | ||
use diesel::{ | ||
deserialize::Queryable, prelude::Insertable, BoolExpressionMethods, ExpressionMethods, | ||
QueryDsl, Selectable, | ||
}; | ||
|
||
use crate::schema::assignment_completions; | ||
|
||
use super::{Paginate, PaginatedModel, DB}; | ||
|
||
#[derive(Queryable, Selectable, Clone, Insertable)] | ||
#[diesel(primary_key(assignment_id, member_id))] | ||
#[diesel(table_name = assignment_completions)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
pub struct AssignmentCompletion { | ||
pub assignment_id: i32, | ||
pub member_id: i32, | ||
} | ||
|
||
pub struct AssignmentCompletionRepository; | ||
|
||
impl AssignmentCompletionRepository { | ||
/// Checks whether a user has completed assignment | ||
pub fn is_completed_by(assignment_id: i32, member_id: i32, conn: &mut DB) -> bool { | ||
assignment_completions::dsl::assignment_completions | ||
.filter( | ||
assignment_completions::assignment_id | ||
.eq(assignment_id) | ||
.and(assignment_completions::member_id.eq(member_id)), | ||
) | ||
.first::<AssignmentCompletion>(conn) | ||
.optional() | ||
.expect("Cannot fetch is completed state") | ||
.is_some() | ||
} | ||
|
||
/// Creates a new completion in the system | ||
pub fn create_completion(comp: AssignmentCompletion, conn: &mut DB) { | ||
diesel::insert_into(assignment_completions::table) | ||
.values(comp) | ||
.execute(conn) | ||
.expect("Cannot insert assignment completion"); | ||
} | ||
|
||
/// Gets all completion IDs for assignment | ||
pub fn get_completion_ids_for_assignment( | ||
assignment_id: i32, | ||
page: i64, | ||
conn: &mut DB, | ||
) -> PaginatedModel<i32> { | ||
assignment_completions::dsl::assignment_completions | ||
.filter(assignment_completions::assignment_id.eq(assignment_id)) | ||
.select(assignment_completions::member_id) | ||
.paginate(page) | ||
.load_and_count_pages::<i32>(conn) | ||
.expect("Cannot load completions") | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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.