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

 phone integer NOT NULL default '1',
--GENERATE:phoneconfig:NEW.phone:
--HELP_EN_INFO:phone
--HELP_EN_LONG:The phone for which this button is defined.
--HELP_NL_INFO:telefoon
--HELP_NL_LONG:De telefoon waarvoor deze toets is gedefinieerd.

 contacttype integer NOT NULL default '1',
--HELP_EN_INFO:contact type
--HELP_EN_LONG:The contact type for which this ringtone is valid.
--HELP_NL_INFO:contact type
--HELP_NL_LONG:Het type contact voor deze beltoon.

 ringtone integer NOT NULL default '1',
--HELP_EN_INFO:ringtone
--HELP_EN_LONG:The ringtone to play with this contact type.
--HELP_NL_INFO:beltoon
--HELP_NL_LONG:De beltoon die bij dit type contact afgespeeld moet worden.

 PRIMARY KEY  (id)
);

create unique index phoneringtone_phone_contacttype_index on phoneringtone(phone, contacttype);

GRANT UPDATE, SELECT, INSERT, DELETE ON phoneringtone TO astium;
GRANT UPDATE, SELECT, INSERT, DELETE ON phoneringtone_id_seq TO astium;

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

 phonetype integer NOT NULL default '1',
--GENERATE:phoneconfig:NEW.phone:
--HELP_EN_INFO:phonetype
--HELP_EN_LONG:The phone type for which this button is defined.
--HELP_NL_INFO:telefoontype
--HELP_NL_LONG:Het type telefoon waarvoor deze knop wordt gedefinieerd.

 contact integer NOT NULL default '1',
--GENERATE:phoneconfig:NEW.phone:
--HELP_EN_INFO:contact
--HELP_EN_LONG:The contact whose phone buttons are defined.
--HELP_NL_INFO:persoon
--HELP_NL_LONG:De persoon wiens telefoontoetsen hier gedefinieerd worden.

 contacttype integer NOT NULL default '1',
--HELP_EN_INFO:contact type
--HELP_EN_LONG:The contact type for which this ringtone is played. 
--HELP_NL_INFO:contact type
--HELP_NL_LONG:Het type contact waarvoor deze beltoon geldt.

 ringtone integer NOT NULL default '1',
--HELP_EN_INFO:ringtone
--HELP_EN_LONG:The ringtone to play with this contact type.
--HELP_NL_INFO:ringtoon
--HELP_NL_LONG:De beltoon die bij dit type contactpersoon afgespeeld moet worden.

 PRIMARY KEY  (id)
);

create unique index phonetypecontactringtone_phonetype_contact_contacttype_index on
       phonetypecontactringtone(phonetype, contact, contacttype);

GRANT UPDATE, SELECT, INSERT, DELETE ON phonetypecontactringtone TO astium;
GRANT UPDATE, SELECT, INSERT, DELETE ON phonetypecontactringtone_id_seq TO astium;

-- astglobals
alter table astglobals add column created timestamp with time zone;
alter table astglobals alter column created set default CURRENT_TIMESTAMP;
update astglobals set created = now() where created is null;
alter table astglobals alter column created set not null;

alter table astglobals add column lastupdate timestamp with time zone;
alter table astglobals alter column lastupdate set default CURRENT_TIMESTAMP;
update astglobals set lastupdate = now() where lastupdate is null;
alter table astglobals alter column lastupdate set not null;

-- astium
alter table astium add column created timestamp with time zone;
alter table astium alter column created set default CURRENT_TIMESTAMP;
update astium set created = now() where created is null;
alter table astium alter column created set not null;

alter table astium add column lastupdate timestamp with time zone;
alter table astium alter column lastupdate set default CURRENT_TIMESTAMP;
update astium set lastupdate = now() where lastupdate is null;
alter table astium alter column lastupdate set not null;

-- astmessage
alter table astmessage add column created timestamp with time zone;
alter table astmessage alter column created set default CURRENT_TIMESTAMP;
update astmessage set created = now() where created is null;
alter table astmessage alter column created set not null;

alter table astmessage add column lastupdate timestamp with time zone;
alter table astmessage alter column lastupdate set default CURRENT_TIMESTAMP;
update astmessage set lastupdate = now() where lastupdate is null;
alter table astmessage alter column lastupdate set not null;

-- billnotes
alter table billnotes add column created timestamp with time zone;
alter table billnotes alter column created set default CURRENT_TIMESTAMP;
update billnotes set created = now() where created is null;
alter table billnotes alter column created set not null;

alter table billnotes add column lastupdate timestamp with time zone;
alter table billnotes alter column lastupdate set default CURRENT_TIMESTAMP;
update billnotes set lastupdate = now() where lastupdate is null;
alter table billnotes alter column lastupdate set not null;

-- building
alter table building add column created timestamp with time zone;
alter table building alter column created set default CURRENT_TIMESTAMP;
update building set created = now() where created is null;
alter table building alter column created set not null;

alter table building add column lastupdate timestamp with time zone;
alter table building alter column lastupdate set default CURRENT_TIMESTAMP;
update building set lastupdate = now() where lastupdate is null;
alter table building alter column lastupdate set not null;

-- callrouting
alter table callrouting add column created timestamp with time zone;
alter table callrouting alter column created set default CURRENT_TIMESTAMP;
update callrouting set created = now() where created is null;
alter table callrouting alter column created set not null;

alter table callrouting add column lastupdate timestamp with time zone;
alter table callrouting alter column lastupdate set default CURRENT_TIMESTAMP;
update callrouting set lastupdate = now() where lastupdate is null;
alter table callrouting alter column lastupdate set not null;

-- card_b410p
alter table card_b410p add column created timestamp with time zone;
alter table card_b410p alter column created set default CURRENT_TIMESTAMP;
update card_b410p set created = now() where created is null;
alter table card_b410p alter column created set not null;

alter table card_b410p add column lastupdate timestamp with time zone;
alter table card_b410p alter column lastupdate set default CURRENT_TIMESTAMP;
update card_b410p set lastupdate = now() where lastupdate is null;
alter table card_b410p alter column lastupdate set not null;

-- card_duogsm
alter table card_duogsm add column created timestamp with time zone;
alter table card_duogsm alter column created set default CURRENT_TIMESTAMP;
update card_duogsm set created = now() where created is null;
alter table card_duogsm alter column created set not null;

alter table card_duogsm add column lastupdate timestamp with time zone;
alter table card_duogsm alter column lastupdate set default CURRENT_TIMESTAMP;
update card_duogsm set lastupdate = now() where lastupdate is null;
alter table card_duogsm alter column lastupdate set not null;

