timescaledb/sql/common/cluster_setup_functions.sql
Erik Nordström 7b94c573ba Refactor directory structure and tests
- Directory structure now matches common practices
- Regression tests now run with pg_regress via the PGXS infrastructure.
- Unit tests do not integrate well with pg_regress and have to be run
  separately.
- Docker functionality is separate from main Makefile. Run with
  `make -f docker.mk` to build and `make -f docker.mk run` to run
  the database in a container.
2017-01-31 20:14:19 +01:00

35 lines
1.0 KiB
PL/PgSQL

CREATE SCHEMA IF NOT EXISTS _iobeamdb_internal;
CREATE SCHEMA IF NOT EXISTS _iobeamdb_meta;
CREATE SCHEMA IF NOT EXISTS _iobeamdb_meta_api;
CREATE SCHEMA IF NOT EXISTS _iobeamdb_data_api;
CREATE OR REPLACE FUNCTION _iobeamdb_internal.create_user_mapping(
cluster_user_row _iobeamdb_catalog.cluster_user,
server_name NAME
)
RETURNS VOID LANGUAGE PLPGSQL VOLATILE AS
$BODY$
BEGIN
EXECUTE format(
$$
CREATE USER MAPPING FOR %1$I SERVER %2$I OPTIONS (user '%1$s', password '%3$s')
$$, cluster_user_row.username, server_name, cluster_user_row.password);
END
$BODY$;
CREATE OR REPLACE FUNCTION _iobeamdb_internal.create_server(
server_name NAME,
hostname NAME,
port INT,
database_name NAME
)
RETURNS VOID LANGUAGE PLPGSQL VOLATILE AS
$BODY$
BEGIN
EXECUTE format(
$$
CREATE SERVER %I FOREIGN DATA WRAPPER postgres_fdw OPTIONS(host '%s', dbname '%s', port '%s');
$$, server_name, hostname, database_name, port);
END
$BODY$;