CREATE TABLE switch_schedule (
 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.

 switch integer NOT NULL default '1',
--GENERATE::
--SERVICE::
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 schedule integer NOT NULL default '1',
--GENERATE::
--SERVICE::
--HELP_EN_INFO:
--HELP_EN_LONG:
--HELP_NL_INFO:
--HELP_NL_LONG:

 priority integer,
--GENERATE::
--SERVICE::
--HELP_EN_INFO:schedule priority
--HELP_EN_LONG:<p>A priority can be assigned to a redirect schedule. This can be used if there are two active schedules  
--HELP_EN_LONG:overlapping in time. Choose a priority number between 1 and 99, where 1 has the highest priority.</p>
--HELP_EN_LONG:<p>E.g. Schedule "Easter Sunday" gets a higher priority number than schedule "Weekend", therefore the 
--HELP_EN_LONG:first is assigned a "1" and the latter a "2". See the manual for more examples.</p>
--HELP_NL_INFO:schema prioriteit
--HELP_NL_LONG:<p>Een schema kan een prioriteit toegekend krijgen. Dit kan gebruikt worden als er twee actieve schema's 
--HELP_NL_LONG:zijn die elkaar in tijd overlappen. Kies een nummer tussen 1 en 99. 1 heeft de hoogste prioriteit. </p>                                                                                                  
--HELP_NL_LONG:<p>Voorbeeld: Tijdschema "Paaszondag" heeft voorrang boven schema "Weekend" en krijgen daarom 
--HELP_NL_LONG:respectievelijk prioriteit 1 en 2 toegewezen. De standaard weekend/gesloten-schema's kunnen het 
--HELP_NL_LONG:beste een zo laag mogelijke prioriteit krijgen (bv 50) zodat de feestdagen en vakanties makkelijk 
--HELP_NL_LONG:daarboven gezet kunnen worden (hogere prioriteit). Zie de handleiding voor meer voorbeelden.</p>  

 UNIQUE (switch, schedule),
 PRIMARY KEY  (id)
);

GRANT UPDATE, SELECT, INSERT, DELETE ON switch_schedule TO astium;
GRANT UPDATE, SELECT, INSERT, DELETE ON switch_schedule_id_seq TO astium;

-- switch_schedule
ALTER TABLE switch_schedule ADD CONSTRAINT switch_schedule_switch_constraint FOREIGN KEY (switch) REFERENCES switch (id);
ALTER TABLE switch_schedule ADD CONSTRAINT switch_schedule_schedule_constraint FOREIGN KEY (schedule) REFERENCES schedule (id);

-- remove old fields
alter table inbound drop column switch;
alter table inbound drop column sw_greeting;
alter table inbound drop column sw_phoneline1;
alter table inbound drop column sw_phoneline2;
alter table inbound drop column sw_phoneline3;
