From 4fd361534363ec538d0fe46608dca4f25ebd9bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Wo=C5=BAniak?= Date: Tue, 13 Jun 2023 17:24:59 +0200 Subject: [PATCH] Add more shipping, extract products --- .../src/stocks/m20230603_120810_products.rs | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/migration/src/stocks/m20230603_120810_products.rs b/migration/src/stocks/m20230603_120810_products.rs index 3a557fb..2c96aff 100644 --- a/migration/src/stocks/m20230603_120810_products.rs +++ b/migration/src/stocks/m20230603_120810_products.rs @@ -170,6 +170,47 @@ impl Migration { async fn create_products(&self, m: &SchemaManager<'_>) -> Result<(), DbErr> { use Product::*; + m.create_table( + Table::create() + .table(Products) + .col(auto_uuid_not_null!(Id)) + .col(Title.col().string().not_null()) + .col(Subtitle.col().string()) + .col(Description.col().string()) + .col(Handle.col().string()) + .col(IsGiftcard.col().boolean().default(false).not_null()) + .col(Thumbnail.col().string()) + .col(ProfileId.col().uuid().not_null()) + .col(Weight.col().integer()) + .col(Length.col().integer()) + .col(Height.col().integer()) + .col(Width.col().integer()) + .col(HsCode.col().string()) + .col(OriginCountry.col().string()) + .col(MidCode.col().string()) + .col(Material.col().string()) + .col(ts_def_now_not_null!(CreatedAt)) + .col(ts_def_now_not_null!(UpdatedAt)) + .col(DeletedAt.col().timestamp()) + .col(Metadata.col().json_binary()) + .col(CollectionId.col().uuid()) + .col(TypeId.col().uuid()) + .col(Discountable.col().boolean().default(true).not_null()) + .col( + Status + .col() + .enumeration( + crate::types::ProductStatus::ProductStatuses, + crate::types::ProductStatus::iter().skip(1), + ) + .default(crate::types::ProductStatus::Draft.to_string()) + .not_null(), + ) + .col(ExternalId.col().uuid()) + .to_owned(), + ) + .await?; + Ok(()) } /// ```sql @@ -192,6 +233,24 @@ impl Migration { async fn create_product_categories(&self, m: &SchemaManager<'_>) -> Result<(), DbErr> { use ProductCategory::*; + m.create_table( + Table::create() + .table(ProductCategories) + .col(auto_uuid_not_null!(Id)) + .col(Name.col().string().not_null()) + .col(Handle.col().string().not_null()) + .col(ParentCategoryId.col().uuid()) + .col(Mpath.col().string()) + .col(IsActive.col().boolean().default(false)) + .col(IsInternal.col().boolean().default(false)) + .col(ts_def_now_not_null!(CreatedAt)) + .col(ts_def_now_not_null!(UpdatedAt)) + .col(Rank.col().integer().default(0).not_null()) + .col(Description.col().text().default("".to_string()).not_null()) + .to_owned(), + ) + .await?; + m.create_constraint(ProductCategories, Check::greater_eq(Rank, 0.iden()), None) .await?; @@ -227,6 +286,20 @@ impl Migration { async fn create_product_collections(&self, m: &SchemaManager<'_>) -> Result<(), DbErr> { use ProductCollection::*; + m.create_table( + Table::create() + .table(ProductCollections) + .col(auto_uuid_not_null!(Id)) + .col(Title.col().string().not_null()) + .col(Handle.col().string()) + .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 @@ -259,6 +332,19 @@ impl Migration { async fn create_product_options(&self, m: &SchemaManager<'_>) -> Result<(), DbErr> { use ProductOption::*; + m.create_table( + Table::create() + .table(ProductOptions) + .col(Title.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()) + .col(ProductId.col().uuid()) + .to_owned(), + ) + .await?; + Ok(()) } /// ```sql @@ -277,6 +363,21 @@ impl Migration { async fn create_product_option_values(&self, m: &SchemaManager<'_>) -> Result<(), DbErr> { use ProductOptionValue::*; + m.create_table( + Table::create() + .table(ProductOptionValues) + .col(auto_uuid_not_null!(Id)) + .col(Value.col().string().not_null()) + .col(OptionId.col().uuid().not_null()) + .col(VariantId.col().uuid().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 @@ -308,6 +409,18 @@ impl Migration { async fn create_product_tags(&self, m: &SchemaManager<'_>) -> Result<(), DbErr> { use ProductTag::*; + m.create_table( + Table::create() + .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