From 3fee57891dd9aa05dadea1b1f5fc5dc6b479b231 Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 29 May 2024 21:37:09 +0200 Subject: [PATCH] feat: add unique index on relations --- ...240529_000001_add_relation_unique_index.rs | 31 +++++++++++++++++++ src/migrations/mod.rs | 2 ++ 2 files changed, 33 insertions(+) create mode 100644 src/migrations/m20240529_000001_add_relation_unique_index.rs diff --git a/src/migrations/m20240529_000001_add_relation_unique_index.rs b/src/migrations/m20240529_000001_add_relation_unique_index.rs new file mode 100644 index 00000000..c3c253fc --- /dev/null +++ b/src/migrations/m20240529_000001_add_relation_unique_index.rs @@ -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(()) + } +} diff --git a/src/migrations/mod.rs b/src/migrations/mod.rs index f97d3ec9..a8831e1b 100644 --- a/src/migrations/mod.rs +++ b/src/migrations/mod.rs @@ -5,6 +5,7 @@ mod m20240524_000002_create_relations_likes_shares; mod m20240524_000003_create_users_auth_and_config; mod m20240524_000004_create_addressing_deliveries; mod m20240524_000005_create_attachments_tags_mentions; +mod m20240529_000001_add_relation_unique_index; pub struct Migrator; @@ -17,6 +18,7 @@ impl MigratorTrait for Migrator { Box::new(m20240524_000003_create_users_auth_and_config::Migration), Box::new(m20240524_000004_create_addressing_deliveries::Migration), Box::new(m20240524_000005_create_attachments_tags_mentions::Migration), + Box::new(m20240529_000001_add_relation_unique_index::Migration), ] } }