diff --git a/migration/src/carts/m20230603_120815_cart_discounts.rs b/migration/src/carts/m20230603_120815_cart_discounts.rs index d091d46..6caf0d8 100644 --- a/migration/src/carts/m20230603_120815_cart_discounts.rs +++ b/migration/src/carts/m20230603_120815_cart_discounts.rs @@ -51,7 +51,7 @@ impl Migration { ) .await?; - m.create_2col_idx( + m.create_2_col_primary( CartDiscount::CartDiscounts, CartDiscount::CartId, CartDiscount::DiscountId, @@ -79,7 +79,7 @@ impl Migration { ) .await?; - m.create_2col_idx( + m.create_2_col_primary( CartGiftCard::CartGiftCards, CartGiftCard::CartId, CartGiftCard::GiftCardId, diff --git a/migration/src/checkouts/m20230603_120814_checkouts.rs b/migration/src/checkouts/m20230603_120814_checkouts.rs index 69424c6..b29f6c5 100644 --- a/migration/src/checkouts/m20230603_120814_checkouts.rs +++ b/migration/src/checkouts/m20230603_120814_checkouts.rs @@ -194,7 +194,7 @@ impl Migration { ) .await?; - m.create_2col_idx( + m.create_2_col_primary( OrderDiscount::OrderDiscounts, OrderDiscount::OrderId, OrderDiscount::DiscountId, @@ -270,7 +270,7 @@ impl Migration { ) .await?; - m.create_2col_idx( + m.create_2_col_primary( OrderGiftCard::OrderGiftCards, OrderGiftCard::OrderId, OrderGiftCard::GiftCardId, @@ -454,7 +454,7 @@ impl Migration { ) .await?; - m.create_2col_idx( + m.create_2_col_primary( PaymentCollectionPayment::PaymentCollectionPayments, PaymentCollectionPayment::PaymentCollectionId, PaymentCollectionPayment::PaymentId, @@ -508,7 +508,7 @@ impl Migration { ) .await?; - m.create_2col_idx( + m.create_2_col_primary( PaymentCollectionSession::PaymentCollectionSessions, PaymentCollectionSession::PaymentCollectionId, PaymentCollectionSession::PaymentSessionId, diff --git a/migration/src/sea_ext/mod.rs b/migration/src/sea_ext/mod.rs index 1f924de..f80002a 100644 --- a/migration/src/sea_ext/mod.rs +++ b/migration/src/sea_ext/mod.rs @@ -55,7 +55,12 @@ impl IntoColumnDef for T {} #[async_trait] pub trait CreateIndexExt { - async fn create_2col_idx(&self, table: T, col1: C1, col2: C2) -> Result<(), DbErr> + async fn create_2_col_primary( + &self, + table: T, + col1: C1, + col2: C2, + ) -> Result<(), DbErr> where T: IntoIden + Copy + 'static + Sync + Send, C1: IntoIden + Copy + 'static + Sync + Send, @@ -64,7 +69,12 @@ pub trait CreateIndexExt { #[async_trait] impl CreateIndexExt for SchemaManager<'_> { - async fn create_2col_idx(&self, table: T, col1: C1, col2: C2) -> Result<(), DbErr> + async fn create_2_col_primary( + &self, + table: T, + col1: C1, + col2: C2, + ) -> Result<(), DbErr> where T: IntoIden + Copy + 'static + Sync + Send, C1: IntoIden + Copy + 'static + Sync + Send, @@ -120,7 +130,7 @@ impl CreateBridgeTable for SchemaManager<'_> { ) .await?; - self.create_2col_idx(table, col1, col2).await?; + self.create_2_col_primary(table, col1, col2).await?; Ok(()) } diff --git a/migration/src/shipping/m20230603_120810_shipping.rs b/migration/src/shipping/m20230603_120810_shipping.rs index 9cb7c84..4d0890a 100644 --- a/migration/src/shipping/m20230603_120810_shipping.rs +++ b/migration/src/shipping/m20230603_120810_shipping.rs @@ -355,7 +355,7 @@ impl Migration { ) .await?; - m.create_2col_idx(ShippingTaxRates, ShippingOptionId, RateId) + m.create_2_col_primary(ShippingTaxRates, ShippingOptionId, RateId) .await?; Ok(()) diff --git a/migration/src/stocks/m20230603_120810_products.rs b/migration/src/stocks/m20230603_120810_products.rs index 2c96aff..662b031 100644 --- a/migration/src/stocks/m20230603_120810_products.rs +++ b/migration/src/stocks/m20230603_120810_products.rs @@ -451,6 +451,21 @@ impl Migration { async fn create_product_tax_rates(&self, m: &SchemaManager<'_>) -> Result<(), DbErr> { use ProductTaxRate::*; + m.create_table( + Table::create() + .table(ProductTaxRates) + .col(ProductId.col().uuid().not_null()) + .col(RateId.col().uuid().not_null()) + .col(ts_def_now_not_null!(CreatedAt)) + .col(ts_def_now_not_null!(UpdatedAt)) + .col(Metadata.col().json_binary()) + .to_owned(), + ) + .await?; + + m.create_2_col_primary(ProductTaxRates, ProductId, RateId) + .await?; + Ok(()) } /// ```sql @@ -467,6 +482,19 @@ impl Migration { async fn create_product_types(&self, m: &SchemaManager<'_>) -> Result<(), DbErr> { use ProductType::*; + m.create_table( + Table::create() + .table(ProductTypes) + .col(auto_uuid_not_null!(Id)) + .col(Value.col().string().not_null()) + .col(ts_def_now_not_null!(CreatedAt)) + .col(ts_def_now_not_null!(UpdatedAt)) + .col(DeletedAt.col().timestamp()) + .col(Metadata.col().json_binary()) + .to_owned(), + ) + .await?; + Ok(()) } /// ```sql @@ -482,6 +510,21 @@ impl Migration { async fn create_product_type_tax_rates(&self, m: &SchemaManager<'_>) -> Result<(), DbErr> { use ProductTypeTaxRate::*; + m.create_table( + Table::create() + .table(ProductTypeTaxRates) + .col(ProductTypeId.col().uuid().not_null()) + .col(RateId.col().uuid().not_null()) + .col(ts_def_now_not_null!(CreatedAt)) + .col(ts_def_now_not_null!(UpdatedAt)) + .col(Metadata.col().json_binary()) + .to_owned(), + ) + .await?; + + m.create_2_col_primary(ProductTypeTaxRates, ProductTypeId, RateId) + .await?; + Ok(()) } /// ```sql @@ -515,6 +558,36 @@ impl Migration { async fn create_product_variants(&self, m: &SchemaManager<'_>) -> Result<(), DbErr> { use ProductVariant::*; + m.create_table( + Table::create() + .table(ProductVariants) + .col(auto_uuid_not_null!(Id)) + .col(Title.col().string().not_null()) + .col(ProductId.col().uuid().not_null()) + .col(Sku.col().string()) + .col(Barcode.col().string()) + .col(Ean.col().string()) + .col(Upc.col().string()) + .col(InventoryQuantity.col().integer().not_null()) + .col(AllowBackorder.col().boolean().default(false).not_null()) + .col(ManageInventory.col().boolean().default(true).not_null()) + .col(HsCode.col().string()) + .col(OriginCountry.col().string()) + .col(MidCode.col().string()) + .col(Material.col().string()) + .col(Weight.col().integer()) + .col(Length.col().integer()) + .col(Height.col().integer()) + .col(Width.col().integer()) + .col(ts_def_now_not_null!(CreatedAt)) + .col(ts_def_now_not_null!(UpdatedAt)) + .col(DeletedAt.col().timestamp()) + .col(Metadata.col().json_binary()) + .col(VariantRank.col().integer().default(0)) + .to_owned(), + ) + .await?; + Ok(()) } /// ```sql @@ -535,6 +608,20 @@ impl Migration { ) -> Result<(), DbErr> { use ProductVariantInventoryItem::*; + m.create_table( + Table::create() + .table(ProductVariantInventoryItems) + .col(auto_uuid_not_null!(Id)) + .col(ts_def_now_not_null!(CreatedAt)) + .col(ts_def_now_not_null!(UpdatedAt)) + .col(InventoryItemId.col().uuid().not_null()) + .col(VariantId.col().uuid().not_null()) + .col(RequiredQuantity.col().integer().default(1).not_null()) + .col(DeletedAt.col().timestamp()) + .to_owned(), + ) + .await?; + Ok(()) } /// ```sql @@ -556,6 +643,24 @@ impl Migration { async fn create_money_amounts(&self, m: &SchemaManager<'_>) -> Result<(), DbErr> { use MoneyAmount::*; + m.create_table( + Table::create() + .table(MoneyAmounts) + .col(auto_uuid_not_null!(Id)) + .col(CurrencyCode.col().string().not_null()) + .col(Amount.col().integer().not_null()) + .col(VariantId.col().uuid()) + .col(RegionId.col().uuid()) + .col(ts_def_now_not_null!(CreatedAt)) + .col(ts_def_now_not_null!(UpdatedAt)) + .col(DeletedAt.col().timestamp()) + .col(MinQuantity.col().integer()) + .col(MaxQuantity.col().integer()) + .col(PriceListId.col().uuid()) + .to_owned(), + ) + .await?; + Ok(()) } }