-- 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 switch (
 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.

 company integer default '1',
--GENERATE:/etc/asterisk/company%04d/extensions.conf:OLD.company:
--GENERATE:/etc/asterisk/company%04d/extensions.conf:NEW.company:
--SERVICE:asterisk:reload
--HELP_EN_INFO:company
--HELP_EN_LONG:the company this record belongs to.
--HELP_NL_INFO:bedrijf
--HELP_NL_LONG:het bedrijf waar deze gegevens bij horen.

 phoneline integer NOT NULL default '1',
--HELP_EN_INFO: Extension
--HELP_EN_LONG: The extension for this switch.
--HELP_NL_INFO: Intern nummer
--HELP_NL_LONG: De extensie van deze toepassing.

 status varchar(8) NOT NULL default 'active'
   CHECK (status IN ('active', 'deleted')),
--GENERATE:/etc/asterisk/company%04d/extensions.conf:NEW.company:
--SERVICE:asterisk:reload
--HELP_EN_INFO:status
--HELP_EN_LONG:The IVR menu status.
--HELP_NL_INFO:status
--HELP_NL_LONG:De status van dit IVR menu.

 name varchar(16) NOT NULL default 'empty',
--GENERATE:/etc/asterisk/company%04d/extensions.conf:NEW.company:
--SERVICE:asterisk:reload
--HELP_EN_INFO:name
--HELP_EN_LONG:Name of this switch.
--HELP_NL_INFO:naam
--HELP_NL_LONG:Naam voor deze switch.

 description varchar(256) NOT NULL default '',
--HELP_EN_INFO:Description
--HELP_EN_LONG:A description for this switch.
--HELP_NL_INFO:Omschrijving
--HELP_NL_LONG:Een omschrijving voor deze switch.

 position varchar(3) default 'off'
   CHECK (position IN ('on','off')),
--HELP_EN_INFO:Position
--HELP_EN_LONG:Current switch position
--HELP_NL_INFO:Stand
--HELP_NL_LONG:De stand van de schakelaar.

 PRIMARY KEY  (id)
);

GRANT UPDATE, SELECT, INSERT, DELETE ON switch TO astium;
GRANT UPDATE, SELECT, INSERT, DELETE ON switch_id_seq TO astium;

INSERT INTO switch (name, status) VALUES ('empty', 'deleted');

-- switch
CREATE TRIGGER update_lastupdate_trigger BEFORE UPDATE ON switch FOR EACH ROW EXECUTE PROCEDURE update_lastupdate_column();


