

--------------------------------------------------------------------------
-------------- global.room changes ---------------------------------------
--------------------------------------------------------------------------
-- adding "comments" field
alter table global.room add column comments text;

-- adding old_name_id column
alter table global.room add column old_name_id integer;

-- seting the default for the old_name_id
alter table global.room alter column old_name_id set default 0;

-- adding fk check
alter table global.room add 
  constraint c_room_fk_old_name_id foreign key(old_name_id) references global.translate(id)
  match full
  on update cascade
  on delete set default;

-- adding forgoten fk check for name_id
alter table global.room add 
  constraint c_room_fk_name_id foreign key(name_id) references global.translate(id)
  match full
  on update cascade
  on delete set default;


-- removing loc_max_x/y
alter table global.room drop column loc_max_x;
alter table global.room drop column loc_max_y;

-- renaming loc_min_x/y
alter table global.room rename column loc_min_x to x;
alter table global.room rename column loc_min_y to y;

-- renaming loc_url to map_name
alter table global.room rename column loc_url to map_name;

-------------------------------------------------------------------------
--------------- global.buliding changes ---------------------------------
-------------------------------------------------------------------------

-- removing loc_max_x/y
alter table global.building drop column loc_max_x;
alter table global.building drop column loc_max_y;

-- renaming loc_min_x/y
alter table global.building rename column loc_min_x to x;
alter table global.building rename column loc_min_y to y;

-- renaming loc_url to map_name
alter table global.building rename column loc_url to map_name;



-------------------------------------------------------------------------
--------------- global.roombook drop ------------------------------------
-------------------------------------------------------------------------

drop table global.roombook;


-------------------------------------------------------------------------
--------------- changing "comment" to "comments" ------------------------
-------------------------------------------------------------------------

-- i change "comment" named fields to "comments" named fields
-- in order not to clash with reserved PostgreSQL words: comment

alter table global.object rename column comment to comments;

alter table person.person rename column comment to comments;

alter table person.p2history rename column comment to comments;

