Finish checkouts, start gift carts

This commit is contained in:
eraden 2023-06-08 22:04:03 +02:00
parent 39a34bd53b
commit a6486b4983
5 changed files with 116 additions and 91 deletions

View File

@ -11,6 +11,8 @@ pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
Self::create_types(m).await?;
Self::create_orders(m).await?;
Self::create_order_discounts(m).await?;
Self::create_order_edits(m).await?;
@ -42,26 +44,26 @@ impl MigrationTrait for Migration {
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::OrderPaymentStatus);
drop_type!(m, crate::types::OrderItemChangeType);
drop_type!(m, crate::types::PaymentSessionStatus);
drop_type!(m, crate::types::PaymentCollectionType);
drop_type!(m, crate::types::OrderFulfillmentStatus);
drop_type!(m, crate::types::PaymentCollectionStatus);
drop_type!(m, OrderStatus);
drop_type!(m, OrderPaymentStatus);
drop_type!(m, OrderItemChangeType);
drop_type!(m, PaymentSessionStatus);
drop_type!(m, PaymentCollectionType);
drop_type!(m, OrderFulfillmentStatus);
drop_type!(m, PaymentCollectionStatus);
Ok(())
}
}
impl Migration {
async fn create_types(m: &SchemaManager<'_>) -> Result<(), DbErr> {
create_type!(m, crate::types::OrderStatus);
create_type!(m, crate::types::OrderPaymentStatus);
create_type!(m, crate::types::OrderItemChangeType);
create_type!(m, crate::types::PaymentSessionStatus);
create_type!(m, crate::types::PaymentCollectionType);
create_type!(m, crate::types::OrderFulfillmentStatus);
create_type!(m, crate::types::PaymentCollectionStatus);
create_type!(m, OrderStatus);
create_type!(m, OrderPaymentStatus);
create_type!(m, OrderItemChangeType);
create_type!(m, PaymentSessionStatus);
create_type!(m, PaymentCollectionType);
create_type!(m, OrderFulfillmentStatus);
create_type!(m, PaymentCollectionStatus);
Ok(())
}
/// ```sql
@ -102,7 +104,7 @@ impl Migration {
crate::types::OrderStatus::OrderStatuses,
crate::types::OrderStatus::iter().skip(1),
)
.default(crate::types::OrderStatus::Pending)
.default(crate::types::OrderStatus::Pending.to_string())
.not_null(),
)
.col(
@ -514,7 +516,7 @@ impl Migration {
}
}
#[derive(Inde)]
#[derive(Iden)]
pub enum Order {
Orders,
Id,
@ -541,14 +543,14 @@ pub enum Order {
SalesChannelId,
}
#[derive(Inde)]
#[derive(Iden)]
pub enum OrderDiscount {
OrderDiscounts,
OrderId,
DiscountId,
}
#[derive(Inde)]
#[derive(Iden)]
pub enum OrderEdit {
OrderEdits,
Id,
@ -569,14 +571,14 @@ pub enum OrderEdit {
PaymentCollectionId,
}
#[derive(Inde)]
#[derive(Iden)]
pub enum OrderGiftCard {
OrderGiftCards,
OrderId,
GiftCardId,
}
#[derive(Inde)]
#[derive(Iden)]
pub enum OrderItemChange {
OrderItemChanges,
Id,
@ -589,7 +591,7 @@ pub enum OrderItemChange {
LineItemId,
}
#[derive(Inde)]
#[derive(Iden)]
pub enum Payment {
Payments,
Id,
@ -609,7 +611,7 @@ pub enum Payment {
IdempotencyKey,
}
#[derive(Inde)]
#[derive(Iden)]
pub enum PaymentCollection {
PaymentCollections,
Id,
@ -627,28 +629,28 @@ pub enum PaymentCollection {
CreatedBy,
}
#[derive(Inde)]
#[derive(Iden)]
pub enum PaymentCollectionPayment {
PaymentCollectionPayments,
PaymentCollectionId,
PaymentId,
}
#[derive(Inde)]
#[derive(Iden)]
pub enum PaymentCollectionSession {
PaymentCollectionSessions,
PaymentCollectionId,
PaymentSessionId,
}
#[derive(Inde)]
#[derive(Iden)]
pub enum PaymentProvider {
PaymentProviders,
Id,
IsInstalled,
}
#[derive(Inde)]
#[derive(Iden)]
pub enum PaymentSession {
PaymentSessions,
Id,

View File

@ -0,0 +1,20 @@
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};
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
Ok(())
}
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
Ok(())
}
}
impl Migration {}

View File

@ -1,4 +1,5 @@
mod m20230603_120814_discounts;
mod m20230603_120815_gift_carts;
use sea_orm_migration::{MigrationTrait, MigratorTrait};
@ -7,6 +8,9 @@ pub struct DiscountsMigrator;
#[async_trait::async_trait]
impl MigratorTrait for DiscountsMigrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![Box::new(m20230603_120814_discounts::Migration)]
vec![
Box::new(m20230603_120814_discounts::Migration),
Box::new(m20230603_120815_gift_carts::Migration),
]
}
}

