/* 
 * Copyright (C) 2018 Nauta Tecnològica, SCP - All Rights Reserved.
 * Unauthorized copying, publishing, commercial usage and/or distribution of this file,
 * via any medium, is strictly prohibited without the express permission of the owner.
 */
/**
 * Author:  Jordi Santacana <jordistc@nautalogica.com>
 * Created: 23/05/2018
 */

CREATE TABLE IF NOT EXISTS %tpl_prefix%task (
	id		INTEGER PRIMARY KEY
			AUTOINCREMENT
			NOT NULL
			UNIQUE,
	ppid
			INTEGER KEY
			DEFAULT NULL
			REFERENCES %tpl_prefix%proc(id)
				ON DELETE CASCADE,
	pid		INTEGER KEY
			DEFAULT NULL,
	inici
			DATETIME
			DEFAULT NULL,
	final
			DATETIME
			DEFAULT NULL
);

CREATE UNIQUE INDEX IF NOT EXISTS idx_%tpl_prefix%task_pids ON %tpl_prefix%task(ppid, pid);

CREATE TABLE IF NOT EXISTS %tpl_prefix%queue (
	id		INTEGER PRIMARY KEY
			AUTOINCREMENT NOT NULL
			UNIQUE,
	script		TEXT NOT NULL,
	params		BLOB,
	completat	INTEGER,
	datahora_inici	datetime DEFAULT NULL,
	datahora_final	datetime DEFAULT NULL,
	task_md5_hash	VARCHAR(32) NOT NULL
);
