Merge pull request #370 from Algunenano/ghost_matview

Ghost tables: Add missing tags
This commit is contained in:
Raúl Marín
2019-10-03 15:06:11 +02:00
committed by GitHub
3 changed files with 38 additions and 9 deletions
+3
View File
@@ -1,3 +1,6 @@
0.31.0 (XXXX-XX-XX)
* Ghost tables: Add missing tags (#370)
0.30.0 (2019-07-17) 0.30.0 (2019-07-17)
* Added new admin functions to connect CARTO with user FDW's (#369) * Added new admin functions to connect CARTO with user FDW's (#369)
+8 -8
View File
@@ -191,13 +191,13 @@ BEGIN
-- (not even using IF NOT EXIST to avoid throwing warnings) -- (not even using IF NOT EXIST to avoid throwing warnings)
IF NOT EXISTS ( SELECT * FROM pg_extension WHERE extname = 'postgres_fdw') THEN IF NOT EXISTS ( SELECT * FROM pg_extension WHERE extname = 'postgres_fdw') THEN
CREATE EXTENSION postgres_fdw; CREATE EXTENSION postgres_fdw;
RAISE NOTICE 'Created postgres_fdw extension'; RAISE NOTICE 'Created postgres_fdw EXTENSION';
END IF; END IF;
-- Create FDW first if it does not exist -- Create FDW first if it does not exist
IF NOT EXISTS ( SELECT * FROM pg_foreign_server WHERE srvname = fdw_objects_name) IF NOT EXISTS ( SELECT * FROM pg_foreign_server WHERE srvname = fdw_objects_name)
THEN THEN
EXECUTE FORMAT('CREATE SERVER %I FOREIGN DATA WRAPPER postgres_fdw', fdw_objects_name); EXECUTE FORMAT('CREATE SERVER %I FOREIGN DATA WRAPPER postgres_fdw', fdw_objects_name);
RAISE NOTICE 'Created server % using postgres_fdw', fdw_objects_name; RAISE NOTICE 'Created SERVER % using postgres_fdw', fdw_objects_name;
END IF; END IF;
-- Set FDW settings -- Set FDW settings
@@ -214,7 +214,7 @@ BEGIN
-- Create specific role for this -- Create specific role for this
IF NOT EXISTS ( SELECT 1 FROM pg_roles WHERE rolname = fdw_objects_name) THEN IF NOT EXISTS ( SELECT 1 FROM pg_roles WHERE rolname = fdw_objects_name) THEN
EXECUTE format('CREATE ROLE %I NOLOGIN', fdw_objects_name); EXECUTE format('CREATE ROLE %I NOLOGIN', fdw_objects_name);
RAISE NOTICE 'Created special role % to access the correponding FDW', fdw_objects_name; RAISE NOTICE 'Created special ROLE % to access the correponding FDW', fdw_objects_name;
END IF; END IF;
-- Transfer ownership of the server to the fdw role -- Transfer ownership of the server to the fdw role
@@ -225,7 +225,7 @@ BEGIN
-- so that we don't need to create a mapping for every user nor store credentials elsewhere -- so that we don't need to create a mapping for every user nor store credentials elsewhere
IF NOT EXISTS ( SELECT * FROM pg_user_mappings WHERE srvname = fdw_objects_name AND usename = 'public' ) THEN IF NOT EXISTS ( SELECT * FROM pg_user_mappings WHERE srvname = fdw_objects_name AND usename = 'public' ) THEN
EXECUTE FORMAT ('CREATE USER MAPPING FOR public SERVER %I', fdw_objects_name); EXECUTE FORMAT ('CREATE USER MAPPING FOR public SERVER %I', fdw_objects_name);
RAISE NOTICE 'Created user mapping for accesing foreign server %', fdw_objects_name; RAISE NOTICE 'Created USER MAPPING for accesing foreign server %', fdw_objects_name;
END IF; END IF;
-- Update user mapping settings -- Update user mapping settings
@@ -239,19 +239,19 @@ BEGIN
-- Grant usage on the wrapper and server to the fdw role -- Grant usage on the wrapper and server to the fdw role
EXECUTE FORMAT ('GRANT USAGE ON FOREIGN DATA WRAPPER postgres_fdw TO %I', fdw_objects_name); EXECUTE FORMAT ('GRANT USAGE ON FOREIGN DATA WRAPPER postgres_fdw TO %I', fdw_objects_name);
RAISE NOTICE 'Granted usage on the postgres_fdw to the role %', fdw_objects_name; RAISE NOTICE 'Granted USAGE on the postgres_fdw to the role %', fdw_objects_name;
EXECUTE FORMAT ('GRANT USAGE ON FOREIGN SERVER %I TO %I', fdw_objects_name, fdw_objects_name); EXECUTE FORMAT ('GRANT USAGE ON FOREIGN SERVER %I TO %I', fdw_objects_name, fdw_objects_name);
RAISE NOTICE 'Granted usage on the foreign server to the role %', fdw_objects_name; RAISE NOTICE 'Granted USAGE on the foreign server to the role %', fdw_objects_name;
-- Create schema if it does not exist. -- Create schema if it does not exist.
IF NOT EXISTS ( SELECT * from pg_namespace WHERE nspname=fdw_objects_name) THEN IF NOT EXISTS ( SELECT * from pg_namespace WHERE nspname=fdw_objects_name) THEN
EXECUTE FORMAT ('CREATE SCHEMA %I', fdw_objects_name); EXECUTE FORMAT ('CREATE SCHEMA %I', fdw_objects_name);
RAISE NOTICE 'Created schema % to host foreign tables', fdw_objects_name; RAISE NOTICE 'Created SCHEMA % to host foreign tables', fdw_objects_name;
END IF; END IF;
-- Give the fdw role ownership over the schema -- Give the fdw role ownership over the schema
EXECUTE FORMAT ('ALTER SCHEMA %I OWNER TO %I', fdw_objects_name, fdw_objects_name); EXECUTE FORMAT ('ALTER SCHEMA %I OWNER TO %I', fdw_objects_name, fdw_objects_name);
RAISE NOTICE 'Gave ownership on the schema % to %', fdw_objects_name, fdw_objects_name; RAISE NOTICE 'Gave ownership on the SCHEMA % to %', fdw_objects_name, fdw_objects_name;
-- TODO: Bring here the remote cdb_tablemetadata -- TODO: Bring here the remote cdb_tablemetadata
END END
+27 -1
View File
@@ -106,7 +106,33 @@ AS $$
CREATE EVENT TRIGGER link_ghost_tables CREATE EVENT TRIGGER link_ghost_tables
ON ddl_command_end ON ddl_command_end
WHEN TAG IN ('CREATE TABLE', 'SELECT INTO', 'DROP TABLE', 'ALTER TABLE', 'CREATE TRIGGER', 'DROP TRIGGER', 'CREATE VIEW', 'DROP VIEW', 'ALTER VIEW', 'CREATE FOREIGN TABLE', 'ALTER FOREIGN TABLE', 'DROP FOREIGN TABLE') WHEN TAG IN ('CREATE TABLE',
'SELECT INTO',
'DROP TABLE',
'ALTER TABLE',
'CREATE TRIGGER',
'DROP TRIGGER',
'ALTER TRIGGER',
'CREATE VIEW',
'DROP VIEW',
'ALTER VIEW',
'CREATE FOREIGN TABLE',
'ALTER FOREIGN TABLE',
'DROP FOREIGN TABLE',
'ALTER MATERIALIZED VIEW',
'CREATE MATERIALIZED VIEW',
'DROP MATERIALIZED VIEW',
'IMPORT FOREIGN SCHEMA',
'DROP EXTENSION',
'DROP SCHEMA',
'DROP SERVER',
'DROP TYPE')
EXECUTE PROCEDURE @extschema@.CDB_SaveDDLTransaction(); EXECUTE PROCEDURE @extschema@.CDB_SaveDDLTransaction();
END; END;
$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE; $$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE;