-- Schema: production
-- Brief: used by the Production component to persist the orders current state
-- Created by: rrosauro
-- Table schema_version: must be defined for database update through the Persistence Component
-- Update by: cnascimento
	-- Added table PicklistOrders 2022-10-20 11:00:00 -0200 (Wed, 20 OUC 2022)

CREATE TABLE schema_version AS
SELECT "$Author: rrosauro $" AS Author,
       "$Date: 2010-02-03 10:13:59 -0200 (Wed, 03 Feb 2010) $" AS LastModifiedAt,
       "$Revision: 8ccf520334e3c90e7403ebf85bf8255436eb0505$" AS Revision;
       
-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

CREATE TABLE ProductionOrders (
	OrderId				INTEGER PRIMARY KEY,
	Object				BLOB NOT NULL,
	CreatedAt			TIMESTAMP NOT NULL,
	Purged				BOOLEAN NOT NULL DEFAULT 0
);

CREATE INDEX IDX_ProductionOrders_CreatedAt ON ProductionOrders(CreatedAt);
-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

CREATE TABLE PicklistOrders
(
	Id      		INTEGER PRIMARY KEY AUTOINCREMENT,
    OrderId      	INTEGER,
    OrderIdCount 	VARCHAR(100) NULL,
    JIT          	VARCHAR(100) NOT NULL,
    Course       	VARCHAR(50) NULL,
    Data         	BLOB NOT NULL,
	CreatedAt    	TIMESTAMP NOT NULL,
    PrintOK     	BOOLEAN NOT NULL DEFAULT 0,
	UNIQUE(OrderId, JIT, Course)
);

CREATE INDEX IDX_Orders_OrderId_JIT_Course ON PicklistOrders(OrderId, JIT, Course);
-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

