bazzar/migrations/20230603073510_init.sql

598 lines
20 KiB
MySQL
Raw Permalink Normal View History

2023-06-09 17:30:58 +02:00
CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA
COMMENT ON EXTENSION pg_trgm IS 'text similarity measurement and index searching based on trigrams';
2023-06-03 13:31:57 +02:00
2023-06-09 07:21:40 +02:00
CREATE TYPE payment_collection_statuses AS ENUM (
2023-06-03 13:31:57 +02:00
'not_paid',
'awaiting',
'authorized',
'partially_authorized',
'canceled'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE payment_collection_types AS ENUM (
2023-06-03 13:31:57 +02:00
'order_edit'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE claim_item_reasons AS ENUM (
2023-06-03 13:31:57 +02:00
'missing_item',
'wrong_item',
'production_failure',
'other'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE claim_order_fulfillment_statuses AS ENUM (
2023-06-03 13:31:57 +02:00
'not_fulfilled',
'partially_fulfilled',
'fulfilled',
'partially_shipped',
'shipped',
'partially_returned',
'returned',
'canceled',
'requires_action'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE claim_order_payment_statuses AS ENUM (
2023-06-03 13:31:57 +02:00
'na',
'not_refunded',
'refunded'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE claim_order_types AS ENUM (
2023-06-03 13:31:57 +02:00
'refund',
'replace'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE discount_condition_operators AS ENUM (
2023-06-03 13:31:57 +02:00
'in',
'not_in'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE discount_condition_types AS ENUM (
2023-06-03 13:31:57 +02:00
'products',
'product_types',
'product_collections',
'product_tags',
'customer_groups'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE discount_rule_allocations AS ENUM (
2023-06-03 13:31:57 +02:00
'total',
'item'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE discount_rule_types AS ENUM (
2023-06-03 13:31:57 +02:00
'fixed',
'percentage',
'free_shipping'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE draft_order_statuses AS ENUM (
2023-06-03 13:31:57 +02:00
'open',
'completed'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE invite_roles AS ENUM (
2023-06-03 13:31:57 +02:00
'admin',
'member',
'developer'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE order_fulfillment_statuses AS ENUM (
2023-06-03 13:31:57 +02:00
'not_fulfilled',
'partially_fulfilled',
'fulfilled',
'partially_shipped',
'shipped',
'partially_returned',
'returned',
'canceled',
'requires_action'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE order_item_change_types AS ENUM (
2023-06-03 13:31:57 +02:00
'item_add',
'item_remove',
'item_update'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE order_payment_statuses AS ENUM (
2023-06-03 13:31:57 +02:00
'not_paid',
'awaiting',
'captured',
'partially_refunded',
'refunded',
'canceled',
'requires_action'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE order_statuses AS ENUM (
2023-06-03 13:31:57 +02:00
'pending',
'completed',
'archived',
'canceled',
'requires_action'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE payment_session_statuses AS ENUM (
2023-06-03 13:31:57 +02:00
'authorized',
'pending',
'requires_more',
'error',
'canceled'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE price_list_statuses AS ENUM (
2023-06-03 13:31:57 +02:00
'active',
'draft'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE price_list_types AS ENUM (
2023-06-03 13:31:57 +02:00
'sale',
'override'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE product_statuses AS ENUM (
2023-06-03 13:31:57 +02:00
'draft',
'proposed',
'published',
'rejected'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE refund_reasons AS ENUM (
2023-06-03 13:31:57 +02:00
'discount',
'return',
'swap',
'claim',
'other'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE return_statuses AS ENUM (
2023-06-03 13:31:57 +02:00
'requested',
'received',
'requires_action',
'canceled'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE shipping_option_price_types AS ENUM (
2023-06-03 13:31:57 +02:00
'flat_rate',
'calculated'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE shipping_option_requirement_types AS ENUM (
2023-06-03 13:31:57 +02:00
'min_subtotal',
'max_subtotal'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE shipping_profile_types AS ENUM (
2023-06-03 13:31:57 +02:00
'default',
'gift_card',
'custom'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE swap_fulfillment_statuses AS ENUM (
2023-06-03 13:31:57 +02:00
'not_fulfilled',
'fulfilled',
'shipped',
'partially_shipped',
'canceled',
'requires_action'
);
2023-06-09 07:21:40 +02:00
CREATE TYPE swap_payment_statuses AS ENUM (
2023-06-03 13:31:57 +02:00
'not_paid',
'awaiting',
'captured',
'confirmed',
'canceled',
'difference_refunded',
'partially_refunded',
'refunded',
'requires_action'
);
2023-06-09 07:21:40 +02:00
CREATE TABLE analytics_configs
2023-06-03 13:31:57 +02:00
(
2023-06-07 21:39:39 +02:00
id uuid NOT NULL,
2023-06-03 13:31:57 +02:00
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,
2023-06-07 21:39:39 +02:00
user_id uuid NOT NULL,
2023-06-03 13:31:57 +02:00
opt_out boolean DEFAULT false NOT NULL,
anonymize boolean DEFAULT false NOT NULL
);
2023-06-09 07:21:40 +02:00
CREATE TABLE batch_jobs
2023-06-03 13:31:57 +02:00
(
2023-06-07 21:39:39 +02:00
id uuid NOT NULL,
2023-06-03 13:31:57 +02:00
type text NOT NULL,
created_by character varying,
context jsonb,
result jsonb,
dry_run boolean DEFAULT false NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
pre_processed_at timestamp with time zone,
confirmed_at timestamp with time zone,
processing_at timestamp with time zone,
completed_at timestamp with time zone,
failed_at timestamp with time zone,
canceled_at timestamp with time zone,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
deleted_at timestamp with time zone
);
2023-06-09 07:21:40 +02:00
CREATE TABLE claim_images
2023-06-03 13:31:57 +02:00
(
2023-06-07 21:39:39 +02:00
id uuid NOT NULL,
claim_item_id uuid NOT NULL,
2023-06-03 13:31:57 +02:00
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
);
2023-06-09 07:21:40 +02:00
CREATE TABLE claim_items
2023-06-03 13:31:57 +02:00
(
2023-06-07 21:39:39 +02:00
id uuid NOT NULL,
claim_order_id uuid NOT NULL,
item_id uuid NOT NULL,
variant_id uuid NOT NULL,
2023-06-09 17:30:58 +02:00
reason claim_item_reasons NOT NULL,
2023-06-03 13:31:57 +02:00
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
);
2023-06-09 07:21:40 +02:00
CREATE TABLE claim_item_tags
2023-06-03 13:31:57 +02:00
(
2023-06-06 17:02:42 +02:00
item_id uuid NOT NULL,
2023-06-07 21:39:39 +02:00
tag_id uuid NOT NULL
2023-06-03 13:31:57 +02:00
);
2023-06-09 07:21:40 +02:00
CREATE TABLE claim_orders
2023-06-03 13:31:57 +02:00
(
2023-06-09 17:30:58 +02:00
id uuid NOT NULL,
2023-06-09 07:21:40 +02:00
payment_status claim_order_payment_statuses DEFAULT 'na'::claim_order_payment_statuses NOT NULL,
fulfillment_status claim_order_fulfillment_statuses DEFAULT 'not_fulfilled'::claim_order_fulfillment_statuses NOT NULL,
2023-06-09 17:30:58 +02:00
type claim_order_types NOT NULL,
order_id uuid NOT NULL,
2023-06-07 21:39:39 +02:00
shipping_address_id uuid,
2023-06-03 13:31:57 +02:00
refund_amount integer,
canceled_at timestamp with time zone,
2023-06-09 17:30:58 +02:00
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
2023-06-03 13:31:57 +02:00
deleted_at timestamp with time zone,
metadata jsonb,
idempotency_key character varying,
no_notification boolean
);
2023-06-09 07:21:40 +02:00
CREATE TABLE claim_tags
2023-06-03 13:31:57 +02:00
(
2023-06-07 21:39:39 +02:00
id uuid NOT NULL,
2023-06-03 13:31:57 +02:00
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
);
2023-06-09 07:21:40 +02:00
CREATE TABLE orders
2023-06-08 15:48:02 +02:00
(
2023-06-09 17:30:58 +02:00
id uuid NOT NULL,
2023-06-09 07:21:40 +02:00
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,
2023-06-09 17:30:58 +02:00
display_id integer NOT NULL,
2023-06-08 15:48:02 +02:00
cart_id uuid,
2023-06-09 17:30:58 +02:00
customer_id uuid NOT NULL,
email character varying NOT NULL,
2023-06-08 15:48:02 +02:00
billing_address_id uuid,
shipping_address_id uuid,
2023-06-09 17:30:58 +02:00
region_id uuid NOT NULL,
currency_code character varying NOT NULL,
2023-06-08 15:48:02 +02:00
tax_rate real,
canceled_at timestamp with time zone,
2023-06-09 17:30:58 +02:00
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
2023-06-08 15:48:02 +02:00
metadata jsonb,
idempotency_key character varying,
draft_order_id uuid,
no_notification boolean,
external_id uuid,
sales_channel_id uuid
);
2023-06-09 07:21:40 +02:00
CREATE TABLE order_discounts
2023-06-08 15:48:02 +02:00
(
order_id uuid NOT NULL,
discount_id uuid NOT NULL
);
2023-06-09 07:21:40 +02:00
CREATE TABLE order_edits
2023-06-08 15:48:02 +02:00
(
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
);
2023-06-09 07:21:40 +02:00
CREATE TABLE order_gift_cards
2023-06-08 15:48:02 +02:00
(
order_id uuid NOT NULL,
gift_card_id uuid NOT NULL
);
2023-06-09 07:21:40 +02:00
CREATE TABLE order_item_changes
2023-06-08 15:48:02 +02:00
(
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,
2023-06-09 17:30:58 +02:00
type order_item_change_types NOT NULL,
2023-06-08 15:48:02 +02:00
order_edit_id uuid NOT NULL,
original_line_item_id uuid,
line_item_id uuid
);
2023-06-09 07:21:40 +02:00
CREATE TABLE payments
2023-06-08 15:48:02 +02:00
(
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
);
2023-06-09 07:21:40 +02:00
CREATE TABLE payment_collections
2023-06-08 15:48:02 +02:00
(
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,
2023-06-09 17:30:58 +02:00
type payment_collection_types NOT NULL,
status payment_collection_statuses NOT NULL,
2023-06-08 15:48:02 +02:00
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
);
2023-06-09 07:21:40 +02:00
CREATE TABLE payment_collection_payments
2023-06-08 15:48:02 +02:00
(
payment_collection_id uuid NOT NULL,
payment_id uuid NOT NULL
);
2023-06-09 07:21:40 +02:00
CREATE TABLE payment_collection_sessions
2023-06-08 15:48:02 +02:00
(
payment_collection_id uuid NOT NULL,
payment_session_id uuid NOT NULL
);
2023-06-09 07:21:40 +02:00
CREATE TABLE payment_providers
2023-06-08 15:48:02 +02:00
(
id uuid NOT NULL,
is_installed boolean DEFAULT true NOT NULL
);
2023-06-09 07:21:40 +02:00
CREATE TABLE payment_sessions
2023-06-08 15:48:02 +02:00
(
id uuid NOT NULL,
cart_id uuid,
provider_id uuid NOT NULL,
is_selected boolean,
2023-06-09 17:30:58 +02:00
status payment_session_statuses NOT NULL,
2023-06-08 15:48:02 +02:00
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
);
2023-06-09 17:30:58 +02:00
CREATE TABLE line_items
(
id uuid NOT NULL,
cart_id uuid,
order_id uuid,
swap_id uuid,
title character varying NOT NULL,
description character varying,
thumbnail character varying,
is_giftcard boolean DEFAULT false NOT NULL,
should_merge boolean DEFAULT true NOT NULL,
allow_discounts boolean DEFAULT true NOT NULL,
has_shipping boolean,
unit_price integer NOT NULL,
variant_id uuid,
quantity integer NOT NULL,
fulfilled_quantity integer,
returned_quantity integer,
shipped_quantity integer,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
metadata jsonb,
claim_order_id uuid,
is_return boolean DEFAULT false NOT NULL,
original_item_id uuid,
order_edit_id uuid,
CONSTRAINT "CHK_0cd85e15610d11b553d5e8fda6" CHECK ((shipped_quantity <= fulfilled_quantity)),
CONSTRAINT "CHK_64eef00a5064887634f1680866" CHECK ((quantity > 0)),
CONSTRAINT "CHK_91f40396d847f6ecfd9f752bf8" CHECK ((returned_quantity <= quantity)),
CONSTRAINT "CHK_c61716c68f5ad5de2834c827d3" CHECK ((fulfilled_quantity <= quantity))
);
CREATE TABLE line_item_adjustments
(
id uuid NOT NULL,
item_id uuid NOT NULL,
description character varying NOT NULL,
discount_id uuid,
amount numeric NOT NULL,
metadata jsonb
);
CREATE TABLE line_item_tax_lines
(
id uuid NOT NULL,
rate real NOT NULL,
name character varying NOT NULL,
code character varying,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
metadata jsonb,
item_id uuid NOT NULL
);
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
---- ###########################################################
2023-06-08 15:48:02 +02:00
2023-06-09 07:21:40 +02:00
CREATE TABLE draft_orders
2023-06-03 13:31:57 +02:00
(
2023-06-09 17:30:58 +02:00
id uuid NOT NULL,
status draft_order_statuses DEFAULT 'open'::draft_order_statuses NOT NULL,
display_id sequence NOT NULL,
2023-06-07 21:39:39 +02:00
cart_id uuid,
order_id uuid,
2023-06-03 13:31:57 +02:00
canceled_at timestamp with time zone,
2023-06-09 17:30:58 +02:00
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
2023-06-03 13:31:57 +02:00
completed_at timestamp with time zone,
metadata jsonb,
idempotency_key character varying,
no_notification_order boolean
);
2023-06-09 07:21:40 +02:00
CREATE TABLE fulfillments
2023-06-03 13:31:57 +02:00
(
2023-06-07 21:39:39 +02:00
id uuid NOT NULL,
swap_id uuid,
order_id uuid,
2023-06-03 13:31:57 +02:00
tracking_numbers jsonb DEFAULT '[]'::jsonb NOT NULL,
data jsonb NOT NULL,
shipped_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,
2023-06-07 21:39:39 +02:00
provider_id uuid,
claim_order_id uuid,
2023-06-03 13:31:57 +02:00
no_notification boolean,
2023-06-07 21:39:39 +02:00
location_id uuid
2023-06-03 13:31:57 +02:00
);
2023-06-09 07:21:40 +02:00
CREATE TABLE fulfillment_items
2023-06-03 13:31:57 +02:00
(
2023-06-07 21:39:39 +02:00
fulfillment_id uuid NOT NULL,
item_id uuid NOT NULL,
quantity integer NOT NULL
2023-06-03 13:31:57 +02:00
);
2023-06-09 07:21:40 +02:00
CREATE TABLE fulfillment_providers
2023-06-03 13:31:57 +02:00
(
2023-06-07 21:39:39 +02:00
id uuid NOT NULL,
2023-06-03 13:31:57 +02:00
is_installed boolean DEFAULT true NOT NULL
);
2023-06-09 07:21:40 +02:00
CREATE TABLE images
2023-06-03 13:31:57 +02:00
(
2023-06-07 21:39:39 +02:00
id uuid NOT NULL,
2023-06-03 13:31:57 +02:00
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
);
2023-06-09 07:21:40 +02:00
CREATE TABLE invites
2023-06-03 13:31:57 +02:00
(
2023-06-07 21:39:39 +02:00
id uuid NOT NULL,
2023-06-03 13:31:57 +02:00
user_email character varying NOT NULL,
2023-06-09 17:30:58 +02:00
role invite_roles DEFAULT 'member'::invite_roles,
2023-06-03 13:31:57 +02:00
accepted 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,
token character varying NOT NULL,
expires_at timestamp with time zone DEFAULT now() NOT NULL
);
2023-06-09 07:21:40 +02:00
CREATE TABLE notes
2023-06-03 13:31:57 +02:00
(
2023-06-07 21:39:39 +02:00
id uuid NOT NULL,
2023-06-03 13:31:57 +02:00
value character varying NOT NULL,
resource_type character varying NOT NULL,
2023-06-07 21:39:39 +02:00
resource_id uuid NOT NULL,
author_id uuid,
2023-06-03 13:31:57 +02:00
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
);
2023-06-09 07:21:40 +02:00
CREATE TABLE staged_jobs
2023-06-03 13:31:57 +02:00
(
2023-06-07 21:39:39 +02:00
id uuid NOT NULL,
2023-06-03 13:31:57 +02:00
event_name character varying NOT NULL,
data jsonb NOT NULL,
options jsonb DEFAULT '{}'::jsonb NOT NULL
);
2023-06-09 07:21:40 +02:00
CREATE TABLE swaps
2023-06-03 13:31:57 +02:00
(
2023-06-07 21:39:39 +02:00
id uuid NOT NULL,
2023-06-09 17:30:58 +02:00
fulfillment_status swap_fulfillment_statuses NOT NULL,
payment_status swap_payment_statuses NOT NULL,
2023-06-07 21:39:39 +02:00
order_id uuid NOT NULL,
2023-06-03 13:31:57 +02:00
difference_due integer,
2023-06-07 21:39:39 +02:00
shipping_address_id uuid,
cart_id uuid,
2023-06-03 13:31:57 +02:00
confirmed_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,
canceled_at timestamp with time zone,
allow_backorder boolean DEFAULT false NOT NULL
);