From eee5d6c22d16b68b6354460d7f21b64b1103a052 Mon Sep 17 00:00:00 2001 From: eraden Date: Wed, 7 Jun 2023 21:39:39 +0200 Subject: [PATCH] Add geolocation --- .../carts/m20230603_120815_cart_discounts.rs | 1 - .../src/public/m20230603_120815_claims.rs | 14 +- .../public/m20230603_120816_geolocation.rs | 84 +++ migration/src/public/mod.rs | 2 + migrations/20230603073510_init.sql | 477 +++++++++--------- 5 files changed, 332 insertions(+), 246 deletions(-) create mode 100644 migration/src/public/m20230603_120816_geolocation.rs diff --git a/migration/src/carts/m20230603_120815_cart_discounts.rs b/migration/src/carts/m20230603_120815_cart_discounts.rs index 511fdfe..f740fe6 100644 --- a/migration/src/carts/m20230603_120815_cart_discounts.rs +++ b/migration/src/carts/m20230603_120815_cart_discounts.rs @@ -1,5 +1,4 @@ use sea_orm_migration::prelude::*; -use sea_query::expr::SimpleExpr; /// ```sql /// CREATE TABLE cart_discounts diff --git a/migration/src/public/m20230603_120815_claims.rs b/migration/src/public/m20230603_120815_claims.rs index f3facee..4d62aeb 100644 --- a/migration/src/public/m20230603_120815_claims.rs +++ b/migration/src/public/m20230603_120815_claims.rs @@ -111,7 +111,7 @@ impl Migration { /// tag_id uuid NOT NULL /// ); /// ``` - async fn create_claim_item_tags(manager: &SchemaManager) -> Result<(), DbErr> { + async fn create_claim_item_tags(manager: &SchemaManager<'_>) -> Result<(), DbErr> { manager .create_table( Table::create() @@ -139,7 +139,7 @@ impl Migration { /// metadata jsonb /// ); /// ``` - async fn create_claim_items(manager: &SchemaManager) -> Result<(), DbErr> { + async fn create_claim_items(manager: &SchemaManager<'_>) -> Result<(), DbErr> { manager .create_table( Table::create() @@ -179,7 +179,7 @@ impl Migration { /// metadata jsonb /// ); /// ``` - async fn create_claim_images(manager: &SchemaManager) -> Result<(), DbErr> { + async fn create_claim_images(manager: &SchemaManager<'_>) -> Result<(), DbErr> { manager .create_table( Table::create() @@ -215,7 +215,7 @@ impl Migration { /// no_notification boolean /// ); /// ``` - async fn create_claim_orders(manager: &SchemaManager) -> Result<(), DbErr> { + async fn create_claim_orders(manager: &SchemaManager<'_>) -> Result<(), DbErr> { manager .create_table( Table::create() @@ -227,7 +227,7 @@ impl Migration { ClaimOrderPaymentStatus::ClaimOrderPaymentStatuses, ClaimOrderPaymentStatus::iter().skip(1), ) - .default(ClaimOrderPaymentStatus::NA) + .default(ClaimOrderPaymentStatus::NA.to_string()) .not_null(), ) .col( @@ -236,7 +236,7 @@ impl Migration { ClaimOrderFulfillmentStatus::ClaimOrderFulfillmentStatuses, ClaimOrderFulfillmentStatus::iter().skip(1), ) - .default(ClaimOrderFulfillmentStatus::NotFulfilled) + .default(ClaimOrderFulfillmentStatus::NotFulfilled.to_string()) .not_null(), ) .col( @@ -273,7 +273,7 @@ impl Migration { /// metadata jsonb /// ); /// ``` - async fn create_claim_tags(manager: &SchemaManager) -> Result<(), DbErr> { + async fn create_claim_tags(manager: &SchemaManager<'_>) -> Result<(), DbErr> { manager .create_table( Table::create() diff --git a/migration/src/public/m20230603_120816_geolocation.rs b/migration/src/public/m20230603_120816_geolocation.rs new file mode 100644 index 0000000..383ad04 --- /dev/null +++ b/migration/src/public/m20230603_120816_geolocation.rs @@ -0,0 +1,84 @@ +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> { + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + Ok(()) + } +} + +impl Migration { + /// ```sql + /// CREATE TABLE public.countries + /// ( + /// id sequence NOT NULL, + /// iso_2 character varying NOT NULL, + /// iso_3 character varying NOT NULL, + /// num_code integer NOT NULL, + /// name character varying NOT NULL, + /// display_name character varying NOT NULL, + /// region_id character varying + /// ); + /// ``` + async fn create_countries(manager: &SchemaManager<'_>) -> Result<(), DbErr> { + todo!() + } + + /// ```sql + /// CREATE TABLE public.currencies + /// ( + /// code character varying NOT NULL, + /// symbol character varying NOT NULL, + /// symbol_native character varying NOT NULL, + /// name character varying NOT NULL + /// ); + /// ``` + async fn create_currencies(manager: &SchemaManager<'_>) -> Result<(), DbErr> { + todo!() + } + + /// CREATE TABLE public.regions + /// ( + /// id uuid NOT NULL, + /// name character varying NOT NULL, + /// currency_code character varying NOT NULL, + /// tax_rate real NOT NULL, + /// tax_code character varying, + /// 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, + /// gift_cards_taxable boolean DEFAULT true NOT NULL, + /// automatic_taxes boolean DEFAULT true NOT NULL, + /// tax_provider_id uuid + /// ); + async fn create_regions(manager: &SchemaManager<'_>) -> Result<(), DbErr> { + todo!() + } +} + +#[derive(Iden)] +pub enum ClaimImage { + ClaimImages, + Id, + ClaimItemId, + Url, + CreatedAt, + UpdatedAt, + DeletedAt, + Metadata, +} diff --git a/migration/src/public/mod.rs b/migration/src/public/mod.rs index 29ec79c..bcaeec9 100644 --- a/migration/src/public/mod.rs +++ b/migration/src/public/mod.rs @@ -4,6 +4,7 @@ mod m20230603_102630_schema; mod m20230603_102634_types; mod m20230603_120814_addresses; mod m20230603_120815_claims; +mod m20230603_120816_geolocation; pub struct PublicMigrator; @@ -16,6 +17,7 @@ impl MigratorTrait for PublicMigrator { Box::new(m20230603_102634_types::Migration), Box::new(m20230603_120814_addresses::Migration), Box::new(m20230603_120815_claims::Migration), + Box::new(m20230603_120816_geolocation::Migration), ] } } diff --git a/migrations/20230603073510_init.sql b/migrations/20230603073510_init.sql index 856d1a2..1994a5a 100644 --- a/migrations/20230603073510_init.sql +++ b/migrations/20230603073510_init.sql @@ -206,8 +206,8 @@ CREATE TYPE public.user_roles AS ENUM ( CREATE TABLE public.addresses ( - id uuid NOT NULL, - customer_id character varying, + id uuid NOT NULL, + customer_id uuid, company character varying, first_name character varying, last_name character varying, @@ -226,18 +226,18 @@ CREATE TABLE public.addresses CREATE TABLE public.analytics_configs ( - id uuid NOT NULL, + 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, - user_id uuid NOT NULL, + user_id uuid NOT NULL, opt_out boolean DEFAULT false NOT NULL, anonymize boolean DEFAULT false NOT NULL ); CREATE TABLE public.batch_jobs ( - id uuid NOT NULL, + id uuid NOT NULL, type text NOT NULL, created_by character varying, context jsonb, @@ -256,13 +256,13 @@ CREATE TABLE public.batch_jobs CREATE TABLE public.carts ( - id uuid NOT NULL, + id uuid NOT NULL, email character varying, - billing_address_id character varying, - shipping_address_id character varying, - region_id uuid NOT NULL, - customer_id character varying, - payment_id character varying, + billing_address_id uuid, + shipping_address_id uuid, + region_id uuid NOT NULL, + customer_id uuid, + payment_id uuid, type public.cart_types DEFAULT 'default'::public.cart_types NOT NULL, completed_at timestamp with time zone, created_at timestamp with time zone DEFAULT now() NOT NULL, @@ -272,34 +272,25 @@ CREATE TABLE public.carts idempotency_key character varying, context jsonb, payment_authorized_at timestamp with time zone, - sales_channel_id character varying + sales_channel_id uuid ); CREATE TABLE public.cart_discounts ( - cart_id uuid NOT NULL, + cart_id uuid NOT NULL, discount_id uuid NOT NULL ); CREATE TABLE public.cart_gift_cards ( - cart_id uuid NOT NULL, + cart_id uuid NOT NULL, gift_card_id uuid NOT NULL ); ----- ########################################################### ----- ########################################################### ----- ########################################################### ----- ########################################################### ----- ########################################################### ----- ########################################################### ----- ########################################################### ----- ########################################################### - CREATE TABLE public.claim_images ( - id uuid NOT NULL, - claim_item_id uuid NOT NULL, + id uuid NOT NULL, + claim_item_id uuid NOT NULL, 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, @@ -309,10 +300,10 @@ CREATE TABLE public.claim_images CREATE TABLE public.claim_items ( - id uuid NOT NULL, - claim_order_id uuid NOT NULL, - item_id uuid NOT NULL, - variant_id uuid NOT NULL, + id uuid NOT NULL, + claim_order_id uuid NOT NULL, + item_id uuid NOT NULL, + variant_id uuid NOT NULL, reason public.claim_item_reasons NOT NULL, note character varying, quantity integer NOT NULL, @@ -325,17 +316,17 @@ CREATE TABLE public.claim_items CREATE TABLE public.claim_item_tags ( item_id uuid NOT NULL, - tag_id uuid NOT NULL + tag_id uuid NOT NULL ); CREATE TABLE public.claim_orders ( - id uuid NOT NULL, + id uuid NOT NULL, payment_status public.claim_order_payment_statuses DEFAULT 'na'::public.claim_order_payment_statuses NOT NULL, fulfillment_status public.claim_order_fulfillment_statuses DEFAULT 'not_fulfilled'::public.claim_order_fulfillment_statuses NOT NULL, type public.claim_order_types NOT NULL, - order_id uuid NOT NULL, - shipping_address_id character varying, + order_id uuid NOT NULL, + shipping_address_id uuid, refund_amount integer, canceled_at timestamp with time zone, created_at timestamp with time zone DEFAULT now() NOT NULL, @@ -348,7 +339,7 @@ CREATE TABLE public.claim_orders CREATE TABLE public.claim_tags ( - id uuid NOT NULL, + id uuid NOT NULL, 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, @@ -356,6 +347,32 @@ CREATE TABLE public.claim_tags metadata jsonb ); +---- ########################################################### +---- ########################################################### +---- ########################################################### +---- ########################################################### +---- ########################################################### +---- ########################################################### +---- ########################################################### +---- ########################################################### + + +CREATE TABLE public.regions +( + id uuid NOT NULL, + name character varying NOT NULL, + currency_code character varying NOT NULL, + tax_rate real NOT NULL, + tax_code character varying, + 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, + gift_cards_taxable boolean DEFAULT true NOT NULL, + automatic_taxes boolean DEFAULT true NOT NULL, + tax_provider_id uuid +); + CREATE TABLE public.countries ( id sequence NOT NULL, @@ -364,7 +381,7 @@ CREATE TABLE public.countries num_code integer NOT NULL, name character varying NOT NULL, display_name character varying NOT NULL, - region_id character varying + region_id uuid ); CREATE TABLE public.currencies @@ -377,10 +394,10 @@ CREATE TABLE public.currencies CREATE TABLE public.custom_shipping_options ( - id uuid NOT NULL, + id uuid NOT NULL, price integer NOT NULL, - shipping_option_id uuid NOT NULL, - cart_id character varying, + 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, @@ -389,11 +406,11 @@ CREATE TABLE public.custom_shipping_options CREATE TABLE public.customers ( - id uuid NOT NULL, + id uuid NOT NULL, email character varying NOT NULL, first_name character varying, last_name character varying, - billing_address_id character varying, + billing_address_id uuid, password_hash character varying, phone character varying, has_account boolean DEFAULT false NOT NULL, @@ -405,7 +422,7 @@ CREATE TABLE public.customers CREATE TABLE public.customer_groups ( - id uuid NOT NULL, + 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, @@ -416,17 +433,17 @@ CREATE TABLE public.customer_groups CREATE TABLE public.customer_group_customers ( customer_group_id uuid NOT NULL, - customer_id uuid NOT NULL + customer_id uuid NOT NULL ); CREATE TABLE public.discounts ( - id uuid NOT NULL, + id uuid NOT NULL, code character varying NOT NULL, is_dynamic boolean NOT NULL, - rule_id character varying, + rule_id uuid, is_disabled boolean NOT NULL, - parent_discount_id character varying, + 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, @@ -440,10 +457,10 @@ CREATE TABLE public.discounts CREATE TABLE public.discount_conditions ( - id uuid NOT NULL, + id uuid NOT NULL, type public.discount_condition_types NOT NULL, operator public.discount_condition_operators NOT NULL, - discount_rule_id uuid 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, @@ -452,8 +469,8 @@ CREATE TABLE public.discount_conditions CREATE TABLE public.discount_condition_customer_groups ( - customer_group_id uuid NOT NULL, - condition_id uuid NOT NULL, + 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 @@ -461,8 +478,8 @@ CREATE TABLE public.discount_condition_customer_groups CREATE TABLE public.discount_condition_products ( - product_id uuid NOT NULL, - condition_id uuid NOT NULL, + 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 @@ -470,8 +487,8 @@ CREATE TABLE public.discount_condition_products CREATE TABLE public.discount_condition_product_collections ( - product_collection_id uuid NOT NULL, - condition_id uuid NOT NULL, + 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 @@ -479,8 +496,8 @@ CREATE TABLE public.discount_condition_product_collections CREATE TABLE public.discount_condition_product_tags ( - product_tag_id uuid NOT NULL, - condition_id uuid NOT NULL, + 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 @@ -488,8 +505,8 @@ CREATE TABLE public.discount_condition_product_tags CREATE TABLE public.discount_condition_product_types ( - product_type_id uuid NOT NULL, - condition_id uuid NOT NULL, + 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 @@ -498,12 +515,12 @@ CREATE TABLE public.discount_condition_product_types CREATE TABLE public.discount_regions ( discount_id uuid NOT NULL, - region_id uuid NOT NULL + region_id uuid NOT NULL ); CREATE TABLE public.discount_rules ( - id uuid NOT NULL, + id uuid NOT NULL, description character varying, type public.discount_rule_types NOT NULL, value integer NOT NULL, @@ -517,16 +534,16 @@ CREATE TABLE public.discount_rules CREATE TABLE public.discount_rule_products ( discount_rule_id uuid NOT NULL, - product_id uuid NOT NULL + product_id uuid NOT NULL ); CREATE TABLE public.draft_orders ( - id uuid NOT NULL, + id uuid NOT NULL, status public.draft_order_statuses DEFAULT 'open'::public.draft_order_statuses NOT NULL, display_id sequence NOT NULL, - cart_id character varying, - order_id character varying, + cart_id uuid, + order_id uuid, 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, @@ -538,9 +555,9 @@ CREATE TABLE public.draft_orders CREATE TABLE public.fulfillments ( - id uuid NOT NULL, - swap_id character varying, - order_id character varying, + id uuid NOT NULL, + swap_id uuid, + order_id uuid, tracking_numbers jsonb DEFAULT '[]'::jsonb NOT NULL, data jsonb NOT NULL, shipped_at timestamp with time zone, @@ -549,33 +566,33 @@ CREATE TABLE public.fulfillments updated_at timestamp with time zone DEFAULT now() NOT NULL, metadata jsonb, idempotency_key character varying, - provider_id character varying, - claim_order_id character varying, + provider_id uuid, + claim_order_id uuid, no_notification boolean, - location_id character varying + location_id uuid ); CREATE TABLE public.fulfillment_items ( - fulfillment_id uuid NOT NULL, - item_id uuid NOT NULL, - quantity integer NOT NULL + fulfillment_id uuid NOT NULL, + item_id uuid NOT NULL, + quantity integer NOT NULL ); CREATE TABLE public.fulfillment_providers ( - id uuid NOT NULL, + id uuid NOT NULL, is_installed boolean DEFAULT true NOT NULL ); CREATE TABLE public.gift_cards ( - id uuid NOT NULL, + id uuid NOT NULL, code character varying NOT NULL, value integer NOT NULL, balance integer NOT NULL, - region_id uuid NOT NULL, - order_id character varying, + region_id uuid NOT NULL, + order_id uuid, is_disabled boolean DEFAULT false NOT NULL, ends_at timestamp with time zone, created_at timestamp with time zone DEFAULT now() NOT NULL, @@ -587,9 +604,9 @@ CREATE TABLE public.gift_cards CREATE TABLE public.gift_card_transactions ( - id uuid NOT NULL, - gift_card_id uuid NOT NULL, - order_id uuid NOT NULL, + id uuid NOT NULL, + gift_card_id uuid NOT NULL, + order_id uuid NOT NULL, amount integer NOT NULL, created_at timestamp with time zone DEFAULT now() NOT NULL, is_taxable boolean, @@ -598,7 +615,7 @@ CREATE TABLE public.gift_card_transactions CREATE TABLE public.idempotency_keys ( - id uuid NOT NULL, + 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, @@ -612,7 +629,7 @@ CREATE TABLE public.idempotency_keys CREATE TABLE public.images ( - id uuid NOT NULL, + id uuid NOT NULL, 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, @@ -622,7 +639,7 @@ CREATE TABLE public.images CREATE TABLE public.invites ( - id uuid NOT NULL, + id uuid NOT NULL, user_email character varying NOT NULL, role public.invite_roles DEFAULT 'member'::public.invite_roles, accepted boolean DEFAULT false NOT NULL, @@ -636,10 +653,10 @@ CREATE TABLE public.invites CREATE TABLE public.line_items ( - id uuid NOT NULL, - cart_id character varying, - order_id character varying, - swap_id character varying, + id uuid NOT NULL, + cart_id uuid, + order_id uuid, + swap_id uuid, title character varying NOT NULL, description character varying, thumbnail character varying, @@ -648,7 +665,7 @@ CREATE TABLE public.line_items allow_discounts boolean DEFAULT true NOT NULL, has_shipping boolean, unit_price integer NOT NULL, - variant_id character varying, + variant_id uuid, quantity integer NOT NULL, fulfilled_quantity integer, returned_quantity integer, @@ -656,10 +673,10 @@ CREATE TABLE public.line_items 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 character varying, + claim_order_id uuid, is_return boolean DEFAULT false NOT NULL, - original_item_id character varying, - order_edit_id character varying, + 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)), @@ -668,24 +685,24 @@ CREATE TABLE public.line_items CREATE TABLE public.line_item_adjustments ( - id uuid NOT NULL, - item_id uuid NOT NULL, + id uuid NOT NULL, + item_id uuid NOT NULL, description character varying NOT NULL, - discount_id character varying, + discount_id uuid, amount numeric NOT NULL, metadata jsonb ); CREATE TABLE public.line_item_tax_lines ( - id uuid NOT NULL, + 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 + item_id uuid NOT NULL ); CREATE TABLE public.migrations @@ -697,26 +714,26 @@ CREATE TABLE public.migrations CREATE TABLE public.money_amounts ( - id uuid NOT NULL, + id uuid NOT NULL, currency_code character varying NOT NULL, amount integer NOT NULL, - variant_id character varying, - region_id character varying, + variant_id uuid, + region_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, min_quantity integer, max_quantity integer, - price_list_id character varying + price_list_id uuid ); CREATE TABLE public.notes ( - id uuid NOT NULL, + id uuid NOT NULL, value character varying NOT NULL, resource_type character varying NOT NULL, - resource_id uuid NOT NULL, - author_id character varying, + resource_id uuid NOT NULL, + author_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, @@ -725,28 +742,28 @@ CREATE TABLE public.notes CREATE TABLE public.notifications ( - id uuid NOT NULL, + id uuid NOT NULL, event_name character varying, resource_type character varying NOT NULL, - resource_id uuid NOT NULL, - customer_id character varying, + resource_id uuid NOT NULL, + customer_id uuid, "to" character varying NOT NULL, data jsonb NOT NULL, - parent_id character varying, - provider_id character varying, + 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 public.notification_providers ( - id uuid NOT NULL, + id uuid NOT NULL, is_installed boolean DEFAULT true NOT NULL ); CREATE TABLE public.oauth ( - id uuid NOT NULL, + id uuid NOT NULL, display_name character varying NOT NULL, application_name character varying NOT NULL, install_url character varying, @@ -756,17 +773,17 @@ CREATE TABLE public.oauth CREATE TABLE public.orders ( - id uuid NOT NULL, + 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 character varying, - customer_id uuid NOT NULL, + cart_id uuid, + customer_id uuid NOT NULL, email character varying NOT NULL, - billing_address_id character varying, - shipping_address_id character varying, - region_id uuid 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, @@ -774,24 +791,24 @@ CREATE TABLE public.orders updated_at timestamp with time zone DEFAULT now() NOT NULL, metadata jsonb, idempotency_key character varying, - draft_order_id character varying, + draft_order_id uuid, no_notification boolean, - external_id character varying, - sales_channel_id character varying + external_id uuid, + sales_channel_id uuid ); CREATE TABLE public.order_discounts ( - order_id uuid NOT NULL, + order_id uuid NOT NULL, discount_id uuid NOT NULL ); CREATE TABLE public.order_edits ( - id uuid NOT NULL, + 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, + order_id uuid NOT NULL, internal_note character varying, created_by character varying NOT NULL, requested_by character varying, @@ -803,37 +820,37 @@ CREATE TABLE public.order_edits declined_at timestamp with time zone, canceled_by character varying, canceled_at timestamp with time zone, - payment_collection_id character varying + payment_collection_id uuid ); CREATE TABLE public.order_gift_cards ( - order_id uuid NOT NULL, + order_id uuid NOT NULL, gift_card_id uuid NOT NULL ); CREATE TABLE public.order_item_changes ( - id uuid NOT NULL, + 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 character varying, - line_item_id character varying + 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 character varying, - cart_id character varying, - order_id character varying, + 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, + provider_id uuid NOT NULL, data jsonb NOT NULL, captured_at timestamp with time zone, canceled_at timestamp with time zone, @@ -845,7 +862,7 @@ CREATE TABLE public.payments CREATE TABLE public.payment_collections ( - id uuid NOT NULL, + 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, @@ -854,7 +871,7 @@ CREATE TABLE public.payment_collections description text, amount integer NOT NULL, authorized_amount integer, - region_id uuid NOT NULL, + region_id uuid NOT NULL, currency_code character varying NOT NULL, metadata jsonb, created_by character varying NOT NULL @@ -863,26 +880,26 @@ CREATE TABLE public.payment_collections CREATE TABLE public.payment_collection_payments ( payment_collection_id uuid NOT NULL, - payment_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 + payment_session_id uuid NOT NULL ); CREATE TABLE public.payment_providers ( - id uuid NOT NULL, + id uuid NOT NULL, is_installed boolean DEFAULT true NOT NULL ); CREATE TABLE public.payment_sessions ( - id uuid NOT NULL, - cart_id character varying, - provider_id uuid NOT NULL, + 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, @@ -896,7 +913,7 @@ CREATE TABLE public.payment_sessions CREATE TABLE public.price_lists ( - id uuid NOT NULL, + id uuid NOT NULL, name character varying NOT NULL, description character varying NOT NULL, type public.price_list_types DEFAULT 'sale'::public.price_list_types NOT NULL, @@ -910,20 +927,20 @@ CREATE TABLE public.price_lists CREATE TABLE public.price_list_customer_groups ( - price_list_id uuid NOT NULL, + price_list_id uuid NOT NULL, customer_group_id uuid NOT NULL ); CREATE TABLE public.products ( - id uuid NOT NULL, + id uuid NOT NULL, title character varying NOT NULL, subtitle character varying, description character varying, handle character varying, is_giftcard boolean DEFAULT false NOT NULL, thumbnail character varying, - profile_id uuid NOT NULL, + profile_id uuid NOT NULL, weight integer, length integer, height integer, @@ -936,19 +953,19 @@ CREATE TABLE public.products updated_at timestamp with time zone DEFAULT now() NOT NULL, deleted_at timestamp with time zone, metadata jsonb, - collection_id character varying, - type_id character varying, + collection_id uuid, + type_id uuid, discountable boolean DEFAULT true NOT NULL, status public.product_statuses DEFAULT 'draft'::public.product_statuses NOT NULL, - external_id character varying + external_id uuid ); CREATE TABLE public.product_categories ( - id uuid NOT NULL, + id uuid NOT NULL, name text NOT NULL, handle text NOT NULL, - parent_category_id character varying, + parent_category_id uuid, mpath text, is_active boolean DEFAULT false, is_internal boolean DEFAULT false, @@ -962,12 +979,12 @@ CREATE TABLE public.product_categories CREATE TABLE public.product_category_products ( product_category_id uuid NOT NULL, - product_id uuid NOT NULL + product_id uuid NOT NULL ); CREATE TABLE public.product_collections ( - id uuid NOT NULL, + id uuid NOT NULL, title character varying NOT NULL, handle character varying, created_at timestamp with time zone DEFAULT now() NOT NULL, @@ -979,26 +996,26 @@ CREATE TABLE public.product_collections CREATE TABLE public.product_images ( product_id uuid NOT NULL, - image_id uuid NOT NULL + image_id uuid NOT NULL ); CREATE TABLE public.product_options ( - id uuid NOT NULL, + id uuid NOT NULL, title 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, - product_id character varying + product_id uuid ); CREATE TABLE public.product_option_values ( - id uuid NOT NULL, + id uuid NOT NULL, value character varying NOT NULL, - option_id uuid NOT NULL, - variant_id uuid NOT NULL, + option_id uuid NOT NULL, + variant_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, @@ -1007,13 +1024,13 @@ CREATE TABLE public.product_option_values CREATE TABLE public.product_sales_channels ( - product_id uuid NOT NULL, + product_id uuid NOT NULL, sales_channel_id uuid NOT NULL ); CREATE TABLE public.product_tags ( - id uuid NOT NULL, + id uuid NOT NULL, 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, @@ -1023,14 +1040,14 @@ CREATE TABLE public.product_tags CREATE TABLE public.product_to_tags ( - product_id uuid NOT NULL, + product_id uuid NOT NULL, product_tag_id uuid NOT NULL ); CREATE TABLE public.product_tax_rates ( - product_id uuid NOT NULL, - rate_id uuid NOT NULL, + product_id uuid NOT NULL, + rate_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 @@ -1038,7 +1055,7 @@ CREATE TABLE public.product_tax_rates CREATE TABLE public.product_types ( - id uuid NOT NULL, + id uuid NOT NULL, 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, @@ -1048,8 +1065,8 @@ CREATE TABLE public.product_types CREATE TABLE public.product_type_tax_rates ( - product_type_id uuid NOT NULL, - rate_id uuid NOT NULL, + product_type_id uuid NOT NULL, + rate_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 @@ -1057,9 +1074,9 @@ CREATE TABLE public.product_type_tax_rates CREATE TABLE public.product_variants ( - id uuid NOT NULL, + id uuid NOT NULL, title character varying NOT NULL, - product_id uuid NOT NULL, + product_id uuid NOT NULL, sku character varying, barcode character varying, ean character varying, @@ -1084,7 +1101,7 @@ CREATE TABLE public.product_variants CREATE TABLE public.product_variant_inventory_items ( - id uuid NOT NULL, + id uuid NOT NULL, created_at timestamp with time zone DEFAULT now() NOT NULL, updated_at timestamp with time zone DEFAULT now() NOT NULL, inventory_item_id text NOT NULL, @@ -1095,7 +1112,7 @@ CREATE TABLE public.product_variant_inventory_items CREATE TABLE public.publishable_api_keys ( - id uuid NOT NULL, + id uuid NOT NULL, created_at timestamp with time zone DEFAULT now() NOT NULL, updated_at timestamp with time zone DEFAULT now() NOT NULL, created_by character varying, @@ -1106,14 +1123,14 @@ CREATE TABLE public.publishable_api_keys CREATE TABLE public.publishable_api_key_sales_channels ( - sales_channel_id uuid NOT NULL, + sales_channel_id uuid NOT NULL, publishable_key_id uuid NOT NULL ); CREATE TABLE public.refunds ( - id uuid NOT NULL, - order_id character varying, + id uuid NOT NULL, + order_id uuid, amount integer NOT NULL, note character varying, reason public.refund_reasons NOT NULL, @@ -1121,43 +1138,27 @@ CREATE TABLE public.refunds updated_at timestamp with time zone DEFAULT now() NOT NULL, metadata jsonb, idempotency_key character varying, - payment_id character varying -); - -CREATE TABLE public.regions -( - id uuid NOT NULL, - name character varying NOT NULL, - currency_code character varying NOT NULL, - tax_rate real NOT NULL, - tax_code character varying, - 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, - gift_cards_taxable boolean DEFAULT true NOT NULL, - automatic_taxes boolean DEFAULT true NOT NULL, - tax_provider_id character varying + payment_id uuid ); CREATE TABLE public.region_fulfillment_providers ( - region_id uuid NOT NULL, + region_id uuid NOT NULL, provider_id uuid NOT NULL ); CREATE TABLE public.region_payment_providers ( - region_id uuid NOT NULL, + region_id uuid NOT NULL, provider_id uuid NOT NULL ); CREATE TABLE public.returns ( - id uuid NOT NULL, + id uuid NOT NULL, status public.return_statuses DEFAULT 'requested'::public.return_statuses NOT NULL, - swap_id character varying, - order_id character varying, + swap_id uuid, + order_id uuid, shipping_data jsonb, refund_amount integer NOT NULL, received_at timestamp with time zone, @@ -1165,27 +1166,27 @@ CREATE TABLE public.returns updated_at timestamp with time zone DEFAULT now() NOT NULL, metadata jsonb, idempotency_key character varying, - claim_order_id character varying, + claim_order_id uuid, no_notification boolean, - location_id character varying + location_id uuid ); CREATE TABLE public.return_items ( - return_id uuid NOT NULL, - item_id uuid NOT NULL, + return_id uuid NOT NULL, + item_id uuid NOT NULL, quantity integer NOT NULL, is_requested boolean DEFAULT true NOT NULL, requested_quantity integer, received_quantity integer, metadata jsonb, - reason_id character varying, + reason_id uuid, note character varying ); CREATE TABLE public.return_reasons ( - id uuid NOT NULL, + id uuid NOT NULL, value character varying NOT NULL, label character varying NOT NULL, description character varying, @@ -1193,12 +1194,12 @@ CREATE TABLE public.return_reasons updated_at timestamp with time zone DEFAULT now() NOT NULL, deleted_at timestamp with time zone, metadata jsonb, - parent_return_reason_id character varying + parent_return_reason_id uuid ); CREATE TABLE public.sales_channels ( - id uuid NOT NULL, + 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, @@ -1210,7 +1211,7 @@ CREATE TABLE public.sales_channels CREATE TABLE public.sales_channel_locations ( - id uuid NOT NULL, + id uuid NOT NULL, created_at timestamp with time zone DEFAULT now() NOT NULL, updated_at timestamp with time zone DEFAULT now() NOT NULL, sales_channel_id text NOT NULL, @@ -1220,15 +1221,15 @@ CREATE TABLE public.sales_channel_locations CREATE TABLE public.shipping_methods ( - id uuid NOT NULL, - shipping_option_id uuid NOT NULL, - order_id character varying, - cart_id character varying, - swap_id character varying, - return_id character varying, - price integer NOT NULL, - data jsonb NOT NULL, - claim_order_id character varying, + id uuid NOT NULL, + shipping_option_id uuid NOT NULL, + order_id uuid, + cart_id uuid, + swap_id uuid, + return_id uuid, + price integer NOT NULL, + data jsonb NOT NULL, + claim_order_id uuid, CONSTRAINT "CHK_64c6812fe7815be30d688df513" CHECK ((price >= 0)), CONSTRAINT "CHK_a7020b08665bbd64d84a6641cf" CHECK (((claim_order_id IS NOT NULL) OR (order_id IS NOT NULL) OR (cart_id IS NOT NULL) OR (swap_id IS NOT NULL) OR @@ -1237,23 +1238,23 @@ CREATE TABLE public.shipping_methods CREATE TABLE public.shipping_method_tax_lines ( - id uuid NOT NULL, + 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, - shipping_method_id uuid NOT NULL + shipping_method_id uuid NOT NULL ); CREATE TABLE public.shipping_options ( - id uuid NOT NULL, + id uuid NOT NULL, name character varying NOT NULL, - region_id uuid NOT NULL, - profile_id uuid NOT NULL, - provider_id uuid NOT NULL, + region_id uuid NOT NULL, + profile_id uuid NOT NULL, + provider_id uuid NOT NULL, price_type public.shipping_option_price_types NOT NULL, amount integer, is_return boolean DEFAULT false NOT NULL, @@ -1268,8 +1269,8 @@ CREATE TABLE public.shipping_options CREATE TABLE public.shipping_option_requirements ( - id uuid NOT NULL, - shipping_option_id uuid NOT NULL, + id uuid NOT NULL, + shipping_option_id uuid NOT NULL, type public.shipping_option_requirement_types NOT NULL, amount integer NOT NULL, deleted_at timestamp with time zone @@ -1277,7 +1278,7 @@ CREATE TABLE public.shipping_option_requirements CREATE TABLE public.shipping_profiles ( - id uuid NOT NULL, + id uuid NOT NULL, name character varying NOT NULL, type public.shipping_profile_types NOT NULL, created_at timestamp with time zone DEFAULT now() NOT NULL, @@ -1288,8 +1289,8 @@ CREATE TABLE public.shipping_profiles CREATE TABLE public.shipping_tax_rates ( - shipping_option_id uuid NOT NULL, - rate_id uuid NOT NULL, + shipping_option_id uuid NOT NULL, + rate_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 @@ -1297,7 +1298,7 @@ CREATE TABLE public.shipping_tax_rates CREATE TABLE public.staged_jobs ( - id uuid NOT NULL, + id uuid NOT NULL, event_name character varying NOT NULL, data jsonb NOT NULL, options jsonb DEFAULT '{}'::jsonb NOT NULL @@ -1305,7 +1306,7 @@ CREATE TABLE public.staged_jobs CREATE TABLE public.stores ( - id uuid NOT NULL, + id uuid NOT NULL, name character varying DEFAULT 'Bazaar'::character varying NOT NULL, default_currency_code character varying DEFAULT 'pln'::character varying NOT NULL, swap_link_template character varying, @@ -1314,25 +1315,25 @@ CREATE TABLE public.stores metadata jsonb, payment_link_template character varying, invite_link_template character varying, - default_sales_channel_id character varying, - default_location_id character varying + default_sales_channel_id uuid, + default_location_id uuid ); CREATE TABLE public.store_currencies ( - store_id uuid NOT NULL, + store_id uuid NOT NULL, currency_code character varying NOT NULL ); CREATE TABLE public.swaps ( - id uuid NOT NULL, + id uuid NOT NULL, fulfillment_status public.swap_fulfillment_statuses NOT NULL, payment_status public.swap_payment_statuses NOT NULL, - order_id uuid NOT NULL, + order_id uuid NOT NULL, difference_due integer, - shipping_address_id character varying, - cart_id character varying, + shipping_address_id uuid, + cart_id uuid, 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, @@ -1346,17 +1347,17 @@ CREATE TABLE public.swaps CREATE TABLE public.tax_providers ( - id uuid NOT NULL, + id uuid NOT NULL, is_installed boolean DEFAULT true NOT NULL ); CREATE TABLE public.tax_rates ( - id uuid NOT NULL, + id uuid NOT NULL, rate real, code character varying, name character varying NOT NULL, - region_id uuid NOT NULL, + region_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 @@ -1364,10 +1365,10 @@ CREATE TABLE public.tax_rates CREATE TABLE public.tracking_links ( - id uuid NOT NULL, + id uuid NOT NULL, url character varying, tracking_number character varying NOT NULL, - fulfillment_id uuid 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, @@ -1377,7 +1378,7 @@ CREATE TABLE public.tracking_links CREATE TABLE public.users ( - id uuid NOT NULL, + id uuid NOT NULL, email character varying NOT NULL, first_name character varying, last_name character varying,