The Database

The sales database has been created using MySQL version 8 and consists of 12 tables and 10 stored procedures. A diagram of the relationships between the tables is shown below together with a description of the usage of each item

The following list outlines the purpose of each data table.

Table NameDescription
tbproductHolds product information
tbproductsupplierLinks product to supplier
tbpurchaseorderSupplier purchase orders
tbreportsettingReport configuration
tbsaleRecords sales header data
tbsale_reportingReporting subset of sales table
tbsalelineSales line data
tbsaleline_reportingReporting subset of sales line
tbstocksiloGroups stock received from supplier
tbstoreStore information table
tbsupplierinvoiceInvoices received from suppliers should match with purchase orders
tbunknownprodsupDefault value for reports if supplier yet to be allocated to a product

Stored procedures are used to manipulate the data and are called by various routes and jobs within Talend. In the proof of concept they are called by the root user but in a practical environment this would be a considerable security risk and a database user would be created specifically for this purpose with sufficient privileges for the reqiuired tasks only.

Procedure NameDescription
AllSalesByRegionGet sales totals from reporting tables grouped by region and store.
CheckAssignedSupplierChecks if a product has been assigned to a supplier, returns 1 or 0.
CheckProductSupplierValuesChecks if a supplier and product exist for given parameters, returns 1 or 0.
CreateProductSiloCreate a new product silo for a given product code, purchase order number and order quantity.
GetProductSupplierGets the supplier from a given product code or uses the default table if none have been assigned.
GetSalesByRegionGets sales by store code by product for the defined region using the reporting tables.
ProcessSalesGets cost price from active silo and decrements quantity, returns yes or no depending if reorder level is reached.
RaisePurchaseOrderCreate a purchase order record for a supplied product.
SupplierInvoiceCreate a supplier invoice record from a purchase order.
UpdateReportSettingUpdate the report configuration table and load sales reporting delta for the day.

SQL scripts to build the database can be downloaded from GitHub

  1. RetailPOCDatabase.sql – Database build script
  2. RetailPOC_SQLData.sql – Sample data script
  3. RetailPOC_CleanData.sql – Clear data script

Run the build script to create the database followed by the data script to load in sample data. To clear data and reset the system run the third script followed by the data load.

If you don’t have MySQL available the community edition can be downloaded here.

Close Bitnami banner
Bitnami