mock shops more spelled out

This commit is contained in:
2026-01-22 15:14:44 -07:00
parent b182685ec3
commit 38aa3796b9
11 changed files with 1241 additions and 556 deletions
@@ -1,31 +1,99 @@
BEGIN;
-- mock ebay sync group listings
DROP TABLE mock.shop_ebay_sync_group_listings;
DROP TABLE mock.shop_ebay_listings;
-- mock walmart_marketplace sync group listings
DROP TABLE mock.shop_walmart_marketplace_sync_group_listings;
DROP TABLE mock.shop_walmart_marketplace_listings;
-- mock amazon sync group listings
DROP TABLE mock.shop_amazon_sync_group_listings;
DROP TABLE mock.shop_amazon_listings;
-- mock big_cartel sync group listings
DROP TABLE mock.shop_big_cartel_sync_group_listings;
DROP TABLE mock.shop_big_cartel_listings;
-- mock ecwid sync group listings
DROP TABLE mock.shop_ecwid_sync_group_listings;
DROP TABLE mock.shop_ecwid_listings;
-- mock zoho sync group listings
DROP TABLE mock.shop_zoho_sync_group_listings;
DROP TABLE mock.shop_zoho_listings;
-- mock square_online sync group listings
DROP TABLE mock.shop_square_online_sync_group_listings;
DROP TABLE mock.shop_square_online_listings;
-- mock squarespace sync group listings
DROP TABLE mock.shop_squarespace_sync_group_listings;
DROP TABLE mock.shop_squarespace_listings;
-- mock wix sync group listings
DROP TABLE mock.shop_wix_sync_group_listings;
DROP TABLE mock.shop_wix_listings;
-- mock woo_commerce sync group listings
DROP TABLE mock.shop_woo_commerce_sync_group_listings;
DROP TABLE mock.shop_woo_commerce_listings;
-- mock shopify sync group listings
DROP TABLE mock.shop_shopify_sync_group_listings;
DROP TABLE mock.shop_shopify_listings;
-- mock tiktok sync group listings
DROP TABLE mock.shop_tiktok_sync_group_listings;
DROP TABLE mock.shop_tiktok_listings;
-- mock sync group listings
DROP TABLE mock_sync_group_listings;
DROP TABLE mock_sync_groups;
DROP TABLE mock.sync_group_listing_order_indexes;
DROP TABLE mock.sync_groups;
-- mock stores
-- mock shops
DROP TABLE mock_store_ebay;
DROP TABLE mock_store_walmart_marketplace;
DROP TABLE mock_store_amazon;
DROP TABLE mock_store_big_cartel;
DROP TABLE mock_store_ecwid;
DROP TABLE mock_store_zoho;
DROP TABLE mock_store_square_online;
DROP TABLE mock_store_squarespace;
DROP TABLE mock_store_wix;
DROP TABLE mock_store_woo_commerce;
DROP TABLE mock_store_shopify;
DROP TABLE mock_store_tiktok;
DROP TABLE mock.shop_ebay;
DROP TABLE mock.shop_walmart_marketplace;
DROP TABLE mock.shop_amazon;
DROP TABLE mock.shop_big_cartel;
DROP TABLE mock.shop_ecwid;
DROP TABLE mock.shop_zoho;
DROP TABLE mock.shop_square_online;
DROP TABLE mock.shop_squarespace;
DROP TABLE mock.shop_wix;
DROP TABLE mock.shop_woo_commerce;
DROP TABLE mock.shop_shopify;
DROP TABLE mock.shop_tiktok;
-- mock accounts
DROP TABLE mock_accounts;
DROP TABLE mock.accounts;
-- new mock schema
DROP SCHEMA mock;
COMMIT;
+391 -58
View File
@@ -1,143 +1,476 @@
BEGIN;
-- new mock schema
CREATE SCHEMA mock;
-- mock accounts
CREATE TABLE mock_accounts (
CREATE TABLE mock.accounts (
account_id SERIAL PRIMARY KEY,
user_id TEXT NOT NULL REFERENCES oauth_users (user_id)
);
CREATE UNIQUE INDEX ON mock_accounts (user_id);
CREATE UNIQUE INDEX ON mock_accounts (account_id, user_id);
CREATE UNIQUE INDEX ON mock.accounts (user_id);
CREATE UNIQUE INDEX ON mock.accounts (account_id, user_id);
-- mock stores
-- mock shops
CREATE TABLE mock_store_tiktok (
CREATE TABLE mock.shop_tiktok (
user_id TEXT NOT NULL REFERENCES oauth_users (user_id),
account_id INTEGER NOT NULL REFERENCES mock_accounts (account_id),
store_id TEXT PRIMARY KEY,
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
name TEXT NOT NULL CHECK (char_length(name) > 0),
FOREIGN KEY (account_id, user_id) REFERENCES mock_accounts (account_id, user_id)
PRIMARY KEY (account_id, shop_id),
FOREIGN KEY (account_id, user_id) REFERENCES mock.accounts (account_id, user_id)
);
CREATE TABLE mock_store_shopify (
CREATE TABLE mock.shop_shopify (
user_id TEXT NOT NULL REFERENCES oauth_users (user_id),
account_id INTEGER NOT NULL REFERENCES mock_accounts (account_id),
store_id TEXT PRIMARY KEY,
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
name TEXT NOT NULL CHECK (char_length(name) > 0),
FOREIGN KEY (account_id, user_id) REFERENCES mock_accounts (account_id, user_id)
PRIMARY KEY (account_id, shop_id),
FOREIGN KEY (account_id, user_id) REFERENCES mock.accounts (account_id, user_id)
);
CREATE TABLE mock_store_woo_commerce (
CREATE TABLE mock.shop_woo_commerce (
user_id TEXT NOT NULL REFERENCES oauth_users (user_id),
account_id INTEGER NOT NULL REFERENCES mock_accounts (account_id),
store_id TEXT PRIMARY KEY,
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
name TEXT NOT NULL CHECK (char_length(name) > 0),
FOREIGN KEY (account_id, user_id) REFERENCES mock_accounts (account_id, user_id)
PRIMARY KEY (account_id, shop_id),
FOREIGN KEY (account_id, user_id) REFERENCES mock.accounts (account_id, user_id)
);
CREATE TABLE mock_store_wix (
CREATE TABLE mock.shop_wix (
user_id TEXT NOT NULL REFERENCES oauth_users (user_id),
account_id INTEGER NOT NULL REFERENCES mock_accounts (account_id),
store_id TEXT PRIMARY KEY,
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
name TEXT NOT NULL CHECK (char_length(name) > 0),
FOREIGN KEY (account_id, user_id) REFERENCES mock_accounts (account_id, user_id)
PRIMARY KEY (account_id, shop_id),
FOREIGN KEY (account_id, user_id) REFERENCES mock.accounts (account_id, user_id)
);
CREATE TABLE mock_store_squarespace (
CREATE TABLE mock.shop_squarespace (
user_id TEXT NOT NULL REFERENCES oauth_users (user_id),
account_id INTEGER NOT NULL REFERENCES mock_accounts (account_id),
store_id TEXT PRIMARY KEY,
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
name TEXT NOT NULL CHECK (char_length(name) > 0),
FOREIGN KEY (account_id, user_id) REFERENCES mock_accounts (account_id, user_id)
PRIMARY KEY (account_id, shop_id),
FOREIGN KEY (account_id, user_id) REFERENCES mock.accounts (account_id, user_id)
);
CREATE TABLE mock_store_square_online (
CREATE TABLE mock.shop_square_online (
user_id TEXT NOT NULL REFERENCES oauth_users (user_id),
account_id INTEGER NOT NULL REFERENCES mock_accounts (account_id),
store_id TEXT PRIMARY KEY,
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
name TEXT NOT NULL CHECK (char_length(name) > 0),
FOREIGN KEY (account_id, user_id) REFERENCES mock_accounts (account_id, user_id)
PRIMARY KEY (account_id, shop_id),
FOREIGN KEY (account_id, user_id) REFERENCES mock.accounts (account_id, user_id)
);
CREATE TABLE mock_store_zoho (
CREATE TABLE mock.shop_zoho (
user_id TEXT NOT NULL REFERENCES oauth_users (user_id),
account_id INTEGER NOT NULL REFERENCES mock_accounts (account_id),
store_id TEXT PRIMARY KEY,
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
name TEXT NOT NULL CHECK (char_length(name) > 0),
FOREIGN KEY (account_id, user_id) REFERENCES mock_accounts (account_id, user_id)
PRIMARY KEY (account_id, shop_id),
FOREIGN KEY (account_id, user_id) REFERENCES mock.accounts (account_id, user_id)
);
CREATE TABLE mock_store_ecwid (
CREATE TABLE mock.shop_ecwid (
user_id TEXT NOT NULL REFERENCES oauth_users (user_id),
account_id INTEGER NOT NULL REFERENCES mock_accounts (account_id),
store_id TEXT PRIMARY KEY,
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
name TEXT NOT NULL CHECK (char_length(name) > 0),
FOREIGN KEY (account_id, user_id) REFERENCES mock_accounts (account_id, user_id)
PRIMARY KEY (account_id, shop_id),
FOREIGN KEY (account_id, user_id) REFERENCES mock.accounts (account_id, user_id)
);
CREATE TABLE mock_store_big_cartel (
CREATE TABLE mock.shop_big_cartel (
user_id TEXT NOT NULL REFERENCES oauth_users (user_id),
account_id INTEGER NOT NULL REFERENCES mock_accounts (account_id),
store_id TEXT PRIMARY KEY,
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
name TEXT NOT NULL CHECK (char_length(name) > 0),
FOREIGN KEY (account_id, user_id) REFERENCES mock_accounts (account_id, user_id)
PRIMARY KEY (account_id, shop_id),
FOREIGN KEY (account_id, user_id) REFERENCES mock.accounts (account_id, user_id)
);
CREATE TABLE mock_store_amazon (
CREATE TABLE mock.shop_amazon (
user_id TEXT NOT NULL REFERENCES oauth_users (user_id),
account_id INTEGER NOT NULL REFERENCES mock_accounts (account_id),
store_id TEXT PRIMARY KEY,
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
name TEXT NOT NULL CHECK (char_length(name) > 0),
FOREIGN KEY (account_id, user_id) REFERENCES mock_accounts (account_id, user_id)
PRIMARY KEY (account_id, shop_id),
FOREIGN KEY (account_id, user_id) REFERENCES mock.accounts (account_id, user_id)
);
CREATE TABLE mock_store_walmart_marketplace (
CREATE TABLE mock.shop_walmart_marketplace (
user_id TEXT NOT NULL REFERENCES oauth_users (user_id),
account_id INTEGER NOT NULL REFERENCES mock_accounts (account_id),
store_id TEXT PRIMARY KEY,
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
name TEXT NOT NULL CHECK (char_length(name) > 0),
FOREIGN KEY (account_id, user_id) REFERENCES mock_accounts (account_id, user_id)
PRIMARY KEY (account_id, shop_id),
FOREIGN KEY (account_id, user_id) REFERENCES mock.accounts (account_id, user_id)
);
CREATE TABLE mock_store_ebay (
CREATE TABLE mock.shop_ebay (
user_id TEXT NOT NULL REFERENCES oauth_users (user_id),
account_id INTEGER NOT NULL REFERENCES mock_accounts (account_id),
store_id TEXT PRIMARY KEY,
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
name TEXT NOT NULL CHECK (char_length(name) > 0),
FOREIGN KEY (account_id, user_id) REFERENCES mock_accounts (account_id, user_id)
PRIMARY KEY (account_id, shop_id),
FOREIGN KEY (account_id, user_id) REFERENCES mock.accounts (account_id, user_id)
);
-- mock sync group listings
CREATE TABLE mock_sync_groups (
CREATE TABLE mock.sync_groups (
sync_group_id SERIAL PRIMARY KEY,
account_id INTEGER NOT NULL REFERENCES mock_accounts (account_id)
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
name TEXT NOT NULL CHECK (char_length(name) > 0)
);
CREATE TABLE mock_sync_group_listings (
sync_group_id INTEGER NOT NULL REFERENCES mock_sync_groups (sync_group_id),
CREATE TABLE mock.sync_group_listing_order_indexes (
sync_group_id INTEGER NOT NULL REFERENCES mock.sync_groups (sync_group_id),
order_index INTEGER NOT NULL,
platform platform NOT NULL,
UNIQUE (sync_group_id, order_index)
);
-- mock tiktok sync group listings
CREATE TABLE mock.shop_tiktok_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (sync_group_id, order_index)
PRIMARY KEY (shop_id, listing_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_tiktok (account_id, shop_id)
);
CREATE TABLE mock.shop_tiktok_sync_group_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
sync_group_id INTEGER NOT NULL REFERENCES mock.sync_groups (sync_group_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
order_index INTEGER NOT NULL,
-- allow each shop to have at most ONE listing per sync group
UNIQUE (sync_group_id, shop_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_tiktok (account_id, shop_id),
FOREIGN KEY (sync_group_id, order_index) REFERENCES mock.sync_group_listing_order_indexes (sync_group_id, order_index),
FOREIGN KEY (shop_id, listing_id) REFERENCES mock.shop_tiktok_listings (shop_id, listing_id)
);
-- mock shopify sync group listings
CREATE TABLE mock.shop_shopify_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (shop_id, listing_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_shopify (account_id, shop_id)
);
CREATE TABLE mock.shop_shopify_sync_group_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
sync_group_id INTEGER NOT NULL REFERENCES mock.sync_groups (sync_group_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
order_index INTEGER NOT NULL,
-- allow each shop to have at most ONE listing per sync group
UNIQUE (sync_group_id, shop_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_shopify (account_id, shop_id),
FOREIGN KEY (sync_group_id, order_index) REFERENCES mock.sync_group_listing_order_indexes (sync_group_id, order_index),
FOREIGN KEY (shop_id, listing_id) REFERENCES mock.shop_shopify_listings (shop_id, listing_id)
);
-- mock woo_commerce sync group listings
CREATE TABLE mock.shop_woo_commerce_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (shop_id, listing_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_woo_commerce (account_id, shop_id)
);
CREATE TABLE mock.shop_woo_commerce_sync_group_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
sync_group_id INTEGER NOT NULL REFERENCES mock.sync_groups (sync_group_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
order_index INTEGER NOT NULL,
-- allow each shop to have at most ONE listing per sync group
UNIQUE (sync_group_id, shop_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_woo_commerce (account_id, shop_id),
FOREIGN KEY (sync_group_id, order_index) REFERENCES mock.sync_group_listing_order_indexes (sync_group_id, order_index),
FOREIGN KEY (shop_id, listing_id) REFERENCES mock.shop_woo_commerce_listings (shop_id, listing_id)
);
-- mock wix sync group listings
CREATE TABLE mock.shop_wix_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (shop_id, listing_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_wix (account_id, shop_id)
);
CREATE TABLE mock.shop_wix_sync_group_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
sync_group_id INTEGER NOT NULL REFERENCES mock.sync_groups (sync_group_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
order_index INTEGER NOT NULL,
-- allow each shop to have at most ONE listing per sync group
UNIQUE (sync_group_id, shop_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_wix (account_id, shop_id),
FOREIGN KEY (sync_group_id, order_index) REFERENCES mock.sync_group_listing_order_indexes (sync_group_id, order_index),
FOREIGN KEY (shop_id, listing_id) REFERENCES mock.shop_wix_listings (shop_id, listing_id)
);
-- mock squarespace sync group listings
CREATE TABLE mock.shop_squarespace_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (shop_id, listing_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_squarespace (account_id, shop_id)
);
CREATE TABLE mock.shop_squarespace_sync_group_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
sync_group_id INTEGER NOT NULL REFERENCES mock.sync_groups (sync_group_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
order_index INTEGER NOT NULL,
-- allow each shop to have at most ONE listing per sync group
UNIQUE (sync_group_id, shop_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_squarespace (account_id, shop_id),
FOREIGN KEY (sync_group_id, order_index) REFERENCES mock.sync_group_listing_order_indexes (sync_group_id, order_index),
FOREIGN KEY (shop_id, listing_id) REFERENCES mock.shop_squarespace_listings (shop_id, listing_id)
);
-- mock square_online sync group listings
CREATE TABLE mock.shop_square_online_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (shop_id, listing_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_square_online (account_id, shop_id)
);
CREATE TABLE mock.shop_square_online_sync_group_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
sync_group_id INTEGER NOT NULL REFERENCES mock.sync_groups (sync_group_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
order_index INTEGER NOT NULL,
-- allow each shop to have at most ONE listing per sync group
UNIQUE (sync_group_id, shop_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_square_online (account_id, shop_id),
FOREIGN KEY (sync_group_id, order_index) REFERENCES mock.sync_group_listing_order_indexes (sync_group_id, order_index),
FOREIGN KEY (shop_id, listing_id) REFERENCES mock.shop_square_online_listings (shop_id, listing_id)
);
-- mock zoho sync group listings
CREATE TABLE mock.shop_zoho_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (shop_id, listing_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_zoho (account_id, shop_id)
);
CREATE TABLE mock.shop_zoho_sync_group_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
sync_group_id INTEGER NOT NULL REFERENCES mock.sync_groups (sync_group_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
order_index INTEGER NOT NULL,
-- allow each shop to have at most ONE listing per sync group
UNIQUE (sync_group_id, shop_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_zoho (account_id, shop_id),
FOREIGN KEY (sync_group_id, order_index) REFERENCES mock.sync_group_listing_order_indexes (sync_group_id, order_index),
FOREIGN KEY (shop_id, listing_id) REFERENCES mock.shop_zoho_listings (shop_id, listing_id)
);
-- mock ecwid sync group listings
CREATE TABLE mock.shop_ecwid_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (shop_id, listing_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_ecwid (account_id, shop_id)
);
CREATE TABLE mock.shop_ecwid_sync_group_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
sync_group_id INTEGER NOT NULL REFERENCES mock.sync_groups (sync_group_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
order_index INTEGER NOT NULL,
-- allow each shop to have at most ONE listing per sync group
UNIQUE (sync_group_id, shop_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_ecwid (account_id, shop_id),
FOREIGN KEY (sync_group_id, order_index) REFERENCES mock.sync_group_listing_order_indexes (sync_group_id, order_index),
FOREIGN KEY (shop_id, listing_id) REFERENCES mock.shop_ecwid_listings (shop_id, listing_id)
);
-- mock big_cartel sync group listings
CREATE TABLE mock.shop_big_cartel_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (shop_id, listing_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_big_cartel (account_id, shop_id)
);
CREATE TABLE mock.shop_big_cartel_sync_group_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
sync_group_id INTEGER NOT NULL REFERENCES mock.sync_groups (sync_group_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
order_index INTEGER NOT NULL,
-- allow each shop to have at most ONE listing per sync group
UNIQUE (sync_group_id, shop_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_big_cartel (account_id, shop_id),
FOREIGN KEY (sync_group_id, order_index) REFERENCES mock.sync_group_listing_order_indexes (sync_group_id, order_index),
FOREIGN KEY (shop_id, listing_id) REFERENCES mock.shop_big_cartel_listings (shop_id, listing_id)
);
-- mock amazon sync group listings
CREATE TABLE mock.shop_amazon_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (shop_id, listing_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_amazon (account_id, shop_id)
);
CREATE TABLE mock.shop_amazon_sync_group_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
sync_group_id INTEGER NOT NULL REFERENCES mock.sync_groups (sync_group_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
order_index INTEGER NOT NULL,
-- allow each shop to have at most ONE listing per sync group
UNIQUE (sync_group_id, shop_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_amazon (account_id, shop_id),
FOREIGN KEY (sync_group_id, order_index) REFERENCES mock.sync_group_listing_order_indexes (sync_group_id, order_index),
FOREIGN KEY (shop_id, listing_id) REFERENCES mock.shop_amazon_listings (shop_id, listing_id)
);
-- mock walmart_marketplace sync group listings
CREATE TABLE mock.shop_walmart_marketplace_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (shop_id, listing_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_walmart_marketplace (account_id, shop_id)
);
CREATE TABLE mock.shop_walmart_marketplace_sync_group_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
sync_group_id INTEGER NOT NULL REFERENCES mock.sync_groups (sync_group_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
order_index INTEGER NOT NULL,
-- allow each shop to have at most ONE listing per sync group
UNIQUE (sync_group_id, shop_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_walmart_marketplace (account_id, shop_id),
FOREIGN KEY (sync_group_id, order_index) REFERENCES mock.sync_group_listing_order_indexes (sync_group_id, order_index),
FOREIGN KEY (shop_id, listing_id) REFERENCES mock.shop_walmart_marketplace_listings (shop_id, listing_id)
);
-- mock ebay sync group listings
CREATE TABLE mock.shop_ebay_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (shop_id, listing_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_ebay (account_id, shop_id)
);
CREATE TABLE mock.shop_ebay_sync_group_listings (
account_id INTEGER NOT NULL REFERENCES mock.accounts (account_id),
sync_group_id INTEGER NOT NULL REFERENCES mock.sync_groups (sync_group_id),
shop_id TEXT NOT NULL,
listing_id TEXT NOT NULL,
order_index INTEGER NOT NULL,
-- allow each shop to have at most ONE listing per sync group
UNIQUE (sync_group_id, shop_id),
FOREIGN KEY (account_id, shop_id) REFERENCES mock.shop_ebay (account_id, shop_id),
FOREIGN KEY (sync_group_id, order_index) REFERENCES mock.sync_group_listing_order_indexes (sync_group_id, order_index),
FOREIGN KEY (shop_id, listing_id) REFERENCES mock.shop_ebay_listings (shop_id, listing_id)
);
GRANT ALL ON SCHEMA mock TO PUBLIC;
COMMIT;