View File

@ -65,7 +65,10 @@ pub trait DropTable {
impl<T: MigrationTrait> DropTable for T {}
pub trait IntoColumnDef: IntoIden {
fn col(self) -> ColumnDef {
fn col(self) -> ColumnDef
where
Self: Sized,
{
ColumnDef::new(self)
}
}

View File

@ -484,16 +484,6 @@ CREATE TABLE public.discount_rule_products
product_id uuid NOT NULL
);
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
CREATE TABLE public.orders
(
id uuid NOT NULL,
@ -634,10 +624,65 @@ CREATE TABLE public.payment_sessions
is_initiated boolean DEFAULT false NOT NULL
);
---------
---------
---------
---------
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
CREATE TABLE public.gift_cards
(
id uuid NOT NULL,
code character varying NOT NULL,
value integer NOT NULL,
balance integer NOT NULL,
region_id uuid NOT NULL,
order_id uuid,
is_disabled boolean DEFAULT false NOT NULL,
ends_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,
tax_rate real
);
CREATE TABLE public.gift_card_transactions
(
id uuid NOT NULL,
gift_card_id uuid NOT NULL,
order_id uuid NOT NULL,
amount integer NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
is_taxable boolean,
tax_rate real
);
---------------------------
---------------------------
---------------------------
---------------------------
CREATE TABLE public.idempotency_keys
(
id uuid NOT NULL,
idempotency_key character varying NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
locked_at timestamp with time zone,
request_method character varying,
request_params jsonb,
request_path character varying,
response_code integer,
response_body jsonb,
recovery_point character varying DEFAULT 'started'::character varying NOT NULL
);
---------------------------
---------------------------
---------------------------
CREATE TABLE public.customers
(
@ -731,48 +776,6 @@ CREATE TABLE public.fulfillment_providers
is_installed boolean DEFAULT true NOT NULL
);
CREATE TABLE public.gift_cards
(
id uuid NOT NULL,
code character varying NOT NULL,
value integer NOT NULL,
balance integer NOT NULL,
region_id uuid NOT NULL,
order_id uuid,
is_disabled boolean DEFAULT false NOT NULL,
ends_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,
tax_rate real
);
CREATE TABLE public.gift_card_transactions
(
id uuid NOT NULL,
gift_card_id uuid NOT NULL,
order_id uuid NOT NULL,
amount integer NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
is_taxable boolean,
tax_rate real
);
CREATE TABLE public.idempotency_keys
(
id uuid NOT NULL,
idempotency_key character varying NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
locked_at timestamp with time zone,
request_method character varying,
request_params jsonb,
request_path character varying,
response_code integer,
response_body jsonb,
recovery_point character varying DEFAULT 'started'::character varying NOT NULL
);
CREATE TABLE public.images
(
id uuid NOT NULL,
@ -851,13 +854,6 @@ CREATE TABLE public.line_item_tax_lines
item_id uuid NOT NULL
);
CREATE TABLE public.migrations
(
id sequence NOT NULL,
"timestamp" bigint NOT NULL,
name character varying NOT NULL
);
CREATE TABLE public.money_amounts
(
id uuid NOT NULL,