-- SEQUENCE: tia.copy_log_clid

-- DROP SEQUENCE tia.copy_log_clid;

CREATE SEQUENCE tia.copy_log_clid;

ALTER SEQUENCE tia.copy_log_clid
  OWNER TO ansatt;


-- Table: tia.copy_log

-- DROP TABLE tia.copy_log;

CREATE TABLE tia.copy_log
(
  ts timestamp without time zone DEFAULT now(),
  error_text text COLLATE pg_catalog."default",
  clid integer NOT NULL DEFAULT nextval('tia.copy_log_clid'::regclass),
  CONSTRAINT copy_log_clid_pk PRIMARY KEY (clid)
)
WITH (
OIDS = TRUE
)
TABLESPACE pg_default;

ALTER TABLE tia.copy_log
  OWNER to ansatt;

GRANT ALL ON TABLE tia.copy_log TO ansatt;


-- Table: tia.orgunit

DROP TABLE tia.orgunit;

CREATE TABLE tia.orgunit
(
  category character varying(250) COLLATE pg_catalog."default",
  acronym character varying(50) COLLATE pg_catalog."default",
  orgunitname character varying(250) COLLATE pg_catalog."default",
  orgunitname_eng character varying(250) COLLATE pg_catalog."default",
  url character varying(250) COLLATE pg_catalog."default",
  valid_from date,
  orgunitid integer NOT NULL,
  parentid integer,
  costcenter_main integer,
  CONSTRAINT orgunits_pk_orgunitid PRIMARY KEY (orgunitid)
)
WITH (
OIDS = TRUE
)
TABLESPACE pg_default;

ALTER TABLE tia.orgunit
  OWNER to ansatt;

GRANT ALL ON TABLE tia.orgunit TO ansatt;

CREATE TABLE tia.orgunit_costcenter
(
  orgunitid integer,
  costcenter integer,
  name character varying(255)
)
WITH (
OIDS=TRUE
);
ALTER TABLE tia.orgunit_costcenter
  OWNER TO ansatt;

CREATE TABLE tia.costcenter
(
  costcenter integer NOT NULL,
  costcenter_full integer NOT NULL,
  pnummer integer,
  leiested character varying(10),
  internprosjekt_leiested character varying(100),
  bdm_tilh character varying(50),
  campus character varying(50),
  navn character varying(150),
  CONSTRAINT costcenter_costcenter_pk PRIMARY KEY (costcenter)
)
WITH (
OIDS=FALSE
);
ALTER TABLE tia.costcenter
  OWNER TO ansatt;




-- Table: tia.person

-- DROP TABLE tia.person;

CREATE TABLE tia.person
(
  personid integer NOT NULL,
  dateofbirth date,
  gender character varying COLLATE pg_catalog."default" DEFAULT 20,
  firstname character varying(200) COLLATE pg_catalog."default",
  lastname character varying(200) COLLATE pg_catalog."default",
  email character varying(250) COLLATE pg_catalog."default",
  publicationstatus character varying(100) COLLATE pg_catalog."default",
  username character varying(50) COLLATE pg_catalog."default",
  officeaddress character varying(250) COLLATE pg_catalog."default",
  mobilephone character varying(50) COLLATE pg_catalog."default",
  phone character varying(50) COLLATE pg_catalog."default",
  employee boolean,
  affiliated boolean,
  student boolean,
  url character varying COLLATE pg_catalog."default" DEFAULT 200,
  nationalidentitynumber integer,
  main_orgunit character varying(50) COLLATE pg_catalog."default",
  CONSTRAINT person_pk_personid PRIMARY KEY (personid)
)
WITH (
OIDS = TRUE
)
TABLESPACE pg_default;

ALTER TABLE tia.person
  OWNER to ansatt;

GRANT ALL ON TABLE tia.person TO ansatt;

-- Index: person_username

-- DROP INDEX tia.person_username;

CREATE INDEX person_username
  ON tia.person USING btree
  (username COLLATE pg_catalog."default")
TABLESPACE pg_default;

-- Table: tia.person_extension

-- DROP TABLE tia.person_extension;

CREATE TABLE tia.person_extension
(
  personid character varying COLLATE pg_catalog."default" NOT NULL,
  homestreet character varying COLLATE pg_catalog."default" DEFAULT 100,
  homezip character varying(50) COLLATE pg_catalog."default",
  CONSTRAINT person_extension_pk PRIMARY KEY (personid)
)
WITH (
OIDS = TRUE
)
TABLESPACE pg_default;

ALTER TABLE tia.person_extension
  OWNER to ansatt;

GRANT ALL ON TABLE tia.person_extension TO ansatt;

-- Table: tia.person_role

-- DROP TABLE tia.person_role;

CREATE TABLE tia.person_role
(
  personid integer NOT NULL,
  orgunitid integer,
  affiliation character varying(100) COLLATE pg_catalog."default",
  personrole character varying(50) COLLATE pg_catalog."default",
  rolename character varying(150) COLLATE pg_catalog."default",
  positiontype character varying(100) COLLATE pg_catalog."default",
  code character varying(100) COLLATE pg_catalog."default",
  prid integer NOT NULL,
  CONSTRAINT person_role_pk PRIMARY KEY (prid)
)
WITH (
OIDS = TRUE
)
TABLESPACE pg_default;

ALTER TABLE tia.person_role
  OWNER to ansatt;

GRANT ALL ON TABLE tia.person_role TO ansatt;

COMMENT ON COLUMN tia.person_role.prid
IS 'person_rol id';

-- Index: person_role_orgunitid

-- DROP INDEX tia.person_role_orgunitid;

CREATE INDEX person_role_orgunitid
  ON tia.person_role USING btree
  (orgunitid)
TABLESPACE pg_default;

-- Table: tia.person_role_extension

-- DROP TABLE tia.person_role_extension;

CREATE TABLE tia.person_role_extension
(
  personid integer NOT NULL,
  attribute_name character varying(150) COLLATE pg_catalog."default",
  attribute_value character varying(250) COLLATE pg_catalog."default",
  prid integer
)
WITH (
OIDS = TRUE
)
TABLESPACE pg_default;

ALTER TABLE tia.person_role_extension
  OWNER to ansatt;

GRANT ALL ON TABLE tia.person_role_extension TO ansatt;

COMMENT ON COLUMN tia.person_role_extension.prid
IS 'person_rol id';


-- Table: tia.student_temp

-- DROP TABLE tia.student_temp;

CREATE TABLE tia.student_temp
(
  personid integer NOT NULL,
  dateofbirth date,
  gender character varying COLLATE pg_catalog."default" DEFAULT 20,
  firstname character varying(200) COLLATE pg_catalog."default",
  lastname character varying(200) COLLATE pg_catalog."default",
  email character varying(250) COLLATE pg_catalog."default",
  publicationstatus character varying(100) COLLATE pg_catalog."default",
  username character varying(50) COLLATE pg_catalog."default",
  officeaddress character varying(250) COLLATE pg_catalog."default",
  mobilephone character varying(50) COLLATE pg_catalog."default",
  phone character varying(50) COLLATE pg_catalog."default",
  employee boolean,
  affiliated boolean,
  student boolean,
  url character varying(200) COLLATE pg_catalog."default",
  nationalidentitynumber integer,
  main_orgunit character varying(50) COLLATE pg_catalog."default",
  CONSTRAINT student_pk_personid PRIMARY KEY (personid)
)
WITH (
OIDS = TRUE
)
TABLESPACE pg_default;

ALTER TABLE tia.student_temp
  OWNER to ansatt;

GRANT ALL ON TABLE tia.student_temp TO ansatt;