-- card_e100p
alter table card_e100p add column created timestamp with time zone;
alter table card_e100p alter column created set default CURRENT_TIMESTAMP;
update card_e100p set created = now() where created is null;
alter table card_e100p alter column created set not null;

alter table card_e100p add column lastupdate timestamp with time zone;
alter table card_e100p alter column lastupdate set default CURRENT_TIMESTAMP;
update card_e100p set lastupdate = now() where lastupdate is null;
alter table card_e100p alter column lastupdate set not null;

-- card_octobri
alter table card_octobri add column created timestamp with time zone;
alter table card_octobri alter column created set default CURRENT_TIMESTAMP;
update card_octobri set created = now() where created is null;
alter table card_octobri alter column created set not null;

alter table card_octobri add column lastupdate timestamp with time zone;
alter table card_octobri alter column lastupdate set default CURRENT_TIMESTAMP;
update card_octobri set lastupdate = now() where lastupdate is null;
alter table card_octobri alter column lastupdate set not null;

-- card_quadbri
alter table card_quadbri add column created timestamp with time zone;
alter table card_quadbri alter column created set default CURRENT_TIMESTAMP;
update card_quadbri set created = now() where created is null;
alter table card_quadbri alter column created set not null;

alter table card_quadbri add column lastupdate timestamp with time zone;
alter table card_quadbri alter column lastupdate set default CURRENT_TIMESTAMP;
update card_quadbri set lastupdate = now() where lastupdate is null;
alter table card_quadbri alter column lastupdate set not null;

-- card_quadgsm
alter table card_quadgsm add column created timestamp with time zone;
alter table card_quadgsm alter column created set default CURRENT_TIMESTAMP;
update card_quadgsm set created = now() where created is null;
alter table card_quadgsm alter column created set not null;

alter table card_quadgsm add column lastupdate timestamp with time zone;
alter table card_quadgsm alter column lastupdate set default CURRENT_TIMESTAMP;
update card_quadgsm set lastupdate = now() where lastupdate is null;
alter table card_quadgsm alter column lastupdate set not null;

-- card_t100p
alter table card_t100p add column created timestamp with time zone;
alter table card_t100p alter column created set default CURRENT_TIMESTAMP;
update card_t100p set created = now() where created is null;
alter table card_t100p alter column created set not null;

alter table card_t100p add column lastupdate timestamp with time zone;
alter table card_t100p alter column lastupdate set default CURRENT_TIMESTAMP;
update card_t100p set lastupdate = now() where lastupdate is null;
alter table card_t100p alter column lastupdate set not null;

-- card_tdm2400p
alter table card_tdm2400p add column created timestamp with time zone;
alter table card_tdm2400p alter column created set default CURRENT_TIMESTAMP;
update card_tdm2400p set created = now() where created is null;
alter table card_tdm2400p alter column created set not null;

alter table card_tdm2400p add column lastupdate timestamp with time zone;
alter table card_tdm2400p alter column lastupdate set default CURRENT_TIMESTAMP;
update card_tdm2400p set lastupdate = now() where lastupdate is null;
alter table card_tdm2400p alter column lastupdate set not null;

-- card_tdm400p
alter table card_tdm400p add column created timestamp with time zone;
alter table card_tdm400p alter column created set default CURRENT_TIMESTAMP;
update card_tdm400p set created = now() where created is null;
alter table card_tdm400p alter column created set not null;

alter table card_tdm400p add column lastupdate timestamp with time zone;
alter table card_tdm400p alter column lastupdate set default CURRENT_TIMESTAMP;
update card_tdm400p set lastupdate = now() where lastupdate is null;
alter table card_tdm400p alter column lastupdate set not null;

-- card_tdm410
alter table card_tdm410 add column created timestamp with time zone;
alter table card_tdm410 alter column created set default CURRENT_TIMESTAMP;
update card_tdm410 set created = now() where created is null;
alter table card_tdm410 alter column created set not null;

alter table card_tdm410 add column lastupdate timestamp with time zone;
alter table card_tdm410 alter column lastupdate set default CURRENT_TIMESTAMP;
update card_tdm410 set lastupdate = now() where lastupdate is null;
alter table card_tdm410 alter column lastupdate set not null;

-- card_tdm800p
alter table card_tdm800p add column created timestamp with time zone;
alter table card_tdm800p alter column created set default CURRENT_TIMESTAMP;
update card_tdm800p set created = now() where created is null;
alter table card_tdm800p alter column created set not null;

alter table card_tdm800p add column lastupdate timestamp with time zone;
alter table card_tdm800p alter column lastupdate set default CURRENT_TIMESTAMP;
update card_tdm800p set lastupdate = now() where lastupdate is null;
alter table card_tdm800p alter column lastupdate set not null;

-- card_te110p
alter table card_te110p add column created timestamp with time zone;
alter table card_te110p alter column created set default CURRENT_TIMESTAMP;
update card_te110p set created = now() where created is null;
alter table card_te110p alter column created set not null;

alter table card_te110p add column lastupdate timestamp with time zone;
alter table card_te110p alter column lastupdate set default CURRENT_TIMESTAMP;
update card_te110p set lastupdate = now() where lastupdate is null;
alter table card_te110p alter column lastupdate set not null;

-- card_te120p
alter table card_te120p add column created timestamp with time zone;
alter table card_te120p alter column created set default CURRENT_TIMESTAMP;
update card_te120p set created = now() where created is null;
alter table card_te120p alter column created set not null;

alter table card_te120p add column lastupdate timestamp with time zone;
alter table card_te120p alter column lastupdate set default CURRENT_TIMESTAMP;
update card_te120p set lastupdate = now() where lastupdate is null;
alter table card_te120p alter column lastupdate set not null;

-- card_te205p
alter table card_te205p add column created timestamp with time zone;
alter table card_te205p alter column created set default CURRENT_TIMESTAMP;
update card_te205p set created = now() where created is null;
alter table card_te205p alter column created set not null;

alter table card_te205p add column lastupdate timestamp with time zone;
alter table card_te205p alter column lastupdate set default CURRENT_TIMESTAMP;
update card_te205p set lastupdate = now() where lastupdate is null;
alter table card_te205p alter column lastupdate set not null;

-- card_te210p
alter table card_te210p add column created timestamp with time zone;
alter table card_te210p alter column created set default CURRENT_TIMESTAMP;
update card_te210p set created = now() where created is null;
alter table card_te210p alter column created set not null;

alter table card_te210p add column lastupdate timestamp with time zone;
alter table card_te210p alter column lastupdate set default CURRENT_TIMESTAMP;
update card_te210p set lastupdate = now() where lastupdate is null;
alter table card_te210p alter column lastupdate set not null;

-- card_te405p
alter table card_te405p add column created timestamp with time zone;
alter table card_te405p alter column created set default CURRENT_TIMESTAMP;
update card_te405p set created = now() where created is null;
alter table card_te405p alter column created set not null;

alter table card_te405p add column lastupdate timestamp with time zone;
alter table card_te405p alter column lastupdate set default CURRENT_TIMESTAMP;
update card_te405p set lastupdate = now() where lastupdate is null;
alter table card_te405p alter column lastupdate set not null;

-- card_te410p
alter table card_te410p add column created timestamp with time zone;
alter table card_te410p alter column created set default CURRENT_TIMESTAMP;
update card_te410p set created = now() where created is null;
alter table card_te410p alter column created set not null;

alter table card_te410p add column lastupdate timestamp with time zone;
alter table card_te410p alter column lastupdate set default CURRENT_TIMESTAMP;
update card_te410p set lastupdate = now() where lastupdate is null;
alter table card_te410p alter column lastupdate set not null;

-- card_unogsm
alter table card_unogsm add column created timestamp with time zone;
alter table card_unogsm alter column created set default CURRENT_TIMESTAMP;
update card_unogsm set created = now() where created is null;
alter table card_unogsm alter column created set not null;

alter table card_unogsm add column lastupdate timestamp with time zone;
alter table card_unogsm alter column lastupdate set default CURRENT_TIMESTAMP;
update card_unogsm set lastupdate = now() where lastupdate is null;
alter table card_unogsm alter column lastupdate set not null;

-- card_x100p
alter table card_x100p add column created timestamp with time zone;
alter table card_x100p alter column created set default CURRENT_TIMESTAMP;
update card_x100p set created = now() where created is null;
alter table card_x100p alter column created set not null;

alter table card_x100p add column lastupdate timestamp with time zone;
alter table card_x100p alter column lastupdate set default CURRENT_TIMESTAMP;
update card_x100p set lastupdate = now() where lastupdate is null;
alter table card_x100p alter column lastupdate set not null;

-- certificate_store
alter table certificate_store add column created timestamp with time zone;
alter table certificate_store alter column created set default CURRENT_TIMESTAMP;
update certificate_store set created = now() where created is null;
alter table certificate_store alter column created set not null;

alter table certificate_store add column lastupdate timestamp with time zone;
alter table certificate_store alter column lastupdate set default CURRENT_TIMESTAMP;
update certificate_store set lastupdate = now() where lastupdate is null;
alter table certificate_store alter column lastupdate set not null;

-- channel
alter table channel add column created timestamp with time zone;
alter table channel alter column created set default CURRENT_TIMESTAMP;
update channel set created = now() where created is null;
alter table channel alter column created set not null;

alter table channel add column lastupdate timestamp with time zone;
alter table channel alter column lastupdate set default CURRENT_TIMESTAMP;
update channel set lastupdate = now() where lastupdate is null;
alter table channel alter column lastupdate set not null;

-- company
alter table company add column created timestamp with time zone;
alter table company alter column created set default CURRENT_TIMESTAMP;
update company set created = now() where created is null;
alter table company alter column created set not null;

alter table company add column lastupdate timestamp with time zone;
alter table company alter column lastupdate set default CURRENT_TIMESTAMP;
update company set lastupdate = now() where lastupdate is null;
alter table company alter column lastupdate set not null;

-- conference_log
alter table conference_log add column created timestamp with time zone;
alter table conference_log alter column created set default CURRENT_TIMESTAMP;
update conference_log set created = now() where created is null;
alter table conference_log alter column created set not null;

alter table conference_log add column lastupdate timestamp with time zone;
alter table conference_log alter column lastupdate set default CURRENT_TIMESTAMP;
update conference_log set lastupdate = now() where lastupdate is null;
alter table conference_log alter column lastupdate set not null;

-- conference
alter table conference add column lastupdate timestamp with time zone;
alter table conference alter column lastupdate set default CURRENT_TIMESTAMP;
update conference set lastupdate = now() where lastupdate is null;
alter table conference alter column lastupdate set not null;

-- contact_department
alter table contact_department add column created timestamp with time zone;
alter table contact_department alter column created set default CURRENT_TIMESTAMP;
update contact_department set created = now() where created is null;
alter table contact_department alter column created set not null;

alter table contact_department add column lastupdate timestamp with time zone;
alter table contact_department alter column lastupdate set default CURRENT_TIMESTAMP;
update contact_department set lastupdate = now() where lastupdate is null;
alter table contact_department alter column lastupdate set not null;

-- contact_number
alter table contact_number add column created timestamp with time zone;
alter table contact_number alter column created set default CURRENT_TIMESTAMP;
update contact_number set created = now() where created is null;
alter table contact_number alter column created set not null;

alter table contact_number add column lastupdate timestamp with time zone;
alter table contact_number alter column lastupdate set default CURRENT_TIMESTAMP;
update contact_number set lastupdate = now() where lastupdate is null;
alter table contact_number alter column lastupdate set not null;

-- contact_pickupgroup
alter table contact_pickupgroup add column created timestamp with time zone;
alter table contact_pickupgroup alter column created set default CURRENT_TIMESTAMP;
update contact_pickupgroup set created = now() where created is null;
alter table contact_pickupgroup alter column created set not null;

alter table contact_pickupgroup add column lastupdate timestamp with time zone;
alter table contact_pickupgroup alter column lastupdate set default CURRENT_TIMESTAMP;
update contact_pickupgroup set lastupdate = now() where lastupdate is null;
alter table contact_pickupgroup alter column lastupdate set not null;

-- contact
alter table contact add column lastupdate timestamp with time zone;
alter table contact alter column lastupdate set default CURRENT_TIMESTAMP;
update contact set lastupdate = now() where lastupdate is null;
alter table contact alter column lastupdate set not null;

-- contacttype
alter table contacttype add column created timestamp with time zone;
alter table contacttype alter column created set default CURRENT_TIMESTAMP;
update contacttype set created = now() where created is null;
alter table contacttype alter column created set not null;

alter table contacttype add column lastupdate timestamp with time zone;
alter table contacttype alter column lastupdate set default CURRENT_TIMESTAMP;
update contacttype set lastupdate = now() where lastupdate is null;
alter table contacttype alter column lastupdate set not null;

-- country
alter table country add column created timestamp with time zone;
alter table country alter column created set default CURRENT_TIMESTAMP;
update country set created = now() where created is null;
alter table country alter column created set not null;

alter table country add column lastupdate timestamp with time zone;
alter table country alter column lastupdate set default CURRENT_TIMESTAMP;
update country set lastupdate = now() where lastupdate is null;
alter table country alter column lastupdate set not null;

-- dahdi_channel
alter table dahdi_channel add column created timestamp with time zone;
alter table dahdi_channel alter column created set default CURRENT_TIMESTAMP;
update dahdi_channel set created = now() where created is null;
alter table dahdi_channel alter column created set not null;

alter table dahdi_channel add column lastupdate timestamp with time zone;
alter table dahdi_channel alter column lastupdate set default CURRENT_TIMESTAMP;
update dahdi_channel set lastupdate = now() where lastupdate is null;
alter table dahdi_channel alter column lastupdate set not null;

-- department
alter table department add column created timestamp with time zone;
alter table department alter column created set default CURRENT_TIMESTAMP;
update department set created = now() where created is null;
alter table department alter column created set not null;

alter table department add column lastupdate timestamp with time zone;
alter table department alter column lastupdate set default CURRENT_TIMESTAMP;
update department set lastupdate = now() where lastupdate is null;
alter table department alter column lastupdate set not null;

-- dhcp_parameter
alter table dhcp_parameter add column created timestamp with time zone;
alter table dhcp_parameter alter column created set default CURRENT_TIMESTAMP;
update dhcp_parameter set created = now() where created is null;
alter table dhcp_parameter alter column created set not null;

alter table dhcp_parameter add column lastupdate timestamp with time zone;
alter table dhcp_parameter alter column lastupdate set default CURRENT_TIMESTAMP;
update dhcp_parameter set lastupdate = now() where lastupdate is null;
alter table dhcp_parameter alter column lastupdate set not null;

-- dhcp_parameter_type
alter table dhcp_parameter_type add column created timestamp with time zone;
alter table dhcp_parameter_type alter column created set default CURRENT_TIMESTAMP;
update dhcp_parameter_type set created = now() where created is null;
alter table dhcp_parameter_type alter column created set not null;

alter table dhcp_parameter_type add column lastupdate timestamp with time zone;
alter table dhcp_parameter_type alter column lastupdate set default CURRENT_TIMESTAMP;
update dhcp_parameter_type set lastupdate = now() where lastupdate is null;
alter table dhcp_parameter_type alter column lastupdate set not null;

-- dir_entry
alter table dir_entry add column created timestamp with time zone;
alter table dir_entry alter column created set default CURRENT_TIMESTAMP;
update dir_entry set created = now() where created is null;
alter table dir_entry alter column created set not null;

alter table dir_entry add column lastupdate timestamp with time zone;
alter table dir_entry alter column lastupdate set default CURRENT_TIMESTAMP;
update dir_entry set lastupdate = now() where lastupdate is null;
alter table dir_entry alter column lastupdate set not null;

-- disa
alter table disa add column created timestamp with time zone;
alter table disa alter column created set default CURRENT_TIMESTAMP;
update disa set created = now() where created is null;
alter table disa alter column created set not null;

alter table disa add column lastupdate timestamp with time zone;
alter table disa alter column lastupdate set default CURRENT_TIMESTAMP;
update disa set lastupdate = now() where lastupdate is null;
alter table disa alter column lastupdate set not null;

-- dmz_to_external
alter table dmz_to_external add column created timestamp with time zone;
alter table dmz_to_external alter column created set default CURRENT_TIMESTAMP;
update dmz_to_external set created = now() where created is null;
alter table dmz_to_external alter column created set not null;

alter table dmz_to_external add column lastupdate timestamp with time zone;
alter table dmz_to_external alter column lastupdate set default CURRENT_TIMESTAMP;
update dmz_to_external set lastupdate = now() where lastupdate is null;
alter table dmz_to_external alter column lastupdate set not null;

-- dmz_to_internal
alter table dmz_to_internal add column created timestamp with time zone;
alter table dmz_to_internal alter column created set default CURRENT_TIMESTAMP;
update dmz_to_internal set created = now() where created is null;
alter table dmz_to_internal alter column created set not null;

alter table dmz_to_internal add column lastupdate timestamp with time zone;
alter table dmz_to_internal alter column lastupdate set default CURRENT_TIMESTAMP;
update dmz_to_internal set lastupdate = now() where lastupdate is null;
alter table dmz_to_internal alter column lastupdate set not null;

-- extensionrange
alter table extensionrange add column created timestamp with time zone;
alter table extensionrange alter column created set default CURRENT_TIMESTAMP;
update extensionrange set created = now() where created is null;
alter table extensionrange alter column created set not null;

alter table extensionrange add column lastupdate timestamp with time zone;
alter table extensionrange alter column lastupdate set default CURRENT_TIMESTAMP;
update extensionrange set lastupdate = now() where lastupdate is null;
alter table extensionrange alter column lastupdate set not null;

-- external_to_dmz
alter table external_to_dmz add column created timestamp with time zone;
alter table external_to_dmz alter column created set default CURRENT_TIMESTAMP;
update external_to_dmz set created = now() where created is null;
alter table external_to_dmz alter column created set not null;

alter table external_to_dmz add column lastupdate timestamp with time zone;
alter table external_to_dmz alter column lastupdate set default CURRENT_TIMESTAMP;
update external_to_dmz set lastupdate = now() where lastupdate is null;
alter table external_to_dmz alter column lastupdate set not null;

-- external_to_internal
alter table external_to_internal add column created timestamp with time zone;
alter table external_to_internal alter column created set default CURRENT_TIMESTAMP;
update external_to_internal set created = now() where created is null;
alter table external_to_internal alter column created set not null;

alter table external_to_internal add column lastupdate timestamp with time zone;
alter table external_to_internal alter column lastupdate set default CURRENT_TIMESTAMP;
update external_to_internal set lastupdate = now() where lastupdate is null;
alter table external_to_internal alter column lastupdate set not null;

-- fastdial_company
alter table fastdial_company add column created timestamp with time zone;
alter table fastdial_company alter column created set default CURRENT_TIMESTAMP;
update fastdial_company set created = now() where created is null;
alter table fastdial_company alter column created set not null;

