-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
View for storing monitored entities (#1003)
* build(migrations): add dependency on `common-models` * Revert "build(migrations): add dependency on `common-models`" This reverts commit 575962e. * feat(migrations): create view for monitored entities * feat(models): create entity for new view * feat(migrations): add new column called `origin_collection_id` * chore(models): add new column to entity * feat(services/miscellaneous): use new table for querying * ci: Run CI * fix(database): do not make column nullable * chore(migrations): remove useless semi-comma * feat(frontend): focus on re-ordered exercise * build(backend): upgrade basic versions
- Loading branch information
Showing
11 changed files
with
484 additions
and
178 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
36 changes: 36 additions & 0 deletions
36
crates/migrations/src/m20240904_create_monitored_entity.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,36 @@ | ||
use indoc::indoc; | ||
use sea_orm_migration::prelude::*; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
pub static MONITORED_ENTITY_VIEW_CREATION_SQL: &str = indoc! { r#" | ||
CREATE VIEW monitored_entity AS | ||
SELECT | ||
ute."user_id", | ||
cte."entity_id", | ||
cte."entity_lot", | ||
cte."collection_id" AS "origin_collection_id" | ||
FROM | ||
"collection_to_entity" cte | ||
JOIN | ||
"collection" c ON cte."collection_id" = c."id" | ||
JOIN | ||
"user_to_entity" ute ON cte."collection_id" = ute."collection_id" | ||
WHERE | ||
c."name" = 'Monitoring' | ||
"# }; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
let db = manager.get_connection(); | ||
db.execute_unprepared(MONITORED_ENTITY_VIEW_CREATION_SQL) | ||
.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.2 | ||
|
||
use enums::EntityLot; | ||
use sea_orm::entity::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] | ||
#[sea_orm(table_name = "monitored_entity")] | ||
pub struct Model { | ||
#[sea_orm(primary_key, auto_increment = false)] | ||
pub user_id: String, | ||
#[sea_orm(primary_key, auto_increment = false)] | ||
pub entity_id: String, | ||
#[sea_orm(primary_key, auto_increment = false)] | ||
pub entity_lot: EntityLot, | ||
pub origin_collection_id: String, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation {} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
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