forked from trustification/trustify
-
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 branch 'main' of https://github.com/trustification/trustify
- Loading branch information
Showing
50 changed files
with
1,442 additions
and
131 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
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> { | ||
manager | ||
.alter_table( | ||
Table::alter() | ||
.table(Advisory::Table) | ||
.add_column(ColumnDef::new(Advisory::Version).string().null().to_owned()) | ||
.add_column( | ||
ColumnDef::new(Advisory::Deprecated) | ||
.boolean() | ||
.default(false) | ||
.to_owned(), | ||
) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
manager | ||
.create_index( | ||
Index::create() | ||
.table(Advisory::Table) | ||
.name(Indexes::ByIdAndVersion.to_string()) | ||
.col(Advisory::Identifier) | ||
.col(Advisory::Version) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
// create the function, for updating the state | ||
|
||
manager | ||
.get_connection() | ||
.execute_unprepared(include_str!( | ||
"m0000650_alter_advisory_tracking/update_deprecated_advisory.sql" | ||
)) | ||
.await | ||
.map(|_| ())?; | ||
|
||
// create the state of the "deprecated" column, running the function once | ||
manager | ||
.get_connection() | ||
.execute_unprepared(r#"SELECT update_deprecated_advisory();"#) | ||
.await?; | ||
|
||
manager | ||
.get_connection() | ||
.execute_unprepared( | ||
r#" | ||
CREATE INDEX not_deprecated ON advisory (id) | ||
WHERE deprecated is not true; | ||
"#, | ||
) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.get_connection() | ||
.execute_unprepared(r#"DROP FUNCTION update_deprecated_advisory"#) | ||
.await?; | ||
|
||
manager | ||
.drop_index( | ||
Index::drop() | ||
.table(Advisory::Table) | ||
.name(Indexes::NotDeprecated.to_string()) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
manager | ||
.drop_index( | ||
Index::drop() | ||
.table(Advisory::Table) | ||
.name(Indexes::ByIdAndVersion.to_string()) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
manager | ||
.alter_table( | ||
Table::alter() | ||
.table(Advisory::Table) | ||
.drop_column(Advisory::Deprecated) | ||
.drop_column(Advisory::Version) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum Advisory { | ||
Table, | ||
Identifier, | ||
Version, | ||
Deprecated, | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum Indexes { | ||
ByIdAndVersion, | ||
NotDeprecated, | ||
} |
13 changes: 13 additions & 0 deletions
13
migration/src/m0000650_alter_advisory_tracking/update_deprecated_advisory.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,13 @@ | ||
CREATE OR REPLACE FUNCTION update_deprecated_advisory(identifier_input TEXT DEFAULT NULL) | ||
RETURNS VOID AS | ||
$$ | ||
BEGIN | ||
UPDATE advisory | ||
SET deprecated = (id != (SELECT id | ||
FROM advisory a | ||
WHERE a.identifier = COALESCE(identifier_input, advisory.identifier) | ||
ORDER BY a.modified DESC | ||
LIMIT 1)) | ||
WHERE identifier = COALESCE(identifier_input, identifier); | ||
END; | ||
$$ LANGUAGE plpgsql; |
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
Oops, something went wrong.