alter table fastdial_company add column lastupdate timestamp with time zone;
alter table fastdial_company alter column lastupdate set default CURRENT_TIMESTAMP;
update fastdial_company set lastupdate = now() where lastupdate is null;
alter table fastdial_company alter column lastupdate set not null;

-- fastdial_contact
alter table fastdial_contact add column created timestamp with time zone;
alter table fastdial_contact alter column created set default CURRENT_TIMESTAMP;
update fastdial_contact set created = now() where created is null;
alter table fastdial_contact alter column created set not null;

alter table fastdial_contact add column lastupdate timestamp with time zone;
alter table fastdial_contact alter column lastupdate set default CURRENT_TIMESTAMP;
update fastdial_contact set lastupdate = now() where lastupdate is null;
alter table fastdial_contact alter column lastupdate set not null;

-- fdpin
alter table fdpin add column created timestamp with time zone;
alter table fdpin alter column created set default CURRENT_TIMESTAMP;
update fdpin set created = now() where created is null;
alter table fdpin alter column created set not null;

alter table fdpin add column lastupdate timestamp with time zone;
alter table fdpin alter column lastupdate set default CURRENT_TIMESTAMP;
update fdpin set lastupdate = now() where lastupdate is null;
alter table fdpin alter column lastupdate set not null;

-- host
alter table host add column created timestamp with time zone;
alter table host alter column created set default CURRENT_TIMESTAMP;
update host set created = now() where created is null;
alter table host alter column created set not null;

alter table host add column lastupdate timestamp with time zone;
alter table host alter column lastupdate set default CURRENT_TIMESTAMP;
update host set lastupdate = now() where lastupdate is null;
alter table host alter column lastupdate set not null;

-- inbound_schedule
alter table inbound_schedule add column created timestamp with time zone;
alter table inbound_schedule alter column created set default CURRENT_TIMESTAMP;
update inbound_schedule set created = now() where created is null;
alter table inbound_schedule alter column created set not null;

alter table inbound_schedule add column lastupdate timestamp with time zone;
alter table inbound_schedule alter column lastupdate set default CURRENT_TIMESTAMP;
update inbound_schedule set lastupdate = now() where lastupdate is null;
alter table inbound_schedule alter column lastupdate set not null;

-- inbound
alter table inbound add column created timestamp with time zone;
alter table inbound alter column created set default CURRENT_TIMESTAMP;
update inbound set created = now() where created is null;
alter table inbound alter column created set not null;

alter table inbound add column lastupdate timestamp with time zone;
alter table inbound alter column lastupdate set default CURRENT_TIMESTAMP;
update inbound set lastupdate = now() where lastupdate is null;
alter table inbound alter column lastupdate set not null;

-- internal_to_dmz
alter table internal_to_dmz add column created timestamp with time zone;
alter table internal_to_dmz alter column created set default CURRENT_TIMESTAMP;
update internal_to_dmz set created = now() where created is null;
alter table internal_to_dmz alter column created set not null;

alter table internal_to_dmz add column lastupdate timestamp with time zone;
alter table internal_to_dmz alter column lastupdate set default CURRENT_TIMESTAMP;
update internal_to_dmz set lastupdate = now() where lastupdate is null;
alter table internal_to_dmz alter column lastupdate set not null;

-- internal_to_external
alter table internal_to_external add column created timestamp with time zone;
alter table internal_to_external alter column created set default CURRENT_TIMESTAMP;
update internal_to_external set created = now() where created is null;
alter table internal_to_external alter column created set not null;

alter table internal_to_external add column lastupdate timestamp with time zone;
alter table internal_to_external alter column lastupdate set default CURRENT_TIMESTAMP;
update internal_to_external set lastupdate = now() where lastupdate is null;
alter table internal_to_external alter column lastupdate set not null;

-- ivroption
alter table ivroption add column created timestamp with time zone;
alter table ivroption alter column created set default CURRENT_TIMESTAMP;
update ivroption set created = now() where created is null;
alter table ivroption alter column created set not null;

alter table ivroption add column lastupdate timestamp with time zone;
alter table ivroption alter column lastupdate set default CURRENT_TIMESTAMP;
update ivroption set lastupdate = now() where lastupdate is null;
alter table ivroption alter column lastupdate set not null;

-- ivr
alter table ivr add column created timestamp with time zone;
alter table ivr alter column created set default CURRENT_TIMESTAMP;
update ivr set created = now() where created is null;
alter table ivr alter column created set not null;

alter table ivr add column lastupdate timestamp with time zone;
alter table ivr alter column lastupdate set default CURRENT_TIMESTAMP;
update ivr set lastupdate = now() where lastupdate is null;
alter table ivr alter column lastupdate set not null;

-- mailtime
alter table mailtime add column created timestamp with time zone;
alter table mailtime alter column created set default CURRENT_TIMESTAMP;
update mailtime set created = now() where created is null;
alter table mailtime alter column created set not null;

alter table mailtime add column lastupdate timestamp with time zone;
alter table mailtime alter column lastupdate set default CURRENT_TIMESTAMP;
update mailtime set lastupdate = now() where lastupdate is null;
alter table mailtime alter column lastupdate set not null;

-- moh
alter table moh add column created timestamp with time zone;
alter table moh alter column created set default CURRENT_TIMESTAMP;
update moh set created = now() where created is null;
alter table moh alter column created set not null;

alter table moh add column lastupdate timestamp with time zone;
alter table moh alter column lastupdate set default CURRENT_TIMESTAMP;
update moh set lastupdate = now() where lastupdate is null;
alter table moh alter column lastupdate set not null;

-- national_dialplan
alter table national_dialplan add column created timestamp with time zone;
alter table national_dialplan alter column created set default CURRENT_TIMESTAMP;
update national_dialplan set created = now() where created is null;
alter table national_dialplan alter column created set not null;

alter table national_dialplan add column lastupdate timestamp with time zone;
alter table national_dialplan alter column lastupdate set default CURRENT_TIMESTAMP;
update national_dialplan set lastupdate = now() where lastupdate is null;
alter table national_dialplan alter column lastupdate set not null;

-- network
alter table network add column created timestamp with time zone;
alter table network alter column created set default CURRENT_TIMESTAMP;
update network set created = now() where created is null;
alter table network alter column created set not null;

alter table network add column lastupdate timestamp with time zone;
alter table network alter column lastupdate set default CURRENT_TIMESTAMP;
update network set lastupdate = now() where lastupdate is null;
alter table network alter column lastupdate set not null;

