BEGIN;

-- Copyright (c) 1997-now, NeoNova BV, The Netherlands. All rights Reserved.
--
-- This software is the copyrighted work of NeoNova BV.
-- Use of the software is subject to the general business terms and conditions of NeoNova BV
-- and its related transaction documents like license sheets or other written notices.#
-- Any reproduction or redistribution of the software not in accordance with the license terms
-- is expressly prohibited by law, and may result in severe civil and criminally penalties.
-- Violators will be prosecuted to the maximum extent possible.

CREATE TABLE parkinglot (
 id serial,

 created timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Creation Date
--HELP_EN_LONG:The date and time this record was created.
--HELP_NL_INFO:Datum aanmaak
--HELP_NL_LONG:De tijd en datum waarop dit is aangemaakt.

 lastupdate timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Last Update
--HELP_EN_LONG:The date and time this record was updated.
--HELP_NL_INFO:Laatste wijziging
--HELP_NL_LONG:De tijd en datum van laatste wijziging.

 status varchar(8) NOT NULL default 'active'
   CHECK (status IN ('active', 'deleted')),
--HELP_EN_INFO:status
--HELP_EN_LONG:The status of the parkinglot box.
--HELP_NL_INFO:status
--HELP_NL_LONG:Status van dit parkeervlak.

 phoneline integer NOT NULL default '1',
--HELP_EN_INFO: Extension
--HELP_EN_LONG: The extension for the parkinglot.
--HELP_NL_INFO: Extensie
--HELP_NL_LONG: Het nummer (extensie) van dit parkeervlak. 

 name varchar(32) NOT NULL default '',
--HELP_EN_INFO:parkinglot name
--HELP_EN_LONG:The name for this parkinglot.
--HELP_NL_INFO:naam parkeervlak
--HELP_NL_LONG:De naam van dit parkeervlak.

 lastused timestamp,
--HELP_EN_INFO: Last used
--HELP_EN_LONG: The date on which the parkinglot was last used. 
--HELP_NL_INFO: Laatst gebruikt
--HELP_NL_LONG: De datum dat het parkeervlak voor het laatst is gebruikt. 

 description varchar(256) not NULL default '',
--HELP_EN_INFO: Description
--HELP_EN_LONG: A description of the parkinglot.
--HELP_NL_INFO: Omschrijving
--HELP_NL_LONG: Geef een omschrijving voor dit parkeervlak. 

 first varchar(16) not NULL default '',
--HELP_EN_INFO: First extension
--HELP_EN_LONG: The extension of the first parking slot
--HELP_NL_INFO: Eerste extensie
--HELP_NL_LONG: De extensie van het eerste vak in dit parkeervlak

 last varchar(16) not NULL default '',
--HELP_EN_INFO: Last extension
--HELP_EN_LONG: The extension of the last parking slot.
--HELP_NL_INFO: Laatste extensie
--HELP_NL_LONG: De extensie van het laatste vak in dit parkeervlak

 maxtime integer default '60',
--HELP_EN_INFO:maximum parkinglot time
--HELP_EN_LONG:Maximum time that a caller can be waiting in the parkinglot. The minimum is 10 seconds.
--HELP_NL_INFO:maximum wachttijd
--HELP_NL_LONG:De maximale tijd dat iemand in het parkeervlak kan staan. Het minimum is 10 seconden.

 music varchar(64) NOT NULL default 'default',
--HELP_EN_INFO:music on hold
--HELP_EN_LONG:<p>Music on Hold for this parkinglot. Choose from the available categories. 'Default' (easy listening),
--HELP_EN_LONG:'Ringing' (the tone you hear you are trying to call someone) and 'Beepbeep'
--HELP_EN_LONG:are default Music on Hold types.</p>
--HELP_EN_LONG:<p>You can also upload your own MP3 files or streams.</p>
--HELP_NL_INFO:wachtmuziek
--HELP_NL_LONG:<p>Wachtmuziek voor dit parkeervlak. Kies uit de standaard categorieen 'Standaard' (easy listening),
--HELP_NL_LONG:'Ringing' (dezelfde toon die je hoort als de telefoon aan de andere kant overgaat) of 'Beepbeep'.</p>
--HELP_NL_LONG:<p>U kunt ook uw eigen MP3-bestanden of MP3-streams uploaden. </p>

 announce varchar(3) NOT NULL default 'yes'
   CHECK (announce IN ('yes', 'no')),
--HELP_EN_INFO:announce
--HELP_EN_LONG:If yes, the system will tell you the parking extension to call was parked to.
--HELP_NL_INFO:kondig aan
--HELP_NL_LONG:Indien Ja, dan zal het systeem de extensie uitspreken waarop het gesprek geparkeerd staat.

 PRIMARY KEY  (id)
);

GRANT UPDATE, SELECT, INSERT, DELETE ON parkinglot TO astium;
GRANT UPDATE, SELECT, INSERT, DELETE ON parkinglot_id_seq TO astium;
INSERT INTO parkinglot (status, description) VALUES ('deleted', 'empty');
ALTER TABLE parkinglot ADD CONSTRAINT parkinglot_phoneline_constraint FOREIGN KEY (phoneline) REFERENCES phoneline (id);

alter table contact add column parkinglot integer;
update contact set parkinglot = '1' where parkinglot IS NULL;
alter table contact alter column parkinglot set default '1';
alter table contact alter column parkinglot set not null;
ALTER TABLE contact ADD CONSTRAINT contact_parkinglot_constraint FOREIGN KEY (parkinglot) REFERENCES parkinglot (id);

COMMIT;
