Skip to content

Commit

Permalink
fix genres migration to adjust old import tables
Browse files Browse the repository at this point in the history
  • Loading branch information
lucat1 committed Dec 9, 2023
1 parent aa67461 commit e8d14ab
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions migration/src/m20231126_000002_genres.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use sea_orm::prelude::*;
use sea_orm::{DatabaseBackend, Schema, Statement};
use sea_orm::{ColumnTrait, DatabaseBackend, Schema, Statement};
use sea_orm_migration::prelude::*;
use std::collections::HashMap;
use uuid::Uuid;

use entity::{
conflict::{GENRE_CONFLICT, GENRE_RELEASE_CONFLICT, GENRE_TRACK_CONFLICT},
GenreColumn, GenreEntity, GenreReleaseColumn, GenreReleaseEntity, GenreTrackColumn,
GenreTrackEntity, ReleaseEntity, TrackEntity,
GenreTrackEntity, ImportColumn, ImportEntity, ReleaseEntity, TrackEntity,
};

#[derive(DeriveMigrationName)]
Expand Down Expand Up @@ -93,6 +93,24 @@ impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let backend = manager.get_database_backend();
let schema = Schema::new(backend);
let mut binding = Table::alter();

let table = binding
.table(ImportEntity)
.add_column_if_not_exists(&mut sea_query::table::ColumnDef::new_with_type(
ImportColumn::Genres,
ImportColumn::Genres.def().get_column_type().clone(),
))
.add_column_if_not_exists(&mut sea_query::table::ColumnDef::new_with_type(
ImportColumn::TrackGenres,
ImportColumn::TrackGenres.def().get_column_type().clone(),
))
.add_column_if_not_exists(&mut sea_query::table::ColumnDef::new_with_type(
ImportColumn::ReleaseGenres,
ImportColumn::ReleaseGenres.def().get_column_type().clone(),
));
manager.alter_table(table.to_owned()).await?;

manager
.exec_stmt(schema.create_table_from_entity(GenreEntity))
.await?;
Expand Down

0 comments on commit e8d14ab

Please sign in to comment.