Add gift cars (part 1)

This commit is contained in:
eraden 2023-06-06 21:39:53 +02:00
parent 37241b2357
commit 9a3d61aaf6
6 changed files with 344 additions and 9 deletions

View File

@ -0,0 +1,66 @@
use sea_orm_migration::prelude::*;
use sea_query::expr::SimpleExpr;
/// ```sql
/// CREATE TABLE cart_discounts
/// (
/// cart_id uuid NOT NULL,
/// discount_id uuid NOT NULL
/// );
/// CREATE TABLE cart_gift_cards
/// (
/// cart_id uuid NOT NULL,
/// gift_card_id uuid NOT NULL
/// );
/// ```
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(CartDiscount::CartDiscounts)
.col(ColumnDef::new(CartDiscount::CartId).uuid().not_null())
.col(ColumnDef::new(CartDiscount::DiscountId).uuid().not_null())
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
.table(CartGiftCard::CartGiftCards)
.col(ColumnDef::new(CartGiftCard::CartId).uuid().not_null())
.col(ColumnDef::new(CartGiftCard::GiftCardId).uuid().not_null())
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(CartDiscount::CartDiscounts).to_owned())
.await?;
manager
.drop_table(Table::drop().table(CartGiftCard::CartGiftCards).to_owned())
.await?;
Ok(())
}
}
#[derive(Iden)]
enum CartDiscount {
CartDiscounts,
CartId,
DiscountId,
}
#[derive(Iden)]
enum CartGiftCard {
CartGiftCards,
CartId,
GiftCardId,
}

View File

@ -2,6 +2,7 @@ use sea_orm_migration::{MigrationTrait, MigratorTrait};
mod m20230603_102634_types; mod m20230603_102634_types;
mod m20230603_120814_carts; mod m20230603_120814_carts;
mod m20230603_120815_cart_discounts;
pub struct CartsMigrator; pub struct CartsMigrator;
@ -11,6 +12,7 @@ impl MigratorTrait for CartsMigrator {
vec![ vec![
Box::new(m20230603_102634_types::Migration), Box::new(m20230603_102634_types::Migration),
Box::new(m20230603_120814_carts::Migration), Box::new(m20230603_120814_carts::Migration),
Box::new(m20230603_120815_cart_discounts::Migration),
] ]
} }
} }

View File

@ -5,3 +5,13 @@ pub mod jobs;
pub mod public; pub mod public;
pub mod schema_list; pub mod schema_list;
pub mod types; pub mod types;
#[macro_export]
macro_rules! ts_def_now_not_null {
($identifier: expr) => {
ColumnDef::new($identifier)
.timestamp()
.default(SimpleExpr::Custom("now()".into()))
.not_null()
};
}

View File

