From 4e50cb34c0932f324c1e4e702d19f7a9e88a8f75 Mon Sep 17 00:00:00 2001 From: Awiteb Date: Thu, 18 Jul 2024 11:07:50 +0300 Subject: [PATCH] fix: Create the index after the table Signed-off-by: Awiteb --- .../create_incoming_chat_requests_table.rs | 24 ++++++++--------- .../create_outgoing_chat_requests_table.rs | 26 +++++++++---------- .../src/create_users_status.rs | 25 +++++++++--------- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/crates/oxidetalis_migrations/src/create_incoming_chat_requests_table.rs b/crates/oxidetalis_migrations/src/create_incoming_chat_requests_table.rs index a2bab90..51113e0 100644 --- a/crates/oxidetalis_migrations/src/create_incoming_chat_requests_table.rs +++ b/crates/oxidetalis_migrations/src/create_incoming_chat_requests_table.rs @@ -29,18 +29,6 @@ pub struct Migration; #[async_trait::async_trait] impl MigrationTrait for Migration { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .create_index( - Index::create() - .if_not_exists() - .name("sep_request") - .table(InChatRequests::Table) - .col(InChatRequests::RecipientId) - .col(InChatRequests::Sender) - .unique() - .to_owned(), - ) - .await?; manager .create_table( Table::create() @@ -74,6 +62,18 @@ impl MigrationTrait for Migration { ) .to_owned(), ) + .await?; + manager + .create_index( + Index::create() + .if_not_exists() + .name("sep_request") + .table(InChatRequests::Table) + .col(InChatRequests::RecipientId) + .col(InChatRequests::Sender) + .unique() + .to_owned(), + ) .await } } diff --git a/crates/oxidetalis_migrations/src/create_outgoing_chat_requests_table.rs b/crates/oxidetalis_migrations/src/create_outgoing_chat_requests_table.rs index 8ef6161..4b03e99 100644 --- a/crates/oxidetalis_migrations/src/create_outgoing_chat_requests_table.rs +++ b/crates/oxidetalis_migrations/src/create_outgoing_chat_requests_table.rs @@ -29,19 +29,6 @@ pub struct Migration; #[async_trait::async_trait] impl MigrationTrait for Migration { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .create_index( - Index::create() - .if_not_exists() - .name("sep_request") - .table(OutChatRequests::Table) - .col(OutChatRequests::SenderId) - .col(OutChatRequests::Recipient) - .unique() - .to_owned(), - ) - .await?; - manager .create_table( Table::create() @@ -79,6 +66,19 @@ impl MigrationTrait for Migration { ) .to_owned(), ) + .await?; + + manager + .create_index( + Index::create() + .if_not_exists() + .name("sep_request") + .table(OutChatRequests::Table) + .col(OutChatRequests::SenderId) + .col(OutChatRequests::Recipient) + .unique() + .to_owned(), + ) .await } } diff --git a/crates/oxidetalis_migrations/src/create_users_status.rs b/crates/oxidetalis_migrations/src/create_users_status.rs index dd7aa59..6f3b571 100644 --- a/crates/oxidetalis_migrations/src/create_users_status.rs +++ b/crates/oxidetalis_migrations/src/create_users_status.rs @@ -40,18 +40,6 @@ impl MigrationTrait for Migration { .to_owned(), ) .await?; - manager - .create_index( - Index::create() - .if_not_exists() - .name("sep_status") - .table(UsersStatus::Table) - .col(UsersStatus::UserId) - .col(UsersStatus::Target) - .unique() - .to_owned(), - ) - .await?; manager .create_table( @@ -90,6 +78,19 @@ impl MigrationTrait for Migration { ) .to_owned(), ) + .await?; + + manager + .create_index( + Index::create() + .if_not_exists() + .name("sep_status") + .table(UsersStatus::Table) + .col(UsersStatus::UserId) + .col(UsersStatus::Target) + .unique() + .to_owned(), + ) .await } }