diff --git a/application/__pycache__/database_payloads.cpython-313.pyc b/application/__pycache__/database_payloads.cpython-313.pyc index 278919b..6d92e3d 100644 Binary files a/application/__pycache__/database_payloads.cpython-313.pyc and b/application/__pycache__/database_payloads.cpython-313.pyc differ diff --git a/application/administration/sql/logins.sql b/application/administration/sql/logins.sql new file mode 100644 index 0000000..fadc842 --- /dev/null +++ b/application/administration/sql/logins.sql @@ -0,0 +1,25 @@ +CREATE TABLE IF NOT EXISTS logins( + id SERIAL PRIMARY KEY, + username VARCHAR(255), + password VARCHAR(255), + email VARCHAR(255) UNIQUE NOT NULL, + favorites JSONB DEFAULT '{}', + unseen_pantry_items INTEGER [] DEFAULT '{}', + unseen_groups INTEGER [] DEFAULT '{}', + unseen_shopping_lists INTEGER [] DEFAULT '{}', + unseen_recipes INTEGER [] DEFAULT '{}', + seen_pantry_items INTEGER [] DEFAULT '{}', + seen_groups INTEGER[] DEFAULT '{}', + seen_shopping_lists INTEGER [] DEFAULT '{}', + seen_recipes INTEGER [] DEFAULT '{}', + sites INTEGER [] DEFAULT '{}', + site_roles INTEGER [] DEFAULT '{}', + system_admin BOOLEAN DEFAULT FALSE, + flags JSONB DEFAULT '{}', + row_type VARCHAR(50), + profile_pic_url VARCHAR(255), + login_type VARCHAR(32), + UNIQUE(username), + CHECK (email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$') +); + diff --git a/application/administration/sql/roles.sql b/application/administration/sql/roles.sql new file mode 100644 index 0000000..802584f --- /dev/null +++ b/application/administration/sql/roles.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS roles( + id SERIAL PRIMARY KEY, + role_name VARCHAR(255) NOT NULL, + role_description TEXT, + site_id INTEGER NOT NULL, + flags JSONB DEFAULT '{}', + UNIQUE(role_name, site_id), + CONSTRAINT fk_site + FOREIGN KEY(site_id) + REFERENCES sites(id) +); \ No newline at end of file diff --git a/application/administration/sql/sites.sql b/application/administration/sql/sites.sql new file mode 100644 index 0000000..ace8adb --- /dev/null +++ b/application/administration/sql/sites.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS sites ( + id SERIAL PRIMARY KEY, + site_name VARCHAR(120), + site_description TEXT, + creation_date TIMESTAMP, + site_owner_id INTEGER NOT NULL, + flags JSONB, + default_zone INTEGER DEFAULT NULL, + default_auto_issue_location INTEGER DEFAULT NULL, + default_primary_location INTEGER DEFAULT NULL, + UNIQUE(site_name) +); \ No newline at end of file diff --git a/application/administration/sql/units.sql b/application/administration/sql/units.sql new file mode 100644 index 0000000..bb28637 --- /dev/null +++ b/application/administration/sql/units.sql @@ -0,0 +1,10 @@ +CREATE TABLE IF NOT EXISTS units ( + id SERIAL PRIMARY KEY, + plural VARCHAR(32), + single VARCHAR(32), + fullname VARCHAR(255), + description TEXT, + unique(plural), + unique(single), + unique(fullname) +); \ No newline at end of file diff --git a/application/database_payloads.py b/application/database_payloads.py index b3ed303..13c9393 100644 --- a/application/database_payloads.py +++ b/application/database_payloads.py @@ -619,8 +619,8 @@ class SiteManager: "transactions", "item", "vendors", - "groups", - "group_items", + #"groups", + #"group_items", "receipts", "receipt_items", "recipes", @@ -631,6 +631,7 @@ class SiteManager: "conversions", "sku_prefix", "barcodes", + "plans", "plan_events" ] self.drop_order = [ @@ -657,5 +658,6 @@ class SiteManager: "conversions", "sku_prefix", "barcodes", + "plans", "plan_events" ] \ No newline at end of file diff --git a/application/database_postgres/BarcodesModel.py b/application/database_postgres/BarcodesModel.py new file mode 100644 index 0000000..4eca6e5 --- /dev/null +++ b/application/database_postgres/BarcodesModel.py @@ -0,0 +1,15 @@ +from dataclasses import dataclass +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class BarcodesModel(BaseModel): + table_name = "barcodes" + primary_key = "barcode" + + @dataclass + class Payload(BasePayload): + barcode: str + item_uuid: str + in_exchange: float + out_exchange: float + descriptor: str + diff --git a/application/database_postgres/BaseModel.py b/application/database_postgres/BaseModel.py new file mode 100644 index 0000000..d73028e --- /dev/null +++ b/application/database_postgres/BaseModel.py @@ -0,0 +1,227 @@ +from abc import ABC +import psycopg2 +import datetime +import uuid +import json +import random +import string +from copy import deepcopy + +import config + + +def validateUUID(uuid_string, version): + try: + u = uuid.UUID(uuid_string, version=version) + return u.version == version + except ValueError: + return False + +class DatabaseError(Exception): + def __init__(self, message, payload=[], sql=""): + super().__init__(message) + self.payload = payload + self.message = str(message).replace("\n", "") + self.sql = sql.replace("\n", "") + self.log_error() + + def log_error(self): + with open("logs/database.log", "a+") as file: + file.write("\n") + file.write(f"{datetime.datetime.now()} --- ERROR --- DatabaseError(message='{self.message}',\n") + file.write(f"{" "*41}payload={self.payload},\n") + file.write(f"{" "*41}sql='{self.sql}')") + + def __str__(self): + return f"DatabaseError(message='{self.message}', payload={self.payload}, sql='{self.sql}')" + +def tupleDictionaryFactory(columns, row): + columns = [desc[0] for desc in columns] + return dict(zip(columns, row)) + +def lst2pgarr(alist): + return '{' + ','.join(alist) + '}' + +def updateStringFactory(updated_values: dict): + set_clause = ', '.join([f"{key} = %s" for key in updated_values.keys()]) + values = [] + for value in updated_values.values(): + if isinstance(value, dict): + value = json.dumps(value) + values.append(value) + + return set_clause, values + +def getUUID(n): + random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=n)) + return random_string + +class BasePayload(ABC): + """BasePayloads holds the bare minimum methods required of a Payload. """ + def payload_dictionary(self): + return deepcopy(self.__dict__) + +class BaseModel(ABC): + """Base Model holds the CRUD functionality for database management. Anything beyond what is built in this + model must be built into the specific models Class that extends this Class. + + For each of these CRUD methods to work there must be a SQL file named {table_name}.sql inside of the + sql/INSERT, sql/CREATE, and sql/DROP that defines basic operations. + + Inheritors MUST assign a 'table_name' and 'primary_key' class level variable. They must also define + a 'Payload' inner dataclass that returns a matching data scheme for INSERT basic funtions. You can + have any payloads inherit the BasePayload class in order to get basic payload functions intended to + be used in these basic operations. + + """ + table_name: str = None # All extended class must assign a table name that CRUD uses to call upon + primary_key: str = 'id' # All extended class can assign a different primary key/cloumn which is used to call delete and update queries on. + + def __init_subclass__(cls, **kwargs): + super().__init_subclass__(**kwargs) + if not hasattr(cls, 'Payload'): + raise NotImplementedError( + f"{cls.__name__} must define an inner Payload class." + ) + if not hasattr(cls, 'table_name') or cls.table_name is None: + raise NotImplementedError(f"{cls.__name__} must define 'table_name' class variable.") + if not hasattr(cls, 'primary_key') or cls.primary_key is None: + raise NotImplementedError(f"{cls.__name__} must define 'primary_key' class variable.") + if not isinstance(cls.table_name, str): + raise ValueError(f"{cls.__name__} must have table_name that is of type str") + if not isinstance(cls.primary_key, str): + raise ValueError(f"{cls.__name__} must have primary_key that is of type str") + + @classmethod + def create_table(self, site, conn=None): + self_conn = False + with open(f"application/database_postgres/sql/CREATE/{self.table_name}.sql", 'r') as file: + sql = file.read().replace("%%site_name%%", site) + try: + if not conn: + database_config = config.config() + conn = psycopg2.connect(**database_config) + conn.autocommit = True + self_conn = True + + with conn.cursor() as cur: + cur.execute(sql) + + if self_conn: + conn.commit() + conn.close() + + except Exception as error: + raise DatabaseError(error, sql, self.table_name) + + @classmethod + def drop_table(self, site, conn=None): + self_conn = False + with open(f"application/database_postgres/sql/DROP/{self.table_name}.sql", 'r') as file: + sql = file.read().replace("%%site_name%%", site) + try: + if not conn: + database_config = config.config() + conn = psycopg2.connect(**database_config) + conn.autocommit = True + self_conn = True + + with conn.cursor() as cur: + cur.execute(sql) + + if self_conn: + conn.commit() + conn.close() + + except Exception as error: + raise DatabaseError(error, sql, self.table_name) + + @classmethod + def delete_tuples(self, site: str, payload: tuple, convert: bool = True, conn=None): + deleted = () + self_conn = False + sql = f"WITH deleted_rows AS (DELETE FROM {site}_{self.table_name} WHERE {self.primary_key} IN ({','.join(['%s'] * len(payload))}) RETURNING *) SELECT * FROM deleted_rows;" + try: + if not conn: + database_config = config.config() + conn = psycopg2.connect(**database_config) + conn.autocommit = True + self_conn = True + + with conn.cursor() as cur: + cur.execute(sql, payload) + rows = cur.fetchall() + if rows and convert: + deleted = [tupleDictionaryFactory(cur.description, r) for r in rows] + elif rows and not convert: + deleted = rows + + if self_conn: + conn.commit() + conn.close() + + return deleted + except Exception as error: + raise DatabaseError(error, payload, sql) + + @classmethod + def update_tuple(self, site: str, payload: dict, convert: bool = True, conn=None): + """ payload (dict): {'key': row_id, 'update': {... column_to_update: value_to_update_to...}} """ + updated = () + self_conn = False + set_clause, values = updateStringFactory(payload['update']) + values.append(payload['key']) + sql = f"UPDATE {site}_{self.table_name} SET {set_clause} WHERE {self.primary_key}=%s RETURNING *;" + try: + if not conn: + database_config = config.config() + conn = psycopg2.connect(**database_config) + conn.autocommit = False + self_conn = True + + with conn.cursor() as cur: + cur.execute(sql, values) + rows = cur.fetchone() + if rows and convert: + updated = tupleDictionaryFactory(cur.description, rows) + elif rows and not convert: + updated = rows + + if self_conn: + conn.commit() + conn.close() + + return updated + except Exception as error: + raise DatabaseError(error, payload, sql) + + @classmethod + def insert_tuple(self, site: str, payload: dict, convert: bool = True, conn=None): + record = () + self_conn = False + + with open(f"application/database_postgres/sql/INSERT/{self.table_name}.sql", 'r') as file: + sql = file.read().replace("%%site_name%%", site) + try: + if not conn: + database_config = config.config() + conn = psycopg2.connect(**database_config) + conn.autocommit = True + self_conn = True + + with conn.cursor() as cur: + cur.execute(sql, payload) + rows = cur.fetchone() + if rows and convert: + record = tupleDictionaryFactory(cur.description, rows) + elif rows and not convert: + record = rows + + if self_conn: + conn.commit() + conn.close() + + return record + + except Exception as error: + raise DatabaseError(error, payload, sql) diff --git a/application/database_postgres/BrandsModel.py b/application/database_postgres/BrandsModel.py new file mode 100644 index 0000000..4f9b329 --- /dev/null +++ b/application/database_postgres/BrandsModel.py @@ -0,0 +1,11 @@ +from dataclasses import dataclass + +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class BrandsModel(BaseModel): + table_name = "brands" + + @dataclass + class Payload(BasePayload): + name: str + \ No newline at end of file diff --git a/application/database_postgres/ConversionsModel.py b/application/database_postgres/ConversionsModel.py new file mode 100644 index 0000000..cca3ab3 --- /dev/null +++ b/application/database_postgres/ConversionsModel.py @@ -0,0 +1,12 @@ +from dataclasses import dataclass +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class ConversionsModel(BaseModel): + table_name = "conversions" + + @dataclass + class Payload(BasePayload): + item_id: int + uom_id: int + conv_factor: float + \ No newline at end of file diff --git a/application/database_postgres/CostLayersModel.py b/application/database_postgres/CostLayersModel.py new file mode 100644 index 0000000..0fcfb46 --- /dev/null +++ b/application/database_postgres/CostLayersModel.py @@ -0,0 +1,17 @@ +from dataclasses import dataclass +import datetime + +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class CostLayersModel(BaseModel): + table_name = "cost_layers" + + @dataclass + class Payload(BasePayload): + aquisition_date: datetime.datetime + quantity: float + cost: float + currency_type: str + vendor: int = 0 + expires: datetime.datetime = None + \ No newline at end of file diff --git a/application/database_postgres/FoodInfoModel.py b/application/database_postgres/FoodInfoModel.py new file mode 100644 index 0000000..f3f6151 --- /dev/null +++ b/application/database_postgres/FoodInfoModel.py @@ -0,0 +1,24 @@ +from dataclasses import dataclass, field +import json + +from application.database_postgres.BaseModel import BasePayload, BaseModel, lst2pgarr + +class FoodInfoModel(BaseModel): + table_name = "food_info" + + @dataclass + class Payload(BasePayload): + food_groups: list = field(default_factory=list) + ingrediants: list = field(default_factory=list) + nutrients: dict = field(default_factory=dict) + expires: bool = False + default_expiration: float = 0.0 + + def payload_dictionary(self): + return { + 'food_groups': lst2pgarr(self.food_groups), + 'ingrediants': lst2pgarr(self.ingrediants), + 'nutrients': json.dumps(self.nutrients), + 'expires': self.expires, + 'default_expiration': self.default_expiration + } \ No newline at end of file diff --git a/application/database_postgres/ItemInfoModel.py b/application/database_postgres/ItemInfoModel.py new file mode 100644 index 0000000..d7fb0f4 --- /dev/null +++ b/application/database_postgres/ItemInfoModel.py @@ -0,0 +1,24 @@ +from dataclasses import dataclass, field +import json + +from application.database_postgres.BaseModel import BasePayload, BaseModel, lst2pgarr + +class ItemInfoModel(BaseModel): + table_name = "item_info" + + @dataclass + class Payload(BasePayload): + barcode: str + packaging: str = "" + uom_quantity: float = 1.0 + uom: int = 1 + cost: float = 0.0 + safety_stock: float = 0.0 + lead_time_days: float = 0.0 + ai_pick: bool = False + prefixes: list = field(default_factory=list) + + def payload_dictionary(self): + payload = super().payload_dictionary() + payload['prefixes'] = lst2pgarr(self.prefixes) + return payload \ No newline at end of file diff --git a/application/database_postgres/ItemLocationsModel.py b/application/database_postgres/ItemLocationsModel.py new file mode 100644 index 0000000..0e26ea5 --- /dev/null +++ b/application/database_postgres/ItemLocationsModel.py @@ -0,0 +1,18 @@ +from dataclasses import dataclass, field +from application.database_postgres.BaseModel import BasePayload, BaseModel, lst2pgarr + +class ItemLocationsModel(BaseModel): + table_name = "item_locations" + + @dataclass + class Payload(BasePayload): + part_id: int + location_id: int + quantity_on_hand: float = 0.0 + cost_layers: list = field(default_factory=list) + + def payload_dictionary(self): + payload = super().payload_dictionary() + payload['cost_layers'] = lst2pgarr(self.cost_layers) + return payload + \ No newline at end of file diff --git a/application/database_postgres/ItemsModel.py b/application/database_postgres/ItemsModel.py new file mode 100644 index 0000000..545c175 --- /dev/null +++ b/application/database_postgres/ItemsModel.py @@ -0,0 +1,31 @@ +from dataclasses import dataclass, field +import json + +from application.database_postgres.BaseModel import BasePayload, BaseModel, lst2pgarr + +class ItemsModel(BaseModel): + table_name = "items" + + @dataclass + class Payload(BasePayload): + item_info_id: int + item_info_uuid: str + logistics_info_id: int + logistics_info_uuid: str + food_info_id: int + food_info_uuid: str + barcode: str = "" + item_name: str = "" + brand: int = 0 + description: str = "" + tags: list = field(default_factory=list) + links: dict = field(default_factory=dict) + row_type: str = "" + item_type: str = "" + search_string: str ="" + + def payload_dictionary(self): + payload = super().payload_dictionary() + payload['tags'] = lst2pgarr(self.tags) + payload['links'] = json.dumps(self.links) + return payload \ No newline at end of file diff --git a/application/database_postgres/LocationsModel.py b/application/database_postgres/LocationsModel.py new file mode 100644 index 0000000..54f3efe --- /dev/null +++ b/application/database_postgres/LocationsModel.py @@ -0,0 +1,13 @@ +from dataclasses import dataclass + +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class LocationsModel(BaseModel): + table_name = "locations" + + @dataclass + class Payload(BasePayload): + uuid: str + name: str + zone_id: int + \ No newline at end of file diff --git a/application/database_postgres/LogisticsInfoModel.py b/application/database_postgres/LogisticsInfoModel.py new file mode 100644 index 0000000..f7796b9 --- /dev/null +++ b/application/database_postgres/LogisticsInfoModel.py @@ -0,0 +1,15 @@ +from dataclasses import dataclass + +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class LogisticsInfoModel(BaseModel): + table_name = "logistics_info" + + @dataclass + class Payload(BasePayload): + barcode: str + primary_location: int + primary_zone: int + auto_issue_location: int + auto_issue_zone: int + \ No newline at end of file diff --git a/application/database_postgres/PlanEventsModel.py b/application/database_postgres/PlanEventsModel.py new file mode 100644 index 0000000..bc95d69 --- /dev/null +++ b/application/database_postgres/PlanEventsModel.py @@ -0,0 +1,20 @@ +from dataclasses import dataclass +import datetime + +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class PlanEventsModel(BaseModel): + table_name = "plan_events" + + @dataclass + class Payload(BasePayload): + plan_uuid: str + event_shortname: str + event_description: str + event_date_start: datetime.datetime + event_date_end: datetime.datetime + created_by: int + recipe_uuid: str + receipt_uuid: str + event_type: str + diff --git a/application/database_postgres/PlansModel.py b/application/database_postgres/PlansModel.py new file mode 100644 index 0000000..046c9ca --- /dev/null +++ b/application/database_postgres/PlansModel.py @@ -0,0 +1,12 @@ +from dataclasses import dataclass +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class PlansModel(BaseModel): + table_name = "plans" + + @dataclass + class Payload(BasePayload): + plan_shortname: str + plan_description: str + created_by: int + diff --git a/application/database_postgres/ReceiptItemsModel.py b/application/database_postgres/ReceiptItemsModel.py new file mode 100644 index 0000000..5ca53cf --- /dev/null +++ b/application/database_postgres/ReceiptItemsModel.py @@ -0,0 +1,24 @@ +from dataclasses import dataclass, field +import json + +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class ReceiptItemsModel(BaseModel): + table_name = "receipt_items" + + @dataclass + class Payload(BasePayload): + type: str + receipt_id: int + barcode: str + item_uuid: str + name: str + qty: float = 1.0 + uom: str = "each" + data: dict = field(default_factory=dict) + status: str = "Unresolved" + + def payload_dictionary(self): + payload = super().payload_dictionary() + payload['data'] = json.dumps(self.data) + return payload \ No newline at end of file diff --git a/application/database_postgres/ReceiptsModel.py b/application/database_postgres/ReceiptsModel.py new file mode 100644 index 0000000..917b62e --- /dev/null +++ b/application/database_postgres/ReceiptsModel.py @@ -0,0 +1,25 @@ +from dataclasses import dataclass, field +import json +import datetime + +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class ReceiptsModel(BaseModel): + table_name = "receipts" + + @dataclass + class Payload(BasePayload): + receipt_id: str + receipt_status: str = "Unresolved" + date_submitted: datetime.datetime = field(init=False) + submitted_by: int = 0 + vendor_id: int = 1 + files: dict = field(default_factory=dict) + + def __post_init__(self): + self.date_submitted = datetime.datetime.now() + + def payload_dictionary(self): + payload = super().payload_dictionary() + payload['files'] = json.dumps(self.files) + return payload \ No newline at end of file diff --git a/application/database_postgres/RecipeItemsModel.py b/application/database_postgres/RecipeItemsModel.py new file mode 100644 index 0000000..a0d97a0 --- /dev/null +++ b/application/database_postgres/RecipeItemsModel.py @@ -0,0 +1,23 @@ +from dataclasses import dataclass, field +import json + +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class RecipeItemsModel(BaseModel): + table_name = "recipe_items" + + @dataclass + class Payload(BasePayload): + uuid: str + rp_id: int + item_type: str + item_name:str + uom: str + qty: float = 0.0 + item_id: int = None + links: dict = field(default_factory=dict) + + def payload_dictionary(self): + payload = super().payload_dictionary() + payload['links'] = json.dumps(self.links) + return payload \ No newline at end of file diff --git a/application/database_postgres/RecipesModel.py b/application/database_postgres/RecipesModel.py new file mode 100644 index 0000000..5778f75 --- /dev/null +++ b/application/database_postgres/RecipesModel.py @@ -0,0 +1,24 @@ +from dataclasses import dataclass, field +import datetime + +from application.database_postgres.BaseModel import BasePayload, BaseModel, lst2pgarr + +class RecipesModel(BaseModel): + table_name = "recipes" + + @dataclass + class Payload(BasePayload): + name: str + author: int + description: str + creation_date: datetime.datetime = field(init=False) + instructions: list = field(default_factory=list) + picture_path: str = "" + + def __post_init__(self): + self.creation_date = datetime.datetime.now() + + def payload_dictionary(self): + payload = super().payload_dictionary() + payload['instructions'] = lst2pgarr(self.instructions) + return payload \ No newline at end of file diff --git a/application/database_postgres/SKUPrefixModel.py b/application/database_postgres/SKUPrefixModel.py new file mode 100644 index 0000000..994eaff --- /dev/null +++ b/application/database_postgres/SKUPrefixModel.py @@ -0,0 +1,12 @@ +from dataclasses import dataclass +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class SKUPrefixModel(BaseModel): + table_name = "sku_prefix" + + @dataclass + class Payload(BasePayload): + uuid: str + name: str + description: str + \ No newline at end of file diff --git a/application/database_postgres/ShoppingListItemsModel.py b/application/database_postgres/ShoppingListItemsModel.py new file mode 100644 index 0000000..383cb34 --- /dev/null +++ b/application/database_postgres/ShoppingListItemsModel.py @@ -0,0 +1,22 @@ +from dataclasses import dataclass, field +import json + +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class ShoppingListItemsModel(BaseModel): + table_name = "shopping_list_items" + + @dataclass + class Payload(BasePayload): + list_uuid: str + item_type: str + item_name: str + uom: int + qty: float + item_uuid: str = None + links: dict = field(default_factory=dict) + + def payload_dictionary(self): + payload = super().payload_dictionary() + payload['links'] = json.dumps(self.links) + return payload \ No newline at end of file diff --git a/application/database_postgres/ShoppingListsModel.py b/application/database_postgres/ShoppingListsModel.py new file mode 100644 index 0000000..1509e9c --- /dev/null +++ b/application/database_postgres/ShoppingListsModel.py @@ -0,0 +1,18 @@ +from dataclasses import dataclass, field +import datetime +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class ShoppingListsModel(BaseModel): + table_name = "shopping_lists" + + @dataclass + class Payload(BasePayload): + name: str + description: str + author: int + sub_type: str = "plain" + creation_date: datetime.datetime = field(init=False) + list_type: str = "temporary" + + def __post_init__(self): + self.creation_date = datetime.datetime.now() \ No newline at end of file diff --git a/application/database_postgres/TransactionsModel.py b/application/database_postgres/TransactionsModel.py new file mode 100644 index 0000000..932ba1e --- /dev/null +++ b/application/database_postgres/TransactionsModel.py @@ -0,0 +1,25 @@ +from dataclasses import dataclass, field +import json +import datetime + +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class TransactionsModel(BaseModel): + table_name = "transactions" + + @dataclass + class Payload(BasePayload): + timestamp: datetime.datetime + logistics_info_id: int + barcode: str + name: str + transaction_type: str + quantity: float + description: str + user_id: int + data: dict = field(default_factory=dict) + + def payload_dictionary(self): + payload = super().payload_dictionary() + payload['data'] = json.dumps(self.data) + return payload \ No newline at end of file diff --git a/application/database_postgres/VendorsModel.py b/application/database_postgres/VendorsModel.py new file mode 100644 index 0000000..415f4f8 --- /dev/null +++ b/application/database_postgres/VendorsModel.py @@ -0,0 +1,18 @@ +from dataclasses import dataclass, field +import datetime + +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class VendorsModel(BaseModel): + table_name = "vendors" + + @dataclass + class Payload(BasePayload): + vendor_name: str + created_by: int + vendor_address: str = "" + creation_date: datetime.datetime = field(init=False) + phone_number: str = "" + + def __post_init__(self): + self.creation_date = datetime.datetime.now() \ No newline at end of file diff --git a/application/database_postgres/ZonesModel.py b/application/database_postgres/ZonesModel.py new file mode 100644 index 0000000..a9db6ab --- /dev/null +++ b/application/database_postgres/ZonesModel.py @@ -0,0 +1,12 @@ +from dataclasses import dataclass + +from application.database_postgres.BaseModel import BasePayload, BaseModel + +class ZonesModel(BaseModel): + table_name = "zones" + + @dataclass + class Payload(BasePayload): + name: str + description: str = "" + \ No newline at end of file diff --git a/application/database_postgres/__init__.py b/application/database_postgres/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/application/database_postgres/__pycache__/BarcodeModel.cpython-313.pyc b/application/database_postgres/__pycache__/BarcodeModel.cpython-313.pyc new file mode 100644 index 0000000..6f3be6e Binary files /dev/null and b/application/database_postgres/__pycache__/BarcodeModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/BarcodesModel.cpython-313.pyc b/application/database_postgres/__pycache__/BarcodesModel.cpython-313.pyc new file mode 100644 index 0000000..da0f144 Binary files /dev/null and b/application/database_postgres/__pycache__/BarcodesModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/BaseModel.cpython-313.pyc b/application/database_postgres/__pycache__/BaseModel.cpython-313.pyc new file mode 100644 index 0000000..9378289 Binary files /dev/null and b/application/database_postgres/__pycache__/BaseModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/BrandsModel.cpython-313.pyc b/application/database_postgres/__pycache__/BrandsModel.cpython-313.pyc new file mode 100644 index 0000000..d9d87cb Binary files /dev/null and b/application/database_postgres/__pycache__/BrandsModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/ConversionsModel.cpython-313.pyc b/application/database_postgres/__pycache__/ConversionsModel.cpython-313.pyc new file mode 100644 index 0000000..119103d Binary files /dev/null and b/application/database_postgres/__pycache__/ConversionsModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/CostLayersModel.cpython-313.pyc b/application/database_postgres/__pycache__/CostLayersModel.cpython-313.pyc new file mode 100644 index 0000000..baaeffd Binary files /dev/null and b/application/database_postgres/__pycache__/CostLayersModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/FoodInfoModel.cpython-313.pyc b/application/database_postgres/__pycache__/FoodInfoModel.cpython-313.pyc new file mode 100644 index 0000000..314415b Binary files /dev/null and b/application/database_postgres/__pycache__/FoodInfoModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/ItemInfoModel.cpython-313.pyc b/application/database_postgres/__pycache__/ItemInfoModel.cpython-313.pyc new file mode 100644 index 0000000..caa025c Binary files /dev/null and b/application/database_postgres/__pycache__/ItemInfoModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/ItemLocationsModel.cpython-313.pyc b/application/database_postgres/__pycache__/ItemLocationsModel.cpython-313.pyc new file mode 100644 index 0000000..cf9eda2 Binary files /dev/null and b/application/database_postgres/__pycache__/ItemLocationsModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/ItemsModel.cpython-313.pyc b/application/database_postgres/__pycache__/ItemsModel.cpython-313.pyc new file mode 100644 index 0000000..94ed310 Binary files /dev/null and b/application/database_postgres/__pycache__/ItemsModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/LocationsModel.cpython-313.pyc b/application/database_postgres/__pycache__/LocationsModel.cpython-313.pyc new file mode 100644 index 0000000..894d7f0 Binary files /dev/null and b/application/database_postgres/__pycache__/LocationsModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/LogisticsInfoModel.cpython-313.pyc b/application/database_postgres/__pycache__/LogisticsInfoModel.cpython-313.pyc new file mode 100644 index 0000000..12c0707 Binary files /dev/null and b/application/database_postgres/__pycache__/LogisticsInfoModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/PlanEventsModel.cpython-313.pyc b/application/database_postgres/__pycache__/PlanEventsModel.cpython-313.pyc new file mode 100644 index 0000000..8eaf5a1 Binary files /dev/null and b/application/database_postgres/__pycache__/PlanEventsModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/PlansModel.cpython-313.pyc b/application/database_postgres/__pycache__/PlansModel.cpython-313.pyc new file mode 100644 index 0000000..c031a55 Binary files /dev/null and b/application/database_postgres/__pycache__/PlansModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/ReceiptItemsModel.cpython-313.pyc b/application/database_postgres/__pycache__/ReceiptItemsModel.cpython-313.pyc new file mode 100644 index 0000000..7d45c21 Binary files /dev/null and b/application/database_postgres/__pycache__/ReceiptItemsModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/ReceiptsModel.cpython-313.pyc b/application/database_postgres/__pycache__/ReceiptsModel.cpython-313.pyc new file mode 100644 index 0000000..4226b07 Binary files /dev/null and b/application/database_postgres/__pycache__/ReceiptsModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/RecipeItemsModel.cpython-313.pyc b/application/database_postgres/__pycache__/RecipeItemsModel.cpython-313.pyc new file mode 100644 index 0000000..540ace7 Binary files /dev/null and b/application/database_postgres/__pycache__/RecipeItemsModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/RecipesModel.cpython-313.pyc b/application/database_postgres/__pycache__/RecipesModel.cpython-313.pyc new file mode 100644 index 0000000..1853814 Binary files /dev/null and b/application/database_postgres/__pycache__/RecipesModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/SKUPrefixModel.cpython-313.pyc b/application/database_postgres/__pycache__/SKUPrefixModel.cpython-313.pyc new file mode 100644 index 0000000..804d5bb Binary files /dev/null and b/application/database_postgres/__pycache__/SKUPrefixModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/ShoppingListItemsModel.cpython-313.pyc b/application/database_postgres/__pycache__/ShoppingListItemsModel.cpython-313.pyc new file mode 100644 index 0000000..4f5465a Binary files /dev/null and b/application/database_postgres/__pycache__/ShoppingListItemsModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/ShoppingListsModel.cpython-313.pyc b/application/database_postgres/__pycache__/ShoppingListsModel.cpython-313.pyc new file mode 100644 index 0000000..d110b25 Binary files /dev/null and b/application/database_postgres/__pycache__/ShoppingListsModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/TransactionsModel.cpython-313.pyc b/application/database_postgres/__pycache__/TransactionsModel.cpython-313.pyc new file mode 100644 index 0000000..292dd72 Binary files /dev/null and b/application/database_postgres/__pycache__/TransactionsModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/VendorsModel.cpython-313.pyc b/application/database_postgres/__pycache__/VendorsModel.cpython-313.pyc new file mode 100644 index 0000000..e450639 Binary files /dev/null and b/application/database_postgres/__pycache__/VendorsModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/ZonesModel.cpython-313.pyc b/application/database_postgres/__pycache__/ZonesModel.cpython-313.pyc new file mode 100644 index 0000000..49db8ea Binary files /dev/null and b/application/database_postgres/__pycache__/ZonesModel.cpython-313.pyc differ diff --git a/application/database_postgres/__pycache__/__init__.cpython-313.pyc b/application/database_postgres/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..bb8b1a5 Binary files /dev/null and b/application/database_postgres/__pycache__/__init__.cpython-313.pyc differ diff --git a/application/database_postgres/sql/CREATE/barcodes.sql b/application/database_postgres/sql/CREATE/barcodes.sql new file mode 100644 index 0000000..97ace78 --- /dev/null +++ b/application/database_postgres/sql/CREATE/barcodes.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_barcodes ( + barcode VARCHAR(32) PRIMARY KEY, + item_uuid UUID, + in_exchange FLOAT, + out_exchange FLOAT, + descriptor VARCHAR(255) +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/brands.sql b/application/database_postgres/sql/CREATE/brands.sql new file mode 100644 index 0000000..371e12a --- /dev/null +++ b/application/database_postgres/sql/CREATE/brands.sql @@ -0,0 +1,4 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_brands ( + id SERIAL PRIMARY KEY, + name VARCHAR(255) +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/conversions.sql b/application/database_postgres/sql/CREATE/conversions.sql new file mode 100644 index 0000000..69d6747 --- /dev/null +++ b/application/database_postgres/sql/CREATE/conversions.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_conversions ( + id SERIAL PRIMARY KEY, + item_id INTEGER NOT NULL, + uom_id INTEGER NOT NULL, + conv_factor FLOAT8 NOT NULL, + UNIQUE(item_id, uom_id) +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/cost_layers.sql b/application/database_postgres/sql/CREATE/cost_layers.sql new file mode 100644 index 0000000..3c4ca5a --- /dev/null +++ b/application/database_postgres/sql/CREATE/cost_layers.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_cost_layers ( + id SERIAL PRIMARY KEY, + aquisition_date TIMESTAMP NOT NULL, + quantity FLOAT8 NOT NULL, + cost FLOAT8 NOT NULL, + currency_type VARCHAR(16) NOT NULL, + expires TIMESTAMP, + vendor INTEGER DEFAULT 0 +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/food_info.sql b/application/database_postgres/sql/CREATE/food_info.sql new file mode 100644 index 0000000..98e51d1 --- /dev/null +++ b/application/database_postgres/sql/CREATE/food_info.sql @@ -0,0 +1,10 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_food_info ( + id SERIAL PRIMARY KEY, + food_info_uuid UUID DEFAULT uuid_generate_v4(), + food_groups TEXT [], + ingrediants TEXT [], + nutrients JSONB, + expires BOOLEAN, + default_expiration FLOAT8, + UNIQUE(food_info_uuid) +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/item_info.sql b/application/database_postgres/sql/CREATE/item_info.sql new file mode 100644 index 0000000..45546f2 --- /dev/null +++ b/application/database_postgres/sql/CREATE/item_info.sql @@ -0,0 +1,14 @@ +CREATE TABLE IF NOt EXISTS %%site_name%%_item_info ( + id SERIAL PRIMARY KEY, + item_info_uuid UUID DEFAULT uuid_generate_v4(), + barcode VARCHAR(255), + packaging VARCHAR(255), + uom_quantity FLOAT8, + uom INTEGER, + cost FLOAT8, + safety_stock FLOAT8, + lead_time_days FLOAT8, + ai_pick BOOLEAN, + prefixes INTEGER [], + UNIQUE(item_info_uuid) +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/item_locations.sql b/application/database_postgres/sql/CREATE/item_locations.sql new file mode 100644 index 0000000..f13338c --- /dev/null +++ b/application/database_postgres/sql/CREATE/item_locations.sql @@ -0,0 +1,16 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_item_locations( + id SERIAL PRIMARY KEY, + part_id INTEGER NOT NULL, + location_id INTEGER NOT NULL, + quantity_on_hand FLOAT8 NOT NULL, + cost_layers INTEGER[] DEFAULT '{}', + 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 +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/items.sql b/application/database_postgres/sql/CREATE/items.sql new file mode 100644 index 0000000..0d134d1 --- /dev/null +++ b/application/database_postgres/sql/CREATE/items.sql @@ -0,0 +1,36 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_items( + id SERIAL PRIMARY KEY, + item_uuid UUID DEFAULT uuid_generate_v4(), + barcode VARCHAR(255), + item_name VARCHAR(255) NOT NULL, + brand INTEGER, + description TEXT, + tags TEXT [], + links JSONB, + item_info_id INTEGER NOT NULL, + item_info_uuid UUID NOT NULL, + logistics_info_id INTEGER 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 + FOREIGN KEY(brand) + REFERENCES %%site_name%%_brands(id), + CONSTRAINT fk_logistics_info + FOREIGN KEY(logistics_info_id) + REFERENCES %%site_name%%_logistics_info(id) + ON DELETE CASCADE +); diff --git a/application/database_postgres/sql/CREATE/locations.sql b/application/database_postgres/sql/CREATE/locations.sql new file mode 100644 index 0000000..a3896e2 --- /dev/null +++ b/application/database_postgres/sql/CREATE/locations.sql @@ -0,0 +1,10 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_locations( + id SERIAL PRIMARY KEY, + uuid VARCHAR(255) NOT NULL, + name VARCHAR(32) NOT NULL, + zone_id INTEGER NOT NULL, + UNIQUE(uuid), + CONSTRAINT fk_zone + FOREIGN KEY(zone_id) + REFERENCES %%site_name%%_zones(id) +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/logistics_info.sql b/application/database_postgres/sql/CREATE/logistics_info.sql new file mode 100644 index 0000000..df92cfe --- /dev/null +++ b/application/database_postgres/sql/CREATE/logistics_info.sql @@ -0,0 +1,22 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_logistics_info( + id SERIAL PRIMARY KEY, + logistics_info_uuid UUID DEFAULT uuid_generate_v4(), + barcode VARCHAR(255), + primary_location INTEGER NOT NULL, + primary_zone INTEGER NOT 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) +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/plan_events.sql b/application/database_postgres/sql/CREATE/plan_events.sql new file mode 100644 index 0000000..ca65296 --- /dev/null +++ b/application/database_postgres/sql/CREATE/plan_events.sql @@ -0,0 +1,14 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_plan_events( + id SERIAL PRIMARY KEY, + event_uuid UUID DEFAULT gen_random_uuid(), + plan_uuid UUID, + recipe_uuid UUID, + receipt_uuid UUID DEFAULT NULL, + event_shortname VARCHAR(32) NOT NULL, + event_description TEXT, + event_date_start TIMESTAMP NOT NULL, + event_date_end TIMESTAMP NOT NULL, + created_by INTEGER NOT NULL, + event_type VARCHAR(32) NOT NULL, + UNIQUE(event_uuid) +) diff --git a/application/database_postgres/sql/CREATE/plans.sql b/application/database_postgres/sql/CREATE/plans.sql new file mode 100644 index 0000000..4b3422f --- /dev/null +++ b/application/database_postgres/sql/CREATE/plans.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_plans( + plan_uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(), + plan_shortname VARCHAR(32) NOT NULL, + plan_description TEXT, + created_by INTEGER NOT NULL +) diff --git a/application/database_postgres/sql/CREATE/receipt_items.sql b/application/database_postgres/sql/CREATE/receipt_items.sql new file mode 100644 index 0000000..8dbdc16 --- /dev/null +++ b/application/database_postgres/sql/CREATE/receipt_items.sql @@ -0,0 +1,16 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_receipt_items ( + id SERIAL PRIMARY KEY, + type VARCHAR(255) NOT NULL, + receipt_id INTEGER NOT NULL, + barcode VARCHAR(255), + item_uuid UUID, + name VARCHAR(255) NOT NULL, + qty FLOAT8 NOT NULL, + uom INTEGER NOT NULL, + data JSONB, + status VARCHAR (64), + CONSTRAINT fk_receipt + FOREIGN KEY(receipt_id) + REFERENCES %%site_name%%_receipts(id) + ON DELETE CASCADE +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/receipts.sql b/application/database_postgres/sql/CREATE/receipts.sql new file mode 100644 index 0000000..a5667bc --- /dev/null +++ b/application/database_postgres/sql/CREATE/receipts.sql @@ -0,0 +1,13 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_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 %%site_name%%_vendors(id) +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/recipe_items.sql b/application/database_postgres/sql/CREATE/recipe_items.sql new file mode 100644 index 0000000..5261db4 --- /dev/null +++ b/application/database_postgres/sql/CREATE/recipe_items.sql @@ -0,0 +1,19 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_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 %%site_name%%_recipes(id) + ON DELETE CASCADE, + CONSTRAINT fk_item_id + FOREIGN KEY(item_id) + REFERENCES %%site_name%%_items(id) + ON DELETE CASCADE +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/recipes.sql b/application/database_postgres/sql/CREATE/recipes.sql new file mode 100644 index 0000000..c0320b0 --- /dev/null +++ b/application/database_postgres/sql/CREATE/recipes.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_recipes ( + id SERIAL PRIMARY KEY, + recipe_uuid UUID DEFAULT gen_random_uuid() NOT NULL, + name VARCHAR, + author INTEGER, + description TEXT, + creation_date TIMESTAMP, + instructions TEXT [], + picture_path TEXT, + UNIQUE(recipe_uuid) +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/shopping_list_items.sql b/application/database_postgres/sql/CREATE/shopping_list_items.sql new file mode 100644 index 0000000..938b91e --- /dev/null +++ b/application/database_postgres/sql/CREATE/shopping_list_items.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_shopping_list_items ( + list_item_uuid UUID DEFAULT uuid_generate_v4() NOT NULL PRIMARY KEY, + list_uuid UUID NOT NULL, + item_type VARCHAR(32) NOT NULL, + item_name TEXT NOT NULL, + uom INTEGER NOT NULL, + qty FLOAT8 NOT NULL, + item_uuid UUID DEFAULT NULL, + links JSONB DEFAULT '{"main": ""}', + list_item_state BOOLEAN DEFAULT false, + UNIQUE(list_uuid, item_uuid) +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/shopping_lists.sql b/application/database_postgres/sql/CREATE/shopping_lists.sql new file mode 100644 index 0000000..a4fcdb0 --- /dev/null +++ b/application/database_postgres/sql/CREATE/shopping_lists.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_shopping_lists ( + id SERIAL PRIMARY KEY, + list_uuid UUID DEFAULT uuid_generate_v4() NOT NULL, + list_type VARCHAR(32), + name VARCHAR(255) NOT NULL, + description TEXT, + author INTEGER, + creation_date TIMESTAMP, + sub_type VARCHAR(64), + UNIQUE(list_uuid, name) +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/sku_prefix.sql b/application/database_postgres/sql/CREATE/sku_prefix.sql new file mode 100644 index 0000000..2ac29d0 --- /dev/null +++ b/application/database_postgres/sql/CREATE/sku_prefix.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_sku_prefix( + id SERIAL PRIMARY KEY, + uuid VARCHAR(16) NOT NULL, + name VARCHAR(255) NOT NULL, + description TEXT, + UNIQUE (name, uuid) +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/transactions.sql b/application/database_postgres/sql/CREATE/transactions.sql new file mode 100644 index 0000000..6fef0e2 --- /dev/null +++ b/application/database_postgres/sql/CREATE/transactions.sql @@ -0,0 +1,16 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_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 %%site_name%%_logistics_info(id) + ON DELETE CASCADE +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/vendors.sql b/application/database_postgres/sql/CREATE/vendors.sql new file mode 100644 index 0000000..2ffb408 --- /dev/null +++ b/application/database_postgres/sql/CREATE/vendors.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_vendors ( + id SERIAL PRIMARY KEY, + vendor_name VARCHAR(255) NOT NULL, + vendor_address VARCHAR(255), + creation_date TIMESTAMP NOT NULL, + created_by INTEGER NOT NULL, + phone_number VARCHAR(32) +); \ No newline at end of file diff --git a/application/database_postgres/sql/CREATE/zones.sql b/application/database_postgres/sql/CREATE/zones.sql new file mode 100644 index 0000000..5a60c54 --- /dev/null +++ b/application/database_postgres/sql/CREATE/zones.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS %%site_name%%_zones( + id SERIAL PRIMARY KEY, + name VARCHAR(32) NOT NULL, + description TEXT, + UNIQUE(name) +); diff --git a/application/database_postgres/sql/DROP/barcodes.sql b/application/database_postgres/sql/DROP/barcodes.sql new file mode 100644 index 0000000..20ebf18 --- /dev/null +++ b/application/database_postgres/sql/DROP/barcodes.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_barcodes CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/brands.sql b/application/database_postgres/sql/DROP/brands.sql new file mode 100644 index 0000000..c3ab4cf --- /dev/null +++ b/application/database_postgres/sql/DROP/brands.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_brands CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/conversions.sql b/application/database_postgres/sql/DROP/conversions.sql new file mode 100644 index 0000000..030c936 --- /dev/null +++ b/application/database_postgres/sql/DROP/conversions.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_conversions CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/cost_layers.sql b/application/database_postgres/sql/DROP/cost_layers.sql new file mode 100644 index 0000000..366d26f --- /dev/null +++ b/application/database_postgres/sql/DROP/cost_layers.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_cost_layers CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/food_info.sql b/application/database_postgres/sql/DROP/food_info.sql new file mode 100644 index 0000000..95d461a --- /dev/null +++ b/application/database_postgres/sql/DROP/food_info.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_food_info CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/item_info.sql b/application/database_postgres/sql/DROP/item_info.sql new file mode 100644 index 0000000..d962ebd --- /dev/null +++ b/application/database_postgres/sql/DROP/item_info.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_item_info CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/item_locations.sql b/application/database_postgres/sql/DROP/item_locations.sql new file mode 100644 index 0000000..d775626 --- /dev/null +++ b/application/database_postgres/sql/DROP/item_locations.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_item_locations CASCADE; diff --git a/application/database_postgres/sql/DROP/items.sql b/application/database_postgres/sql/DROP/items.sql new file mode 100644 index 0000000..8ae4f73 --- /dev/null +++ b/application/database_postgres/sql/DROP/items.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_items CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/locations.sql b/application/database_postgres/sql/DROP/locations.sql new file mode 100644 index 0000000..ed8cf16 --- /dev/null +++ b/application/database_postgres/sql/DROP/locations.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_locations CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/logistics_info.sql b/application/database_postgres/sql/DROP/logistics_info.sql new file mode 100644 index 0000000..e22f275 --- /dev/null +++ b/application/database_postgres/sql/DROP/logistics_info.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_logistics_info CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/plan_events.sql b/application/database_postgres/sql/DROP/plan_events.sql new file mode 100644 index 0000000..da6ba52 --- /dev/null +++ b/application/database_postgres/sql/DROP/plan_events.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_plan_events CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/plans.sql b/application/database_postgres/sql/DROP/plans.sql new file mode 100644 index 0000000..1822733 --- /dev/null +++ b/application/database_postgres/sql/DROP/plans.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_plans CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/receipt_items.sql b/application/database_postgres/sql/DROP/receipt_items.sql new file mode 100644 index 0000000..91b7156 --- /dev/null +++ b/application/database_postgres/sql/DROP/receipt_items.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_receipt_items CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/receipts.sql b/application/database_postgres/sql/DROP/receipts.sql new file mode 100644 index 0000000..de97bb8 --- /dev/null +++ b/application/database_postgres/sql/DROP/receipts.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_receipts CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/recipe_items.sql b/application/database_postgres/sql/DROP/recipe_items.sql new file mode 100644 index 0000000..2f2300b --- /dev/null +++ b/application/database_postgres/sql/DROP/recipe_items.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_recipe_items CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/recipes.sql b/application/database_postgres/sql/DROP/recipes.sql new file mode 100644 index 0000000..dfc421d --- /dev/null +++ b/application/database_postgres/sql/DROP/recipes.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_recipes CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/shopping_list_items.sql b/application/database_postgres/sql/DROP/shopping_list_items.sql new file mode 100644 index 0000000..d8f8055 --- /dev/null +++ b/application/database_postgres/sql/DROP/shopping_list_items.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_shopping_list_items CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/shopping_lists.sql b/application/database_postgres/sql/DROP/shopping_lists.sql new file mode 100644 index 0000000..a66fbf6 --- /dev/null +++ b/application/database_postgres/sql/DROP/shopping_lists.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_shopping_lists CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/sku_prefix.sql b/application/database_postgres/sql/DROP/sku_prefix.sql new file mode 100644 index 0000000..8266dc8 --- /dev/null +++ b/application/database_postgres/sql/DROP/sku_prefix.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_sku_prefix CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/transactions.sql b/application/database_postgres/sql/DROP/transactions.sql new file mode 100644 index 0000000..5ef5a56 --- /dev/null +++ b/application/database_postgres/sql/DROP/transactions.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_transactions CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/vendors.sql b/application/database_postgres/sql/DROP/vendors.sql new file mode 100644 index 0000000..14c5e96 --- /dev/null +++ b/application/database_postgres/sql/DROP/vendors.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_vendors CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/DROP/zones.sql b/application/database_postgres/sql/DROP/zones.sql new file mode 100644 index 0000000..81b784b --- /dev/null +++ b/application/database_postgres/sql/DROP/zones.sql @@ -0,0 +1 @@ +DROP TABLE %%site_name%%_zones CASCADE; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/barcodes.sql b/application/database_postgres/sql/INSERT/barcodes.sql new file mode 100644 index 0000000..602bed3 --- /dev/null +++ b/application/database_postgres/sql/INSERT/barcodes.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_barcodes +(barcode, item_uuid, in_exchange, out_exchange, descriptor) +VALUES (%(barcode)s, %(item_uuid)s, %(in_exchange)s, %(out_exchange)s, %(descriptor)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/brands.sql b/application/database_postgres/sql/INSERT/brands.sql new file mode 100644 index 0000000..f107386 --- /dev/null +++ b/application/database_postgres/sql/INSERT/brands.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_brands +(name) +VALUES (%(name)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/conversions.sql b/application/database_postgres/sql/INSERT/conversions.sql new file mode 100644 index 0000000..3bcceea --- /dev/null +++ b/application/database_postgres/sql/INSERT/conversions.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_conversions +(item_id, uom_id, conv_factor) +VALUES (%(item_id)s, %(uom_id)s, %(conv_factor)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/cost_layers.sql b/application/database_postgres/sql/INSERT/cost_layers.sql new file mode 100644 index 0000000..5515a0e --- /dev/null +++ b/application/database_postgres/sql/INSERT/cost_layers.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_cost_layers +(aquisition_date, quantity, cost, currency_type, expires, vendor) +VALUES (%(aquisition_date)s, %(quantity)s, %(cost)s, %(currency_type)s, %(expires)s, %(vendor)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/food_info.sql b/application/database_postgres/sql/INSERT/food_info.sql new file mode 100644 index 0000000..0258ae4 --- /dev/null +++ b/application/database_postgres/sql/INSERT/food_info.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_food_info +(ingrediants, food_groups, nutrients, expires, default_expiration) +VALUES (%(ingrediants)s, %(food_groups)s, %(nutrients)s, %(expires)s, %(default_expiration)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/item_info.sql b/application/database_postgres/sql/INSERT/item_info.sql new file mode 100644 index 0000000..83ecc49 --- /dev/null +++ b/application/database_postgres/sql/INSERT/item_info.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_item_info +(barcode, packaging, uom_quantity, uom, cost, safety_stock, lead_time_days, ai_pick, prefixes) +VALUES (%(barcode)s, %(packaging)s, %(uom_quantity)s, %(uom)s, %(cost)s, %(safety_stock)s, %(lead_time_days)s, %(ai_pick)s, %(prefixes)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/item_locations.sql b/application/database_postgres/sql/INSERT/item_locations.sql new file mode 100644 index 0000000..b020ce2 --- /dev/null +++ b/application/database_postgres/sql/INSERT/item_locations.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_item_locations +(part_id, location_id, quantity_on_hand, cost_layers) +VALUES (%(part_id)s, %(location_id)s, %(quantity_on_hand)s, %(cost_layers)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/items.sql b/application/database_postgres/sql/INSERT/items.sql new file mode 100644 index 0000000..ef69cc3 --- /dev/null +++ b/application/database_postgres/sql/INSERT/items.sql @@ -0,0 +1,7 @@ +INSERT INTO %%site_name%%_items +(barcode, item_name, brand, description, tags, links, item_info_id, item_info_uuid, +logistics_info_id, logistics_info_uuid, food_info_id, food_info_uuid, row_type, item_type, search_string) +VALUES(%(barcode)s, %(item_name)s, %(brand)s, %(description)s, %(tags)s, %(links)s, %(item_info_id)s, %(item_info_uuid)s, +%(logistics_info_id)s, %(logistics_info_uuid)s, %(food_info_id)s, %(food_info_uuid)s, +%(row_type)s, %(item_type)s, %(search_string)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/locations.sql b/application/database_postgres/sql/INSERT/locations.sql new file mode 100644 index 0000000..06f1f58 --- /dev/null +++ b/application/database_postgres/sql/INSERT/locations.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_locations +(uuid, name, zone_id) +VALUES (%s, %s, %s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/logistics_info.sql b/application/database_postgres/sql/INSERT/logistics_info.sql new file mode 100644 index 0000000..1d2ca28 --- /dev/null +++ b/application/database_postgres/sql/INSERT/logistics_info.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_logistics_info +(barcode, primary_location, primary_zone, auto_issue_location, auto_issue_zone) +VALUES (%(barcode)s, %(primary_location)s, %(primary_zone)s, %(auto_issue_location)s, %(auto_issue_zone)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/plan_events.sql b/application/database_postgres/sql/INSERT/plan_events.sql new file mode 100644 index 0000000..60a7f92 --- /dev/null +++ b/application/database_postgres/sql/INSERT/plan_events.sql @@ -0,0 +1,6 @@ +INSERT INTO %%site_name%%_plan_events +(plan_uuid, event_shortname, event_description, event_date_start, event_date_end, +created_by, recipe_uuid, receipt_uuid, event_type) +VALUES (%(plan_uuid)s, %(event_shortname)s, %(event_description)s, %(event_date_start)s, %(event_date_end)s, +%(created_by)s, %(recipe_uuid)s, %(receipt_uuid)s, %(event_type)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/plans.sql b/application/database_postgres/sql/INSERT/plans.sql new file mode 100644 index 0000000..634aa2f --- /dev/null +++ b/application/database_postgres/sql/INSERT/plans.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_plans +(plan_shortname, plan_description, created_by) +VALUES (%(plan_shortname)s, %(plan_description)s, %(created_by)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/receipt_items.sql b/application/database_postgres/sql/INSERT/receipt_items.sql new file mode 100644 index 0000000..12934b1 --- /dev/null +++ b/application/database_postgres/sql/INSERT/receipt_items.sql @@ -0,0 +1,5 @@ +INSERT INTO %%site_name%%_receipt_items +(type, receipt_id, barcode, item_uuid, name, qty, uom, data, status) +VALUES (%(type)s, %(receipt_id)s, %(barcode)s, %(item_uuid)s, %(name)s, %(qty)s, +%(uom)s, %(data)s, %(status)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/receipts.sql b/application/database_postgres/sql/INSERT/receipts.sql new file mode 100644 index 0000000..d6033e5 --- /dev/null +++ b/application/database_postgres/sql/INSERT/receipts.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_receipts +(receipt_id, receipt_status, date_submitted, submitted_by, vendor_id, files) +VALUES (%(receipt_id)s, %(receipt_status)s, %(date_submitted)s, %(submitted_by)s, %(vendor_id)s, %(files)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/recipe_items.sql b/application/database_postgres/sql/INSERT/recipe_items.sql new file mode 100644 index 0000000..ac509ba --- /dev/null +++ b/application/database_postgres/sql/INSERT/recipe_items.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_recipe_items +(item_uuid, rp_id, item_type, item_name, uom, qty, item_id, links) +VALUES (%(item_uuid)s, %(rp_id)s, %(item_type)s, %(item_name)s, %(uom)s, %(qty)s, %(item_id)s, %(links)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/recipes.sql b/application/database_postgres/sql/INSERT/recipes.sql new file mode 100644 index 0000000..3c9a6ea --- /dev/null +++ b/application/database_postgres/sql/INSERT/recipes.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_recipes +(name, author, description, creation_date, instructions, picture_path) +VALUES (%(name)s, %(author)s, %(description)s, %(creation_date)s, %(instructions)s, %(picture_path)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/shopping_list_items.sql b/application/database_postgres/sql/INSERT/shopping_list_items.sql new file mode 100644 index 0000000..6a7070d --- /dev/null +++ b/application/database_postgres/sql/INSERT/shopping_list_items.sql @@ -0,0 +1,6 @@ +INSERT INTO %%site_name%%_shopping_list_items +(list_uuid, item_type, item_name, uom, qty, item_uuid, links) +VALUES (%(list_uuid)s, %(item_type)s, %(item_name)s, %(uom)s, %(qty)s, %(item_uuid)s, %(links)s) +ON CONFLICT (list_uuid, item_uuid) DO UPDATE +SET qty = %%site_name%%_shopping_list_items.qty + EXCLUDED.qty +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/shopping_lists.sql b/application/database_postgres/sql/INSERT/shopping_lists.sql new file mode 100644 index 0000000..2b3247f --- /dev/null +++ b/application/database_postgres/sql/INSERT/shopping_lists.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_shopping_lists +(name, description, author, creation_date, sub_type, list_type) +VALUES (%(name)s, %(description)s, %(author)s, %(creation_date)s, %(sub_type)s, %(list_type)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/sku_prefix.sql b/application/database_postgres/sql/INSERT/sku_prefix.sql new file mode 100644 index 0000000..6d43615 --- /dev/null +++ b/application/database_postgres/sql/INSERT/sku_prefix.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_sku_prefix +(uuid, name, description) +VALUES (%(uuid)s, %(name)s, %(description)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/transactions.sql b/application/database_postgres/sql/INSERT/transactions.sql new file mode 100644 index 0000000..dd0ee91 --- /dev/null +++ b/application/database_postgres/sql/INSERT/transactions.sql @@ -0,0 +1,6 @@ +INSERT INTO %%site_name%%_transactions +(timestamp, logistics_info_id, barcode, name, transaction_type, +quantity, description, user_id, data) +VALUES (%(timestamp)s, %(logistics_info_id)s, %(barcode)s, %(name)s, %(transaction_type)s, +%(quantity)s, %(description)s, %(user_id)s, %(data)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/vendors.sql b/application/database_postgres/sql/INSERT/vendors.sql new file mode 100644 index 0000000..6c8376a --- /dev/null +++ b/application/database_postgres/sql/INSERT/vendors.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_vendors +(vendor_name, vendor_address, creation_date, created_by, phone_number) +VALUES (%(vendor_name)s, %(vendor_address)s, %(creation_date)s, %(created_by)s, %(phone_number)s) +RETURNING *; \ No newline at end of file diff --git a/application/database_postgres/sql/INSERT/zones.sql b/application/database_postgres/sql/INSERT/zones.sql new file mode 100644 index 0000000..e6a7da2 --- /dev/null +++ b/application/database_postgres/sql/INSERT/zones.sql @@ -0,0 +1,4 @@ +INSERT INTO %%site_name%%_zones +(name, description) +VALUES (%(name)s, %(description)s) +RETURNING *; \ No newline at end of file diff --git a/application/recipes/__pycache__/recipe_processes.cpython-313.pyc b/application/recipes/__pycache__/recipe_processes.cpython-313.pyc index 5789dd4..9a36f64 100644 Binary files a/application/recipes/__pycache__/recipe_processes.cpython-313.pyc and b/application/recipes/__pycache__/recipe_processes.cpython-313.pyc differ diff --git a/application/recipes/recipe_processes.py b/application/recipes/recipe_processes.py index 45fa488..51293e1 100644 --- a/application/recipes/recipe_processes.py +++ b/application/recipes/recipe_processes.py @@ -112,7 +112,6 @@ def process_recipe_receipt(site_name, user_id, data:dict, conn=None): rp_item_uom = item['uom']['id'] item_stuff = database_recipes.selectItemTupleByUUID(site_name, (item['item_uuid'],), conn=conn) conv_factor = database_recipes.selectConversionTuple(site_name, (item_stuff['item_id'], rp_item_uom)) - print(conv_factor) conversion = conv_factor.get('conv_factor', 1) qty = float(item['qty']) / float(conversion) payload = { diff --git a/application/site_management/sql/insertLocationsTuple.sql b/application/site_management/sql/insertLocationsTuple.sql index 06f1f58..985e04a 100644 --- a/application/site_management/sql/insertLocationsTuple.sql +++ b/application/site_management/sql/insertLocationsTuple.sql @@ -1,4 +1,4 @@ INSERT INTO %%site_name%%_locations (uuid, name, zone_id) -VALUES (%s, %s, %s) +VALUES (%(uuid)s, %(name)s, %(zone_id)s) RETURNING *; \ No newline at end of file diff --git a/logs/database.log b/logs/database.log index bbcfd87..44eeccf 100644 --- a/logs/database.log +++ b/logs/database.log @@ -658,4 +658,49 @@ sql='SELECT * FROM test_vendors ORDER BY name ASC LIMIT %s OFFSET %s;') 2025-08-23 07:01:48.754381 --- ERROR --- DatabaseError(message='column rp_item.type does not existLINE 11: ... SELECT items.id AS item_id, rp_item.rp_id, rp_item.ty... ^', payload=(2025, 8), - sql='WITH arguments AS ( SELECT %s AS year, %s AS month),sum_cte AS ( SELECT mi.item_uuid, SUM(mil.quantity_on_hand)::FLOAT8 AS total_sum FROM main_item_locations mil JOIN main_items mi ON mil.part_id = mi.id GROUP BY mi.id ),cte_recipe_items AS ( SELECT items.id AS item_id, rp_item.rp_id, rp_item.type, rp_item.qty, rp_item.uom AS ingrediant_uom, item_info.uom AS item_uom, COALESCE(sum_cte.total_sum, 0) as quantity_on_hand FROM main_recipe_items rp_item LEFT JOIN sum_cte ON sum_cte.item_uuid = rp_item.item_uuid LEFT JOIN main_items items ON rp_item.item_uuid = items.item_uuid LEFT JOIN main_item_info item_info ON items.item_info_id = item_info.id ) SELECT events.*, COALESCE(row_to_json(recipes.*), '{}') as recipe, COALESCE(ritems.recipe_items, '{}') as recipe_itemsFROM main_plan_events eventsLEFT JOIN main_recipes recipes ON recipes.recipe_uuid = events.recipe_uuidLEFT JOIN LATERAL ( SELECT array_agg(row_to_json(ri.*)) AS recipe_items FROM cte_recipe_items ri WHERE ri.rp_id = recipes.id) ritems ON TRUEWHERE event_date_end >= make_date((SELECT year FROM arguments), (SELECT month FROM arguments), 1) AND event_date_start < (make_date((SELECT year FROM arguments), (SELECT month FROM arguments), 1) + INTERVAL '1 month');') \ No newline at end of file + sql='WITH arguments AS ( SELECT %s AS year, %s AS month),sum_cte AS ( SELECT mi.item_uuid, SUM(mil.quantity_on_hand)::FLOAT8 AS total_sum FROM main_item_locations mil JOIN main_items mi ON mil.part_id = mi.id GROUP BY mi.id ),cte_recipe_items AS ( SELECT items.id AS item_id, rp_item.rp_id, rp_item.type, rp_item.qty, rp_item.uom AS ingrediant_uom, item_info.uom AS item_uom, COALESCE(sum_cte.total_sum, 0) as quantity_on_hand FROM main_recipe_items rp_item LEFT JOIN sum_cte ON sum_cte.item_uuid = rp_item.item_uuid LEFT JOIN main_items items ON rp_item.item_uuid = items.item_uuid LEFT JOIN main_item_info item_info ON items.item_info_id = item_info.id ) SELECT events.*, COALESCE(row_to_json(recipes.*), '{}') as recipe, COALESCE(ritems.recipe_items, '{}') as recipe_itemsFROM main_plan_events eventsLEFT JOIN main_recipes recipes ON recipes.recipe_uuid = events.recipe_uuidLEFT JOIN LATERAL ( SELECT array_agg(row_to_json(ri.*)) AS recipe_items FROM cte_recipe_items ri WHERE ri.rp_id = recipes.id) ritems ON TRUEWHERE event_date_end >= make_date((SELECT year FROM arguments), (SELECT month FROM arguments), 1) AND event_date_start < (make_date((SELECT year FROM arguments), (SELECT month FROM arguments), 1) + INTERVAL '1 month');') +2025-08-23 09:44:32.979264 --- ERROR --- DatabaseError(message='can't adapt type 'dict'', + payload={'food_groups': [], 'ingrediants': [], 'nutrients': {}, 'expires': False, 'default_expiration': 0.0}, + sql='INSERT INTO test2_food_info(ingrediants, food_groups, nutrients, expires, default_expiration) VALUES (%(ingrediants)s, %(food_groups)s, %(nutrients)s, %(expires)s, %(default_expiration)s) RETURNING *;') +2025-08-23 09:47:55.518415 --- ERROR --- DatabaseError(message=''default_expiration'', + payload={'food_groups': '[]', 'ingrediants': '[]', 'nutrients': '{}', 'expires': False, 'default_exipration': 0.0}, + sql='INSERT INTO test2_food_info(ingrediants, food_groups, nutrients, expires, default_expiration) VALUES (%(ingrediants)s, %(food_groups)s, %(nutrients)s, %(expires)s, %(default_expiration)s) RETURNING *;') +2025-08-23 09:48:20.421772 --- ERROR --- DatabaseError(message='malformed array literal: "[]"LINE 3: VALUES ('[]', '[]', '{}', false, 0.0) ^DETAIL: "[" must introduce explicitly-specified array dimensions.', + payload={'food_groups': '[]', 'ingrediants': '[]', 'nutrients': '{}', 'expires': False, 'default_expiration': 0.0}, + sql='INSERT INTO test2_food_info(ingrediants, food_groups, nutrients, expires, default_expiration) VALUES (%(ingrediants)s, %(food_groups)s, %(nutrients)s, %(expires)s, %(default_expiration)s) RETURNING *;') +2025-08-23 09:56:18.404047 --- ERROR --- DatabaseError(message='malformed array literal: "[]"LINE 3: VALUES ('1234', '', 1.0, 1, 0.0, 0.0, 0.0, false, '[]') ^DETAIL: "[" must introduce explicitly-specified array dimensions.', + payload={'barcode': '1234', 'packaging': '', 'uom_quantity': 1.0, 'uom': 1, 'cost': 0.0, 'safety_stock': 0.0, 'lead_time_days': 0.0, 'ai_pick': False, 'prefixes': '[]'}, + sql='INSERT INTO test2_item_info(barcode, packaging, uom_quantity, uom, cost, safety_stock, lead_time_days, ai_pick, prefixes) VALUES (%(barcode)s, %(packaging)s, %(uom_quantity)s, %(uom)s, %(cost)s, %(safety_stock)s, %(lead_time_days)s, %(ai_pick)s, %(prefixes)s) RETURNING *;') +2025-08-23 10:00:20.053169 --- ERROR --- DatabaseError(message='relation "test2_locations" does not exist', + payload=CREATE TABLE IF NOT EXISTS test2_logistics_info( + id SERIAL PRIMARY KEY, + logistics_info_uuid UUID DEFAULT uuid_generate_v4(), + barcode VARCHAR(255), + primary_location INTEGER NOT NULL, + primary_zone INTEGER NOT 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 test2_locations(id), + CONSTRAINT fk_primary_zone + FOREIGN KEY(primary_zone) + REFERENCES test2_zones(id), + CONSTRAINT fk_auto_issue_location + FOREIGN KEY(auto_issue_location) + REFERENCES test2_locations(id), + CONSTRAINT fk_auto_issue_zone + FOREIGN KEY(auto_issue_zone) + REFERENCES test2_zones(id) +);, + sql='logistics_info') +2025-08-23 11:30:10.936510 --- ERROR --- DatabaseError(message='function gen_random_uuid4() does not existLINE 2: plan_uuid UUID PRIMARY KEY DEFAULT gen_random_uuid4(), ^HINT: No function matches the given name and argument types. You might need to add explicit type casts.', + payload=CREATE TABLE IF NOT EXISTS test2_plans( + plan_uuid UUID PRIMARY KEY DEFAULT gen_random_uuid4(), + plan_shortname VARCHAR(32) NOT NULL, + plan_description TEXT, + created_by INTEGER NOT NULL +) +, + sql='plans') \ No newline at end of file