Add some indices

This commit is contained in:
eraden 2023-06-09 07:21:40 +02:00
parent a6486b4983
commit 1abefd40f7
8 changed files with 1311 additions and 1423 deletions

View File

@ -2,7 +2,8 @@ use sea_orm_migration::prelude::*;
use crate::sea_orm::Iterable; use crate::sea_orm::Iterable;
use crate::{ use crate::{
auto_uuid_not_null, create_type, drop_type, ts_def_now_not_null, DropTable, IntoColumnDef, auto_uuid_not_null, create_type, drop_type, to_fk_name, to_pk2_name, ts_def_now_not_null,
DropTable, IntoColumnDef,
}; };
#[derive(DeriveMigrationName)] #[derive(DeriveMigrationName)]
@ -28,6 +29,28 @@ impl MigrationTrait for Migration {
} }
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> { async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
m.drop_index(
IndexDropStatement::new()
.table(PaymentCollectionSession::PaymentCollectionSessions)
.name(&to_pk2_name(
PaymentCollectionSession::PaymentCollectionSessions,
PaymentCollectionSession::PaymentCollectionId,
PaymentCollectionSession::PaymentSessionId,
))
.to_owned(),
);
m.drop_index(
IndexDropStatement::new()
.table(PaymentCollectionPayment::PaymentCollectionPayments)
.name(&to_pk2_name(
PaymentCollectionPayment::PaymentCollectionPayments,
PaymentCollectionPayment::PaymentCollectionId,
PaymentCollectionPayment::PaymentId,
))
.to_owned(),
);
self.drop_table(m, PaymentCollectionSession::PaymentCollectionSessions) self.drop_table(m, PaymentCollectionSession::PaymentCollectionSessions)
.await?; .await?;
self.drop_table(m, PaymentCollectionPayment::PaymentCollectionPayments) self.drop_table(m, PaymentCollectionPayment::PaymentCollectionPayments)
@ -408,6 +431,37 @@ impl Migration {
.to_owned(), .to_owned(),
) )
.await?; .await?;
m.create_index(
IndexCreateStatement::new()
.table(PaymentCollectionPayment::PaymentCollectionPayments)
.col(PaymentCollectionPayment::PaymentCollectionId)
.col(PaymentCollectionPayment::PaymentId)
.primary()
.name(&to_pk2_name(
PaymentCollectionPayment::PaymentCollectionPayments,
PaymentCollectionPayment::PaymentCollectionId,
PaymentCollectionPayment::PaymentId,
))
.to_owned(),
);
m.create_foreign_key(
ForeignKeyCreateStatement::new()
.from(
PaymentCollectionPayment::PaymentCollectionPayments,
PaymentCollectionPayment::PaymentCollectionId,
)
.to(PaymentCollection::PaymentCollections, PaymentCollection::Id)
.name(&to_fk_name(
PaymentCollectionPayment::PaymentCollectionPayments,
PaymentCollectionPayment::PaymentCollectionId,
PaymentCollection::PaymentCollections,
PaymentCollection::Id,
))
.to_owned(),
);
Ok(()) Ok(())
} }
@ -435,6 +489,20 @@ impl Migration {
.to_owned(), .to_owned(),
) )
.await?; .await?;
m.create_index(
IndexCreateStatement::new()
.table(PaymentCollectionSession::PaymentCollectionSessions)
.col(PaymentCollectionSession::PaymentCollectionId)
.col(PaymentCollectionSession::PaymentSessionId)
.primary()
.name(&to_pk2_name(
PaymentCollectionSession::PaymentCollectionSessions,
PaymentCollectionSession::PaymentCollectionId,
PaymentCollectionSession::PaymentSessionId,
))
.to_owned(),
);
Ok(()) Ok(())
} }
/// ```sql /// ```sql

View File

@ -74,3 +74,35 @@ pub trait IntoColumnDef: IntoIden {
} }
impl<T: IntoIden> IntoColumnDef for T {} impl<T: IntoIden> IntoColumnDef for T {}
pub fn to_pk2_name<T1: IntoIden, C1: IntoIden, C2: IntoIden>(t1: T1, c1: C1, c2: C2) -> String {
let t1 = to_snake(t1.into_iden().to_string());
let c1 = to_snake(c1.into_iden().to_string());
let c2 = to_snake(c2.into_iden().to_string());
format!("pk_{}_{}_{}", t1, c1, c2)
}
pub fn to_fk_name<T1: IntoIden, C1: IntoIden, T2: IntoIden, C2: IntoIden>(
t1: T1,
c1: C1,
t2: T2,
c2: C2,
) -> String {
let t1 = to_snake(t1.into_iden().to_string());
let c1 = to_snake(c1.into_iden().to_string());
let t2 = to_snake(t2.into_iden().to_string());
let c2 = to_snake(c2.into_iden().to_string());
format!("fk_{}_{}_{}_{}", t1, c1, t2, c2)
}
fn to_snake(s: String) -> String {
s.chars().fold(String::new(), |mut m, c| {
if c.is_ascii_uppercase() {
m.push('_');
}
m.push(c.to_ascii_lowercase());
m
})
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
---- PENDING
CREATE TABLE 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
);

View File

@ -0,0 +1,33 @@
------ PENDING
CREATE TABLE 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 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 customer_group_customers
(
customer_group_id uuid NOT NULL,
customer_id uuid NOT NULL
);

View File

@ -0,0 +1,24 @@
CREATE TABLE tracking_links
(
id uuid NOT NULL,
url character varying,
tracking_number character varying NOT NULL,
fulfillment_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,
idempotency_key character varying
);
CREATE TABLE 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
);

View File

@ -0,0 +1,22 @@
---- PENDING
CREATE TABLE notifications
(
id uuid NOT NULL,
event_name character varying,
resource_type character varying NOT NULL,
resource_id uuid NOT NULL,
customer_id uuid,
"to" character varying NOT NULL,
data jsonb NOT NULL,
parent_id uuid,
provider_id uuid,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL
);
CREATE TABLE notification_providers
(
id uuid NOT NULL,
is_installed boolean DEFAULT true NOT NULL
);

View File

@ -0,0 +1,968 @@
ALTER TABLE ONLY payment_sessions
ADD CONSTRAINT "OneSelected" UNIQUE (cart_id, is_selected);
ALTER TABLE ONLY store_currencies
ADD CONSTRAINT "PK_0f2bff3bccc785c320a4df836de" PRIMARY KEY (store_id, currency_code);
ALTER TABLE ONLY cart_discounts
ADD CONSTRAINT "PK_10bd412c9071ccc0cf555afd9bb" PRIMARY KEY (cart_id, discount_id);
ALTER TABLE ONLY product_images
ADD CONSTRAINT "PK_10de97980da2e939c4c0e8423f2" PRIMARY KEY (product_id, image_id);
ALTER TABLE ONLY discount_regions
ADD CONSTRAINT "PK_15974566a8b6e04a7c754e85b75" PRIMARY KEY (discount_id, region_id);
ALTER TABLE ONLY price_list_customer_groups
ADD CONSTRAINT "PK_1afcbe15cc8782dc80c05707df9" PRIMARY KEY (price_list_id, customer_group_id);
ALTER TABLE ONLY product_to_tags
ADD CONSTRAINT "PK_1cf5c9537e7198df494b71b993f" PRIMARY KEY (product_id, product_tag_id);
ALTER TABLE ONLY cart_gift_cards
ADD CONSTRAINT "PK_2389be82bf0ef3635e2014c9ef1" PRIMARY KEY (cart_id, gift_card_id);
ALTER TABLE ONLY product_tax_rates
ADD CONSTRAINT "PK_326257ce468df46cd5c8c5922e9" PRIMARY KEY (product_id, rate_id);
ALTER TABLE ONLY discount_rule_products
ADD CONSTRAINT "PK_351c8c92f5d27283c445cd022ee" PRIMARY KEY (discount_rule_id, product_id);
ALTER TABLE ONLY discount_condition_product_types
ADD CONSTRAINT "PK_35d538a5a24399d0df978df12ed" PRIMARY KEY (product_type_id, condition_id);
ALTER TABLE ONLY return_items
ADD CONSTRAINT "PK_46409dc1dd5f38509b9000c3069" PRIMARY KEY (return_id, item_id);
ALTER TABLE ONLY order_gift_cards
ADD CONSTRAINT "PK_49a8ec66a6625d7c2e3526e05b4" PRIMARY KEY (order_id, gift_card_id);
ALTER TABLE ONLY claim_item_tags
ADD CONSTRAINT "PK_54ab8ce0f7e99167068188fbd81" PRIMARY KEY (item_id, tag_id);
ALTER TABLE ONLY region_fulfillment_providers
ADD CONSTRAINT "PK_5b7d928a1fb50d6803868cfab3a" PRIMARY KEY (region_id, provider_id);
ALTER TABLE ONLY publishable_api_key_sales_channels
ADD CONSTRAINT "PK_68eaeb14bdac8954460054c567c" PRIMARY KEY (sales_channel_id, publishable_key_id);
ALTER TABLE ONLY currencies
ADD CONSTRAINT "PK_723472e41cae44beb0763f4039c" PRIMARY KEY (code);
ALTER TABLE ONLY discount_condition_products
ADD CONSTRAINT "PK_994eb4529fdbf14450d64ec17e8" PRIMARY KEY (product_id, condition_id);
ALTER TABLE ONLY region_payment_providers
ADD CONSTRAINT "PK_9fa1e69914d3dd752de6b1da407" PRIMARY KEY (region_id, provider_id);
ALTER TABLE ONLY order_discounts
ADD CONSTRAINT "PK_a7418714ffceebc125bf6d8fcfe" PRIMARY KEY (order_id, discount_id);
ALTER TABLE ONLY discount_condition_product_tags
ADD CONSTRAINT "PK_a95382c1e62205b121aa058682b" PRIMARY KEY (product_tag_id, condition_id);
ALTER TABLE ONLY discount_condition_product_collections
ADD CONSTRAINT "PK_b3508fc787aa4a38705866cbb6d" PRIMARY KEY (product_collection_id, condition_id);
ALTER TABLE ONLY fulfillment_items
ADD CONSTRAINT "PK_bc3e8a388de75db146a249922e0" PRIMARY KEY (fulfillment_id, item_id);
ALTER TABLE ONLY shipping_tax_rates
ADD CONSTRAINT "PK_bcd93b14d7e2695365d383f5eae" PRIMARY KEY (shipping_option_id, rate_id);
ALTER TABLE ONLY discount_condition_customer_groups
ADD CONSTRAINT "PK_cdc8b2277169a16b8b7d4c73e0e" PRIMARY KEY (customer_group_id, condition_id);
ALTER TABLE ONLY product_type_tax_rates
ADD CONSTRAINT "PK_ddc9242de1d99bc7674969289f0" PRIMARY KEY (product_type_id, rate_id);
ALTER TABLE ONLY customer_group_customers
ADD CONSTRAINT "PK_e28a55e34ad1e2d3df9a0ac86d3" PRIMARY KEY (customer_group_id, customer_id);
ALTER TABLE ONLY product_sales_channels
ADD CONSTRAINT "PK_fd29b6a8bd641052628dee19583" PRIMARY KEY (product_id, sales_channel_id);
ALTER TABLE ONLY shipping_methods
ADD CONSTRAINT "REL_1d9ad62038998c3a85c77a53cf" UNIQUE (return_id);
ALTER TABLE ONLY swaps
ADD CONSTRAINT "REL_402e8182bc553e082f6380020b" UNIQUE (cart_id);
ALTER TABLE ONLY draft_orders
ADD CONSTRAINT "REL_5bd11d0e2a9628128e2c26fd0a" UNIQUE (cart_id);
ALTER TABLE ONLY order_item_changes
ADD CONSTRAINT "REL_5f9688929761f7df108b630e64" UNIQUE (line_item_id);
ALTER TABLE ONLY customers
ADD CONSTRAINT "REL_8abe81b9aac151ae60bf507ad1" UNIQUE (billing_address_id);
ALTER TABLE ONLY draft_orders
ADD CONSTRAINT "REL_8f6dd6c49202f1466ebf21e77d" UNIQUE (order_id);
ALTER TABLE ONLY carts
ADD CONSTRAINT "REL_9d1a161434c610aae7c3df2dc7" UNIQUE (payment_id);
ALTER TABLE ONLY returns
ADD CONSTRAINT "REL_bad82d7bff2b08b87094bfac3d" UNIQUE (swap_id);
ALTER TABLE ONLY payments
ADD CONSTRAINT "REL_c17aff091441b7c25ec3d68d36" UNIQUE (swap_id);
ALTER TABLE ONLY orders
ADD CONSTRAINT "REL_c99a206eb11ad45f6b7f04f2dc" UNIQUE (cart_id);
ALTER TABLE ONLY custom_shipping_options
ADD CONSTRAINT "UQ_0f838b122a9a01d921aa1cdb669" UNIQUE (shipping_option_id, cart_id);
ALTER TABLE ONLY line_item_tax_lines
ADD CONSTRAINT "UQ_3c2af51043ed7243e7d9775a2ad" UNIQUE (item_id, code);
ALTER TABLE ONLY order_item_changes
ADD CONSTRAINT "UQ_5b7a99181e4db2ea821be0b6196" UNIQUE (order_edit_id, original_line_item_id);
ALTER TABLE ONLY stores
ADD CONSTRAINT "UQ_61b0f48cccbb5f41c750bac7286" UNIQUE (default_sales_channel_id);
ALTER TABLE ONLY returns
ADD CONSTRAINT "UQ_71773d56eb2bacb922bc3283398" UNIQUE (claim_order_id);
ALTER TABLE ONLY orders
ADD CONSTRAINT "UQ_727b872f86c7378474a8fa46147" UNIQUE (draft_order_id);
ALTER TABLE ONLY product_variant_inventory_items
ADD CONSTRAINT "UQ_c9be7c1b11a1a729eb51d1b6bca" UNIQUE (variant_id, inventory_item_id);
ALTER TABLE ONLY shipping_method_tax_lines
ADD CONSTRAINT "UQ_cd147fca71e50bc954139fa3104" UNIQUE (shipping_method_id, code);
ALTER TABLE ONLY order_item_changes
ADD CONSTRAINT "UQ_da93cee3ca0dd50a5246268c2e9" UNIQUE (order_edit_id, line_item_id);
ALTER TABLE ONLY customers
ADD CONSTRAINT "UQ_unique_email_for_guests_and_customer_accounts" UNIQUE (email, has_account);
ALTER TABLE ONLY discount_conditions
ADD CONSTRAINT dctypeuniq UNIQUE (type, operator, discount_rule_id);
ALTER TABLE ONLY gift_card_transactions
ADD CONSTRAINT gcuniq UNIQUE (gift_card_id, order_id);
CREATE UNIQUE INDEX "IDX_00605f9d662c06b81c1b60ce24" ON return_reasons USING btree (value);
CREATE INDEX "IDX_012a62ba743e427b5ebe9dee18" ON shipping_option_requirements USING btree (shipping_option_id);
CREATE INDEX "IDX_01486cc9dc6b36bf658685535f" ON discount_condition_product_tags USING btree (product_tag_id);
CREATE INDEX "IDX_017d58bf8260c6e1a2588d258e" ON claim_orders USING btree (shipping_address_id);
CREATE UNIQUE INDEX "IDX_045d4a149c09f4704e0bc08dd4" ON product_variants USING btree (barcode) WHERE (deleted_at IS NULL);
CREATE INDEX "IDX_0fb38b6d167793192bc126d835" ON cart_gift_cards USING btree (gift_card_id);
CREATE INDEX "IDX_0fc1ec4e3db9001ad60c19daf1" ON order_discounts USING btree (discount_id);
CREATE INDEX "IDX_118e3c48f09a7728f41023c94e" ON line_items USING btree (claim_order_id);
CREATE INDEX "IDX_19b0c6293443d1b464f604c331" ON orders USING btree (shipping_address_id);
CREATE INDEX "IDX_1d04aebeabb6a89f87e536a124" ON product_tax_rates USING btree (product_id);
CREATE INDEX "IDX_1d9ad62038998c3a85c77a53cf" ON shipping_methods USING btree (return_id);
CREATE INDEX "IDX_21683a063fe82dafdf681ecc9c" ON product_to_tags USING btree (product_tag_id);
CREATE INDEX "IDX_21cbfedd83d736d86f4c6f4ce5" ON claim_images USING btree (claim_item_id);
CREATE INDEX "IDX_2212515ba306c79f42c46a99db" ON product_images USING btree (image_id);
CREATE INDEX "IDX_242205c81c1152fab1b6e84847" ON carts USING btree (customer_id);
CREATE INDEX "IDX_2484cf14c437a04586b07e7ddd" ON product_tax_rates USING btree (rate_id);
CREATE INDEX "IDX_25a3138bb236f63d9bb6c8ff11" ON product_type_tax_rates USING btree (product_type_id);
CREATE INDEX "IDX_27283ee631862266d0f1c68064" ON line_items USING btree (cart_id);
CREATE UNIQUE INDEX "IDX_2ca8cfbdafb998ecfd6d340389" ON product_variants USING btree (sku) WHERE (deleted_at IS NULL);
CREATE INDEX "IDX_2f41b20a71f30e60471d7e3769" ON line_item_adjustments USING btree (discount_id);
CREATE INDEX "IDX_3287f98befad26c3a7dab088cf" ON notes USING btree (resource_id);
CREATE INDEX "IDX_346e0016cf045b998074774764" ON shipping_tax_rates USING btree (rate_id);
CREATE INDEX "IDX_37341bad297fe5cca91f921032" ON product_sales_channels USING btree (sales_channel_id);
CREATE UNIQUE INDEX "IDX_379ca70338ce9991f3affdeedf" ON analytics_configs USING btree (id, user_id) WHERE (deleted_at IS NULL);
CREATE INDEX "IDX_37f361c38a18d12a3fa3158d0c" ON region_fulfillment_providers USING btree (provider_id);
CREATE INDEX "IDX_3a6947180aeec283cd92c59ebb" ON region_payment_providers USING btree (provider_id);
CREATE INDEX "IDX_3c6412d076292f439269abe1a2" ON customer_group_customers USING btree (customer_id);
CREATE INDEX "IDX_3fa354d8d1233ff81097b2fcb6" ON line_items USING btree (swap_id);
CREATE INDEX "IDX_43a2b24495fe1d9fc2a9c835bc" ON line_items USING btree (order_id);
CREATE INDEX "IDX_44090cb11b06174cbcc667e91c" ON custom_shipping_options USING btree (shipping_option_id);
CREATE INDEX "IDX_4665f17abc1e81dd58330e5854" ON payments USING btree (cart_id);
CREATE INDEX "IDX_484c329f4783be4e18e5e2ff09" ON carts USING btree (region_id);
CREATE INDEX "IDX_4d5f98645a67545d8dea42e2eb" ON discount_condition_customer_groups USING btree (customer_group_id);
CREATE INDEX "IDX_4e0739e5f0244c08d41174ca08" ON discount_rule_products USING btree (discount_rule_id);
CREATE INDEX "IDX_4f166bb8c2bfcef2498d97b406" ON product_images USING btree (product_id);
CREATE INDEX "IDX_5077fa54b0d037e984385dfe8a" ON line_item_tax_lines USING btree (item_id);
CREATE INDEX "IDX_5267705a43d547e232535b656c" ON shipping_methods USING btree (order_id);
CREATE INDEX "IDX_52875734e9dd69064f0041f4d9" ON price_list_customer_groups USING btree (price_list_id);
CREATE INDEX "IDX_52dd74e8c989aa5665ad2852b8" ON swaps USING btree (order_id);
CREATE INDEX "IDX_5371cbaa3be5200f373d24e3d5" ON line_items USING btree (variant_id);
CREATE UNIQUE INDEX "IDX_53cb5605fa42e82b4d47b47bda" ON gift_cards USING btree (code);
CREATE INDEX "IDX_5568d3b9ce9f7abeeb37511ecf" ON orders USING btree (billing_address_id);
CREATE INDEX "IDX_579e01fb94f4f58db480857e05" ON orders USING btree (display_id);
CREATE INDEX "IDX_5a4d5e1e60f97633547821ec8d" ON product_sales_channels USING btree (product_id);
CREATE INDEX "IDX_5b0c6fc53c574299ecc7f9ee22" ON product_to_tags USING btree (product_id);
CREATE INDEX "IDX_5bd11d0e2a9628128e2c26fd0a" ON draft_orders USING btree (cart_id);
CREATE INDEX "IDX_5c58105f1752fca0f4ce69f466" ON shipping_options USING btree (region_id);
CREATE INDEX "IDX_620330964db8d2999e67b0dbe3" ON customer_group_customers USING btree (customer_group_id);
CREATE INDEX "IDX_64980511ca32c8e92b417644af" ON claim_items USING btree (variant_id);
CREATE INDEX "IDX_6680319ebe1f46d18f106191d5" ON cart_discounts USING btree (cart_id);
CREATE UNIQUE INDEX "IDX_6b0ce4b4bcfd24491510bf19d1" ON invites USING btree (user_email);
CREATE INDEX "IDX_6b9c66b5e36f7c827dfaa092f9" ON carts USING btree (billing_address_id);
CREATE INDEX "IDX_6e0cad0daef76bb642675910b9" ON claim_items USING btree (item_id);
CREATE INDEX "IDX_6ef23ce0b1d9cf9b5b833e52b9" ON discount_condition_product_types USING btree (condition_id);
CREATE UNIQUE INDEX "IDX_6f234f058bbbea810dce1d04d0" ON product_collections USING btree (handle) WHERE (deleted_at IS NULL);
CREATE INDEX "IDX_71773d56eb2bacb922bc328339" ON returns USING btree (claim_order_id);
CREATE INDEX "IDX_80823b7ae866dc5acae2dac6d2" ON products USING btree (profile_id);
CREATE INDEX "IDX_82a6bbb0b527c20a0002ddcbd6" ON store_currencies USING btree (currency_code);
CREATE INDEX "IDX_8486ee16e69013c645d0b8716b" ON discount_condition_customer_groups USING btree (condition_id);
CREATE INDEX "IDX_8aaa78ba90d3802edac317df86" ON region_payment_providers USING btree (region_id);
CREATE INDEX "IDX_8abe81b9aac151ae60bf507ad1" ON customers USING btree (billing_address_id);
CREATE INDEX "IDX_8df75ef4f35f217768dc113545" ON cart_discounts USING btree (discount_id);
CREATE INDEX "IDX_8f6dd6c49202f1466ebf21e77d" ON draft_orders USING btree (order_id);
CREATE INDEX "IDX_900a9c3834257304396b2b0fe7" ON claim_items USING btree (claim_order_id);
CREATE INDEX "IDX_926ca9f29014af8091722dede0" ON shipping_method_tax_lines USING btree (shipping_method_id);
CREATE INDEX "IDX_93caeb1bb70d37c1d36d6701a7" ON custom_shipping_options USING btree (cart_id);
CREATE INDEX "IDX_9c9614b2f9d01665800ea8dbff" ON addresses USING btree (customer_id);
CREATE INDEX "IDX_9d1a161434c610aae7c3df2dc7" ON carts USING btree (payment_id);
CREATE INDEX "IDX_a0b05dc4257abe639cb75f8eae" ON discount_condition_product_collections USING btree (product_collection_id);
CREATE INDEX "IDX_a0e206bfaed3cb63c186091734" ON shipping_options USING btree (provider_id);
CREATE INDEX "IDX_a1c4f9cfb599ad1f0db39cadd5" ON discount_condition_product_collections USING btree (condition_id);
CREATE INDEX "IDX_a21a7ffbe420d492eb46c305fe" ON discount_regions USING btree (region_id);
CREATE UNIQUE INDEX "IDX_a421bf4588d0004a9b0c0fe84f" ON idempotency_keys USING btree (idempotency_key);
CREATE INDEX "IDX_a52e234f729db789cf473297a5" ON fulfillments USING btree (swap_id);
CREATE UNIQUE INDEX "IDX_aa16f61348be02dd07ce3fc54e" ON product_variants USING btree (upc) WHERE (deleted_at IS NULL);
CREATE INDEX "IDX_aac4855eadda71aa1e4b6d7684" ON payments USING btree (cart_id) WHERE (canceled_at IS NOT NULL);
CREATE INDEX "IDX_ac2c280de3701b2d66f6817f76" ON discounts USING btree (rule_id);
CREATE INDEX "IDX_b1aac8314662fa6b25569a575b" ON countries USING btree (region_id);
CREATE INDEX "IDX_b4f4b63d1736689b7008980394" ON store_currencies USING btree (store_id);
CREATE UNIQUE INDEX "IDX_b5b6225539ee8501082fbc0714" ON product_variants USING btree (ean) WHERE (deleted_at IS NULL);
CREATE INDEX "IDX_b5df0f53a74b9d0c0a2b652c88" ON notifications USING btree (customer_id);
CREATE INDEX "IDX_b6bcf8c3903097b84e85154eed" ON gift_cards USING btree (region_id);
CREATE UNIQUE INDEX "IDX_ba8de19442d86957a3aa3b5006" ON users USING btree (email) WHERE (deleted_at IS NULL);
CREATE INDEX "IDX_bad82d7bff2b08b87094bfac3d" ON returns USING btree (swap_id);
CREATE INDEX "IDX_be66106a673b88a81c603abe7e" ON discount_rule_products USING btree (product_id);
CREATE INDEX "IDX_be9aea2ccf3567007b6227da4d" ON line_item_adjustments USING btree (item_id);
CREATE INDEX "IDX_beb35a6de60a6c4f91d5ae57e4" ON fulfillments USING btree (provider_id);
CREATE UNIQUE INDEX "IDX_bf701b88d2041392a288785ada" ON line_item_adjustments USING btree (discount_id, item_id) WHERE (discount_id IS NOT NULL);
CREATE INDEX "IDX_c17aff091441b7c25ec3d68d36" ON payments USING btree (swap_id);
CREATE INDEX "IDX_c2c0f3edf39515bd15432afe6e" ON claim_item_tags USING btree (item_id);
CREATE UNIQUE INDEX "IDX_c49c061b1a686843c5d673506f" ON oauth USING btree (application_name);
CREATE UNIQUE INDEX "IDX_c4c3a5225a7a1f0af782c40abc" ON customer_groups USING btree (name) WHERE (deleted_at IS NULL);
CREATE INDEX "IDX_c5516f550433c9b1c2630d787a" ON price_list_customer_groups USING btree (customer_group_id);
CREATE INDEX "IDX_c556e14eff4d6f03db593df955" ON region_fulfillment_providers USING btree (region_id);
CREATE INDEX "IDX_c759f53b2e48e8cfb50638fe4e" ON discount_condition_products USING btree (product_id);
CREATE INDEX "IDX_c951439af4c98bf2bd7fb8726c" ON shipping_options USING btree (profile_id);
CREATE INDEX "IDX_c99a206eb11ad45f6b7f04f2dc" ON orders USING btree (cart_id);
CREATE INDEX "IDX_ca67dd080aac5ecf99609960cd" ON product_variants USING btree (product_id);
CREATE INDEX "IDX_cd7812c96209c5bdd48a6b858b" ON orders USING btree (customer_id);
CREATE INDEX "IDX_ced15a9a695d2b5db9dabce763" ON carts USING btree (shipping_address_id);
CREATE UNIQUE INDEX "IDX_cf9cc6c3f2e6414b992223fff1" ON products USING btree (handle) WHERE (deleted_at IS NULL);
CREATE INDEX "IDX_d18ad72f2fb7c87f075825b6f8" ON payment_sessions USING btree (provider_id);
CREATE INDEX "IDX_d25ba0787e1510ddc5d442ebcf" ON payment_sessions USING btree (cart_id);
CREATE INDEX "IDX_d38047a90f3d42f0be7909e8ae" ON cart_gift_cards USING btree (cart_id);
CREATE INDEX "IDX_d4bd17f918fc6c332b74a368c3" ON returns USING btree (order_id);
CREATE INDEX "IDX_d73e55964e0ff2db8f03807d52" ON fulfillments USING btree (claim_order_id);
CREATE INDEX "IDX_d783a66d1c91c0858752c933e6" ON shipping_methods USING btree (claim_order_id);
CREATE INDEX "IDX_d7d441b81012f87d4265fa57d2" ON gift_card_transactions USING btree (order_id);
CREATE INDEX "IDX_d92993a7d554d84571f4eea1d1" ON shipping_methods USING btree (cart_id);
CREATE INDEX "IDX_dc9bbf9fcb9ba458d25d512811" ON claim_item_tags USING btree (tag_id);
CREATE INDEX "IDX_df1494d263740fcfb1d09a98fc" ON notifications USING btree (resource_type);
CREATE INDEX "IDX_dfc1f02bb0552e79076aa58dbb" ON gift_cards USING btree (order_id);
CREATE INDEX "IDX_e1fcce2b18dbcdbe0a5ba9a68b" ON orders USING btree (region_id);
CREATE INDEX "IDX_e62ff11e4730bb3adfead979ee" ON order_gift_cards USING btree (order_id);
CREATE INDEX "IDX_e706deb68f52ab2756119b9e70" ON discount_condition_product_types USING btree (product_type_id);
CREATE UNIQUE INDEX "IDX_e78901b1131eaf8203d9b1cb5f" ON countries USING btree (iso_2);
CREATE INDEX "IDX_e7b488cebe333f449398769b2c" ON order_discounts USING btree (order_id);
CREATE INDEX "IDX_e87cc617a22ef4edce5601edab" ON draft_orders USING btree (display_id);
CREATE INDEX "IDX_ea6a358d9ce41c16499aae55f9" ON notifications USING btree (resource_id);
CREATE INDEX "IDX_ea94f42b6c88e9191c3649d752" ON payments USING btree (provider_id);
CREATE INDEX "IDX_ec10c54769877840c132260e4a" ON claim_tags USING btree (value);
CREATE INDEX "IDX_ece65a774192b34253abc4cd67" ON product_type_tax_rates USING btree (rate_id);
CREATE INDEX "IDX_eec9d9af4ca098e19ea6b499ea" ON refunds USING btree (order_id);
CREATE INDEX "IDX_efff700651718e452ca9580a62" ON discount_conditions USING btree (discount_rule_id);
CREATE INDEX "IDX_f05132301e95bdab4ba1cf29a2" ON discount_condition_products USING btree (condition_id);
CREATE INDEX "IDX_f129acc85e346a10eed12b86fc" ON fulfillments USING btree (order_id);
CREATE INDEX "IDX_f2bb9f71e95b315eb24b2b84cb" ON order_gift_cards USING btree (gift_card_id);
CREATE INDEX "IDX_f4194aa81073f3fab8aa86906f" ON discount_regions USING btree (discount_id);
CREATE INDEX "IDX_f49e3974465d3c3a33d449d3f3" ON claim_orders USING btree (order_id);
CREATE INDEX "IDX_f5221735ace059250daac9d980" ON payments USING btree (order_id);
CREATE UNIQUE INDEX "IDX_f65bf52e2239ace276ece2b2f4" ON discounts USING btree (code) WHERE (deleted_at IS NULL);
CREATE INDEX "IDX_f672727ab020df6c50fb64c1a7" ON shipping_tax_rates USING btree (shipping_option_id);
CREATE INDEX "IDX_f74980b411cf94af523a72af7d" ON notes USING btree (resource_type);
CREATE INDEX "IDX_fb94fa8d5ca940daa2a58139f8" ON shipping_methods USING btree (swap_id);
CREATE INDEX "IDX_fbb2499551ed074526f3ee3624" ON discount_condition_product_tags USING btree (condition_id);
CREATE INDEX "IDX_fc963e94854bff2714ca84cd19" ON shipping_methods USING btree (shipping_option_id);
CREATE INDEX "IDX_money_amount_currency_code" ON money_amounts USING btree (currency_code);
CREATE INDEX "IDX_order_currency_code" ON orders USING btree (currency_code);
CREATE INDEX "IDX_order_edit_order_id" ON order_edits USING btree (order_id);
CREATE INDEX "IDX_order_edit_payment_collection_id" ON order_edits USING btree (payment_collection_id);
CREATE INDEX "IDX_payment_collection_currency_code" ON payment_collections USING btree (currency_code) WHERE (deleted_at IS NULL);
CREATE INDEX "IDX_payment_collection_payments_payment_collection_id" ON payment_collection_payments USING btree (payment_collection_id);
CREATE INDEX "IDX_payment_collection_payments_payment_id" ON payment_collection_payments USING btree (payment_id);
CREATE INDEX "IDX_payment_collection_region_id" ON payment_collections USING btree (region_id) WHERE (deleted_at IS NULL);
CREATE INDEX "IDX_payment_collection_sessions_payment_collection_id" ON payment_collection_sessions USING btree (payment_collection_id);
CREATE INDEX "IDX_payment_collection_sessions_payment_session_id" ON payment_collection_sessions USING btree (payment_session_id);
CREATE INDEX "IDX_payment_currency_code" ON payments USING btree (currency_code);
CREATE INDEX "IDX_pcp_product_category_id" ON product_category_products USING btree (product_category_id);
CREATE INDEX "IDX_pcp_product_id" ON product_category_products USING btree (product_id);
CREATE INDEX "IDX_product_category_active_" ON product_categories USING btree (parent_category_id, is_active, is_internal)
WHERE ((is_active IS TRUE) AND (is_internal IS FALSE));
CREATE UNIQUE INDEX "IDX_product_category_handle" ON product_categories USING btree (handle);
CREATE INDEX "IDX_product_category_path" ON product_categories USING btree (mpath);
CREATE INDEX "IDX_product_variant_inventory_item_inventory_item_id" ON product_variant_inventory_items USING btree (inventory_item_id) WHERE (deleted_at IS NULL);
CREATE INDEX "IDX_product_variant_inventory_item_variant_id" ON product_variant_inventory_items USING btree (variant_id) WHERE (deleted_at IS NULL);
CREATE INDEX "IDX_refund_payment_id" ON refunds USING btree (payment_id);
CREATE INDEX "IDX_region_currency_code" ON regions USING btree (currency_code);
CREATE INDEX "IDX_sales_channel_location_location_id" ON sales_channel_locations USING btree (location_id) WHERE (deleted_at IS NULL);
CREATE INDEX "IDX_sales_channel_location_sales_channel_id" ON sales_channel_locations USING btree (sales_channel_id) WHERE (deleted_at IS NULL);
CREATE UNIQUE INDEX "IDX_upcp_product_id_product_category_id" ON product_category_products USING btree (product_category_id, product_id);
CREATE UNIQUE INDEX "UniqPaymentSessionCartIdProviderId" ON payment_sessions USING btree (cart_id, provider_id) WHERE (cart_id IS NOT NULL);
CREATE UNIQUE INDEX "UniqProductCategoryParentIdRank" ON product_categories USING btree (parent_category_id, rank);
CREATE UNIQUE INDEX "UniquePaymentActive" ON payments USING btree (cart_id) WHERE (canceled_at IS NULL);
CREATE INDEX idx_gin_product_collection ON product_collections USING gin (title gin_trgm_ops) WHERE (deleted_at IS NULL);
CREATE INDEX idx_gin_product_description ON products USING gin (description gin_trgm_ops) WHERE (deleted_at IS NULL);
CREATE INDEX idx_gin_product_title ON products USING gin (title gin_trgm_ops) WHERE (deleted_at IS NULL);
CREATE INDEX idx_gin_product_variant_sku ON product_variants USING gin (sku gin_trgm_ops) WHERE (deleted_at IS NULL);
CREATE INDEX idx_gin_product_variant_title ON product_variants USING gin (title gin_trgm_ops) WHERE (deleted_at IS NULL);
CREATE INDEX idx_money_amount_region_id ON money_amounts USING btree (region_id);
CREATE INDEX idx_money_amount_variant_id ON money_amounts USING btree (variant_id);
CREATE INDEX idx_product_option_value_option_id ON product_option_values USING btree (option_id);
CREATE INDEX idx_product_option_value_variant_id ON product_option_values USING btree (variant_id);
CREATE UNIQUE INDEX unique_li_original_item_id_order_edit_id ON line_items USING btree (order_edit_id, original_item_id) WHERE ((original_item_id IS NOT NULL) AND (order_edit_id IS NOT NULL));
ALTER TABLE ONLY shipping_option_requirements
ADD CONSTRAINT "FK_012a62ba743e427b5ebe9dee18e" FOREIGN KEY (shipping_option_id) REFERENCES shipping_options (id);
ALTER TABLE ONLY discount_condition_product_tags
ADD CONSTRAINT "FK_01486cc9dc6b36bf658685535f6" FOREIGN KEY (product_tag_id) REFERENCES product_tags (id) ON DELETE CASCADE;
ALTER TABLE ONLY claim_orders
ADD CONSTRAINT "FK_017d58bf8260c6e1a2588d258e2" FOREIGN KEY (shipping_address_id) REFERENCES addresses (id);
ALTER TABLE ONLY notifications
ADD CONSTRAINT "FK_0425c2423e2ce9fdfd5c23761d9" FOREIGN KEY (provider_id) REFERENCES notification_providers (id);
ALTER TABLE ONLY cart_gift_cards
ADD CONSTRAINT "FK_0fb38b6d167793192bc126d835e" FOREIGN KEY (gift_card_id) REFERENCES gift_cards (id) ON DELETE CASCADE;
ALTER TABLE ONLY order_discounts
ADD CONSTRAINT "FK_0fc1ec4e3db9001ad60c19daf16" FOREIGN KEY (discount_id) REFERENCES discounts (id) ON DELETE CASCADE;
ALTER TABLE ONLY line_items
ADD CONSTRAINT "FK_118e3c48f09a7728f41023c94ef" FOREIGN KEY (claim_order_id) REFERENCES claim_orders (id);
ALTER TABLE ONLY money_amounts
ADD CONSTRAINT "FK_17a06d728e4cfbc5bd2ddb70af0" FOREIGN KEY (variant_id) REFERENCES product_variants (id) ON DELETE CASCADE;
ALTER TABLE ONLY orders
ADD CONSTRAINT "FK_19b0c6293443d1b464f604c3316" FOREIGN KEY (shipping_address_id) REFERENCES addresses (id);
ALTER TABLE ONLY product_tax_rates
ADD CONSTRAINT "FK_1d04aebeabb6a89f87e536a124d" FOREIGN KEY (product_id) REFERENCES products (id) ON DELETE CASCADE;
ALTER TABLE ONLY shipping_methods
ADD CONSTRAINT "FK_1d9ad62038998c3a85c77a53cfb" FOREIGN KEY (return_id) REFERENCES returns (id);
ALTER TABLE ONLY order_edits
ADD CONSTRAINT "FK_1f3a251488a91510f57e1bf93cd" FOREIGN KEY (order_id) REFERENCES orders (id);
ALTER TABLE ONLY product_to_tags
ADD CONSTRAINT "FK_21683a063fe82dafdf681ecc9c4" FOREIGN KEY (product_tag_id) REFERENCES product_tags (id) ON DELETE CASCADE;
ALTER TABLE ONLY claim_images
ADD CONSTRAINT "FK_21cbfedd83d736d86f4c6f4ce56" FOREIGN KEY (claim_item_id) REFERENCES claim_items (id);
ALTER TABLE ONLY product_images
ADD CONSTRAINT "FK_2212515ba306c79f42c46a99db7" FOREIGN KEY (image_id) REFERENCES images (id) ON DELETE CASCADE;
ALTER TABLE ONLY return_reasons
ADD CONSTRAINT "FK_2250c5d9e975987ab212f61a657" FOREIGN KEY (parent_return_reason_id) REFERENCES return_reasons (id);
ALTER TABLE ONLY discounts
ADD CONSTRAINT "FK_2250c5d9e975987ab212f61a663" FOREIGN KEY (parent_discount_id) REFERENCES discounts (id);
ALTER TABLE ONLY carts
ADD CONSTRAINT "FK_242205c81c1152fab1b6e848470" FOREIGN KEY (customer_id) REFERENCES customers (id);
ALTER TABLE ONLY product_tax_rates
ADD CONSTRAINT "FK_2484cf14c437a04586b07e7dddb" FOREIGN KEY (rate_id) REFERENCES tax_rates (id) ON DELETE CASCADE;
ALTER TABLE ONLY product_type_tax_rates
ADD CONSTRAINT "FK_25a3138bb236f63d9bb6c8ff111" FOREIGN KEY (product_type_id) REFERENCES product_types (id) ON DELETE CASCADE;
ALTER TABLE ONLY line_items
ADD CONSTRAINT "FK_27283ee631862266d0f1c680646" FOREIGN KEY (cart_id) REFERENCES carts (id);
ALTER TABLE ONLY line_item_adjustments
ADD CONSTRAINT "FK_2f41b20a71f30e60471d7e3769c" FOREIGN KEY (discount_id) REFERENCES discounts (id);
ALTER TABLE ONLY shipping_tax_rates
ADD CONSTRAINT "FK_346e0016cf045b9980747747645" FOREIGN KEY (rate_id) REFERENCES tax_rates (id) ON DELETE CASCADE;
ALTER TABLE ONLY notifications
ADD CONSTRAINT "FK_371db513192c083f48ba63c33be" FOREIGN KEY (parent_id) REFERENCES notifications (id);
ALTER TABLE ONLY product_sales_channels
ADD CONSTRAINT "FK_37341bad297fe5cca91f921032b" FOREIGN KEY (sales_channel_id) REFERENCES sales_channels (id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE ONLY region_fulfillment_providers
ADD CONSTRAINT "FK_37f361c38a18d12a3fa3158d0cf" FOREIGN KEY (provider_id) REFERENCES fulfillment_providers (id) ON DELETE CASCADE;
ALTER TABLE ONLY region_payment_providers
ADD CONSTRAINT "FK_3a6947180aeec283cd92c59ebb0" FOREIGN KEY (provider_id) REFERENCES payment_providers (id) ON DELETE CASCADE;
ALTER TABLE ONLY regions
ADD CONSTRAINT "FK_3bdd5896ec93be2f1c62a3309a5" FOREIGN KEY (currency_code) REFERENCES currencies (code);
ALTER TABLE ONLY customer_group_customers
ADD CONSTRAINT "FK_3c6412d076292f439269abe1a23" FOREIGN KEY (customer_id) REFERENCES customers (id) ON DELETE CASCADE;
ALTER TABLE ONLY line_items
ADD CONSTRAINT "FK_3fa354d8d1233ff81097b2fcb6b" FOREIGN KEY (swap_id) REFERENCES swaps (id);
ALTER TABLE ONLY gift_card_transactions
ADD CONSTRAINT "FK_3ff5597f1d7e02bba41541846f4" FOREIGN KEY (gift_card_id) REFERENCES gift_cards (id);
ALTER TABLE ONLY swaps
ADD CONSTRAINT "FK_402e8182bc553e082f6380020b4" FOREIGN KEY (cart_id) REFERENCES carts (id);
ALTER TABLE ONLY line_items
ADD CONSTRAINT "FK_43a2b24495fe1d9fc2a9c835bc7" FOREIGN KEY (order_id) REFERENCES orders (id);
ALTER TABLE ONLY custom_shipping_options
ADD CONSTRAINT "FK_44090cb11b06174cbcc667e91ca" FOREIGN KEY (shipping_option_id) REFERENCES shipping_options (id);
ALTER TABLE ONLY order_item_changes
ADD CONSTRAINT "FK_44feeebb258bf4cfa4cc4202281" FOREIGN KEY (order_edit_id) REFERENCES order_edits (id);
ALTER TABLE ONLY payments
ADD CONSTRAINT "FK_4665f17abc1e81dd58330e58542" FOREIGN KEY (cart_id) REFERENCES carts (id);
ALTER TABLE ONLY tracking_links
ADD CONSTRAINT "FK_471e9e4c96e02ba209a307db32b" FOREIGN KEY (fulfillment_id) REFERENCES fulfillments (id);
ALTER TABLE ONLY carts
ADD CONSTRAINT "FK_484c329f4783be4e18e5e2ff090" FOREIGN KEY (region_id) REFERENCES regions (id);
ALTER TABLE ONLY products
ADD CONSTRAINT "FK_49d419fc77d3aed46c835c558ac" FOREIGN KEY (collection_id) REFERENCES product_collections (id);
ALTER TABLE ONLY discount_condition_customer_groups
ADD CONSTRAINT "FK_4d5f98645a67545d8dea42e2eb8" FOREIGN KEY (customer_group_id) REFERENCES customer_groups (id) ON DELETE CASCADE;
ALTER TABLE ONLY discount_rule_products
ADD CONSTRAINT "FK_4e0739e5f0244c08d41174ca08a" FOREIGN KEY (discount_rule_id) REFERENCES discount_rules (id) ON DELETE CASCADE;
ALTER TABLE ONLY product_images
ADD CONSTRAINT "FK_4f166bb8c2bfcef2498d97b4068" FOREIGN KEY (product_id) REFERENCES products (id) ON DELETE CASCADE;
ALTER TABLE ONLY line_item_tax_lines
ADD CONSTRAINT "FK_5077fa54b0d037e984385dfe8ad" FOREIGN KEY (item_id) REFERENCES line_items (id);
ALTER TABLE ONLY shipping_methods
ADD CONSTRAINT "FK_5267705a43d547e232535b656c2" FOREIGN KEY (order_id) REFERENCES orders (id);
ALTER TABLE ONLY price_list_customer_groups
ADD CONSTRAINT "FK_52875734e9dd69064f0041f4d92" FOREIGN KEY (price_list_id) REFERENCES price_lists (id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE ONLY swaps
ADD CONSTRAINT "FK_52dd74e8c989aa5665ad2852b8b" FOREIGN KEY (order_id) REFERENCES orders (id);
ALTER TABLE ONLY line_items
ADD CONSTRAINT "FK_5371cbaa3be5200f373d24e3d5b" FOREIGN KEY (variant_id) REFERENCES product_variants (id);
ALTER TABLE ONLY orders
ADD CONSTRAINT "FK_5568d3b9ce9f7abeeb37511ecf2" FOREIGN KEY (billing_address_id) REFERENCES addresses (id);
ALTER TABLE ONLY stores
ADD CONSTRAINT "FK_55beebaa09e947cccca554af222" FOREIGN KEY (default_currency_code) REFERENCES currencies (code);
ALTER TABLE ONLY product_sales_channels
ADD CONSTRAINT "FK_5a4d5e1e60f97633547821ec8d6" FOREIGN KEY (product_id) REFERENCES products (id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE ONLY product_to_tags
ADD CONSTRAINT "FK_5b0c6fc53c574299ecc7f9ee22e" FOREIGN KEY (product_id) REFERENCES products (id) ON DELETE CASCADE;
ALTER TABLE ONLY draft_orders
ADD CONSTRAINT "FK_5bd11d0e2a9628128e2c26fd0a6" FOREIGN KEY (cart_id) REFERENCES carts (id);
ALTER TABLE ONLY shipping_options
ADD CONSTRAINT "FK_5c58105f1752fca0f4ce69f4663" FOREIGN KEY (region_id) REFERENCES regions (id);
ALTER TABLE ONLY order_item_changes
ADD CONSTRAINT "FK_5f9688929761f7df108b630e64a" FOREIGN KEY (line_item_id) REFERENCES line_items (id);
ALTER TABLE ONLY stores
ADD CONSTRAINT "FK_61b0f48cccbb5f41c750bac7286" FOREIGN KEY (default_sales_channel_id) REFERENCES sales_channels (id);
ALTER TABLE ONLY customer_group_customers
ADD CONSTRAINT "FK_620330964db8d2999e67b0dbe3e" FOREIGN KEY (customer_group_id) REFERENCES customer_groups (id) ON DELETE CASCADE;
ALTER TABLE ONLY claim_items
ADD CONSTRAINT "FK_64980511ca32c8e92b417644afa" FOREIGN KEY (variant_id) REFERENCES product_variants (id);
ALTER TABLE ONLY cart_discounts
ADD CONSTRAINT "FK_6680319ebe1f46d18f106191d59" FOREIGN KEY (cart_id) REFERENCES carts (id) ON DELETE CASCADE;
ALTER TABLE ONLY carts
ADD CONSTRAINT "FK_6b9c66b5e36f7c827dfaa092f94" FOREIGN KEY (billing_address_id) REFERENCES addresses (id);
ALTER TABLE ONLY addresses
ADD CONSTRAINT "FK_6df8c6bf969a51d24c1980c4ff4" FOREIGN KEY (country_code) REFERENCES countries (iso_2);
ALTER TABLE ONLY claim_items
ADD CONSTRAINT "FK_6e0cad0daef76bb642675910b9d" FOREIGN KEY (item_id) REFERENCES line_items (id);
ALTER TABLE ONLY discount_condition_product_types
ADD CONSTRAINT "FK_6ef23ce0b1d9cf9b5b833e52b9d" FOREIGN KEY (condition_id) REFERENCES discount_conditions (id) ON DELETE CASCADE;
ALTER TABLE ONLY orders
ADD CONSTRAINT "FK_6ff7e874f01b478c115fdd462eb" FOREIGN KEY (sales_channel_id) REFERENCES sales_channels (id);
ALTER TABLE ONLY returns
ADD CONSTRAINT "FK_71773d56eb2bacb922bc3283398" FOREIGN KEY (claim_order_id) REFERENCES claim_orders (id);
ALTER TABLE ONLY orders
ADD CONSTRAINT "FK_717a141f96b76d794d409f38129" FOREIGN KEY (currency_code) REFERENCES currencies (code);
ALTER TABLE ONLY product_option_values
ADD CONSTRAINT "FK_7234ed737ff4eb1b6ae6e6d7b01" FOREIGN KEY (variant_id) REFERENCES product_variants (id) ON DELETE CASCADE;
ALTER TABLE ONLY orders
ADD CONSTRAINT "FK_727b872f86c7378474a8fa46147" FOREIGN KEY (draft_order_id) REFERENCES draft_orders (id);
ALTER TABLE ONLY return_items
ADD CONSTRAINT "FK_7edab75b4fc88ea6d4f2574f087" FOREIGN KEY (return_id) REFERENCES returns (id);
ALTER TABLE ONLY products
ADD CONSTRAINT "FK_80823b7ae866dc5acae2dac6d2c" FOREIGN KEY (profile_id) REFERENCES shipping_profiles (id);
ALTER TABLE ONLY store_currencies
ADD CONSTRAINT "FK_82a6bbb0b527c20a0002ddcbd60" FOREIGN KEY (currency_code) REFERENCES currencies (code) ON DELETE CASCADE;
ALTER TABLE ONLY discount_condition_customer_groups
ADD CONSTRAINT "FK_8486ee16e69013c645d0b8716b6" FOREIGN KEY (condition_id) REFERENCES discount_conditions (id) ON DELETE CASCADE;
ALTER TABLE ONLY return_items
ADD CONSTRAINT "FK_87774591f44564effd8039d7162" FOREIGN KEY (item_id) REFERENCES line_items (id);
ALTER TABLE ONLY region_payment_providers
ADD CONSTRAINT "FK_8aaa78ba90d3802edac317df869" FOREIGN KEY (region_id) REFERENCES regions (id) ON DELETE CASCADE;
ALTER TABLE ONLY customers
ADD CONSTRAINT "FK_8abe81b9aac151ae60bf507ad15" FOREIGN KEY (billing_address_id) REFERENCES addresses (id);
ALTER TABLE ONLY cart_discounts
ADD CONSTRAINT "FK_8df75ef4f35f217768dc1135458" FOREIGN KEY (discount_id) REFERENCES discounts (id) ON DELETE CASCADE;
ALTER TABLE ONLY draft_orders
ADD CONSTRAINT "FK_8f6dd6c49202f1466ebf21e77da" FOREIGN KEY (order_id) REFERENCES orders (id);
ALTER TABLE ONLY claim_items
ADD CONSTRAINT "FK_900a9c3834257304396b2b0fe7c" FOREIGN KEY (claim_order_id) REFERENCES claim_orders (id);
ALTER TABLE ONLY regions
ADD CONSTRAINT "FK_91f88052197680f9790272aaf5b" FOREIGN KEY (tax_provider_id) REFERENCES tax_providers (id);
ALTER TABLE ONLY shipping_method_tax_lines
ADD CONSTRAINT "FK_926ca9f29014af8091722dede08" FOREIGN KEY (shipping_method_id) REFERENCES shipping_methods (id);
ALTER TABLE ONLY custom_shipping_options
ADD CONSTRAINT "FK_93caeb1bb70d37c1d36d6701a7a" FOREIGN KEY (cart_id) REFERENCES carts (id);
ALTER TABLE ONLY addresses
ADD CONSTRAINT "FK_9c9614b2f9d01665800ea8dbff7" FOREIGN KEY (customer_id) REFERENCES customers (id);
ALTER TABLE ONLY carts
ADD CONSTRAINT "FK_9d1a161434c610aae7c3df2dc7e" FOREIGN KEY (payment_id) REFERENCES payments (id);
ALTER TABLE ONLY fulfillment_items
ADD CONSTRAINT "FK_a033f83cc6bd7701a5687ab4b38" FOREIGN KEY (fulfillment_id) REFERENCES fulfillments (id);
ALTER TABLE ONLY discount_condition_product_collections
ADD CONSTRAINT "FK_a0b05dc4257abe639cb75f8eae2" FOREIGN KEY (product_collection_id) REFERENCES product_collections (id) ON DELETE CASCADE;
ALTER TABLE ONLY shipping_options
ADD CONSTRAINT "FK_a0e206bfaed3cb63c1860917347" FOREIGN KEY (provider_id) REFERENCES fulfillment_providers (id);
ALTER TABLE ONLY discount_condition_product_collections
ADD CONSTRAINT "FK_a1c4f9cfb599ad1f0db39cadd5f" FOREIGN KEY (condition_id) REFERENCES discount_conditions (id) ON DELETE CASCADE;
ALTER TABLE ONLY discount_regions
ADD CONSTRAINT "FK_a21a7ffbe420d492eb46c305fec" FOREIGN KEY (region_id) REFERENCES regions (id) ON DELETE CASCADE;
ALTER TABLE ONLY carts
ADD CONSTRAINT "FK_a2bd3c26f42e754b9249ba78fd6" FOREIGN KEY (sales_channel_id) REFERENCES sales_channels (id);
ALTER TABLE ONLY fulfillments
ADD CONSTRAINT "FK_a52e234f729db789cf473297a5c" FOREIGN KEY (swap_id) REFERENCES swaps (id);
ALTER TABLE ONLY discounts
ADD CONSTRAINT "FK_ac2c280de3701b2d66f6817f760" FOREIGN KEY (rule_id) REFERENCES discount_rules (id);
ALTER TABLE ONLY countries
ADD CONSTRAINT "FK_b1aac8314662fa6b25569a575bb" FOREIGN KEY (region_id) REFERENCES regions (id);
ALTER TABLE ONLY money_amounts
ADD CONSTRAINT "FK_b433e27b7a83e6d12ab26b15b03" FOREIGN KEY (region_id) REFERENCES regions (id);
ALTER TABLE ONLY order_item_changes
ADD CONSTRAINT "FK_b4d53b8d03c9f5e7d4317e818d9" FOREIGN KEY (original_line_item_id) REFERENCES line_items (id);
ALTER TABLE ONLY store_currencies
ADD CONSTRAINT "FK_b4f4b63d1736689b7008980394c" FOREIGN KEY (store_id) REFERENCES stores (id) ON DELETE CASCADE;
ALTER TABLE ONLY notifications
ADD CONSTRAINT "FK_b5df0f53a74b9d0c0a2b652c88d" FOREIGN KEY (customer_id) REFERENCES customers (id);
ALTER TABLE ONLY gift_cards
ADD CONSTRAINT "FK_b6bcf8c3903097b84e85154eed3" FOREIGN KEY (region_id) REFERENCES regions (id);
ALTER TABLE ONLY tax_rates
ADD CONSTRAINT "FK_b95a1e03b051993d208366cb960" FOREIGN KEY (region_id) REFERENCES regions (id);
ALTER TABLE ONLY returns
ADD CONSTRAINT "FK_bad82d7bff2b08b87094bfac3d6" FOREIGN KEY (swap_id) REFERENCES swaps (id);
ALTER TABLE ONLY discount_rule_products
ADD CONSTRAINT "FK_be66106a673b88a81c603abe7eb" FOREIGN KEY (product_id) REFERENCES products (id) ON DELETE CASCADE;
ALTER TABLE ONLY line_item_adjustments
ADD CONSTRAINT "FK_be9aea2ccf3567007b6227da4d2" FOREIGN KEY (item_id) REFERENCES line_items (id) ON DELETE CASCADE;
ALTER TABLE ONLY fulfillments
ADD CONSTRAINT "FK_beb35a6de60a6c4f91d5ae57e44" FOREIGN KEY (provider_id) REFERENCES fulfillment_providers (id);
ALTER TABLE ONLY payments
ADD CONSTRAINT "FK_c17aff091441b7c25ec3d68d36c" FOREIGN KEY (swap_id) REFERENCES swaps (id);
ALTER TABLE ONLY claim_item_tags
ADD CONSTRAINT "FK_c2c0f3edf39515bd15432afe6e5" FOREIGN KEY (item_id) REFERENCES claim_items (id) ON DELETE CASCADE;
ALTER TABLE ONLY price_list_customer_groups
ADD CONSTRAINT "FK_c5516f550433c9b1c2630d787a7" FOREIGN KEY (customer_group_id) REFERENCES customer_groups (id) ON DELETE CASCADE;
ALTER TABLE ONLY region_fulfillment_providers
ADD CONSTRAINT "FK_c556e14eff4d6f03db593df955e" FOREIGN KEY (region_id) REFERENCES regions (id) ON DELETE CASCADE;
ALTER TABLE ONLY discount_condition_products
ADD CONSTRAINT "FK_c759f53b2e48e8cfb50638fe4e0" FOREIGN KEY (product_id) REFERENCES products (id) ON DELETE CASCADE;
ALTER TABLE ONLY shipping_options
ADD CONSTRAINT "FK_c951439af4c98bf2bd7fb8726cd" FOREIGN KEY (profile_id) REFERENCES shipping_profiles (id);
ALTER TABLE ONLY orders
ADD CONSTRAINT "FK_c99a206eb11ad45f6b7f04f2dcc" FOREIGN KEY (cart_id) REFERENCES carts (id);
ALTER TABLE ONLY product_variants
ADD CONSTRAINT "FK_ca67dd080aac5ecf99609960cd2" FOREIGN KEY (product_id) REFERENCES products (id);
ALTER TABLE ONLY orders
ADD CONSTRAINT "FK_cd7812c96209c5bdd48a6b858b0" FOREIGN KEY (customer_id) REFERENCES customers (id);
ALTER TABLE ONLY product_option_values
ADD CONSTRAINT "FK_cdf4388f294b30a25c627d69fe9" FOREIGN KEY (option_id) REFERENCES product_options (id);
ALTER TABLE ONLY carts
ADD CONSTRAINT "FK_ced15a9a695d2b5db9dabce763d" FOREIGN KEY (shipping_address_id) REFERENCES addresses (id);
ALTER TABLE ONLY payment_sessions
ADD CONSTRAINT "FK_d25ba0787e1510ddc5d442ebcfa" FOREIGN KEY (cart_id) REFERENCES carts (id);
ALTER TABLE ONLY cart_gift_cards
ADD CONSTRAINT "FK_d38047a90f3d42f0be7909e8aea" FOREIGN KEY (cart_id) REFERENCES carts (id) ON DELETE CASCADE;
ALTER TABLE ONLY returns
ADD CONSTRAINT "FK_d4bd17f918fc6c332b74a368c36" FOREIGN KEY (order_id) REFERENCES orders (id);
ALTER TABLE ONLY fulfillments
ADD CONSTRAINT "FK_d73e55964e0ff2db8f03807d52e" FOREIGN KEY (claim_order_id) REFERENCES claim_orders (id);
ALTER TABLE ONLY return_items
ADD CONSTRAINT "FK_d742532378a65022e7ceb328828" FOREIGN KEY (reason_id) REFERENCES return_reasons (id);
ALTER TABLE ONLY shipping_methods
ADD CONSTRAINT "FK_d783a66d1c91c0858752c933e68" FOREIGN KEY (claim_order_id) REFERENCES claim_orders (id);
ALTER TABLE ONLY gift_card_transactions
ADD CONSTRAINT "FK_d7d441b81012f87d4265fa57d24" FOREIGN KEY (order_id) REFERENCES orders (id);
ALTER TABLE ONLY shipping_methods
ADD CONSTRAINT "FK_d92993a7d554d84571f4eea1d13" FOREIGN KEY (cart_id) REFERENCES carts (id);
ALTER TABLE ONLY claim_item_tags
ADD CONSTRAINT "FK_dc9bbf9fcb9ba458d25d512811b" FOREIGN KEY (tag_id) REFERENCES claim_tags (id) ON DELETE CASCADE;
ALTER TABLE ONLY gift_cards
ADD CONSTRAINT "FK_dfc1f02bb0552e79076aa58dbb0" FOREIGN KEY (order_id) REFERENCES orders (id);
ALTER TABLE ONLY products
ADD CONSTRAINT "FK_e0843930fbb8854fe36ca39dae1" FOREIGN KEY (type_id) REFERENCES product_types (id);
ALTER TABLE ONLY fulfillment_items
ADD CONSTRAINT "FK_e13ff60e74206b747a1896212d1" FOREIGN KEY (item_id) REFERENCES line_items (id);
ALTER TABLE ONLY money_amounts
ADD CONSTRAINT "FK_e15811f81339e4bd8c440aebe1c" FOREIGN KEY (currency_code) REFERENCES currencies (code);
ALTER TABLE ONLY orders
ADD CONSTRAINT "FK_e1fcce2b18dbcdbe0a5ba9a68b8" FOREIGN KEY (region_id) REFERENCES regions (id);
ALTER TABLE ONLY order_gift_cards
ADD CONSTRAINT "FK_e62ff11e4730bb3adfead979ee2" FOREIGN KEY (order_id) REFERENCES orders (id) ON DELETE CASCADE;
ALTER TABLE ONLY product_options
ADD CONSTRAINT "FK_e634fca34f6b594b87fdbee95f6" FOREIGN KEY (product_id) REFERENCES products (id);
ALTER TABLE ONLY discount_condition_product_types
ADD CONSTRAINT "FK_e706deb68f52ab2756119b9e704" FOREIGN KEY (product_type_id) REFERENCES product_types (id) ON DELETE CASCADE;
ALTER TABLE ONLY order_discounts
ADD CONSTRAINT "FK_e7b488cebe333f449398769b2cc" FOREIGN KEY (order_id) REFERENCES orders (id) ON DELETE CASCADE;
ALTER TABLE ONLY product_type_tax_rates
ADD CONSTRAINT "FK_ece65a774192b34253abc4cd672" FOREIGN KEY (rate_id) REFERENCES tax_rates (id) ON DELETE CASCADE;
ALTER TABLE ONLY refunds
ADD CONSTRAINT "FK_eec9d9af4ca098e19ea6b499eaa" FOREIGN KEY (order_id) REFERENCES orders (id);
ALTER TABLE ONLY discount_conditions
ADD CONSTRAINT "FK_efff700651718e452ca9580a624" FOREIGN KEY (discount_rule_id) REFERENCES discount_rules (id);
ALTER TABLE ONLY discount_condition_products
ADD CONSTRAINT "FK_f05132301e95bdab4ba1cf29a24" FOREIGN KEY (condition_id) REFERENCES discount_conditions (id) ON DELETE CASCADE;
ALTER TABLE ONLY fulfillments
ADD CONSTRAINT "FK_f129acc85e346a10eed12b86fca" FOREIGN KEY (order_id) REFERENCES orders (id);
ALTER TABLE ONLY money_amounts
ADD CONSTRAINT "FK_f249976b079375499662eb80c40" FOREIGN KEY (price_list_id) REFERENCES price_lists (id) ON DELETE CASCADE;
ALTER TABLE ONLY order_gift_cards
ADD CONSTRAINT "FK_f2bb9f71e95b315eb24b2b84cb3" FOREIGN KEY (gift_card_id) REFERENCES gift_cards (id) ON DELETE CASCADE;
ALTER TABLE ONLY payments
ADD CONSTRAINT "FK_f41553459a4b1491c9893ebc921" FOREIGN KEY (currency_code) REFERENCES currencies (code);
ALTER TABLE ONLY discount_regions
ADD CONSTRAINT "FK_f4194aa81073f3fab8aa86906ff" FOREIGN KEY (discount_id) REFERENCES discounts (id) ON DELETE CASCADE;
ALTER TABLE ONLY claim_orders
ADD CONSTRAINT "FK_f49e3974465d3c3a33d449d3f31" FOREIGN KEY (order_id) REFERENCES orders (id);
ALTER TABLE ONLY swaps
ADD CONSTRAINT "FK_f5189d38b3d3bd496618bf54c57" FOREIGN KEY (shipping_address_id) REFERENCES addresses (id);
ALTER TABLE ONLY payments
ADD CONSTRAINT "FK_f5221735ace059250daac9d9803" FOREIGN KEY (order_id) REFERENCES orders (id);
ALTER TABLE ONLY shipping_tax_rates
ADD CONSTRAINT "FK_f672727ab020df6c50fb64c1a70" FOREIGN KEY (shipping_option_id) REFERENCES shipping_options (id) ON DELETE CASCADE;
ALTER TABLE ONLY batch_jobs
ADD CONSTRAINT "FK_fa53ca4f5fd90605b532802a626" FOREIGN KEY (created_by) REFERENCES users (id);
ALTER TABLE ONLY shipping_methods
ADD CONSTRAINT "FK_fb94fa8d5ca940daa2a58139f86" FOREIGN KEY (swap_id) REFERENCES swaps (id);
ALTER TABLE ONLY discount_condition_product_tags
ADD CONSTRAINT "FK_fbb2499551ed074526f3ee36241" FOREIGN KEY (condition_id) REFERENCES discount_conditions (id) ON DELETE CASCADE;
ALTER TABLE ONLY shipping_methods
ADD CONSTRAINT "FK_fc963e94854bff2714ca84cd193" FOREIGN KEY (shipping_option_id) REFERENCES shipping_options (id);
ALTER TABLE ONLY order_edits
ADD CONSTRAINT "FK_order_edit_payment_collection_id" FOREIGN KEY (payment_collection_id) REFERENCES payment_collections (id);
ALTER TABLE ONLY payment_collection_payments
ADD CONSTRAINT "FK_payment_collection_payments_payment_collection_id" FOREIGN KEY (payment_collection_id) REFERENCES payment_collections (id) ON DELETE CASCADE;
ALTER TABLE ONLY payment_collection_payments
ADD CONSTRAINT "FK_payment_collection_payments_payment_id" FOREIGN KEY (payment_id) REFERENCES payments (id) ON DELETE CASCADE;
ALTER TABLE ONLY payment_collections
ADD CONSTRAINT "FK_payment_collection_region_id" FOREIGN KEY (region_id) REFERENCES regions (id);
ALTER TABLE ONLY payment_collection_sessions
ADD CONSTRAINT "FK_payment_collection_sessions_payment_collection_id" FOREIGN KEY (payment_collection_id) REFERENCES payment_collections (id) ON DELETE CASCADE;
ALTER TABLE ONLY payment_collection_sessions
ADD CONSTRAINT "FK_payment_collection_sessions_payment_session_id" FOREIGN KEY (payment_session_id) REFERENCES payment_sessions (id) ON DELETE CASCADE;
ALTER TABLE ONLY product_category_products
ADD CONSTRAINT "FK_product_category_id" FOREIGN KEY (product_category_id) REFERENCES product_categories (id) ON DELETE CASCADE;
ALTER TABLE ONLY product_category_products
ADD CONSTRAINT "FK_product_id" FOREIGN KEY (product_id) REFERENCES products (id) ON DELETE CASCADE;
ALTER TABLE ONLY refunds
ADD CONSTRAINT "FK_refund_payment_id" FOREIGN KEY (payment_id) REFERENCES payments (id);
ALTER TABLE ONLY line_items
ADD CONSTRAINT line_item_order_edit_fk FOREIGN KEY (order_edit_id) REFERENCES order_edits (id);
ALTER TABLE ONLY line_items
ADD CONSTRAINT line_item_original_item_fk FOREIGN KEY (original_item_id) REFERENCES line_items (id);