ALTER TABLE object_acl 
  ALTER COLUMN object_id TYPE INT USING object_id::int;
ALTER TABLE object_acl 
  ALTER COLUMN auth_id   TYPE INT USING auth_id::int;

ALTER TABLE document ADD COLUMN company_id INT NULL;

CREATE TABLE ctags (
  entity VARCHAR NOT NULL,
  ctag  INTEGER NOT NULL DEFAULT 0
);

ALTER TABLE ctags ADD CONSTRAINT ctag_unique_entity
  UNIQUE (entity);

INSERT INTO ctags (entity) VALUES ('Person'); 
INSERT INTO ctags (entity) VALUES ('Enterprise');
INSERT INTO ctags (entity) VALUES ('Date');
INSERT INTO ctags (entity) VALUES ('Job');
INSERT INTO ctags (entity) VALUES ('Team');

ALTER TABLE company ADD COLUMN birthplace    VARCHAR(255) NULL;
ALTER TABLE company ADD COLUMN birthname     VARCHAR(255) NULL;
ALTER TABLE company ADD COLUMN family_status VARCHAR(255) NULL;
ALTER TABLE company ADD COLUMN citizenship   VARCHAR(255) NULL; -- CSV?!
ALTER TABLE company ADD COLUMN dayofdeath    TIMESTAMP WITH TIME ZONE NULL;

ALTER TABLE address ADD COLUMN district    VARCHAR(255) NULL;
ALTER TABLE address   ADD CONSTRAINT company_unique_adrtype
  UNIQUE ( company_id, type );

ALTER TABLE project ADD COLUMN parent_project_id INT NULL;

CREATE TABLE login_token (
  token           VARCHAR(4096) PRIMARY KEY,
  account_id      INT   NOT NULL,
  environment     TEXT  NULL,
  info            TEXT  NULL,
  creation_date   TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
  touch_date      TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
  timeout         INT DEFAULT 3600 NOT NULL,
  expiration_date TIMESTAMP WITH TIME ZONE NULL
);

ALTER TABLE job  ADD COLUMN owner_id INT;
UPDATE job SET owner_id = creator_id;
