-- Troca da tabela de pessoas para view do Alfa
-- nao funciona FK para view

ALTER TABLE baspersonlink DROP CONSTRAINT baspersonlink_personid_fkey;
ALTER TABLE baspersonoperationprocess DROP CONSTRAINT baspersonoperationprocess_personid_fkey;
ALTER TABLE gtcemailcontrolnotifyaquisition DROP CONSTRAINT gtcemailcontrolnotifyaquisition_personid_fkey;
ALTER TABLE gtcfavorite DROP CONSTRAINT gtcfavorite_personid_fkey;
ALTER TABLE gtcinterestsarea DROP CONSTRAINT gtcinterestsarea_personid_fkey;
ALTER TABLE gtcloan DROP CONSTRAINT gtcloan_personid_fkey;
ALTER TABLE gtcloanbetweenlibrary DROP CONSTRAINT gtcloanbetweenlibrary_personid_fkey;
ALTER TABLE gtcpenalty DROP CONSTRAINT gtcpenalty_personid_fkey;
ALTER TABLE gtcpersonconfig DROP CONSTRAINT gtcpersonconfig_personid_fkey;
ALTER TABLE gtcpersonlibraryunit DROP CONSTRAINT gtcpersonlibraryunit_personid_fkey;
ALTER TABLE gtcrequestchangeexemplarystatus DROP CONSTRAINT gtcrequestchangeexemplarystatus_personid_fkey;
ALTER TABLE gtcreserve DROP CONSTRAINT gtcreserve_personid_fkey; 

alter table basperson rename to basperson_table;
CREATE VIEW basperson AS
  SELECT *
    FROM dblink('dbname=alfa hostaddr=10.100.0.91 user=sagu_virtual password=sagu_virtual port=5432', 'SELECT id, nome, cidade, cep, rua, numero, complemento, bairro, email, senha FROM cmn_pessoas') AS  cmn_pessoas(personid integer, name varchar, city varchar, zipcode varchar, location varchar, number varchar, complement varchar, neighborhood text, email varchar, password integer); 