-- nightsettings
alter table nightsettings add column created timestamp with time zone;
alter table nightsettings alter column created set default CURRENT_TIMESTAMP;
update nightsettings set created = now() where created is null;
alter table nightsettings alter column created set not null;

alter table nightsettings add column lastupdate timestamp with time zone;
alter table nightsettings alter column lastupdate set default CURRENT_TIMESTAMP;
update nightsettings set lastupdate = now() where lastupdate is null;
alter table nightsettings alter column lastupdate set not null;

-- pagegroup_phone
alter table pagegroup_phone add column created timestamp with time zone;
alter table pagegroup_phone alter column created set default CURRENT_TIMESTAMP;
update pagegroup_phone set created = now() where created is null;
alter table pagegroup_phone alter column created set not null;

alter table pagegroup_phone add column lastupdate timestamp with time zone;
alter table pagegroup_phone alter column lastupdate set default CURRENT_TIMESTAMP;
update pagegroup_phone set lastupdate = now() where lastupdate is null;
alter table pagegroup_phone alter column lastupdate set not null;

-- pagegroup
alter table pagegroup add column created timestamp with time zone;
alter table pagegroup alter column created set default CURRENT_TIMESTAMP;
update pagegroup set created = now() where created is null;
alter table pagegroup alter column created set not null;

alter table pagegroup add column lastupdate timestamp with time zone;
alter table pagegroup alter column lastupdate set default CURRENT_TIMESTAMP;
update pagegroup set lastupdate = now() where lastupdate is null;
alter table pagegroup alter column lastupdate set not null;

-- permissions
alter table permissions add column created timestamp with time zone;
alter table permissions alter column created set default CURRENT_TIMESTAMP;
update permissions set created = now() where created is null;
alter table permissions alter column created set not null;

alter table permissions add column lastupdate timestamp with time zone;
alter table permissions alter column lastupdate set default CURRENT_TIMESTAMP;
update permissions set lastupdate = now() where lastupdate is null;
alter table permissions alter column lastupdate set not null;

-- phonebutton
alter table phonebutton add column created timestamp with time zone;
alter table phonebutton alter column created set default CURRENT_TIMESTAMP;
update phonebutton set created = now() where created is null;
alter table phonebutton alter column created set not null;

alter table phonebutton add column lastupdate timestamp with time zone;
alter table phonebutton alter column lastupdate set default CURRENT_TIMESTAMP;
update phonebutton set lastupdate = now() where lastupdate is null;
alter table phonebutton alter column lastupdate set not null;

-- phonelegend
alter table phonelegend add column created timestamp with time zone;
alter table phonelegend alter column created set default CURRENT_TIMESTAMP;
update phonelegend set created = now() where created is null;
alter table phonelegend alter column created set not null;

alter table phonelegend add column lastupdate timestamp with time zone;
alter table phonelegend alter column lastupdate set default CURRENT_TIMESTAMP;
update phonelegend set lastupdate = now() where lastupdate is null;
alter table phonelegend alter column lastupdate set not null;

-- phoneline_forwarding
alter table phoneline_forwarding add column created timestamp with time zone;
alter table phoneline_forwarding alter column created set default CURRENT_TIMESTAMP;
update phoneline_forwarding set created = now() where created is null;
alter table phoneline_forwarding alter column created set not null;

alter table phoneline_forwarding add column lastupdate timestamp with time zone;
alter table phoneline_forwarding alter column lastupdate set default CURRENT_TIMESTAMP;
update phoneline_forwarding set lastupdate = now() where lastupdate is null;
alter table phoneline_forwarding alter column lastupdate set not null;

-- phoneline_member
alter table phoneline_member add column created timestamp with time zone;
alter table phoneline_member alter column created set default CURRENT_TIMESTAMP;
update phoneline_member set created = now() where created is null;
alter table phoneline_member alter column created set not null;

alter table phoneline_member add column lastupdate timestamp with time zone;
alter table phoneline_member alter column lastupdate set default CURRENT_TIMESTAMP;
update phoneline_member set lastupdate = now() where lastupdate is null;
alter table phoneline_member alter column lastupdate set not null;

-- phoneline_schedule
alter table phoneline_schedule add column created timestamp with time zone;
alter table phoneline_schedule alter column created set default CURRENT_TIMESTAMP;
update phoneline_schedule set created = now() where created is null;
alter table phoneline_schedule alter column created set not null;

alter table phoneline_schedule add column lastupdate timestamp with time zone;
alter table phoneline_schedule alter column lastupdate set default CURRENT_TIMESTAMP;
update phoneline_schedule set lastupdate = now() where lastupdate is null;
alter table phoneline_schedule alter column lastupdate set not null;

-- phoneline
alter table phoneline add column created timestamp with time zone;
alter table phoneline alter column created set default CURRENT_TIMESTAMP;
update phoneline set created = now() where created is null;
alter table phoneline alter column created set not null;

alter table phoneline add column lastupdate timestamp with time zone;
alter table phoneline alter column lastupdate set default CURRENT_TIMESTAMP;
update phoneline set lastupdate = now() where lastupdate is null;
alter table phoneline alter column lastupdate set not null;

-- phoneringtone
alter table phoneringtone add column created timestamp with time zone;
alter table phoneringtone alter column created set default CURRENT_TIMESTAMP;
update phoneringtone set created = now() where created is null;
alter table phoneringtone alter column created set not null;

alter table phoneringtone add column lastupdate timestamp with time zone;
alter table phoneringtone alter column lastupdate set default CURRENT_TIMESTAMP;
update phoneringtone set lastupdate = now() where lastupdate is null;
alter table phoneringtone alter column lastupdate set not null;

-- phonetypebutton
alter table phonetypebutton add column created timestamp with time zone;
alter table phonetypebutton alter column created set default CURRENT_TIMESTAMP;
update phonetypebutton set created = now() where created is null;
alter table phonetypebutton alter column created set not null;

alter table phonetypebutton add column lastupdate timestamp with time zone;
alter table phonetypebutton alter column lastupdate set default CURRENT_TIMESTAMP;
update phonetypebutton set lastupdate = now() where lastupdate is null;
alter table phonetypebutton alter column lastupdate set not null;

-- phonetypecontactbutton
alter table phonetypecontactbutton add column created timestamp with time zone;
alter table phonetypecontactbutton alter column created set default CURRENT_TIMESTAMP;
update phonetypecontactbutton set created = now() where created is null;
alter table phonetypecontactbutton alter column created set not null;

