Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions jupiter/src/migration/m20250804_151214_alter_builds_end_at.rs
Original file line number Diff line number Diff line change
@@ -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 => {}

Copilot AI Aug 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The migration only handles PostgreSQL but ignores SQLite and MySQL backends. This could lead to inconsistent database schemas across different database types. Consider implementing the equivalent ALTER TABLE statements for these backends or add a comment explaining why they're not needed.

Suggested change
DatabaseBackend::Sqlite | DatabaseBackend::MySql => {}
DatabaseBackend::Sqlite => {
// SQLite: ALTER TABLE builds ALTER COLUMN end_at DROP NOT NULL
// SQLite supports altering column nullability via SeaORM migration
manager
.alter_table(
Table::alter()
.table(Builds::Table)
.modify_column(timestamp_null(Builds::EndAt).to_owned())
.to_owned(),
)
.await?;
}
DatabaseBackend::MySql => {
// MySQL: ALTER TABLE builds MODIFY end_at TIMESTAMP NULL
manager
.alter_table(
Table::alter()
.table(Builds::Table)
.modify_column(timestamp_null(Builds::EndAt).to_owned())
.to_owned(),
)
.await?;
}

Copilot uses AI. Check for mistakes.
}

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 => {}

Copilot AI Aug 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The down migration also only handles PostgreSQL. If the up migration is ever extended to support other backends, the down migration should be updated accordingly to maintain consistency.

Suggested change
DatabaseBackend::Sqlite | DatabaseBackend::MySql => {}
DatabaseBackend::Sqlite | DatabaseBackend::MySql => {
// No action required for Sqlite or MySql.
// If the up migration is extended to support these backends,
// update this arm accordingly to maintain consistency.
}

Copilot uses AI. Check for mistakes.
}

Ok(())
}
}

#[derive(DeriveIden)]
enum Builds {
Table,
EndAt,
}
3 changes: 2 additions & 1 deletion jupiter/src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
]
}
}
Expand Down
Loading