-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix circular deps and add purl migration for get_purl psql func
- Loading branch information
1 parent
0e3a828
commit 793c426
Showing
4 changed files
with
65 additions
and
4 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
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,26 @@ | ||
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 | ||
.get_connection() | ||
.execute_unprepared(include_str!("m0000740_ensure_get_purl_fns/get_purl.sql")) | ||
.await | ||
.map(|_| ())?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.get_connection() | ||
.execute_unprepared(include_str!("m0000590_get_purl_fns/get_purl.sql")) | ||
.await?; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
CREATE OR REPLACE FUNCTION get_purl(qualified_purl_id UUID) | ||
RETURNS TEXT AS $$ | ||
DECLARE | ||
result TEXT; | ||
BEGIN | ||
SELECT | ||
COALESCE( | ||
'pkg:' || bp.type || | ||
'/' || COALESCE(bp.namespace, '') || '/' || | ||
bp.name || | ||
'@' || vp.version || | ||
CASE | ||
WHEN qp.qualifiers IS NOT NULL AND qp.qualifiers <> '{}'::jsonb THEN | ||
'?' || ( | ||
SELECT string_agg(key || '=' || value, '&') | ||
FROM jsonb_each_text(qp.qualifiers) | ||
) | ||
ELSE | ||
'' | ||
END, | ||
qualified_purl_id::text | ||
) | ||
INTO result | ||
FROM | ||
qualified_purl qp | ||
LEFT JOIN versioned_purl vp ON vp.id = qp.versioned_purl_id | ||
LEFT JOIN base_purl bp ON bp.id = vp.base_purl_id | ||
WHERE | ||
qp.id = qualified_purl_id; | ||
|
||
RETURN result; | ||
END; | ||
$$ LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE; |
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