alter table phonetypecontactbutton add column lastupdate timestamp with time zone;
alter table phonetypecontactbutton alter column lastupdate set default CURRENT_TIMESTAMP;
update phonetypecontactbutton set lastupdate = now() where lastupdate is null;
alter table phonetypecontactbutton alter column lastupdate set not null;

-- phonetypecontactringtone
alter table phonetypecontactringtone add column created timestamp with time zone;
alter table phonetypecontactringtone alter column created set default CURRENT_TIMESTAMP;
update phonetypecontactringtone set created = now() where created is null;
alter table phonetypecontactringtone alter column created set not null;

alter table phonetypecontactringtone add column lastupdate timestamp with time zone;
alter table phonetypecontactringtone alter column lastupdate set default CURRENT_TIMESTAMP;
update phonetypecontactringtone set lastupdate = now() where lastupdate is null;
alter table phonetypecontactringtone alter column lastupdate set not null;

-- phonetypecontacttyperingtone
alter table phonetypecontacttyperingtone add column created timestamp with time zone;
alter table phonetypecontacttyperingtone alter column created set default CURRENT_TIMESTAMP;
update phonetypecontacttyperingtone set created = now() where created is null;
alter table phonetypecontacttyperingtone alter column created set not null;

alter table phonetypecontacttyperingtone add column lastupdate timestamp with time zone;
alter table phonetypecontacttyperingtone alter column lastupdate set default CURRENT_TIMESTAMP;
update phonetypecontacttyperingtone set lastupdate = now() where lastupdate is null;
alter table phonetypecontacttyperingtone alter column lastupdate set not null;

-- phonetyperingtone
alter table phonetyperingtone add column created timestamp with time zone;
alter table phonetyperingtone alter column created set default CURRENT_TIMESTAMP;
update phonetyperingtone set created = now() where created is null;
alter table phonetyperingtone alter column created set not null;

alter table phonetyperingtone add column lastupdate timestamp with time zone;
alter table phonetyperingtone alter column lastupdate set default CURRENT_TIMESTAMP;
update phonetyperingtone set lastupdate = now() where lastupdate is null;
alter table phonetyperingtone alter column lastupdate set not null;

-- pickupgroup
alter table pickupgroup add column created timestamp with time zone;
alter table pickupgroup alter column created set default CURRENT_TIMESTAMP;
update pickupgroup set created = now() where created is null;
alter table pickupgroup alter column created set not null;

alter table pickupgroup add column lastupdate timestamp with time zone;
alter table pickupgroup alter column lastupdate set default CURRENT_TIMESTAMP;
update pickupgroup set lastupdate = now() where lastupdate is null;
alter table pickupgroup alter column lastupdate set not null;

-- plugin
alter table plugin add column created timestamp with time zone;
alter table plugin alter column created set default CURRENT_TIMESTAMP;
update plugin set created = now() where created is null;
alter table plugin alter column created set not null;

alter table plugin add column lastupdate timestamp with time zone;
alter table plugin alter column lastupdate set default CURRENT_TIMESTAMP;
update plugin set lastupdate = now() where lastupdate is null;
alter table plugin alter column lastupdate set not null;

-- presence
alter table presence add column created timestamp with time zone;
alter table presence alter column created set default CURRENT_TIMESTAMP;
update presence set created = now() where created is null;
alter table presence alter column created set not null;

alter table presence add column lastupdate timestamp with time zone;
alter table presence alter column lastupdate set default CURRENT_TIMESTAMP;
update presence set lastupdate = now() where lastupdate is null;
alter table presence alter column lastupdate set not null;

-- profile
alter table profile add column created timestamp with time zone;
alter table profile alter column created set default CURRENT_TIMESTAMP;
update profile set created = now() where created is null;
alter table profile alter column created set not null;

alter table profile add column lastupdate timestamp with time zone;
alter table profile alter column lastupdate set default CURRENT_TIMESTAMP;
update profile set lastupdate = now() where lastupdate is null;
alter table profile alter column lastupdate set not null;

-- queue_contact
alter table queue_contact add column created timestamp with time zone;
alter table queue_contact alter column created set default CURRENT_TIMESTAMP;
update queue_contact set created = now() where created is null;
alter table queue_contact alter column created set not null;

alter table queue_contact add column lastupdate timestamp with time zone;
alter table queue_contact alter column lastupdate set default CURRENT_TIMESTAMP;
update queue_contact set lastupdate = now() where lastupdate is null;
alter table queue_contact alter column lastupdate set not null;

-- queuelog
alter table queuelog add column created timestamp with time zone;
alter table queuelog alter column created set default CURRENT_TIMESTAMP;
update queuelog set created = now() where created is null;
alter table queuelog alter column created set not null;

alter table queuelog add column lastupdate timestamp with time zone;
alter table queuelog alter column lastupdate set default CURRENT_TIMESTAMP;
update queuelog set lastupdate = now() where lastupdate is null;
alter table queuelog alter column lastupdate set not null;

-- queue
alter table queue add column created timestamp with time zone;
alter table queue alter column created set default CURRENT_TIMESTAMP;
update queue set created = now() where created is null;
alter table queue alter column created set not null;

alter table queue add column lastupdate timestamp with time zone;
alter table queue alter column lastupdate set default CURRENT_TIMESTAMP;
update queue set lastupdate = now() where lastupdate is null;
alter table queue alter column lastupdate set not null;

-- rateplanschedule
alter table rateplanschedule add column created timestamp with time zone;
alter table rateplanschedule alter column created set default CURRENT_TIMESTAMP;
update rateplanschedule set created = now() where created is null;
alter table rateplanschedule alter column created set not null;

alter table rateplanschedule add column lastupdate timestamp with time zone;
alter table rateplanschedule alter column lastupdate set default CURRENT_TIMESTAMP;
update rateplanschedule set lastupdate = now() where lastupdate is null;
alter table rateplanschedule alter column lastupdate set not null;

-- rateplan
alter table rateplan add column created timestamp with time zone;
alter table rateplan alter column created set default CURRENT_TIMESTAMP;
update rateplan set created = now() where created is null;
alter table rateplan alter column created set not null;

alter table rateplan add column lastupdate timestamp with time zone;
alter table rateplan alter column lastupdate set default CURRENT_TIMESTAMP;
update rateplan set lastupdate = now() where lastupdate is null;
alter table rateplan alter column lastupdate set not null;

-- rate
alter table rate add column created timestamp with time zone;
alter table rate alter column created set default CURRENT_TIMESTAMP;
update rate set created = now() where created is null;
alter table rate alter column created set not null;

