feat: added repo mirrors migration
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint Pipeline failed

This commit is contained in:
Jef Roosens 2024-07-18 22:40:31 +02:00
parent f761e3b36d
commit cbb04a40e0
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
9 changed files with 135 additions and 1 deletions

View file

@ -1,12 +1,16 @@
pub use sea_orm_migration::prelude::*;
mod m20230730_000001_create_repo_tables;
mod m20240716_184104_repo_mirrors;
pub struct Migrator;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![Box::new(m20230730_000001_create_repo_tables::Migration)]
vec![
Box::new(m20230730_000001_create_repo_tables::Migration),
Box::new(m20240716_184104_repo_mirrors::Migration),
]
}
}

View file

@ -0,0 +1,74 @@
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(Repo::Table)
.add_column(
ColumnDef::new(Repo::Type)
.integer()
.not_null()
.default(0),
)
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
.table(RepoMirror::Table)
.col(
ColumnDef::new(RepoMirror::Id)
.integer()
.not_null()
.auto_increment()
.primary_key()
)
.col(ColumnDef::new(RepoMirror::RepoId).integer().not_null())
.col(ColumnDef::new(RepoMirror::Url).string().not_null())
.foreign_key(
ForeignKey::create()
.name("fk-repo_mirror-repo-id")
.from(RepoMirror::Table, RepoMirror::RepoId)
.to(Repo::Table, Repo::Id)
.on_delete(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(RepoMirror::Table).to_owned())
.await?;
manager
.alter_table(Table::alter().drop_column(Repo::Type).to_owned())
.await?;
Ok(())
}
}
#[derive(Iden)]
pub enum Repo {
Table,
Id,
Type,
}
#[derive(Iden)]
pub enum RepoMirror {
Table,
Id,
RepoId,
Url,
}