Preorder - Prelim DB changes

main
Ashelyn Dawn 3 years ago
parent 3dbee8e088
commit be32530b40

@ -1,7 +1,7 @@
create type sos."delivery_type_enum" as enum ('hand_shipped', 'easypost', 'hand_delivered');
create type sos."transaction_state_enum" as enum ('started', 'completed', 'cancelled', 'expired');
create type sos."payment_type_enum" as enum ('ks_reward', 'stripe', 'paypal', 'account_credit', 'admin_granted');
create type sos."stockchange_type_enum" as enum ('purchase', 'shipment', 'admin');
create type sos."stockchange_type_enum" as enum ('purchase', 'shipment', 'admin', 'preorder');
create type sos."stock_change_dir_enum" as enum ('added', 'subtracted');
create type sos."email_link_type_enum" as enum ('email_confirm', 'email_change', 'password_reset');
@ -53,7 +53,14 @@ create table sos."item" (
item_customs_description text not null,
item_customs_origin_country text not null,
item_weight_oz integer not null,
item_published boolean not null default true
item_published boolean not null default true,
item_preorder_availability_date timestamptz,
item_preorder_maximum integer check (item_preorder_maximum is null or item_preorder_maximum >= 0),
constraint item_cannot_have_preorder_date_without_max check (
( item_preorder_availability_date is not null and item_preorder_maximum is not null )
or ( item_preorder_availability_date is null and item_preorder_maximum is null )
)
);
create table sos."cart_item" (
@ -267,6 +274,16 @@ create table sos."item_stockchange_purchase" (
stockchange_transaction_uuid uuid references sos."transaction" (transaction_uuid)
);
create table sos."item_stockchange_preorder" (
stockchange_uuid uuid primary key default uuid_generate_v4(),
stockchange_type sos.stockchange_type_enum check (stockchange_type = 'preorder'),
foreign key (stockchange_uuid, stockchange_type) references sos."item_stockchange" (stockchange_uuid, stockchange_type),
stockchange_transaction_uuid uuid references sos."transaction" (transaction_uuid),
stockchange_preorder_estimated_fulfill_date timestamptz not null,
stockchange_preorder_ready_to_ship boolean not null default false
);
create table sos."item_stockchange_shipment" (
stockchange_uuid uuid primary key default uuid_generate_v4(),
stockchange_type sos.stockchange_type_enum check (stockchange_type = 'shipment'),

@ -162,6 +162,7 @@ create or replace view sos.v_stockchange as
from sos."item_stockchange"
left join sos."item_stockchange_shipment" on item_stockchange.stockchange_uuid = item_stockchange_shipment.stockchange_uuid
left join sos."item_stockchange_purchase" on item_stockchange.stockchange_uuid = item_stockchange_purchase.stockchange_uuid
left join sos."item_stockchange_preorder" on item_stockchange.stockchange_uuid = item_stockchange_preorder.stockchange_uuid
left join sos."item_stockchange_admin" on item_stockchange.stockchange_uuid = item_stockchange_admin.stockchange_uuid;
create or replace view sos.v_shipment as

Loading…
Cancel
Save