alter table rate add column lastupdate timestamp with time zone;
alter table rate alter column lastupdate set default CURRENT_TIMESTAMP;
update rate set lastupdate = now() where lastupdate is null;
alter table rate alter column lastupdate set not null;

-- ringtone
alter table ringtone add column created timestamp with time zone;
alter table ringtone alter column created set default CURRENT_TIMESTAMP;
update ringtone set created = now() where created is null;
alter table ringtone alter column created set not null;

alter table ringtone add column lastupdate timestamp with time zone;
alter table ringtone alter column lastupdate set default CURRENT_TIMESTAMP;
update ringtone set lastupdate = now() where lastupdate is null;
alter table ringtone alter column lastupdate set not null;

-- schedule
alter table schedule add column created timestamp with time zone;
alter table schedule alter column created set default CURRENT_TIMESTAMP;
update schedule set created = now() where created is null;
alter table schedule alter column created set not null;

alter table schedule add column lastupdate timestamp with time zone;
alter table schedule alter column lastupdate set default CURRENT_TIMESTAMP;
update schedule set lastupdate = now() where lastupdate is null;
alter table schedule alter column lastupdate set not null;

-- screenpos
alter table screenpos add column created timestamp with time zone;
alter table screenpos alter column created set default CURRENT_TIMESTAMP;
update screenpos set created = now() where created is null;
alter table screenpos alter column created set not null;

alter table screenpos add column lastupdate timestamp with time zone;
alter table screenpos alter column lastupdate set default CURRENT_TIMESTAMP;
update screenpos set lastupdate = now() where lastupdate is null;
alter table screenpos alter column lastupdate set not null;

-- sender_whitelist
alter table sender_whitelist add column created timestamp with time zone;
alter table sender_whitelist alter column created set default CURRENT_TIMESTAMP;
update sender_whitelist set created = now() where created is null;
alter table sender_whitelist alter column created set not null;

alter table sender_whitelist add column lastupdate timestamp with time zone;
alter table sender_whitelist alter column lastupdate set default CURRENT_TIMESTAMP;
update sender_whitelist set lastupdate = now() where lastupdate is null;
alter table sender_whitelist alter column lastupdate set not null;

-- sessions
alter table sessions add column created timestamp with time zone;
alter table sessions alter column created set default CURRENT_TIMESTAMP;
update sessions set created = now() where created is null;
alter table sessions alter column created set not null;

alter table sessions add column lastupdate timestamp with time zone;
alter table sessions alter column lastupdate set default CURRENT_TIMESTAMP;
update sessions set lastupdate = now() where lastupdate is null;
alter table sessions alter column lastupdate set not null;

-- soundfile
alter table soundfile add column created timestamp with time zone;
alter table soundfile alter column created set default CURRENT_TIMESTAMP;
update soundfile set created = now() where created is null;
alter table soundfile alter column created set not null;

alter table soundfile add column lastupdate timestamp with time zone;
alter table soundfile alter column lastupdate set default CURRENT_TIMESTAMP;
update soundfile set lastupdate = now() where lastupdate is null;
alter table soundfile alter column lastupdate set not null;

-- subnet
alter table subnet add column created timestamp with time zone;
alter table subnet alter column created set default CURRENT_TIMESTAMP;
update subnet set created = now() where created is null;
alter table subnet alter column created set not null;

alter table subnet add column lastupdate timestamp with time zone;
alter table subnet alter column lastupdate set default CURRENT_TIMESTAMP;
update subnet set lastupdate = now() where lastupdate is null;
alter table subnet alter column lastupdate set not null;

-- to_intf_external
alter table to_intf_external add column created timestamp with time zone;
alter table to_intf_external alter column created set default CURRENT_TIMESTAMP;
update to_intf_external set created = now() where created is null;
alter table to_intf_external alter column created set not null;

alter table to_intf_external add column lastupdate timestamp with time zone;
alter table to_intf_external alter column lastupdate set default CURRENT_TIMESTAMP;
update to_intf_external set lastupdate = now() where lastupdate is null;
alter table to_intf_external alter column lastupdate set not null;

-- trunk_lcr_trunk
alter table trunk_lcr_trunk add column created timestamp with time zone;
alter table trunk_lcr_trunk alter column created set default CURRENT_TIMESTAMP;
update trunk_lcr_trunk set created = now() where created is null;
alter table trunk_lcr_trunk alter column created set not null;

alter table trunk_lcr_trunk add column lastupdate timestamp with time zone;
alter table trunk_lcr_trunk alter column lastupdate set default CURRENT_TIMESTAMP;
update trunk_lcr_trunk set lastupdate = now() where lastupdate is null;
alter table trunk_lcr_trunk alter column lastupdate set not null;

-- trunk
alter table trunk add column created timestamp with time zone;
alter table trunk alter column created set default CURRENT_TIMESTAMP;
update trunk set created = now() where created is null;
alter table trunk alter column created set not null;

alter table trunk add column lastupdate timestamp with time zone;
alter table trunk alter column lastupdate set default CURRENT_TIMESTAMP;
update trunk set lastupdate = now() where lastupdate is null;
alter table trunk alter column lastupdate set not null;

-- voicemail
alter table voicemail add column lastupdate timestamp with time zone;
alter table voicemail alter column lastupdate set default CURRENT_TIMESTAMP;
update voicemail set lastupdate = now() where lastupdate is null;
alter table voicemail alter column lastupdate set not null;

-- zonedst
alter table zonedst add column created timestamp with time zone;
alter table zonedst alter column created set default CURRENT_TIMESTAMP;
update zonedst set created = now() where created is null;
alter table zonedst alter column created set not null;

alter table zonedst add column lastupdate timestamp with time zone;
alter table zonedst alter column lastupdate set default CURRENT_TIMESTAMP;
update zonedst set lastupdate = now() where lastupdate is null;
alter table zonedst alter column lastupdate set not null;

-- zonetab
alter table zonetab add column created timestamp with time zone;
alter table zonetab alter column created set default CURRENT_TIMESTAMP;
update zonetab set created = now() where created is null;
alter table zonetab alter column created set not null;

alter table zonetab add column lastupdate timestamp with time zone;
alter table zonetab alter column lastupdate set default CURRENT_TIMESTAMP;
update zonetab set lastupdate = now() where lastupdate is null;
alter table zonetab alter column lastupdate set not null;

CREATE OR REPLACE FUNCTION update_lastupdate_column() RETURNS TRIGGER AS '
  BEGIN
    NEW.lastupdate = NOW();
    RETURN NEW;
  END;
' LANGUAGE 'plpgsql';

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


