From 3db4486eb8306cfcd3964959c4f9b6d1cc20f302 Mon Sep 17 00:00:00 2001 From: yyjeqhc <1772413353@qq.com> Date: Mon, 4 Aug 2025 15:30:00 +0800 Subject: [PATCH] fix: add migration for change orion-server table build --- .../m20250804_151214_alter_builds_end_at.rs | 56 +++++++++++++++++++ jupiter/src/migration/mod.rs | 3 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 jupiter/src/migration/m20250804_151214_alter_builds_end_at.rs diff --git a/jupiter/src/migration/m20250804_151214_alter_builds_end_at.rs b/jupiter/src/migration/m20250804_151214_alter_builds_end_at.rs new file mode 100644 index 000000000..e0cf5e456 --- /dev/null +++ b/jupiter/src/migration/m20250804_151214_alter_builds_end_at.rs @@ -0,0 +1,56 @@ +use sea_orm_migration::{prelude::*, schema::*, sea_orm::DatabaseBackend}; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + let backend = manager.get_database_backend(); + + match backend { + DatabaseBackend::Postgres => { + // ALTER TABLE builds ALTER COLUMN end_at DROP NOT NULL + manager + .alter_table( + Table::alter() + .table(Builds::Table) + .modify_column(timestamp_null(Builds::EndAt).to_owned()) + .to_owned(), + ) + .await?; + } + DatabaseBackend::Sqlite | DatabaseBackend::MySql => {} + } + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + let backend = manager.get_database_backend(); + + match backend { + DatabaseBackend::Postgres => { + // Reverting the change - making end_at NOT NULL again + // Note: This could fail if there are NULL values in the column + manager + .alter_table( + Table::alter() + .table(Builds::Table) + .modify_column(timestamp(Builds::EndAt).to_owned()) + .to_owned(), + ) + .await?; + } + DatabaseBackend::Sqlite | DatabaseBackend::MySql => {} + } + + Ok(()) + } +} + +#[derive(DeriveIden)] +enum Builds { + Table, + EndAt, +} diff --git a/jupiter/src/migration/mod.rs b/jupiter/src/migration/mod.rs index b54b3eb77..7bd5ea4d6 100644 --- a/jupiter/src/migration/mod.rs +++ b/jupiter/src/migration/mod.rs @@ -45,7 +45,7 @@ mod m20250628_025312_add_username_in_conversation; mod m20250702_072055_add_item_assignees; mod m20250710_073119_create_reactions; mod m20250725_103004_add_note; - +mod m20250804_151214_alter_builds_end_at; /// Creates a primary key column definition with big integer type. /// /// # Arguments @@ -78,6 +78,7 @@ impl MigratorTrait for Migrator { Box::new(m20250702_072055_add_item_assignees::Migration), Box::new(m20250710_073119_create_reactions::Migration), Box::new(m20250725_103004_add_note::Migration), + Box::new(m20250804_151214_alter_builds_end_at::Migration), ] } }