Compare commits
2 Commits
fcb3a18416
...
0565328ea8
| Author | SHA1 | Date |
|---|---|---|
|
|
0565328ea8 | |
|
|
2f7c4c34f7 |
|
|
@ -0,0 +1,98 @@
|
||||||
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
|
pub struct Migration;
|
||||||
|
|
||||||
|
impl MigrationName for Migration {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"m_20230813_000001_create_dist_tables"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl MigrationTrait for Migration {
|
||||||
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.create_table(
|
||||||
|
Table::create()
|
||||||
|
.table(Distro::Table)
|
||||||
|
.col(
|
||||||
|
ColumnDef::new(Distro::Id)
|
||||||
|
.integer()
|
||||||
|
.not_null()
|
||||||
|
.auto_increment()
|
||||||
|
.primary_key(),
|
||||||
|
)
|
||||||
|
.col(
|
||||||
|
ColumnDef::new(Distro::Slug)
|
||||||
|
.string_len(255)
|
||||||
|
.not_null()
|
||||||
|
.unique_key(),
|
||||||
|
)
|
||||||
|
.col(
|
||||||
|
ColumnDef::new(Distro::Name)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
.unique_key(),
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(Distro::Description).string())
|
||||||
|
.col(ColumnDef::new(Distro::Url).string())
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
manager
|
||||||
|
.create_table(
|
||||||
|
Table::create()
|
||||||
|
.table(Repo::Table)
|
||||||
|
.col(
|
||||||
|
ColumnDef::new(Repo::Id)
|
||||||
|
.integer()
|
||||||
|
.not_null()
|
||||||
|
.auto_increment()
|
||||||
|
.primary_key(),
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(Repo::DistroId).integer().not_null())
|
||||||
|
.col(ColumnDef::new(Repo::Name).string().not_null().unique_key())
|
||||||
|
.col(ColumnDef::new(Repo::Description).string())
|
||||||
|
.foreign_key(
|
||||||
|
ForeignKey::create()
|
||||||
|
.name("fk-repo-distro_id")
|
||||||
|
.from(Repo::Table, Repo::DistroId)
|
||||||
|
.to(Distro::Table, Distro::Id)
|
||||||
|
.on_delete(ForeignKeyAction::Cascade),
|
||||||
|
)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define how to rollback this migration: Drop the Bakery table.
|
||||||
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.drop_table(Table::drop().table(Repo::Table).to_owned())
|
||||||
|
.await?;
|
||||||
|
manager
|
||||||
|
.drop_table(Table::drop().table(Distro::Table).to_owned())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Iden)]
|
||||||
|
pub enum Distro {
|
||||||
|
Table,
|
||||||
|
Id,
|
||||||
|
Slug,
|
||||||
|
Name,
|
||||||
|
Description,
|
||||||
|
Url,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Iden)]
|
||||||
|
pub enum Repo {
|
||||||
|
Table,
|
||||||
|
Id,
|
||||||
|
DistroId,
|
||||||
|
Name,
|
||||||
|
Description,
|
||||||
|
}
|
||||||
|
|
@ -4,29 +4,13 @@ pub struct Migration;
|
||||||
|
|
||||||
impl MigrationName for Migration {
|
impl MigrationName for Migration {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"m_20230730_000001_create_repo_tables"
|
"m_20230813_000002_create_package_tables"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigrationTrait for Migration {
|
impl MigrationTrait for Migration {
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(Repo::Table)
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(Repo::Id)
|
|
||||||
.integer()
|
|
||||||
.not_null()
|
|
||||||
.auto_increment()
|
|
||||||
.primary_key(),
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Repo::Name).string().not_null().unique_key())
|
|
||||||
.col(ColumnDef::new(Repo::Description).string())
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
manager
|
manager
|
||||||
.create_table(
|
.create_table(
|
||||||
Table::create()
|
Table::create()
|
||||||
|
|
@ -292,9 +276,6 @@ impl MigrationTrait for Migration {
|
||||||
.await?;
|
.await?;
|
||||||
manager
|
manager
|
||||||
.drop_table(Table::drop().table(Package::Table).to_owned())
|
.drop_table(Table::drop().table(Package::Table).to_owned())
|
||||||
.await?;
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(Repo::Table).to_owned())
|
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -303,8 +284,6 @@ impl MigrationTrait for Migration {
|
||||||
pub enum Repo {
|
pub enum Repo {
|
||||||
Table,
|
Table,
|
||||||
Id,
|
Id,
|
||||||
Name,
|
|
||||||
Description,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
|
mod m20230813_000001_create_dist_tables;
|
||||||
|
mod m20230813_000002_create_package_tables;
|
||||||
|
|
||||||
use sea_orm_migration::prelude::*;
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
|
|
||||||
mod m20230730_000001_create_repo_tables;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigratorTrait for Migrator {
|
impl MigratorTrait for Migrator {
|
||||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||||
vec![Box::new(m20230730_000001_create_repo_tables::Migration)]
|
vec![
|
||||||
|
Box::new(m20230813_000001_create_dist_tables::Migration),
|
||||||
|
Box::new(m20230813_000002_create_package_tables::Migration),
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue