Start checkout db

This commit is contained in:
Adrian Woźniak 2023-06-08 15:48:02 +02:00
parent eee5d6c22d
commit c0e8d9da34
14 changed files with 1391 additions and 283 deletions

View File

@ -1,8 +1,6 @@
use sea_orm::Iterable;
use sea_orm_migration::prelude::*;
use crate::extension::postgres::Type;
use crate::types::*;
use crate::{create_type, drop_type};
#[derive(DeriveMigrationName)]

View File

@ -0,0 +1,435 @@
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> {
Self::create_orders(m).await?;
Self::create_order_discounts(m).await?;
Self::create_order_edits(m).await?;
Self::create_order_gift_cards(m).await?;
Self::create_order_item_changes(m).await?;
Self::create_payments(m).await?;
Self::create_payment_collections(m).await?;
Self::create_payment_collection_payments(m).await?;
Self::create_payment_collection_sessions(m).await?;
Self::create_payment_providers(m).await?;
Self::create_payment_sessions(m).await?;
Ok(())
}
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
drop_type!(m, crate::types::OrderStatus);
drop_type!(m, crate::types::OrderFulfillmentStatus);
drop_type!(m, crate::types::OrderPaymentStatus);
Ok(())
}
}
impl Migration {
async fn create_types(m: &SchemaManager<'_>) -> Result<(), DbErr> {
create_type!(m, crate::types::OrderStatus);
create_type!(m, crate::types::OrderFulfillmentStatus);
create_type!(m, crate::types::OrderPaymentStatus);
Ok(())
}
/// ```sql
/// CREATE TABLE orders
/// (
/// id uuid NOT NULL,
/// status order_statuses DEFAULT 'pending'::order_statuses NOT NULL,
/// fulfillment_status order_fulfillment_statuses DEFAULT 'not_fulfilled'::order_fulfillment_statuses NOT NULL,
/// payment_status order_payment_statuses DEFAULT 'not_paid'::order_payment_statuses NOT NULL,
/// display_id integer NOT NULL,
/// cart_id uuid,
/// customer_id uuid NOT NULL,
/// email character varying NOT NULL,
/// billing_address_id uuid,
/// shipping_address_id uuid,
/// region_id uuid NOT NULL,
/// currency_code character varying NOT NULL,
/// tax_rate real,
/// 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,
/// draft_order_id uuid,
/// no_notification boolean,
/// external_id uuid,
/// sales_channel_id uuid
/// }
/// ```
async fn create_orders(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(Order::Orders)
.col(auto_uuid_not_null!(Order::Id))
.col(
ColumnDef::new(Order::Status)
.enumeration(
crate::types::OrderStatus::OrderStatuses,
crate::types::OrderStatus::iter().skip(1),
)
.default(crate::types::OrderStatus::Pending)
.not_null(),
)
.col(
ColumnDef::new(Order::FulfillmentStatus)
.enumeration(
crate::types::OrderFulfillmentStatus::OrderFulfillmentStatuses,
crate::types::OrderFulfillmentStatus::iter().take(1),
)
.not_null(),
)
.col(
ColumnDef::new(Order::PaymentStatus)
.enumeration(
crate::types::OrderPaymentStatus::OrderPaymentStatuses,
crate::types::OrderPaymentStatus::iter().take(1),
)
.not_null(),
)
.col(ColumnDef::new(Order::DisplayId).uuid())
.col(ColumnDef::new(Order::CartId).uuid())
.col(ColumnDef::new(Order::CustomerId).uuid())
.col(ColumnDef::new(Order::Email).uuid())
.col(ColumnDef::new(Order::BillingAddressId).uuid())
.col(ColumnDef::new(Order::ShippingAddressId).uuid())
.col(ColumnDef::new(Order::RegionId).uuid())
.col(ColumnDef::new(Order::CurrencyCode).uuid())
.col(ColumnDef::new(Order::TaxRate).uuid())
.col(ColumnDef::new(Order::CanceledAt).uuid())
.col(ColumnDef::new(Order::CreatedAt).uuid())
.col(ColumnDef::new(Order::UpdatedAt).uuid())
.col(ColumnDef::new(Order::Metadata).uuid())
.col(ColumnDef::new(Order::IdempotencyKey).uuid())
.col(ColumnDef::new(Order::DraftOrderId).uuid())
.col(ColumnDef::new(Order::NoNotification).uuid())
.col(ColumnDef::new(Order::ExternalId).uuid())
.col(ColumnDef::new(Order::SalesChannelId).uuid())
.to_owned(),
)
.await?;
Ok(())
}
/// ```sql
/// CREATE TABLE order_discounts
/// (
/// order_id uuid NOT NULL,
/// discount_id uuid NOT NULL
/// }
async fn create_order_discounts(m: &SchemaManager<'_>) -> Result<(), DbErr> {
Ok(())
}
/// ```sql
/// CREATE TABLE order_edits
/// (
/// id uuid NOT NULL,
/// created_at timestamp with time zone DEFAULT now() NOT NULL,
/// updated_at timestamp with time zone DEFAULT now() NOT NULL,
/// order_id uuid NOT NULL,
/// internal_note character varying,
/// created_by character varying NOT NULL,
/// requested_by character varying,
/// requested_at timestamp with time zone,
/// confirmed_by character varying,
/// confirmed_at timestamp with time zone,
/// declined_by character varying,
/// declined_reason character varying,
/// declined_at timestamp with time zone,
/// canceled_by character varying,
/// canceled_at timestamp with time zone,
/// payment_collection_id uuid
/// }
/// ```
async fn create_order_edits(m: &SchemaManager<'_>) -> Result<(), DbErr> {
Ok(())
}
/// ```sql
/// CREATE TABLE order_gift_cards
/// (
/// order_id uuid NOT NULL,
/// gift_card_id uuid NOT NULL
/// }
/// ```
async fn create_order_gift_cards(m: &SchemaManager<'_>) -> Result<(), DbErr> {
Ok(())
}
/// ```sql
/// CREATE TABLE order_item_changes
/// (
/// id uuid 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,
/// type order_item_change_types NOT NULL,
/// order_edit_id uuid NOT NULL,
/// original_line_item_id uuid,
/// line_item_id uuid
/// }
/// ```
async fn create_order_item_changes(m: &SchemaManager<'_>) -> Result<(), DbErr> {
Ok(())
}
/// ```sql
/// 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> {
Ok(())
}
/// ```sql
/// CREATE TABLE payment_collections
/// (
/// id uuid 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,
/// type payment_collection_types NOT NULL,
/// status payment_collection_statuses NOT NULL,
/// description text,
/// amount integer NOT NULL,
/// authorized_amount integer,
/// region_id uuid NOT NULL,
/// currency_code character varying NOT NULL,
/// metadata jsonb,
/// created_by character varying NOT NULL
/// }
/// ```
async fn create_payment_collections(m: &SchemaManager<'_>) -> Result<(), DbErr> {
Ok(())
}
/// ```sql
/// CREATE TABLE payment_collection_payments
/// (
/// payment_collection_id uuid NOT NULL,
/// payment_id uuid NOT NULL
/// }
/// ```
async fn create_payment_collection_payments(m: &SchemaManager<'_>) -> Result<(), DbErr> {
Ok(())
}
/// ```sql
/// CREATE TABLE payment_collection_sessions
/// (
/// payment_collection_id uuid NOT NULL,
/// payment_session_id uuid NOT NULL
/// }
/// ````
async fn create_payment_collection_sessions(m: &SchemaManager<'_>) -> Result<(), DbErr> {
Ok(())
}
/// ```sql
/// CREATE TABLE payment_providers
/// (
/// id uuid NOT NULL,
/// is_installed boolean DEFAULT true NOT NULL
/// }
/// ```
async fn create_payment_providers(m: &SchemaManager<'_>) -> Result<(), DbErr> {
Ok(())
}
/// ```sql
/// CREATE TABLE payment_sessions
/// (
/// id uuid NOT NULL,
/// cart_id uuid,
/// provider_id uuid NOT NULL,
/// is_selected boolean,
/// status payment_session_statuses NOT NULL,
/// data jsonb NOT NULL,
/// created_at timestamp with time zone DEFAULT now() NOT NULL,
/// updated_at timestamp with time zone DEFAULT now() NOT NULL,
/// idempotency_key character varying,
/// payment_authorized_at timestamp with time zone,
/// amount integer,
/// is_initiated boolean DEFAULT false NOT NULL
/// }
/// ```
async fn create_payment_sessions(m: &SchemaManager<'_>) -> Result<(), DbErr> {
Ok(())
}
}
#[derive(Inde)]
pub enum Order {
Orders,
Id,
Status,
FulfillmentStatus,
PaymentStatus,
DisplayId,
CartId,
CustomerId,
Email,
BillingAddressId,
ShippingAddressId,
RegionId,
CurrencyCode,
TaxRate,
CanceledAt,
CreatedAt,
UpdatedAt,
Metadata,
IdempotencyKey,
DraftOrderId,
NoNotification,
ExternalId,
SalesChannelId,
}
#[derive(Inde)]
pub enum OrderDiscount {
OrderDiscounts,
OrderId,
DiscountId,
}
#[derive(Inde)]
pub enum OrderEdit {
OrderEdits,
Id,
CreatedAt,
UpdatedAt,
OrderId,
InternalNote,
CreatedBy,
RequestedBy,
RequestedAt,
ConfirmedBy,
ConfirmedAt,
DeclinedBy,
DeclinedReason,
DeclinedAt,
CanceledBy,
CanceledAt,
PaymentCollectionId,
}
#[derive(Inde)]
pub enum OrderGiftCard {
OrderGiftCards,
OrderId,
GiftCardId,
}
#[derive(Inde)]
pub enum OrderItemChange {
OrderItemChanges,
Id,
CreatedAt,
UpdatedAt,
DeletedAt,
Type,
OrderEditId,
OriginalLineItemId,
LineItemId,
}
#[derive(Inde)]
pub enum Payment {
Payments,
Id,
SwapId,
CartId,
OrderId,
Amount,
CurrencyCode,
AmountRefunded,
ProviderId,
Data,
CapturedAt,
CanceledAt,
CreatedAt,
UpdatedAt,
Metadata,
IdempotencyKey,
}
#[derive(Inde)]
pub enum PaymentCollection {
PaymentCollections,
Id,
CreatedAt,
UpdatedAt,
DeletedAt,
Type,
Status,
Description,
Amount,
AuthorizedAmount,
RegionId,
CurrencyCode,
Metadata,
CreatedBy,
}
#[derive(Inde)]
pub enum PaymentCollectionPayment {
PaymentCollectionPayments,
PaymentCollectionId,
PaymentId,
}
#[derive(Inde)]
pub enum PaymentCollectionSession {
PaymentCollectionSessions,
PaymentCollectionId,
PaymentSessionId,
}
#[derive(Inde)]
pub enum PaymentProvider {
PaymentProviders,
Id,
IsInstalled,
}
#[derive(Inde)]
pub enum PaymentSession {
PaymentSessions,
Id,
CartId,
ProviderId,
IsSelected,
Status,
Data,
CreatedAt,
UpdatedAt,
IdempotencyKey,
PaymentAuthorizedAt,
Amount,
IsInitiated,
}

View File

@ -0,0 +1,12 @@
mod m20230603_120814_checkouts;
use sea_orm_migration::{MigrationTrait, MigratorTrait};
pub struct CheckoutsMigrator;
#[async_trait::async_trait]
impl MigratorTrait for CheckoutsMigrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![Box::new(m20230603_120814_checkouts::Migration)]
}
}

View File

@ -0,0 +1,544 @@
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> {
create_type!(m, DiscountConditionType);
create_type!(m, DiscountConditionOperator);
create_type!(m, DiscountRuleType);
create_type!(m, DiscountRuleAllocation);
Self::create_discounts(m).await?;
Self::create_discount_conditions(m).await?;
Self::create_discount_condition_customer_groups(m).await?;
Self::create_discount_condition_products(m).await?;
Self::create_discount_condition_product_collections(m).await?;
Self::create_discount_condition_product_tags(m).await?;
Self::create_discount_condition_product_types(m).await?;
Self::create_discount_regions(m).await?;
Self::create_discount_rules(m).await?;
Self::create_discount_rule_products(m).await?;
Ok(())
}
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
self.drop_table(m, Discount::Discounts).await?;
self.drop_table(m, DiscountCondition::DiscountConditions)
.await?;
self.drop_table(
m,
DiscountConditionCustomerGroup::DiscountConditionCustomerGroups,
)
.await?;
self.drop_table(m, DiscountConditionProduct::DiscountConditionProducts)
.await?;
self.drop_table(
m,
DiscountConditionProductCollection::DiscountConditionProductCollections,
)
.await?;
self.drop_table(m, DiscountConditionProductTag::DiscountConditionProductTags)
.await?;
self.drop_table(
m,
DiscountConditionProductType::DiscountConditionProductTypes,
)
.await?;
self.drop_table(m, DiscountRegion::DiscountRegions).await?;
self.drop_table(m, DiscountRule::DiscountRules).await?;
self.drop_table(m, DiscountRuleProduct::DiscountRuleProducts)
.await?;
drop_type!(m, DiscountConditionType);
drop_type!(m, DiscountConditionOperator);
drop_type!(m, DiscountRuleType);
drop_type!(m, DiscountRuleAllocation);
Ok(())
}
}
impl Migration {
/// ```sql
/// CREATE TABLE discounts
/// (
/// id uuid NOT NULL,
/// code character varying NOT NULL,
/// is_dynamic boolean NOT NULL,
/// rule_id uuid,
/// is_disabled boolean NOT NULL,
/// parent_discount_id uuid,
/// starts_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP 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,
/// usage_limit integer,
/// usage_count integer DEFAULT 0 NOT NULL,
/// valid_duration character varying
/// );
/// ```
async fn create_discounts(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(Discount::Discounts)
.col(auto_uuid_not_null!(Discount::Id))
.col(ColumnDef::new(Discount::Code).string().not_null())
.col(ColumnDef::new(Discount::IsDynamic).boolean().not_null())
.col(ColumnDef::new(Discount::RuleId).uuid())
.col(ColumnDef::new(Discount::IsDisabled).boolean().not_null())
.col(ColumnDef::new(Discount::ParentDiscountId).uuid())
.col(
ColumnDef::new(Discount::StartsAt)
.timestamp()
.default(SimpleExpr::Custom("CURRENT_TIMESTAMP".into()))
.not_null(),
)
.col(ColumnDef::new(Discount::EndsAt).timestamp())
.col(ts_def_now_not_null!(Discount::CreatedAt))
.col(ts_def_now_not_null!(Discount::UpdatedAt))
.col(ColumnDef::new(Discount::DeletedAt).timestamp())
.col(ColumnDef::new(Discount::Metadata).json_binary())
.col(ColumnDef::new(Discount::UsageLimit).integer())
.col(
ColumnDef::new(Discount::UsageCount)
.integer()
.default(0)
.not_null(),
)
.col(ColumnDef::new(Discount::ValidDuration).string())
.to_owned(),
)
.await?;
Ok(())
}
/// ```sql
/// CREATE TABLE discount_conditions
/// (
/// id uuid NOT NULL,
/// type public.discount_condition_types NOT NULL,
/// operator public.discount_condition_operators NOT NULL,
/// discount_rule_id uuid 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
/// );
/// ```
async fn create_discount_conditions(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(DiscountCondition::DiscountConditions)
.col(auto_uuid_not_null!(DiscountCondition::Id))
.col(
ColumnDef::new(DiscountCondition::DiscountConditionType).enumeration(
crate::types::DiscountConditionType::DiscountConditionTypes,
crate::types::DiscountConditionType::iter().skip(1),
),
)
.col(ColumnDef::new(DiscountCondition::Operator).enumeration(
crate::types::DiscountConditionOperator::DiscountConditionOperators,
crate::types::DiscountConditionOperator::iter().skip(1),
))
.col(
ColumnDef::new(DiscountCondition::DiscountRuleId)
.uuid()
.not_null(),
)
.col(ts_def_now_not_null!(DiscountCondition::CreatedAt))
.col(ts_def_now_not_null!(DiscountCondition::UpdatedAt))
.col(ColumnDef::new(DiscountCondition::DeletedAt).timestamp())
.col(ColumnDef::new(DiscountCondition::Metadata).json_binary())
.to_owned(),
)
.await?;
Ok(())
}
/// ```sql
/// CREATE TABLE discount_condition_customer_groups
/// (
/// customer_group_id uuid NOT NULL,
/// condition_id uuid NOT NULL,
/// created_at timestamp with time zone DEFAULT now() NOT NULL,
/// updated_at timestamp with time zone DEFAULT now() NOT NULL,
/// metadata jsonb
/// );
/// ```
async fn create_discount_condition_customer_groups(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(DiscountConditionCustomerGroup::DiscountConditionCustomerGroups)
.col(
ColumnDef::new(DiscountConditionCustomerGroup::CustomerGroupId)
.uuid()
.not_null(),
)
.col(
ColumnDef::new(DiscountConditionCustomerGroup::ConditionId)
.uuid()
.not_null(),
)
.col(ts_def_now_not_null!(
DiscountConditionCustomerGroup::CreatedAt
))
.col(ts_def_now_not_null!(
DiscountConditionCustomerGroup::UpdatedAt
))
.col(ColumnDef::new(DiscountConditionCustomerGroup::Metadata).json_binary())
.to_owned(),
)
.await?;
Ok(())
}
/// ```sql
/// CREATE TABLE discount_condition_products
/// (
/// product_id uuid NOT NULL,
/// condition_id uuid NOT NULL,
/// created_at timestamp with time zone DEFAULT now() NOT NULL,
/// updated_at timestamp with time zone DEFAULT now() NOT NULL,
/// metadata jsonb
/// );
/// ```
async fn create_discount_condition_products(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(DiscountConditionProduct::DiscountConditionProducts)
.col(
ColumnDef::new(DiscountConditionProduct::ProductId)
.uuid()
.not_null(),
)
.col(
ColumnDef::new(DiscountConditionProduct::ConditionId)
.uuid()
.not_null(),
)
.col(ts_def_now_not_null!(DiscountConditionProduct::CreatedAt))
.col(ts_def_now_not_null!(DiscountConditionProduct::UpdatedAt))
.col(ColumnDef::new(DiscountConditionProduct::Metadata).json_binary())
.to_owned(),
)
.await?;
Ok(())
}
/// ```sql
/// CREATE TABLE discount_condition_product_collections
/// (
/// product_collection_id uuid NOT NULL,
/// condition_id uuid NOT NULL,
/// created_at timestamp with time zone DEFAULT now() NOT NULL,
/// updated_at timestamp with time zone DEFAULT now() NOT NULL,
/// metadata jsonb
/// );
/// ```
async fn create_discount_condition_product_collections(
m: &SchemaManager<'_>,
) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(DiscountConditionProductCollection::DiscountConditionProductCollections)
.col(
ColumnDef::new(DiscountConditionProductCollection::ProductCollectionId)
.uuid()
.not_null(),
)
.col(
ColumnDef::new(DiscountConditionProductCollection::ConditionId)
.uuid()
.not_null(),
)
.col(ts_def_now_not_null!(
DiscountConditionProductCollection::CreatedAt
))
.col(ts_def_now_not_null!(
DiscountConditionProductCollection::UpdatedAt
))
.col(ColumnDef::new(DiscountConditionProductCollection::Metadata).json_binary())
.to_owned(),
)
.await?;
Ok(())
}
/// ```sql
/// CREATE TABLE discount_condition_product_tags
/// (
/// product_tag_id uuid NOT NULL,
/// condition_id uuid NOT NULL,
/// created_at timestamp with time zone DEFAULT now() NOT NULL,
/// updated_at timestamp with time zone DEFAULT now() NOT NULL,
/// metadata jsonb
/// );
/// ```
async fn create_discount_condition_product_tags(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(DiscountConditionProductTag::DiscountConditionProductTags)
.col(
ColumnDef::new(DiscountConditionProductTag::ProductTagId)
.uuid()
.not_null(),
)
.col(
ColumnDef::new(DiscountConditionProductTag::ConditionId)
.uuid()
.not_null(),
)
.col(ts_def_now_not_null!(DiscountConditionProductTag::CreatedAt))
.col(ts_def_now_not_null!(DiscountConditionProductTag::UpdatedAt))
.col(ColumnDef::new(DiscountConditionProductTag::Metadata).json_binary())
.to_owned(),
)
.await?;
Ok(())
}
/// ```sql
/// CREATE TABLE discount_condition_product_types
/// (
/// product_type_id uuid NOT NULL,
/// condition_id uuid NOT NULL,
/// created_at timestamp with time zone DEFAULT now() NOT NULL,
/// updated_at timestamp with time zone DEFAULT now() NOT NULL,
/// metadata jsonb
/// );
/// ```
async fn create_discount_condition_product_types(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(DiscountConditionProductType::DiscountConditionProductTypes)
.col(
ColumnDef::new(DiscountConditionProductType::ProductTypeId)
.uuid()
.not_null(),
)
.col(
ColumnDef::new(DiscountConditionProductType::ConditionId)
.uuid()
.not_null(),
)
.col(ts_def_now_not_null!(
DiscountConditionProductType::CreatedAt
))
.col(ts_def_now_not_null!(
DiscountConditionProductType::UpdatedAt
))
.col(ColumnDef::new(DiscountConditionProductType::Metadata).json_binary())
.to_owned(),
)
.await?;
Ok(())
}
/// ```sql
/// CREATE TABLE discount_regions
/// (
/// discount_id uuid NOT NULL,
/// region_id uuid NOT NULL
/// );
/// ```
async fn create_discount_regions(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(DiscountRegion::DiscountRegions)
.col(ColumnDef::new(DiscountRegion::DiscountId).uuid().not_null())
.col(ColumnDef::new(DiscountRegion::RegionId).uuid().not_null())
.to_owned(),
)
.await?;
Ok(())
}
/// ```sql
/// CREATE TABLE discount_rules
/// (
/// id uuid NOT NULL,
/// description character varying,
/// type public.discount_rule_types NOT NULL,
/// value integer NOT NULL,
/// allocation public.discount_rule_allocations,
/// 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
/// );
/// ```
async fn create_discount_rules(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(DiscountRule::DiscountRules)
.col(auto_uuid_not_null!(DiscountRule::Id))
.col(ColumnDef::new(DiscountRule::Description).string())
.col(
ColumnDef::new(DiscountRule::DiscountRuleType)
.enumeration(
crate::types::DiscountRuleType::DiscountRuleTypes,
crate::types::DiscountRuleType::iter().skip(1),
)
.not_null(),
)
.col(ColumnDef::new(DiscountRule::Value).integer().not_null())
.col(ColumnDef::new(DiscountRule::Allocation).enumeration(
crate::types::DiscountRuleAllocation::DiscountRuleAllocations,
crate::types::DiscountRuleAllocation::iter().skip(1),
))
.col(ts_def_now_not_null!(DiscountRule::CreatedAt))
.col(ts_def_now_not_null!(DiscountRule::UpdatedAt))
.col(ColumnDef::new(DiscountRule::DeletedAt).timestamp())
.col(ColumnDef::new(DiscountRule::Metadata).json_binary())
.to_owned(),
)
.await?;
Ok(())
}
/// ```sql
/// CREATE TABLE discount_rule_products
/// (
/// discount_rule_id uuid NOT NULL,
/// product_id uuid NOT NULL
/// );
/// ```
async fn create_discount_rule_products(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(DiscountRuleProduct::DiscountRuleProducts)
.col(
ColumnDef::new(DiscountRuleProduct::DiscountRuleId)
.uuid()
.not_null(),
)
.col(
ColumnDef::new(DiscountRuleProduct::ProductId)
.uuid()
.not_null(),
)
.to_owned(),
)
.await?;
Ok(())
}
}
#[derive(Iden)]
pub enum Discount {
Discounts,
Id,
Code,
IsDynamic,
RuleId,
IsDisabled,
ParentDiscountId,
StartsAt,
EndsAt,
CreatedAt,
UpdatedAt,
DeletedAt,
Metadata,
UsageLimit,
UsageCount,
ValidDuration,
}
#[derive(Iden)]
pub enum DiscountCondition {
DiscountConditions,
Id,
DiscountConditionType,
Operator,
DiscountRuleId,
CreatedAt,
UpdatedAt,
DeletedAt,
Metadata,
}
#[derive(Iden)]
pub enum DiscountConditionCustomerGroup {
DiscountConditionCustomerGroups,
CustomerGroupId,
ConditionId,
CreatedAt,
UpdatedAt,
Metadata,
}
#[derive(Iden)]
pub enum DiscountConditionProduct {
DiscountConditionProducts,
ProductId,
ConditionId,
CreatedAt,
UpdatedAt,
Metadata,
}
#[derive(Iden)]
pub enum DiscountConditionProductCollection {
DiscountConditionProductCollections,
ProductCollectionId,
ConditionId,
CreatedAt,
UpdatedAt,
Metadata,
}
#[derive(Iden)]
pub enum DiscountConditionProductTag {
DiscountConditionProductTags,
ProductTagId,
ConditionId,
CreatedAt,
UpdatedAt,
Metadata,
}
#[derive(Iden)]
pub enum DiscountConditionProductType {
DiscountConditionProductTypes,
ProductTypeId,
ConditionId,
CreatedAt,
UpdatedAt,
Metadata,
}
#[derive(Iden)]
pub enum DiscountRegion {
DiscountRegions,
DiscountId,
RegionId,
}
#[derive(Iden)]
pub enum DiscountRule {
DiscountRules,
Id,
Description,
DiscountRuleType,
Value,
Allocation,
CreatedAt,
UpdatedAt,
DeletedAt,
Metadata,
}
#[derive(Iden)]
pub enum DiscountRuleProduct {
DiscountRuleProducts,
DiscountRuleId,
ProductId,
}

View File

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

View File

@ -1,10 +1,19 @@
pub use sea_orm_migration::prelude::*;
pub mod carts;
pub use carts::*;
pub mod discounts;
pub use discounts::*;
pub mod jobs;
pub use jobs::*;
pub mod public;
pub use public::*;
pub mod schema_list;
pub use schema_list::*;
pub mod checkouts;
pub use checkouts::*;
pub mod types;
pub use types::*;
#[macro_export]
macro_rules! ts_def_now_not_null {
@ -22,7 +31,35 @@ macro_rules! auto_uuid_not_null {
ColumnDef::new($identifier)
.uuid()
.not_null()
.default(SimpleExpr::Custom("uuid_generate_v4()".into()))
.default(SimpleExpr::Custom("public.uuid_generate_v4()".into()))
.primary_key()
};
}
// #[macro_export]
// macro_rules! col {
// ($name: expr $ty: expr) => {
// ColumnDef::new($name).$ty()
// };
// ($name: expr auto uuid) => {
// $crate::auto_uuid_not_null!($name)
// };
// ($name: expr $ty: expr default $value: expr) => {
// $crate::col!($name $ty).default($value)
// };
// }
#[async_trait::async_trait]
pub trait DropTable {
async fn drop_table<I: Iden + 'static>(
&self,
manager: &SchemaManager<'_>,
identifier: I,
) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(identifier).to_owned())
.await
}
}
impl<T: MigrationTrait> DropTable for T {}

View File

@ -1,3 +1,5 @@
#![feature(concat_idents)]
use std::error::Error;
use std::fmt::Display;
use std::process::exit;
@ -13,6 +15,17 @@ use tracing_subscriber::EnvFilter;
// const MIGRATION_DIR: &str = "./";
macro_rules! migrate_schema {
($cli: expr, $schema_name: ident, $migrator_name: ident) => {{
run_cli(
&mut $cli,
PostgreSQLSchema::$schema_name,
migration::$migrator_name,
)
.await;
}};
}
#[async_std::main]
async fn main() {
dotenv().ok();
@ -20,24 +33,10 @@ async fn main() {
init_logger(cli.verbose);
run_cli(
&mut cli,
PostgreSQLSchema::Public,
migration::public::PublicMigrator,
)
.await;
run_cli(
&mut cli,
PostgreSQLSchema::Jobs,
migration::jobs::JobsMigrator,
)
.await;
run_cli(
&mut cli,
PostgreSQLSchema::Carts,
migration::carts::CartsMigrator,
)
.await;
migrate_schema!(cli, Public, PublicMigrator);
migrate_schema!(cli, Jobs, JobsMigrator);
migrate_schema!(cli, Carts, CartsMigrator);
migrate_schema!(cli, Discounts, DiscountsMigrator);
}
pub async fn run_cli<M>(cli: &mut Cli, schema: PostgreSQLSchema, migrator: M)
@ -57,6 +56,10 @@ where
.await
.expect("Fail to acquire database connection");
db.execute_unprepared(&format!("CREATE SCHEMA {}", schema))
.await
.ok();
db.execute_unprepared(&format!("SET search_path = '{}'", schema))
.await
.unwrap();

View File

@ -1,37 +0,0 @@
use sea_orm::Iterable;
use sea_orm_migration::prelude::*;
use sea_orm_migration::sea_orm::{DatabaseBackend, Statement};
use crate::schema_list::PostgreSQLSchema;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
for schema in PostgreSQLSchema::iter().skip(1) {
manager
.get_connection()
.execute(Statement::from_string(
DatabaseBackend::Postgres,
format!("CREATE SCHEMA {}", schema.as_str()),
))
.await?;
}
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
for schema in PostgreSQLSchema::iter().skip(1) {
manager
.get_connection()
.execute(Statement::from_string(
DatabaseBackend::Postgres,
format!("DROP SCHEMA {}", schema.as_str()),
))
.await?;
}
Ok(())
}
}

View File

@ -1,8 +1,6 @@
use sea_orm::Iterable;
use sea_orm_migration::prelude::*;
use crate::extension::postgres::Type;
use crate::types::*;
use crate::{create_type, drop_type};
#[derive(DeriveMigrationName)]
@ -18,10 +16,6 @@ impl MigrationTrait for Migration {
create_type!(manager, ClaimOrderFulfillmentStatus);
create_type!(manager, ClaimOrderPaymentStatus);
create_type!(manager, ClaimOrderType);
create_type!(manager, DiscountConditionOperator);
create_type!(manager, DiscountConditionType);
create_type!(manager, DiscountRuleAllocation);
create_type!(manager, DiscountRuleType);
create_type!(manager, DraftOrderStatus);
create_type!(manager, InviteRole);
create_type!(manager, OrderFulfillmentStatus);
@ -50,10 +44,6 @@ impl MigrationTrait for Migration {
drop_type!(manager, ClaimOrderFulfillmentStatus);
drop_type!(manager, ClaimOrderPaymentStatus);
drop_type!(manager, ClaimOrderType);
drop_type!(manager, DiscountConditionOperator);
drop_type!(manager, DiscountConditionType);
drop_type!(manager, DiscountRuleAllocation);
drop_type!(manager, DiscountRuleType);
drop_type!(manager, DraftOrderStatus);
drop_type!(manager, InviteRole);
drop_type!(manager, OrderFulfillmentStatus);

View File

@ -1,22 +1,27 @@
use sea_orm_migration::prelude::*;
use sea_orm_migration::sea_orm::Iterable;
use sea_query::expr::SimpleExpr;
use crate::types::*;
use crate::{auto_uuid_not_null, ts_def_now_not_null};
/// ```sql
/// ```
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
Self::create_countries(manager).await?;
Self::create_currencies(manager).await?;
Self::create_regions(manager).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
m.drop_table(Table::drop().table(Country::Countries).to_owned())
.await?;
m.drop_table(Table::drop().table(Currency::Currencies).to_owned())
.await?;
m.drop_table(Table::drop().table(Currency::Currencies).to_owned())
.await?;
Ok(())
}
}
@ -34,8 +39,35 @@ impl Migration {
/// region_id character varying
/// );
/// ```
async fn create_countries(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
todo!()
async fn create_countries(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(Country::Countries)
.col(auto_uuid_not_null!(Country::Id))
.col(ColumnDef::new(Country::Iso2).char_len(2).not_null())
.col(ColumnDef::new(Country::Iso3).char_len(3).not_null())
.col(ColumnDef::new(Country::NumCode).integer().not_null())
.col(ColumnDef::new(Country::Name).string().not_null())
.col(ColumnDef::new(Country::DisplayName).string().not_null())
.col(ColumnDef::new(Country::RegionId).uuid())
.to_owned(),
)
.await?;
m.create_index(
IndexCreateStatement::new()
.table(Country::Countries)
.col(Country::Iso2)
.to_owned(),
)
.await?;
m.create_index(
IndexCreateStatement::new()
.table(Country::Countries)
.col(Country::Iso3)
.to_owned(),
)
.await?;
Ok(())
}
/// ```sql
@ -47,8 +79,25 @@ impl Migration {
/// name character varying NOT NULL
/// );
/// ```
async fn create_currencies(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
todo!()
async fn create_currencies(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(Currency::Currencies)
.col(ColumnDef::new(Currency::Code).string().not_null())
.col(ColumnDef::new(Currency::Symbol).string().not_null())
.col(ColumnDef::new(Currency::SymbolNative).string().not_null())
.col(ColumnDef::new(Currency::Name).string().not_null())
.to_owned(),
)
.await?;
m.create_index(
IndexCreateStatement::new()
.table(Currency::Currencies)
.col(Currency::Code)
.to_owned(),
)
.await?;
Ok(())
}
/// CREATE TABLE public.regions
@ -66,19 +115,73 @@ impl Migration {
/// automatic_taxes boolean DEFAULT true NOT NULL,
/// tax_provider_id uuid
/// );
async fn create_regions(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
todo!()
async fn create_regions(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table(
Table::create()
.table(Region::Regions)
.col(auto_uuid_not_null!(Region::Id))
.col(ColumnDef::new(Region::Name).string().not_null())
.col(ColumnDef::new(Region::CurrencyCode).string().not_null())
.col(ColumnDef::new(Region::TaxRate).double().not_null())
.col(ColumnDef::new(Region::TaxCode).string().not_null())
.col(ts_def_now_not_null!(Region::CreatedAt))
.col(ts_def_now_not_null!(Region::UpdatedAt))
.col(ColumnDef::new(Region::DeletedAt).timestamp())
.col(ColumnDef::new(Region::Metadata).json_binary())
.col(
ColumnDef::new(Region::GiftCardsTaxable)
.boolean()
.default(true)
.not_null(),
)
.col(
ColumnDef::new(Region::AutomaticTaxes)
.boolean()
.default(true)
.not_null(),
)
.col(ColumnDef::new(Region::TaxProviderId).uuid().not_null())
.to_owned(),
)
.await?;
Ok(())
}
}
#[derive(Iden)]
pub enum ClaimImage {
ClaimImages,
pub enum Country {
Countries,
Id,
ClaimItemId,
Url,
Iso2,
Iso3,
NumCode,
Name,
DisplayName,
RegionId,
}
#[derive(Iden)]
pub enum Currency {
Currencies,
Code,
Symbol,
SymbolNative,
Name,
}
#[derive(Iden)]
pub enum Region {
Regions,
Id,
Name,
CurrencyCode,
TaxRate,
TaxCode,
CreatedAt,
UpdatedAt,
DeletedAt,
Metadata,
GiftCardsTaxable,
AutomaticTaxes,
TaxProviderId,
}

View File

@ -1,6 +1,5 @@
use sea_orm_migration::{MigrationTrait, MigratorTrait};
mod m20230603_102630_schema;
mod m20230603_102634_types;
mod m20230603_120814_addresses;
mod m20230603_120815_claims;
@ -11,9 +10,7 @@ pub struct PublicMigrator;
#[async_trait::async_trait]
impl MigratorTrait for PublicMigrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
eprintln!("PublicMigrator");
vec![
Box::new(m20230603_102630_schema::Migration),
Box::new(m20230603_102634_types::Migration),
Box::new(m20230603_120814_addresses::Migration),
Box::new(m20230603_120815_claims::Migration),

View File

@ -7,6 +7,7 @@ pub enum PostgreSQLSchema {
Public,
Jobs,
Carts,
Discounts,
}
impl PostgreSQLSchema {
@ -15,6 +16,7 @@ impl PostgreSQLSchema {
PostgreSQLSchema::Public => "public",
PostgreSQLSchema::Jobs => "jobs",
PostgreSQLSchema::Carts => "carts",
PostgreSQLSchema::Discounts => "discounts",
}
}
}

View File

@ -3,7 +3,10 @@ use sea_orm_migration::prelude::*;
#[macro_export]
macro_rules! create_type {
($manager: ident, $ty: ident) => {
($manager: ident, $ty: ident) => {{
use crate::extension::postgres::Type;
use crate::types::*;
$manager
.create_type(
Type::create()
@ -12,11 +15,14 @@ macro_rules! create_type {
.to_owned(),
)
.await?;
};
}};
}
#[macro_export]
macro_rules! drop_type {
($manager: ident, $ty: ident) => {
($manager: ident, $ty: ident) => {{
use crate::extension::postgres::Type;
use crate::types::*;
$manager
.drop_type(
Type::drop()
@ -26,7 +32,7 @@ macro_rules! drop_type {
.to_owned(),
)
.await?;
};
}};
}
#[derive(Iden, EnumIter)]

View File

@ -347,15 +347,6 @@ CREATE TABLE public.claim_tags
metadata jsonb
);
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
CREATE TABLE public.regions
(
@ -392,50 +383,6 @@ CREATE TABLE public.currencies
name character varying NOT NULL
);
CREATE TABLE public.custom_shipping_options
(
id uuid NOT NULL,
price integer NOT NULL,
shipping_option_id uuid NOT NULL,
cart_id uuid,
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 public.customers
(
id uuid NOT NULL,
email character varying NOT NULL,
first_name character varying,
last_name character varying,
billing_address_id uuid,
password_hash character varying,
phone character varying,
has_account boolean DEFAULT false 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 public.customer_groups
(
id uuid NOT NULL,
name 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 public.customer_group_customers
(
customer_group_id uuid NOT NULL,
customer_id uuid NOT NULL
);
CREATE TABLE public.discounts
(
id uuid NOT NULL,
@ -537,6 +484,205 @@ CREATE TABLE public.discount_rule_products
product_id uuid NOT NULL
);
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
CREATE TABLE public.orders
(
id uuid NOT NULL,
status public.order_statuses DEFAULT 'pending'::public.order_statuses NOT NULL,
fulfillment_status public.order_fulfillment_statuses DEFAULT 'not_fulfilled'::public.order_fulfillment_statuses NOT NULL,
payment_status public.order_payment_statuses DEFAULT 'not_paid'::public.order_payment_statuses NOT NULL,
display_id integer NOT NULL,
cart_id uuid,
customer_id uuid NOT NULL,
email character varying NOT NULL,
billing_address_id uuid,
shipping_address_id uuid,
region_id uuid NOT NULL,
currency_code character varying NOT NULL,
tax_rate real,
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,
draft_order_id uuid,
no_notification boolean,
external_id uuid,
sales_channel_id uuid
);
CREATE TABLE public.order_discounts
(
order_id uuid NOT NULL,
discount_id uuid NOT NULL
);
CREATE TABLE public.order_edits
(
id uuid NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
order_id uuid NOT NULL,
internal_note character varying,
created_by character varying NOT NULL,
requested_by character varying,
requested_at timestamp with time zone,
confirmed_by character varying,
confirmed_at timestamp with time zone,
declined_by character varying,
declined_reason character varying,
declined_at timestamp with time zone,
canceled_by character varying,
canceled_at timestamp with time zone,
payment_collection_id uuid
);
CREATE TABLE public.order_gift_cards
(
order_id uuid NOT NULL,
gift_card_id uuid NOT NULL
);
CREATE TABLE public.order_item_changes
(
id uuid 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,
type public.order_item_change_types NOT NULL,
order_edit_id uuid NOT NULL,
original_line_item_id uuid,
line_item_id uuid
);
CREATE TABLE public.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
);
CREATE TABLE public.payment_collections
(
id uuid 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,
type public.payment_collection_types NOT NULL,
status public.payment_collection_statuses NOT NULL,
description text,
amount integer NOT NULL,
authorized_amount integer,
region_id uuid NOT NULL,
currency_code character varying NOT NULL,
metadata jsonb,
created_by character varying NOT NULL
);
CREATE TABLE public.payment_collection_payments
(
payment_collection_id uuid NOT NULL,
payment_id uuid NOT NULL
);
CREATE TABLE public.payment_collection_sessions
(
payment_collection_id uuid NOT NULL,
payment_session_id uuid NOT NULL
);
CREATE TABLE public.payment_providers
(
id uuid NOT NULL,
is_installed boolean DEFAULT true NOT NULL
);
CREATE TABLE public.payment_sessions
(
id uuid NOT NULL,
cart_id uuid,
provider_id uuid NOT NULL,
is_selected boolean,
status public.payment_session_statuses NOT NULL,
data jsonb NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
idempotency_key character varying,
payment_authorized_at timestamp with time zone,
amount integer,
is_initiated boolean DEFAULT false NOT NULL
);
---------
---------
---------
---------
CREATE TABLE public.customers
(
id uuid NOT NULL,
email character varying NOT NULL,
first_name character varying,
last_name character varying,
billing_address_id uuid,
password_hash character varying,
phone character varying,
has_account boolean DEFAULT false 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 public.customer_groups
(
id uuid NOT NULL,
name 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 public.customer_group_customers
(
customer_group_id uuid NOT NULL,
customer_id uuid NOT NULL
);
CREATE TABLE public.custom_shipping_options
(
id uuid NOT NULL,
price integer NOT NULL,
shipping_option_id uuid NOT NULL,
cart_id uuid,
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 public.draft_orders
(
id uuid NOT NULL,
@ -771,146 +917,6 @@ CREATE TABLE public.oauth
data jsonb
);
CREATE TABLE public.orders
(
id uuid NOT NULL,
status public.order_statuses DEFAULT 'pending'::public.order_statuses NOT NULL,
fulfillment_status public.order_fulfillment_statuses DEFAULT 'not_fulfilled'::public.order_fulfillment_statuses NOT NULL,
payment_status public.order_payment_statuses DEFAULT 'not_paid'::public.order_payment_statuses NOT NULL,
display_id integer NOT NULL,
cart_id uuid,
customer_id uuid NOT NULL,
email character varying NOT NULL,
billing_address_id uuid,
shipping_address_id uuid,
region_id uuid NOT NULL,
currency_code character varying NOT NULL,
tax_rate real,
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,
draft_order_id uuid,
no_notification boolean,
external_id uuid,
sales_channel_id uuid
);
CREATE TABLE public.order_discounts
(
order_id uuid NOT NULL,
discount_id uuid NOT NULL
);
CREATE TABLE public.order_edits
(
id uuid NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
order_id uuid NOT NULL,
internal_note character varying,
created_by character varying NOT NULL,
requested_by character varying,
requested_at timestamp with time zone,
confirmed_by character varying,
confirmed_at timestamp with time zone,
declined_by character varying,
declined_reason character varying,
declined_at timestamp with time zone,
canceled_by character varying,
canceled_at timestamp with time zone,
payment_collection_id uuid
);
CREATE TABLE public.order_gift_cards
(
order_id uuid NOT NULL,
gift_card_id uuid NOT NULL
);
CREATE TABLE public.order_item_changes
(
id uuid 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,
type public.order_item_change_types NOT NULL,
order_edit_id uuid NOT NULL,
original_line_item_id uuid,
line_item_id uuid
);
CREATE TABLE public.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
);
CREATE TABLE public.payment_collections
(
id uuid 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,
type public.payment_collection_types NOT NULL,
status public.payment_collection_statuses NOT NULL,
description text,
amount integer NOT NULL,
authorized_amount integer,
region_id uuid NOT NULL,
currency_code character varying NOT NULL,
metadata jsonb,
created_by character varying NOT NULL
);
CREATE TABLE public.payment_collection_payments
(
payment_collection_id uuid NOT NULL,
payment_id uuid NOT NULL
);
CREATE TABLE public.payment_collection_sessions
(
payment_collection_id uuid NOT NULL,
payment_session_id uuid NOT NULL
);
CREATE TABLE public.payment_providers
(
id uuid NOT NULL,
is_installed boolean DEFAULT true NOT NULL
);
CREATE TABLE public.payment_sessions
(
id uuid NOT NULL,
cart_id uuid,
provider_id uuid NOT NULL,
is_selected boolean,
status public.payment_session_statuses NOT NULL,
data jsonb NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
idempotency_key character varying,
payment_authorized_at timestamp with time zone,
amount integer,
is_initiated boolean DEFAULT false NOT NULL
);
CREATE TABLE public.price_lists
(
id uuid NOT NULL,