Created
October 8, 2019 15:06
-
-
Save emidoots/8c435ed09368bbbf199a4a9f06675fab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE EXTENSION IF NOT EXISTS dblink; | |
CREATE OR REPLACE FUNCTION remote_exec(suffix text, query text) RETURNS void AS $$ | |
BEGIN | |
PERFORM dblink_exec('dbname=' || current_database() || suffix || ' password=MYPASSWORD user=' || current_user, query); | |
END; | |
$$ | |
LANGUAGE plpgsql; | |
CREATE OR REPLACE FUNCTION create_lsif_db() RETURNS void AS $$ | |
BEGIN | |
IF NOT EXISTS (SELECT FROM pg_catalog.pg_database WHERE datname = current_database() || '_lsif') THEN | |
PERFORM remote_exec('', 'CREATE DATABASE "' || current_database() || '_lsif" OWNER DEFAULT TEMPLATE template0 ENCODING ''UTF8'''); | |
END IF; | |
END; | |
$$ LANGUAGE plpgsql; | |
SELECT create_lsif_db(); | |
DROP FUNCTION create_lsif_db(); | |
SELECT remote_exec('_lsif', 'CREATE EXTENSION IF NOT EXISTS dblink;'); | |
UPDATE schema_migrations SET version='1528395595', dirty='f'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment