setup new database schema

This commit is contained in:
Jadowyne Ulve 2025-08-23 15:18:42 -05:00
parent a57b8a2044
commit 0265dd68fc
23 changed files with 358 additions and 223 deletions

View File

@ -1,7 +1,8 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_barcodes ( CREATE TABLE IF NOT EXISTS %%site_name%%_barcodes (
barcode VARCHAR(32) PRIMARY KEY, item_uuid UUID PRIMARY KEY REFERENCES %%site_name%%_items(item_uuid) ON DELETE CASCADE,
item_uuid UUID, barcode VARCHAR(32) NOT NULL,
in_exchange FLOAT, in_exchange FLOAT DEFAULT 0.00 NOT NULL,
out_exchange FLOAT, out_exchange FLOAT DEFAULT 0.00 NOT NULL,
descriptor VARCHAR(255) descriptor VARCHAR(255) DEFAULT '' NOT NULL,
UNIQUE(barcode)
); );

View File

@ -1,4 +1,5 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_brands ( CREATE TABLE IF NOT EXISTS %%site_name%%_brands (
id SERIAL PRIMARY KEY, brand_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name VARCHAR(255) brand_name VARCHAR(255) NOT NULL,
UNIQUE(brand_name)
); );

View File

@ -1,7 +1,7 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_conversions ( CREATE TABLE IF NOT EXISTS %%site_name%%_conversions (
id SERIAL PRIMARY KEY, conversion_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
item_id INTEGER NOT NULL, item_uuid uuid REFERENCES %%site_name%%_items(item_uuid) ON DELETE CASCADE NOT NULL,
uom_id INTEGER NOT NULL, conversion_uom_id INTEGER DEFAULT 1 NOT NULL,
conv_factor FLOAT8 NOT NULL, conversion_conv_factor FLOAT8 DEFAULT 0.00 NOT NULL,
UNIQUE(item_id, uom_id) UNIQUE(item_uuid, conversion_uom_id)
); );

View File

@ -1,9 +1,9 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_cost_layers ( CREATE TABLE IF NOT EXISTS %%site_name%%_cost_layers (
id SERIAL PRIMARY KEY, item_location_uuid UUID REFERENCES %%site_name%%_item_locations(item_location_uuid) ON DELETE SET NULL,
aquisition_date TIMESTAMP NOT NULL, layer_aquisition_date TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
quantity FLOAT8 NOT NULL, layer_quantity FLOAT8 DEFAULT 0.00 NOT NULL,
cost FLOAT8 NOT NULL, layer_cost FLOAT8 DEFAULT 0.00 NOT NULL,
currency_type VARCHAR(16) NOT NULL, layer_currency_type VARCHAR(16) DEFAULT 'USD' NOT NULL,
expires TIMESTAMP, layer_expires TIMESTAMP DEFAULT NULL,
vendor INTEGER DEFAULT 0 layer_vendor INTEGER DEFAULT 0 NOT NULL
); );

View File

@ -1,10 +1,8 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_food_info ( CREATE TABLE IF NOT EXISTS %%site_name%%_food_info (
id SERIAL PRIMARY KEY, item_uuid UUID PRIMARY KEY REFERENCES %%site_name%%_items(item_uuid) ON DELETE CASCADE,
food_info_uuid UUID DEFAULT uuid_generate_v4(), item_food_groups TEXT [] DEFAULT '{}' NOT NULL,
food_groups TEXT [], item_ingredients TEXT [] DEFAULT '{}' NOT NULL,
ingrediants TEXT [], item_nutrients JSONB DEFAULT '{}' NOT NULL,
nutrients JSONB, item_expires BOOLEAN DEFAULT false NOT NULL,
expires BOOLEAN, item_default_expiration FLOAT8 DEFAULT 0.00 NOT NULL
default_expiration FLOAT8,
UNIQUE(food_info_uuid)
); );

View File

@ -1,14 +1,11 @@
CREATE TABLE IF NOt EXISTS %%site_name%%_item_info ( CREATE TABLE IF NOT EXISTS %%site_name%%_item_info (
id SERIAL PRIMARY KEY, item_uuid UUID PRIMARY KEY REFERENCES %%site_name%%_items(item_uuid) ON DELETE CASCADE,
item_info_uuid UUID DEFAULT uuid_generate_v4(), item_uom INTEGER NOT NULL,
barcode VARCHAR(255), item_packaging VARCHAR(255) DEFAULT '' NOT NULL,
packaging VARCHAR(255), item_uom_quantity FLOAT8 DEFAULT 0.00 NOT NULL,
uom_quantity FLOAT8, item_cost FLOAT8 DEFAULT 0.00 NOT NULL,
uom INTEGER, item_safety_stock FLOAT8 DEFAULT 0.00 NOT NULL,
cost FLOAT8, item_lead_time_days FLOAT8 DEFAULT 0.00 NOT NULL,
safety_stock FLOAT8, item_ai_pick BOOLEAN DEFAULT false NOT NULL,
lead_time_days FLOAT8, item_prefixes INTEGER [] DEFAULT '{}' NOT NULL
ai_pick BOOLEAN,
prefixes INTEGER [],
UNIQUE(item_info_uuid)
); );

View File

@ -1,16 +1,7 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_item_locations( CREATE TABLE IF NOT EXISTS %%site_name%%_item_locations(
id SERIAL PRIMARY KEY, item_location_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
part_id INTEGER NOT NULL, item_uuid UUID REFERENCES %%site_name%%_items(item_uuid) ON DELETE SET NULL,
location_id INTEGER NOT NULL, location_uuid UUID REFERENCES %%site_name%%_locations(location_uuid) ON DELETE SET NULL,
quantity_on_hand FLOAT8 NOT NULL, item_quantity_on_hand FLOAT8 DEFAULT 0.00 NOT NULL,
cost_layers INTEGER[] DEFAULT '{}', UNIQUE(item_uuid, location_uuid)
UNIQUE(part_id, location_id),
CONSTRAINT fk_part_id
FOREIGN KEY(part_id)
REFERENCES %%site_name%%_items(id)
ON DELETE CASCADE,
CONSTRAINT fk_location_id
FOREIGN KEY(location_id)
REFERENCES %%site_name%%_locations(id)
ON DELETE CASCADE
); );

View File

@ -1,36 +1,17 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_items( CREATE TABLE IF NOT EXISTS %%site_name%%_items(
id SERIAL PRIMARY KEY, item_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
item_uuid UUID DEFAULT uuid_generate_v4(), item_created_at TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
barcode VARCHAR(255), item_updated_at TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
item_name VARCHAR(255) NOT NULL, item_name VARCHAR(255) NOT NULL,
brand INTEGER, item_description TEXT DEFAULT '' NOT NULL,
description TEXT, item_tags TEXT [] DEFAULT '{}' NOT NULL,
tags TEXT [], item_links JSONB DEFAULT '{}' NOT NULL,
links JSONB, item_brand_uuid UUID DEFAULT NULL,
item_info_id INTEGER NOT NULL, item_category VARCHAR(255) NOT NULL,
item_info_uuid UUID NOT NULL, item_search_string TEXT DEFAULT '' NOT NULL,
logistics_info_id INTEGER NOT NULL, item_inactive BOOLEAN DEFAULT false NOT NULL,
logistics_info_uuid UUID NOT NULL,
food_info_id INTEGER,
food_info_uuid UUID NOT NULL,
row_type VARCHAR(255) NOT NULL,
item_type VARCHAR(255) NOT NULL,
search_string TEXT NOT NULL,
inactive BOOLEAN DEFAULT false NOT NULL,
UNIQUE(item_uuid),
CONSTRAINT fk_item_info
FOREIGN KEY(item_info_id)
REFERENCES %%site_name%%_item_info(id)
ON DELETE CASCADE,
CONSTRAINT fk_food_info
FOREIGN KEY(food_info_id)
REFERENCES %%site_name%%_food_info(id)
ON DELETE CASCADE,
CONSTRAINT fk_brand CONSTRAINT fk_brand
FOREIGN KEY(brand) FOREIGN KEY(item_brand_uuid)
REFERENCES %%site_name%%_brands(id), REFERENCES %%site_name%%_brands(brand_uuid)
CONSTRAINT fk_logistics_info ON DELETE SET NULL
FOREIGN KEY(logistics_info_id)
REFERENCES %%site_name%%_logistics_info(id)
ON DELETE CASCADE
); );

View File

@ -1,10 +1,6 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_locations( CREATE TABLE IF NOT EXISTS %%site_name%%_locations(
id SERIAL PRIMARY KEY, location_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
uuid VARCHAR(255) NOT NULL, location_shortname VARCHAR(255) NOT NULL,
name VARCHAR(32) NOT NULL, location_name VARCHAR(32) NOT NULL,
zone_id INTEGER NOT NULL, zone_uuid UUID REFERENCES %%site_name%%_zones(zone_uuid) ON DELETE SET NULL
UNIQUE(uuid),
CONSTRAINT fk_zone
FOREIGN KEY(zone_id)
REFERENCES %%site_name%%_zones(id)
); );

View File

@ -1,22 +1,7 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_logistics_info( CREATE TABLE IF NOT EXISTS %%site_name%%_logistics_info(
id SERIAL PRIMARY KEY, item_uuid UUID PRIMARY KEY REFERENCES %%site_name%%_items(item_uuid) ON DELETE CASCADE,
logistics_info_uuid UUID DEFAULT uuid_generate_v4(), item_primary_location UUID REFERENCES %%site_name%%_locations(location_uuid) ON DELETE SET NULL,
barcode VARCHAR(255), item_primary_zone UUID REFERENCES %%site_name%%_zones(zone_uuid) ON DELETE SET NULL,
primary_location INTEGER NOT NULL, item_auto_issue_location UUID REFERENCES %%site_name%%_locations(location_uuid) ON DELETE SET NULL,
primary_zone INTEGER NOT NULL, item_auto_issue_zone UUID REFERENCES %%site_name%%_zones(zone_uuid) ON DELETE SET NULL
auto_issue_location INTEGER NOT NULL,
auto_issue_zone INTEGER NOT NULL,
UNIQUE(logistics_info_uuid),
CONSTRAINT fk_primary_location
FOREIGN KEY(primary_location)
REFERENCES %%site_name%%_locations(id),
CONSTRAINT fk_primary_zone
FOREIGN KEY(primary_zone)
REFERENCES %%site_name%%_zones(id),
CONSTRAINT fk_auto_issue_location
FOREIGN KEY(auto_issue_location)
REFERENCES %%site_name%%_locations(id),
CONSTRAINT fk_auto_issue_zone
FOREIGN KEY(auto_issue_zone)
REFERENCES %%site_name%%_zones(id)
); );

View File

@ -1,14 +1,12 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_plan_events( CREATE TABLE IF NOT EXISTS %%site_name%%_plan_events(
id SERIAL PRIMARY KEY, event_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL,
event_uuid UUID DEFAULT gen_random_uuid(), event_plan_uuid UUID REFERENCES %%site_name%%_plans(plan_uuid) ON DELETE CASCADE NOT NULL,
plan_uuid UUID, event_recipe_uuid UUID DEFAULT NULL,
recipe_uuid UUID, event_receipt_uuid UUID DEFAULT NULL,
receipt_uuid UUID DEFAULT NULL,
event_shortname VARCHAR(32) NOT NULL, event_shortname VARCHAR(32) NOT NULL,
event_description TEXT, event_description TEXT DEFAULT '' NOT NULL,
event_date_start TIMESTAMP NOT NULL, event_date_start TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
event_date_end TIMESTAMP NOT NULL, event_date_end TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
created_by INTEGER NOT NULL, event_created_by INTEGER DEFAULT 1 NOT NULL,
event_type VARCHAR(32) NOT NULL, event_type VARCHAR(32) DEFAULT '' NOT NULL
UNIQUE(event_uuid)
) )

View File

@ -1,6 +1,7 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_plans( CREATE TABLE IF NOT EXISTS %%site_name%%_plans(
plan_uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(), plan_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
plan_shortname VARCHAR(32) NOT NULL, plan_shortname VARCHAR(32) NOT NULL,
plan_description TEXT, plan_description TEXT DEFAULT '' NOT NULL,
created_by INTEGER NOT NULL plan_created_by INTEGER DEFAULT 1 NOT NULL,
plan_created_on TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL
) )

View File

@ -1,16 +1,11 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_receipt_items ( CREATE TABLE IF NOT EXISTS %%site_name%%_receipt_items (
id SERIAL PRIMARY KEY, receipt_item_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL,
type VARCHAR(255) NOT NULL, receipt_uuid UUID REFERENCES %%site_name%%_receipts(receipt_uuid) ON DELETE CASCADE NOT NULL,
receipt_id INTEGER NOT NULL, receipt_item_type VARCHAR(255) DEFAULT 'unknown' NOT NULL,
barcode VARCHAR(255), receipt_item_barcode VARCHAR(255) DEFAULT NULL,
item_uuid UUID, receipt_item_name VARCHAR(255) DEFAULT '' NOT NULL,
name VARCHAR(255) NOT NULL, receipt_item_quantity FLOAT8 DEFAULT 0.00 NOT NULL,
qty FLOAT8 NOT NULL, receipt_item_uom INTEGER DEFAULT 1 NOT NULL,
uom INTEGER NOT NULL, receipt_item_data JSONB DEFAULT '{}' NOT NULL,
data JSONB, receipt_item_status VARCHAR (64) DEFAULT 'unknown' NOT NULL
status VARCHAR (64),
CONSTRAINT fk_receipt
FOREIGN KEY(receipt_id)
REFERENCES %%site_name%%_receipts(id)
ON DELETE CASCADE
); );

View File

@ -1,13 +1,10 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_receipts ( CREATE TABLE IF NOT EXISTS %%site_name%%_receipts (
id SERIAL PRIMARY KEY, receipt_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL,
receipt_id VARCHAR (32) NOT NULL, receipt_id VARCHAR (32) NOT NULL,
receipt_status VARCHAR (64) NOT NULL, receipt_status VARCHAR (64) DEFAULT 'Unresolved' NOT NULL,
date_submitted TIMESTAMP NOT NULL, receipt_created_on TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
submitted_by INTEGER NOT NULL, receipt_created_by INTEGER DEFAULT 1 NOT NULL,
vendor_id INTEGER, receipt_vendor_uuid UUID REFERENCES %%site_name%%_vendors(vendor_uuid) ON DELETE RESTRICT,
files JSONB, receipt_files JSONB DEFAULT '{}' NOT NULL,
UNIQUE(receipt_id), UNIQUE(receipt_id)
CONSTRAINT fk_vendor
FOREIGN KEY(vendor_id)
REFERENCES %%site_name%%_vendors(id)
); );

View File

@ -1,19 +1,10 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_recipe_items ( CREATE TABLE IF NOT EXISTS %%site_name%%_recipe_items (
id SERIAL PRIMARY KEY, recipe_item_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
recipe_uuid UUID REFERENCES %%site_name%%_recipes(recipe_uuid) ON DELETE CASCADE NOT NULL,
item_uuid UUID, item_uuid UUID,
rp_id INTEGER NOT NULL, recipe_item_type VARCHAR(32) DEFAULT 'custom' NOT NULL,
item_type VARCHAR(32) NOT NULL, recipe_item_name TEXT DEFAULT '' NOT NULL,
item_name TEXT NOT NULL, recipe_item_uom INTEGER DEFAULT 1 NOT NULL,
uom INTEGER NOT NULL, recipe_item_quantity FLOAT8 DEFAULT 0.00 NOT NULL,
qty FLOAT8 NOT NULL, links JSONB DEFAULT '{"main": ""}' NOT NULL
item_id INTEGER DEFAULT NULL,
links JSONB DEFAULT '{"main": ""}',
CONSTRAINT fk_rp_id
FOREIGN KEY(rp_id)
REFERENCES %%site_name%%_recipes(id)
ON DELETE CASCADE,
CONSTRAINT fk_item_id
FOREIGN KEY(item_id)
REFERENCES %%site_name%%_items(id)
ON DELETE CASCADE
); );

View File

@ -1,11 +1,10 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_recipes ( CREATE TABLE IF NOT EXISTS %%site_name%%_recipes (
id SERIAL PRIMARY KEY, recipe_uuid UUID PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
recipe_uuid UUID DEFAULT gen_random_uuid() NOT NULL, recipe_name VARCHAR(255) DEFAULT '' NOT NULL,
name VARCHAR, recipe_created_by INTEGER DEFAULT 1 NOT NULL,
author INTEGER, recipe_description TEXT DEFAULT '' NOT NULL,
description TEXT, recipe_creation_date TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
creation_date TIMESTAMP, recipe_instructions TEXT [] DEFAULT '{}' NOT NULL,
instructions TEXT [], recipe_picture_path TEXT DEFAULT '' NOT NULL,
picture_path TEXT, UNIQUE(recipe_name)
UNIQUE(recipe_uuid)
); );

View File

@ -1,12 +1,12 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_shopping_list_items ( CREATE TABLE IF NOT EXISTS %%site_name%%_shopping_list_items (
list_item_uuid UUID DEFAULT uuid_generate_v4() NOT NULL PRIMARY KEY, list_item_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
list_uuid UUID NOT NULL, list_uuid UUID REFERENCES %%site_name%%_shopping_lists(list_uuid) ON DELETE CASCADE NOT NULL,
item_type VARCHAR(32) NOT NULL, list_item_type VARCHAR(32) NOT NULL,
item_name TEXT NOT NULL, list_item_name VARCHAR(64) DEFAULT '' NOT NULL,
uom INTEGER NOT NULL, list_item_uom INTEGER DEFAULT 1 NOT NULL,
qty FLOAT8 NOT NULL, list_item_quantity FLOAT8 DEFAULT 0.00 NOT NULL,
item_uuid UUID DEFAULT NULL, item_uuid UUID DEFAULT NULL,
links JSONB DEFAULT '{"main": ""}', list_links JSONB DEFAULT '{"main": ""}',
list_item_state BOOLEAN DEFAULT false, list_item_state BOOLEAN DEFAULT false,
UNIQUE(list_uuid, item_uuid) UNIQUE(list_uuid, item_uuid)
); );

View File

@ -1,11 +1,9 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_shopping_lists ( CREATE TABLE IF NOT EXISTS %%site_name%%_shopping_lists (
id SERIAL PRIMARY KEY, list_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
list_uuid UUID DEFAULT uuid_generate_v4() NOT NULL, list_type VARCHAR(32) NOT NULL,
list_type VARCHAR(32), list_name VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL, list_description TEXT DEFAULT '' NOT NULL,
description TEXT, list_created_by INTEGER DEFAULT 1 NOT NULL,
author INTEGER, list_created_on TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
creation_date TIMESTAMP, UNIQUE(list_name)
sub_type VARCHAR(64),
UNIQUE(list_uuid, name)
); );

View File

@ -1,7 +1,7 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_sku_prefix( CREATE TABLE IF NOT EXISTS %%site_name%%_sku_prefix(
id SERIAL PRIMARY KEY, sku_prefix_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
uuid VARCHAR(16) NOT NULL, sku_prefix_identifier VARCHAR (32) NOT NULL,
name VARCHAR(255) NOT NULL, sku_prefix_name VARCHAR(255) DEFAULT '' NOT NULL,
description TEXT, sku_prefix_description TEXT DEFAULT '' NOT NULL,
UNIQUE (name, uuid) UNIQUE (sku_prefix_identifier, sku_prefix_name)
); );

View File

@ -1,16 +1,11 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_Transactions ( CREATE TABLE IF NOT EXISTS %%site_name%%_transactions (
id SERIAL PRIMARY KEY, item_uuid UUID PRIMARY KEY REFERENCES %%site_name%%_items(item_uuid) ON DELETE CASCADE,
timestamp TIMESTAMP, transaction_created_at TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
logistics_info_id INTEGER NOT NULL, transaction_name VARCHAR(255) DEFAULT NULL,
barcode VARCHAR(255), transaction_type VARCHAR(64) DEFAULT '' NOT NULL,
name VARCHAR(255), transaction_quantity FLOAT8 DEFAULT 0.00 NOT NULL,
transaction_type VARCHAR(255) NOT NULL, transaction_description TEXT DEFAULT '' NOT NULL,
quantity FLOAT8 NOT NULL, transaction_cost FLOAT8 DEFAULT 0.00 NOT NULL,
description TEXT, transaction_created_by INTEGER NOT NULL,
user_id INTEGER NOT NULL, transaction_data JSONB DEFAULT '{}' NOT NULL
data JSONB,
CONSTRAINT fk_logistics_info
FOREIGN KEY(logistics_info_id)
REFERENCES %%site_name%%_logistics_info(id)
ON DELETE CASCADE
); );

View File

@ -1,8 +1,9 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_vendors ( CREATE TABLE IF NOT EXISTS %%site_name%%_vendors (
id SERIAL PRIMARY KEY, vendor_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
vendor_name VARCHAR(255) NOT NULL, vendor_name VARCHAR(255) NOT NULL,
vendor_address VARCHAR(255), vendor_address VARCHAR(255) DEFAULT '' NOT NULL,
creation_date TIMESTAMP NOT NULL, vendor_phone_number VARCHAR(32) DEFAULT '' NOT NULL,
created_by INTEGER NOT NULL, vendor_creation_date TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
phone_number VARCHAR(32) vendor_created_by INTEGER NOT NULL,
UNIQUE(vendor_name, vendor_address, vendor_phone_number)
); );

View File

@ -1,6 +1,6 @@
CREATE TABLE IF NOT EXISTS %%site_name%%_zones( CREATE TABLE IF NOT EXISTS %%site_name%%_zones(
id SERIAL PRIMARY KEY, zone_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name VARCHAR(32) NOT NULL, zone_name VARCHAR(32) NOT NULL,
description TEXT, zone_description TEXT DEFAULT '' NOT NULL,
UNIQUE(name) UNIQUE(zone_name)
); );

View File

@ -704,3 +704,213 @@
) )
, ,
sql='plans') sql='plans')
2025-08-23 12:31:31.722476 --- ERROR --- DatabaseError(message='relation "test2_item_locations" does not exist',
payload=CREATE TABLE IF NOT EXISTS test2_cost_layers (
item_location_uuid UUID REFERENCES test2_item_locations(item_location_uuid) ON DELETE SET NULL,
layer_aquisition_date TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
layer_quantity FLOAT8 DEFAULT 0.00 NOT NULL,
layer_cost FLOAT8 DEFAULT 0.00 NOT NULL,
layer_currency_type VARCHAR(16) DEFAULT 'USD' NOT NULL,
layer_expires TIMESTAMP DEFAULT NULL,
layer_vendor INTEGER DEFAULT 0 NOT NULL
);,
sql='cost_layers')
2025-08-23 12:31:58.480965 --- ERROR --- DatabaseError(message='relation "test2_items" does not exist',
payload=CREATE TABLE IF NOT EXISTS test2_food_info (
item_uuid UUID PRIMARY KEY REFERENCES test2_items(item_uuid) ON DELETE CASCADE,
food_groups TEXT [] DEFAULT '{}' NOT NULL,
ingredients TEXT [] DEFAULT '{}' NOT NULL,
nutrients JSONB DEFAULT '{}' NOT NULL,
expires BOOLEAN DEFAULT false NOT NULL,
default_expiration FLOAT8 DEFAULT 0.00 NOT NULL
);,
sql='food_info')
2025-08-23 12:32:33.418128 --- ERROR --- DatabaseError(message='relation "test2_logistics_info" does not exist',
payload=CREATE TABLE IF NOT EXISTS test2_Transactions (
id SERIAL PRIMARY KEY,
timestamp TIMESTAMP,
logistics_info_id INTEGER NOT NULL,
barcode VARCHAR(255),
name VARCHAR(255),
transaction_type VARCHAR(255) NOT NULL,
quantity FLOAT8 NOT NULL,
description TEXT,
user_id INTEGER NOT NULL,
data JSONB,
CONSTRAINT fk_logistics_info
FOREIGN KEY(logistics_info_id)
REFERENCES test2_logistics_info(id)
ON DELETE CASCADE
);,
sql='transactions')
2025-08-23 12:32:59.145550 --- ERROR --- DatabaseError(message='column "brand_uuid" referenced in foreign key constraint does not exist',
payload=CREATE TABLE IF NOT EXISTS test2_items(
item_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
created_at TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
item_name VARCHAR(255) NOT NULL,
item_description TEXT DEFAULT '' NOT NULL,
item_tags TEXT [] DEFAULT '{}' NOT NULL,
item_links JSONB DEFAULT '{}' NOT NULL,
brand_uuid UUID DEFAULT NULL,
item_category VARCHAR(255) NOT NULL,
search_string TEXT DEFAULT '' NOT NULL,
inactive BOOLEAN DEFAULT false NOT NULL,
CONSTRAINT fk_brand
FOREIGN KEY(brand_uuid)
REFERENCES test2_brands(brand_uuid)
ON DELETE SET NULL
);
,
sql='items')
2025-08-23 12:33:48.793121 --- ERROR --- DatabaseError(message='column "brand_uuid" referenced in foreign key constraint does not exist',
payload=CREATE TABLE IF NOT EXISTS test2_items(
item_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
created_at TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
item_name VARCHAR(255) NOT NULL,
item_description TEXT DEFAULT '' NOT NULL,
item_tags TEXT [] DEFAULT '{}' NOT NULL,
item_links JSONB DEFAULT '{}' NOT NULL,
brand_uuid UUID DEFAULT NULL,
item_category VARCHAR(255) NOT NULL,
search_string TEXT DEFAULT '' NOT NULL,
inactive BOOLEAN DEFAULT false NOT NULL,
CONSTRAINT fk_brand
FOREIGN KEY(brand_uuid)
REFERENCES test2_brands(brand_uuid)
ON DELETE SET NULL
);
,
sql='items')
2025-08-23 12:34:28.182864 --- ERROR --- DatabaseError(message='table "test2_cost_layers" does not exist',
payload=DROP TABLE test2_cost_layers CASCADE;,
sql='cost_layers')
2025-08-23 13:32:49.821424 --- ERROR --- DatabaseError(message='column "zones_uuid" referenced in foreign key constraint does not exist',
payload=CREATE TABLE IF NOT EXISTS test2_logistics_info(
item_uuid UUID PRIMARY KEY REFERENCES test2_items(item_uuid) ON DELETE CASCADE,
primary_location UUID REFERENCES test2_locations(zones_uuid) ON DELETE SET NULL,
primary_zone UUID REFERENCES test2_zones(zones_uuid) ON DELETE SET NULL,
auto_issue_location UUID REFERENCES test2_locations(zones_uuid) ON DELETE SET NULL,
auto_issue_zone UUID REFERENCES test2_zones(zones_uuid) ON DELETE SET NULL
);,
sql='logistics_info')
2025-08-23 13:33:48.791869 --- ERROR --- DatabaseError(message='table "test2_cost_layers" does not exist',
payload=DROP TABLE test2_cost_layers CASCADE;,
sql='cost_layers')
2025-08-23 13:36:33.932188 --- ERROR --- DatabaseError(message='column "zones_uuid" referenced in foreign key constraint does not exist',
payload=CREATE TABLE IF NOT EXISTS test2_logistics_info(
item_uuid UUID PRIMARY KEY REFERENCES test2_items(item_uuid) ON DELETE CASCADE,
primary_location UUID REFERENCES test2_locations(zones_uuid) ON DELETE SET NULL,
primary_zone UUID REFERENCES test2_zones(zones_uuid) ON DELETE SET NULL,
auto_issue_location UUID REFERENCES test2_locations(zones_uuid) ON DELETE SET NULL,
auto_issue_zone UUID REFERENCES test2_zones(zones_uuid) ON DELETE SET NULL
);,
sql='logistics_info')
2025-08-23 13:37:28.841496 --- ERROR --- DatabaseError(message='column "zones_uuid" referenced in foreign key constraint does not exist',
payload=CREATE TABLE IF NOT EXISTS test2_logistics_info(
item_uuid UUID PRIMARY KEY REFERENCES test2_items(item_uuid) ON DELETE CASCADE,
primary_location UUID REFERENCES test2_locations(zones_uuid) ON DELETE SET NULL,
primary_zone UUID REFERENCES test2_zones(zones_uuid) ON DELETE SET NULL,
auto_issue_location UUID REFERENCES test2_locations(zones_uuid) ON DELETE SET NULL,
auto_issue_zone UUID REFERENCES test2_zones(zones_uuid) ON DELETE SET NULL
);,
sql='logistics_info')
2025-08-23 13:38:23.460512 --- ERROR --- DatabaseError(message='there is no unique constraint matching given keys for referenced table "test2_locations"',
payload=CREATE TABLE IF NOT EXISTS test2_logistics_info(
item_uuid UUID PRIMARY KEY REFERENCES test2_items(item_uuid) ON DELETE CASCADE,
primary_location UUID REFERENCES test2_locations(zone_uuid) ON DELETE SET NULL,
primary_zone UUID REFERENCES test2_zones(zone_uuid) ON DELETE SET NULL,
auto_issue_location UUID REFERENCES test2_locations(zone_uuid) ON DELETE SET NULL,
auto_issue_zone UUID REFERENCES test2_zones(zone_uuid) ON DELETE SET NULL
);,
sql='logistics_info')
2025-08-23 13:38:58.644650 --- ERROR --- DatabaseError(message='column "id" referenced in foreign key constraint does not exist',
payload=CREATE TABLE IF NOT EXISTS test2_Transactions (
id SERIAL PRIMARY KEY,
timestamp TIMESTAMP,
logistics_info_id INTEGER NOT NULL,
barcode VARCHAR(255),
name VARCHAR(255),
transaction_type VARCHAR(255) NOT NULL,
quantity FLOAT8 NOT NULL,
description TEXT,
user_id INTEGER NOT NULL,
data JSONB,
CONSTRAINT fk_logistics_info
FOREIGN KEY(logistics_info_id)
REFERENCES test2_logistics_info(id)
ON DELETE CASCADE
);,
sql='transactions')
2025-08-23 13:44:59.778889 --- ERROR --- DatabaseError(message='column "logistics_info_uuid" referenced in foreign key constraint does not exist',
payload=CREATE TABLE IF NOT EXISTS test2_transactions (
logistics_info_uuid INTEGER PRIMARY KEY REFERENCES test2_logistics_info(logistics_info_uuid) ON DELETE CASCADE,
transaction_created_at TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
transaction_name VARCHAR(255) DEFAULT NULL,
transaction_type VARCHAR(64) DEFAULT '' NOT NULL,
transaction_quantity FLOAT8 DEFAULT 0.00 NOT NULL,
transaction_description TEXT DEFAULT '' NOT NULL,
transaction_cost FLOAT8 DEFAULT 0.00 NOT NULL,
user_id INTEGER NOT NULL,
transaction_data JSONB DEFAULT '{}' NOT NULL
);,
sql='transactions')
2025-08-23 13:45:12.041464 --- ERROR --- DatabaseError(message='column "logistics_info_uuid" referenced in foreign key constraint does not exist',
payload=CREATE TABLE IF NOT EXISTS test2_transactions (
logistics_info_uuid UUID PRIMARY KEY REFERENCES test2_logistics_info(logistics_info_uuid) ON DELETE CASCADE,
transaction_created_at TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL,
transaction_name VARCHAR(255) DEFAULT NULL,
transaction_type VARCHAR(64) DEFAULT '' NOT NULL,
transaction_quantity FLOAT8 DEFAULT 0.00 NOT NULL,
transaction_description TEXT DEFAULT '' NOT NULL,
transaction_cost FLOAT8 DEFAULT 0.00 NOT NULL,
user_id INTEGER NOT NULL,
transaction_data JSONB DEFAULT '{}' NOT NULL
);,
sql='transactions')
2025-08-23 13:47:37.787017 --- ERROR --- DatabaseError(message='column "id" referenced in foreign key constraint does not exist',
payload=CREATE TABLE IF NOT EXISTS test2_recipe_items (
id SERIAL PRIMARY KEY,
item_uuid UUID,
rp_id INTEGER NOT NULL,
item_type VARCHAR(32) NOT NULL,
item_name TEXT NOT NULL,
uom INTEGER NOT NULL,
qty FLOAT8 NOT NULL,
item_id INTEGER DEFAULT NULL,
links JSONB DEFAULT '{"main": ""}',
CONSTRAINT fk_rp_id
FOREIGN KEY(rp_id)
REFERENCES test2_recipes(id)
ON DELETE CASCADE,
CONSTRAINT fk_item_id
FOREIGN KEY(item_id)
REFERENCES test2_items(id)
ON DELETE CASCADE
);,
sql='recipe_items')
2025-08-23 14:16:10.788720 --- ERROR --- DatabaseError(message='column "item_id" named in key does not existLINE 6: UNIQUE(item_id, conversion_uom_id) ^',
payload=CREATE TABLE IF NOT EXISTS test2_conversions (
conversion_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
item_uuid uuid REFERENCES test2_items(item_uuid) ON DELETE CASCADE NOT NULL,
conversion_uom_id INTEGER DEFAULT 1 NOT NULL,
conversion_conv_factor FLOAT8 DEFAULT 0.00 NOT NULL,
UNIQUE(item_id, conversion_uom_id)
);,
sql='conversions')
2025-08-23 14:16:21.833781 --- ERROR --- DatabaseError(message='column "id" referenced in foreign key constraint does not exist',
payload=CREATE TABLE IF NOT EXISTS test2_receipts (
id SERIAL PRIMARY KEY,
receipt_id VARCHAR (32) NOT NULL,
receipt_status VARCHAR (64) NOT NULL,
date_submitted TIMESTAMP NOT NULL,
submitted_by INTEGER NOT NULL,
vendor_id INTEGER,
files JSONB,
UNIQUE(receipt_id),
CONSTRAINT fk_vendor
FOREIGN KEY(vendor_id)
REFERENCES test2_vendors(id)
);,
sql='receipts')