@ -0,0 +1,256 @@
use sea_orm_migration::manager;
use sea_orm_migration::prelude::*;
use sea_orm_migration::sea_orm::Statement;
use sea_query::expr::SimpleExpr;
use crate::sea_orm::DatabaseBackend;
use crate::ts_def_now_not_null;
/// ```sql
/// CREATE TABLE claim_images
/// (
/// id uuid NOT NULL,
/// claim_item_id uuid NOT NULL,
/// url character varying NOT NULL,
/// created_at timestamp with time zone DEFAULT now() NOT NULL,
/// updated_at timestamp with time zone DEFAULT now() NOT NULL,
/// deleted_at timestamp with time zone,
/// metadata jsonb
/// );
///
/// CREATE TABLE claim_items
/// (
/// id uuid NOT NULL,
/// claim_order_id uuid NOT NULL,
/// item_id uuid NOT NULL,
/// variant_id uuid NOT NULL,
/// reason claim_item_reasons NOT NULL,
/// note character varying,
/// quantity integer NOT NULL,
/// created_at timestamp with time zone DEFAULT now() NOT NULL,
/// updated_at timestamp with time zone DEFAULT now() NOT NULL,
/// deleted_at timestamp with time zone,
/// metadata jsonb
/// );
///
/// CREATE TABLE claim_item_tags
/// (
/// item_id uuid NOT NULL,
/// tag_id uuid NOT NULL
/// );
///
/// CREATE TABLE claim_orders
/// (
/// id uuid NOT NULL,
/// payment_status public.claim_order_payment_statuses DEFAULT 'na'::public.claim_order_payment_statuses NOT NULL,
/// fulfillment_status public.claim_order_fulfillment_statuses DEFAULT 'not_fulfilled'::public.claim_order_fulfillment_statuses NOT NULL,
/// claim_order_type public.claim_order_types NOT NULL,
/// order_id uuid NOT NULL,
/// shipping_address_id character varying,
/// refund_amount integer,
/// canceled_at timestamp with time zone,
/// created_at timestamp with time zone DEFAULT now() NOT NULL,
/// updated_at timestamp with time zone DEFAULT now() NOT NULL,
/// deleted_at timestamp with time zone,
/// metadata jsonb,
/// idempotency_key character varying,
/// no_notification boolean
/// );
///
/// CREATE TABLE claim_tags
/// (
/// id uuid NOT NULL,
/// value character varying NOT NULL,
/// created_at timestamp with time zone DEFAULT now() NOT NULL,
/// updated_at timestamp with time zone DEFAULT now() NOT NULL,
/// deleted_at timestamp with time zone,
/// metadata jsonb
/// );
/// ```
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(ClaimImage::ClaimImages)
.col(
ColumnDef::new(ClaimImage::Id)
.uuid()
.not_null()
.default(SimpleExpr::Custom("uuid_generate_v4()".into()))
.primary_key(),
)
.col(ColumnDef::new(ClaimImage::ClaimItemId).uuid().not_null())
.col(ColumnDef::new(ClaimImage::Url).string().not_null())
.col(ColumnDef::new(ClaimImage::CreatedAt).string())
.col(ColumnDef::new(ClaimImage::UpdatedAt).string())
.col(ColumnDef::new(ClaimImage::DeletedAt).string())
.col(ColumnDef::new(ClaimImage::Metadata).string())
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
.table(ClaimItem::ClaimItems)
.col(
ColumnDef::new(ClaimItem::Id)
.uuid()
.not_null()
.default(SimpleExpr::Custom("uuid_generate_v4()".into()))
.primary_key(),
)
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
.table(ClaimItemTag::ClaimItemTags)
.col(ColumnDef::new(ClaimItemTag::ItemId).uuid().not_null())
.col(ColumnDef::new(ClaimItemTag::TagId).uuid().not_null())
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
.table(ClaimOrder::ClaimOrders)
.col(
ColumnDef::new(ClaimOrder::Id)
.uuid()
.not_null()
.default(SimpleExpr::Custom("uuid_generate_v4()".into()))
.primary_key(),
)
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
.table(ClaimTag::ClaimTags)
.col(ColumnDef::new(ClaimTag::Id).uuid())
.to_owned(),
)
.await?;
////
// manager
// .create_table(
// Table::create()
// .table(AnalyticsConfig::AnalyticsConfigs)
// .col(
// ColumnDef::new(AnalyticsConfig::Id)
// .uuid()
// .not_null()
// .default(SimpleExpr::Custom("uuid_generate_v4()".into()))
// .primary_key(),
// )
// .col(ts_def_now_not_null!(AnalyticsConfig::CreatedAt))
// .col(ts_def_now_not_null!(AnalyticsConfig::UpdatedAt))
// .col(ColumnDef::new(AnalyticsConfig::DeletedAt).timestamp())
// .col(ColumnDef::new(AnalyticsConfig::UserId).uuid().not_null())
// .col(
// ColumnDef::new(AnalyticsConfig::OptOut)
// .boolean()
// .default(false)
// .not_null(),
// )
// .col(
// ColumnDef::new(AnalyticsConfig::Anonymize)
// .boolean()
// .default(false)
// .not_null(),
// )
// .to_owned(),
// )
// .await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(ClaimImage::ClaimImages).to_owned())
.await?;
manager
.drop_table(Table::drop().table(ClaimItem::ClaimItems).to_owned())
.await?;
manager
.drop_table(Table::drop().table(ClaimItemTag::ClaimItemTags).to_owned())
.await?;
manager
.drop_table(Table::drop().table(ClaimOrder::ClaimOrders).to_owned())
.await?;
manager
.drop_table(Table::drop().table(ClaimTag::ClaimTags).to_owned())
.await?;
Ok(())
}
}
#[derive(Iden)]
pub enum ClaimImage {
ClaimImages,
Id,
ClaimItemId,
Url,
CreatedAt,
UpdatedAt,
DeletedAt,
Metadata,
}
#[derive(Iden)]
pub enum ClaimItem {
ClaimItems,
Id,
ClaimOrderId,
ItemId,
VariantId,
Reason,
Note,
Quantity,
CreatedAt,
UpdatedAt,
DeletedAt,
Metadata,
}
#[derive(Iden)]
pub enum ClaimItemTag {
ClaimItemTags,
ItemId,
TagId,
}
#[derive(Iden)]
pub enum ClaimOrder {
ClaimOrders,
Id,
PaymentStatus,
FulfillmentStatus,
ClaimOrderType,
OrderId,
ShippingAddressId,
RefundAmount,
CanceledAt,
CreatedAt,
}
#[derive(Iden)]
pub enum ClaimTag {
ClaimTags,
Id,
Value,
CreatedAt,
UpdatedAt,
DeletedAt,
Metadata,
}

View File

@ -3,6 +3,7 @@ use sea_orm_migration::{MigrationTrait, MigratorTrait};
mod m20230603_102630_schema; mod m20230603_102630_schema;
mod m20230603_102634_types; mod m20230603_102634_types;
mod m20230603_120814_addresses; mod m20230603_120814_addresses;
mod m20230603_120815_claims;
pub struct PublicMigrator; pub struct PublicMigrator;
@ -14,6 +15,7 @@ impl MigratorTrait for PublicMigrator {
Box::new(m20230603_102630_schema::Migration), Box::new(m20230603_102630_schema::Migration),
Box::new(m20230603_102634_types::Migration), Box::new(m20230603_102634_types::Migration),
Box::new(m20230603_120814_addresses::Migration), Box::new(m20230603_120814_addresses::Migration),
Box::new(m20230603_120815_claims::Migration),
] ]
} }
} }

View File

@ -275,15 +275,6 @@ CREATE TABLE public.carts
sales_channel_id character varying sales_channel_id character varying
); );
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
CREATE TABLE public.cart_discounts CREATE TABLE public.cart_discounts
( (
cart_id uuid NOT NULL, cart_id uuid NOT NULL,
@ -296,6 +287,14 @@ CREATE TABLE public.cart_gift_cards
gift_card_id uuid NOT NULL gift_card_id uuid NOT NULL
); );
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
CREATE TABLE public.claim_images CREATE TABLE public.claim_images
( (