forked from alemi/upub
feat: add unique index on relations
This commit is contained in:
parent
69cff08b5b
commit
3fee57891d
2 changed files with 33 additions and 0 deletions
31
src/migrations/m20240529_000001_add_relation_unique_index.rs
Normal file
31
src/migrations/m20240529_000001_add_relation_unique_index.rs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
|
use super::m20240524_000002_create_relations_likes_shares::Relations;
|
||||||
|
|
||||||
|
#[derive(DeriveMigrationName)]
|
||||||
|
pub struct Migration;
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl MigrationTrait for Migration {
|
||||||
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.create_index(
|
||||||
|
Index::create()
|
||||||
|
.unique()
|
||||||
|
.name("index-relations-follower-following")
|
||||||
|
.table(Relations::Table)
|
||||||
|
.col(Relations::Following)
|
||||||
|
.col(Relations::Follower)
|
||||||
|
.to_owned()
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.drop_index(Index::drop().name("index-relations-follower-following").table(Relations::Table).to_owned())
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ mod m20240524_000002_create_relations_likes_shares;
|
||||||
mod m20240524_000003_create_users_auth_and_config;
|
mod m20240524_000003_create_users_auth_and_config;
|
||||||
mod m20240524_000004_create_addressing_deliveries;
|
mod m20240524_000004_create_addressing_deliveries;
|
||||||
mod m20240524_000005_create_attachments_tags_mentions;
|
mod m20240524_000005_create_attachments_tags_mentions;
|
||||||
|
mod m20240529_000001_add_relation_unique_index;
|
||||||
|
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
|
|
||||||
|
@ -17,6 +18,7 @@ impl MigratorTrait for Migrator {
|
||||||
Box::new(m20240524_000003_create_users_auth_and_config::Migration),
|
Box::new(m20240524_000003_create_users_auth_and_config::Migration),
|
||||||
Box::new(m20240524_000004_create_addressing_deliveries::Migration),
|
Box::new(m20240524_000004_create_addressing_deliveries::Migration),
|
||||||
Box::new(m20240524_000005_create_attachments_tags_mentions::Migration),
|
Box::new(m20240524_000005_create_attachments_tags_mentions::Migration),
|
||||||
|
Box::new(m20240529_000001_add_relation_unique_index::Migration),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue