Skip to content

Commit

Permalink
fix: have a default empty array
Browse files Browse the repository at this point in the history
Closes #984
  • Loading branch information
ctron committed Nov 8, 2024
1 parent 786aa1b commit d5d9d33
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ mod m0000680_fix_update_deprecated_advisory;
mod m0000690_alter_sbom_details;
mod m0000700_advisory_add_reserved;
mod m0000710_create_user_prefs;
mod m0000720_alter_sbom_fix_null_array;

pub struct Migrator;

Expand Down Expand Up @@ -183,6 +184,7 @@ impl MigratorTrait for Migrator {
Box::new(m0000690_alter_sbom_details::Migration),
Box::new(m0000700_advisory_add_reserved::Migration),
Box::new(m0000710_create_user_prefs::Migration),
Box::new(m0000720_alter_sbom_fix_null_array::Migration),
]
}
}
Expand Down
36 changes: 36 additions & 0 deletions migration/src/m0000720_alter_sbom_fix_null_array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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(Sbom::Table)
.modify_column(
ColumnDef::new(Sbom::DataLicenses)
.array(ColumnType::Text)
.not_null()
.default(Value::Array(ArrayType::String, None))
.to_owned(),
)
.to_owned(),
)
.await?;

Ok(())
}

async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
Ok(())
}
}

#[derive(DeriveIden)]
enum Sbom {
Table,
DataLicenses,
}

0 comments on commit d5d9d33

Please sign in to comment.