From 592f1572255e56ada3a2b9cdb586c04e7b0f929d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Wo=C5=BAniak?= Date: Thu, 8 Jun 2023 17:18:38 +0200 Subject: [PATCH] Add additional tables --- .../checkouts/m20230603_120814_checkouts.rs | 153 +++++++++++++++++- migration/src/lib.rs | 8 + migration/src/main.rs | 1 + .../src/public/m20230603_102634_types.rs | 2 - migration/src/schema_list.rs | 2 + 5 files changed, 160 insertions(+), 6 deletions(-) diff --git a/migration/src/checkouts/m20230603_120814_checkouts.rs b/migration/src/checkouts/m20230603_120814_checkouts.rs index 1188280..38a1e7f 100644 --- a/migration/src/checkouts/m20230603_120814_checkouts.rs +++ b/migration/src/checkouts/m20230603_120814_checkouts.rs @@ -1,7 +1,9 @@ use sea_orm_migration::prelude::*; use crate::sea_orm::Iterable; -use crate::{auto_uuid_not_null, create_type, drop_type, ts_def_now_not_null, DropTable}; +use crate::{ + auto_uuid_not_null, create_type, drop_type, ts_def_now_not_null, DropTable, IntoColumnDef, +}; #[derive(DeriveMigrationName)] pub struct Migration; @@ -24,9 +26,25 @@ impl MigrationTrait for Migration { } async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> { + self.drop_table(m, PaymentCollectionSession::PaymentCollectionSessions) + .await?; + self.drop_table(m, PaymentCollectionPayment::PaymentCollectionPayments) + .await?; + self.drop_table(m, OrderItemChange::OrderItemChanges) + .await?; + self.drop_table(m, PaymentProvider::PaymentProviders) + .await?; + + self.drop_table(m, OrderGiftCard::OrderGiftCards).await?; + self.drop_table(m, OrderEdit::OrderEdits).await?; + self.drop_table(m, OrderDiscount::OrderDiscounts).await?; + self.drop_table(m, Order::Orders).await?; + drop_type!(m, crate::types::OrderStatus); - drop_type!(m, crate::types::OrderFulfillmentStatus); drop_type!(m, crate::types::OrderPaymentStatus); + drop_type!(m, crate::types::OrderItemChangeType); + drop_type!(m, crate::types::PaymentCollectionType); + drop_type!(m, crate::types::OrderFulfillmentStatus); Ok(()) } } @@ -34,8 +52,10 @@ impl MigrationTrait for Migration { impl Migration { async fn create_types(m: &SchemaManager<'_>) -> Result<(), DbErr> { create_type!(m, crate::types::OrderStatus); - create_type!(m, crate::types::OrderFulfillmentStatus); create_type!(m, crate::types::OrderPaymentStatus); + create_type!(m, crate::types::OrderItemChangeType); + create_type!(m, crate::types::PaymentCollectionType); + create_type!(m, crate::types::OrderFulfillmentStatus); Ok(()) } /// ```sql @@ -127,6 +147,14 @@ impl Migration { /// discount_id uuid NOT NULL /// } async fn create_order_discounts(m: &SchemaManager<'_>) -> Result<(), DbErr> { + m.create_table( + Table::create() + .table(OrderDiscount::OrderDiscounts) + .col(ColumnDef::new(OrderDiscount::OrderId).uuid().not_null()) + .col(ColumnDef::new(OrderDiscount::DiscountId).uuid().not_null()) + .to_owned(), + ) + .await?; Ok(()) } @@ -152,6 +180,28 @@ impl Migration { /// } /// ``` async fn create_order_edits(m: &SchemaManager<'_>) -> Result<(), DbErr> { + m.create_table( + Table::create() + .table(OrderEdit::OrderEdits) + .col(auto_uuid_not_null!(OrderEdit::Id)) + .col(ts_def_now_not_null!(OrderEdit::CreatedAt)) + .col(ts_def_now_not_null!(OrderEdit::UpdatedAt)) + .col(ColumnDef::new(OrderEdit::OrderId).uuid().not_null()) + .col(ColumnDef::new(OrderEdit::InternalNote).string()) + .col(ColumnDef::new(OrderEdit::CreatedBy).uuid().not_null()) + .col(ColumnDef::new(OrderEdit::RequestedBy).uuid()) + .col(ColumnDef::new(OrderEdit::RequestedAt).timestamp()) + .col(ColumnDef::new(OrderEdit::ConfirmedBy).uuid()) + .col(ColumnDef::new(OrderEdit::ConfirmedAt).timestamp()) + .col(ColumnDef::new(OrderEdit::DeclinedBy).uuid()) + .col(ColumnDef::new(OrderEdit::DeclinedReason).string()) + .col(ColumnDef::new(OrderEdit::DeclinedAt).timestamp()) + .col(ColumnDef::new(OrderEdit::CanceledBy).uuid()) + .col(ColumnDef::new(OrderEdit::CanceledAt).timestamp()) + .col(ColumnDef::new(OrderEdit::PaymentCollectionId).uuid()) + .to_owned(), + ) + .await?; Ok(()) } @@ -163,6 +213,14 @@ impl Migration { /// } /// ``` async fn create_order_gift_cards(m: &SchemaManager<'_>) -> Result<(), DbErr> { + m.create_table( + Table::create() + .table(OrderGiftCard::OrderGiftCards) + .col(ColumnDef::new(OrderGiftCard::OrderId).uuid().not_null()) + .col(ColumnDef::new(OrderGiftCard::GiftCardId).uuid().not_null()) + .to_owned(), + ) + .await?; Ok(()) } @@ -180,6 +238,31 @@ impl Migration { /// } /// ``` async fn create_order_item_changes(m: &SchemaManager<'_>) -> Result<(), DbErr> { + m.create_table( + Table::create() + .table(OrderItemChange::OrderItemChanges) + .col(auto_uuid_not_null!(OrderItemChange::Id)) + .col(ts_def_now_not_null!(OrderItemChange::CreatedAt)) + .col(ts_def_now_not_null!(OrderItemChange::UpdatedAt)) + .col(ColumnDef::new(OrderItemChange::DeletedAt).timestamp()) + .col( + ColumnDef::new(OrderItemChange::OrderItemChangeType) + .enumeration( + crate::types::OrderItemChangeType::OrderItemChangeTypes, + crate::types::OrderItemChangeType::iter().skip(1), + ) + .not_null(), + ) + .col( + ColumnDef::new(OrderItemChange::OrderEditId) + .uuid() + .not_null(), + ) + .col(ColumnDef::new(OrderItemChange::OriginalLineItemId).uuid()) + .col(ColumnDef::new(OrderItemChange::LineItemId).uuid()) + .to_owned(), + ) + .await?; Ok(()) } @@ -226,6 +309,22 @@ impl Migration { /// } /// ``` async fn create_payment_collections(m: &SchemaManager<'_>) -> Result<(), DbErr> { + m.create_table( + Table::create() + .table(PaymentCollection::PaymentCollections) + .col(auto_uuid_not_null!(PaymentCollection::Id)) + .col(ts_def_now_not_null!(PaymentCollection::CreatedAt)) + .col(ts_def_now_not_null!(PaymentCollection::UpdatedAt)) + .col(PaymentCollection::DeletedAt.col().timestamp()) + .col(PaymentCollection::Type.col().enumeration(crate::types::PaymentCollectionType::PaymentCollectionTypes, crate::types::PaymentCollectionType::iter().skip(1))) + //////// + //////// TODO + //////// TODO + //////// TODO + //////// + .to_owned(), + ) + .await?; Ok(()) } @@ -237,6 +336,22 @@ impl Migration { /// } /// ``` async fn create_payment_collection_payments(m: &SchemaManager<'_>) -> Result<(), DbErr> { + m.create_table( + Table::create() + .table(PaymentCollectionPayment::PaymentCollectionPayments) + .col( + ColumnDef::new(PaymentCollectionPayment::PaymentCollectionId) + .uuid() + .not_null(), + ) + .col( + ColumnDef::new(PaymentCollectionPayment::PaymentId) + .uuid() + .not_null(), + ) + .to_owned(), + ) + .await?; Ok(()) } @@ -248,6 +363,22 @@ impl Migration { /// } /// ```` async fn create_payment_collection_sessions(m: &SchemaManager<'_>) -> Result<(), DbErr> { + m.create_table( + Table::create() + .table(PaymentCollectionSession::PaymentCollectionSessions) + .col( + ColumnDef::new(PaymentCollectionSession::PaymentCollectionId) + .uuid() + .not_null(), + ) + .col( + ColumnDef::new(PaymentCollectionSession::PaymentSessionId) + .uuid() + .not_null(), + ) + .to_owned(), + ) + .await?; Ok(()) } /// ```sql @@ -258,6 +389,20 @@ impl Migration { /// } /// ``` async fn create_payment_providers(m: &SchemaManager<'_>) -> Result<(), DbErr> { + m.create_table( + Table::create() + .table(PaymentProvider::PaymentProviders) + .col(auto_uuid_not_null!(PaymentProvider::Id)) + .col( + PaymentProvider::IsInstalled + .col() + .boolean() + .default(true) + .not_null(), + ) + .to_owned(), + ) + .await?; Ok(()) } @@ -352,7 +497,7 @@ pub enum OrderItemChange { CreatedAt, UpdatedAt, DeletedAt, - Type, + OrderItemChangeType, OrderEditId, OriginalLineItemId, LineItemId, diff --git a/migration/src/lib.rs b/migration/src/lib.rs index edc5462..fd3742c 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -63,3 +63,11 @@ pub trait DropTable { } impl DropTable for T {} + +pub trait IntoColumnDef: IntoIden { + fn col(self) -> ColumnDef { + ColumnDef::new(self) + } +} + +impl IntoColumnDef for T {} diff --git a/migration/src/main.rs b/migration/src/main.rs index f5be3ba..f4c5af1 100644 --- a/migration/src/main.rs +++ b/migration/src/main.rs @@ -37,6 +37,7 @@ async fn main() { migrate_schema!(cli, Jobs, JobsMigrator); migrate_schema!(cli, Carts, CartsMigrator); migrate_schema!(cli, Discounts, DiscountsMigrator); + migrate_schema!(cli, Checkouts, CheckoutsMigrator); } pub async fn run_cli(cli: &mut Cli, schema: PostgreSQLSchema, migrator: M) diff --git a/migration/src/public/m20230603_102634_types.rs b/migration/src/public/m20230603_102634_types.rs index 9bf6a91..b23cb5a 100644 --- a/migration/src/public/m20230603_102634_types.rs +++ b/migration/src/public/m20230603_102634_types.rs @@ -10,7 +10,6 @@ pub struct Migration; impl MigrationTrait for Migration { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { create_type!(manager, PaymentCollectionStatus); - create_type!(manager, PaymentCollectionType); create_type!(manager, CartType); create_type!(manager, ClaimItemReason); create_type!(manager, ClaimOrderFulfillmentStatus); @@ -38,7 +37,6 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { drop_type!(manager, PaymentCollectionStatus); - drop_type!(manager, PaymentCollectionType); drop_type!(manager, CartType); drop_type!(manager, ClaimItemReason); drop_type!(manager, ClaimOrderFulfillmentStatus); diff --git a/migration/src/schema_list.rs b/migration/src/schema_list.rs index d75f1ee..f5244aa 100644 --- a/migration/src/schema_list.rs +++ b/migration/src/schema_list.rs @@ -8,6 +8,7 @@ pub enum PostgreSQLSchema { Jobs, Carts, Discounts, + Checkouts, } impl PostgreSQLSchema { @@ -17,6 +18,7 @@ impl PostgreSQLSchema { PostgreSQLSchema::Jobs => "jobs", PostgreSQLSchema::Carts => "carts", PostgreSQLSchema::Discounts => "discounts", + PostgreSQLSchema::Checkouts => "checkouts", } } }