-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default "Completed" collection (#815)
* feat(backend): create default done collection * feat(database): create "Done" collection for existing users * fix(database): add on conflict clause * feat(database): add items to done collection * fix(database): do not add shows or podcasts to done * fix(database): remove extra filter clause * chore(backend,database): change name of new default collection * build(backend): bump version * refactor(backend): fns to easily add/remove from col * feat(backend): add entity to "Done" correctly * chore(database): change name of migration * fix(database): filter by state instead of progress * chore(backend): remove completed filter * chore(backend): try to order by seen state * Revert "chore(backend): try to order by seen state" This reverts commit e21b35e.
- Loading branch information
Showing
8 changed files
with
124 additions
and
89 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
30 changes: 30 additions & 0 deletions
30
libs/database/src/migrations/m20240506_0_add_done_collection_for_existing_users.rs
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,30 @@ | ||
use sea_orm_migration::prelude::*; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
let db = manager.get_connection(); | ||
db.execute_unprepared(r#" | ||
DO $$ | ||
DECLARE | ||
aUser RECORD; | ||
BEGIN | ||
FOR aUser IN SELECT id FROM "user" | ||
LOOP | ||
INSERT INTO collection (name, description, user_id, visibility, created_on, last_updated_on) | ||
VALUES ('Completed', 'Media items that I have completed.', aUser.id, 'PR', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) | ||
ON CONFLICT DO NOTHING; | ||
END LOOP; | ||
END $$; | ||
"#) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> { | ||
Ok(()) | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...database/src/migrations/m20240506_1_add_entities_to_done_collection_for_existing_users.rs
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,44 @@ | ||
use sea_orm_migration::prelude::*; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
let db = manager.get_connection(); | ||
db.execute_unprepared( | ||
r#" | ||
DO $$ | ||
DECLARE | ||
user_rec RECORD; | ||
seen_rec RECORD; | ||
done_collection_id INTEGER; | ||
BEGIN | ||
FOR user_rec IN SELECT id FROM "user" | ||
LOOP | ||
SELECT id INTO done_collection_id FROM collection | ||
WHERE user_id = user_rec.id AND name = 'Completed' LIMIT 1; | ||
FOR seen_rec IN ( | ||
SELECT metadata_id FROM seen s | ||
JOIN metadata m ON s.metadata_id = m.id | ||
WHERE s.user_id = user_rec.id AND s.state = 'CO' | ||
) | ||
LOOP | ||
INSERT INTO collection_to_entity (collection_id, metadata_id) | ||
VALUES (done_collection_id, seen_rec.metadata_id) | ||
ON CONFLICT DO NOTHING; | ||
END LOOP; | ||
END LOOP; | ||
END$$; | ||
"#, | ||
) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> { | ||
Ok(()) | ||
} | ||
} |
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