Add another checkout table

This commit is contained in:
eraden 2023-06-08 21:45:12 +02:00
parent 379910081a
commit 39a34bd53b

View File

@ -30,6 +30,8 @@ impl MigrationTrait for Migration {
.await?;
self.drop_table(m, PaymentCollectionPayment::PaymentCollectionPayments)
.await?;
self.drop_table(m, PaymentSession::PaymentSessions).await?;
self.drop_table(m, Payment::Payments).await?;
self.drop_table(m, OrderItemChange::OrderItemChanges)
.await?;
self.drop_table(m, PaymentProvider::PaymentProviders)
@ -43,6 +45,7 @@ impl MigrationTrait for Migration {
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);
@ -55,6 +58,7 @@ impl Migration {
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);
@ -272,23 +276,57 @@ impl Migration {
/// CREATE TABLE payments
/// (
/// id uuid NOT NULL,
///
/// swap_id uuid,
/// cart_id uuid,
///
/// order_id uuid,
/// amount integer NOT NULL,
///
/// currency_code character varying NOT NULL,
/// amount_refunded integer DEFAULT 0 NOT NULL,
///
/// provider_id uuid NOT NULL,
/// data jsonb NOT NULL,
///
/// captured_at timestamp with time zone,
/// 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,
///
/// metadata jsonb,
/// idempotency_key character varying
/// }
/// ```
async fn create_payments(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(Payment::Payments)
.col(auto_uuid_not_null!(Payment::Id))
.col(Payment::SwapId.col().uuid())
.col(Payment::CartId.col().uuid())
.col(Payment::OrderId.col().uuid())
.col(Payment::Amount.col().integer().not_null())
.col(Payment::CurrencyCode.col().string().not_null())
.col(
Payment::AmountRefunded
.col()
.integer()
.default(0)
.not_null(),
)
.col(Payment::ProviderId.col().uuid().not_null())
.col(Payment::Data.col().json_binary().not_null())
.col(Payment::CapturedAt.col().timestamp())
.col(Payment::CanceledAt.col().timestamp())
.col(ts_def_now_not_null!(Payment::CreatedAt))
.col(ts_def_now_not_null!(Payment::UpdatedAt))
.col(Payment::Metadata.col().json_binary())
.col(Payment::IdempotencyKey.col().uuid())
.to_owned(),
)
.await?;
Ok(())
}
@ -440,6 +478,38 @@ impl Migration {
/// }
/// ```
async fn create_payment_sessions(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(PaymentSession::PaymentSessions)
.col(auto_uuid_not_null!(PaymentSession::Id))
.col(PaymentSession::CartId.col().uuid())
.col(PaymentSession::ProviderId.col().uuid().not_null())
.col(PaymentSession::IsSelected.col().boolean())
.col(
PaymentSession::PaymentSessionStatus
.col()
.enumeration(
crate::types::PaymentSessionStatus::PaymentSessionStatuses,
crate::types::PaymentCollectionStatus::iter().skip(1),
)
.not_null(),
)
.col(PaymentSession::Data.col().json_binary().not_null())
.col(ts_def_now_not_null!(PaymentSession::CreatedAt))
.col(ts_def_now_not_null!(PaymentSession::UpdatedAt))
.col(PaymentSession::IdempotencyKey.col().uuid())
.col(PaymentSession::PaymentAuthorizedAt.col().timestamp())
.col(PaymentSession::Amount.col().integer())
.col(
PaymentSession::IsInitiated
.col()
.boolean()
.default(false)
.not_null(),
)
.to_owned(),
)
.await?;
Ok(())
}
}
@ -585,7 +655,7 @@ pub enum PaymentSession {
CartId,
ProviderId,
IsSelected,
Status,
PaymentSessionStatus,
Data,
CreatedAt,
UpdatedAt,