-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
196 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
pub use sea_orm_migration::prelude::*; | ||
|
||
mod m20231207_000001_create_table; | ||
mod m20240821_000001_create_tag; | ||
|
||
pub struct Migrator; | ||
|
||
#[async_trait::async_trait] | ||
impl MigratorTrait for Migrator { | ||
fn migrations() -> Vec<Box<dyn MigrationTrait>> { | ||
vec![Box::new(m20231207_000001_create_table::Migration)] | ||
vec![Box::new(m20231207_000001_create_table::Migration), Box::new(m20240821_000001_create_tag::Migration)] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use crate::m20231207_000001_create_table::Problem; | ||
use sea_orm::{DatabaseBackend, Statement}; | ||
use sea_orm_migration::prelude::*; | ||
|
||
#[derive(Iden)] | ||
enum Tag { | ||
Table, | ||
Id, | ||
Name, | ||
} | ||
|
||
#[derive(Iden)] | ||
enum TagProblem { | ||
Table, | ||
Id, | ||
ProblemId, | ||
TagId, | ||
} | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.create_table( | ||
Table::create() | ||
.table(Tag::Table) | ||
.if_not_exists() | ||
.col( | ||
ColumnDef::new(Tag::Id) | ||
.integer() | ||
.not_null() | ||
.auto_increment() | ||
.primary_key(), | ||
) | ||
.col(ColumnDef::new(Tag::Name).string().unique_key().not_null()) | ||
.to_owned(), | ||
) | ||
.await?; | ||
manager | ||
.create_index( | ||
Index::create() | ||
.name("idx-tag-name".to_lowercase()) | ||
.table(Tag::Table) | ||
.col(Tag::Name) | ||
.to_owned(), | ||
) | ||
.await?; | ||
manager | ||
.create_table( | ||
Table::create() | ||
.table(TagProblem::Table) | ||
.if_not_exists() | ||
.col( | ||
ColumnDef::new(TagProblem::Id) | ||
.integer() | ||
.not_null() | ||
.auto_increment() | ||
.primary_key(), | ||
) | ||
.col(ColumnDef::new(TagProblem::ProblemId).integer().not_null()) | ||
.foreign_key( | ||
ForeignKey::create() | ||
.name("fk-pivot-problem-tag") | ||
.from(TagProblem::Table, TagProblem::ProblemId) | ||
.to(Problem::Table, Problem::Id), | ||
) | ||
.col(ColumnDef::new(TagProblem::TagId).integer().not_null()) | ||
.foreign_key( | ||
ForeignKey::create() | ||
.name("fk-pivot-tag-problem") | ||
.from(TagProblem::Table, TagProblem::TagId) | ||
.to(Tag::Table, Tag::Id), | ||
) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.