Skip to content
Snippets Groups Projects
Commit e852736d authored by Marcel Huber's avatar Marcel Huber
Browse files

use FORCE option when dropping database

try reuse existing database connection when switching users/databases

install extensions as superuser

use CREATE ROLE instead of CREATE USER
parent 3d8f5375
Branches
No related tags found
No related merge requests found
\echo \conninfo
\echo
\echo -n 'client encoding: '\encoding
\echo -n 'current client encoding: '\encoding
\echo
SET client_min_messages = ERROR;
\set user anguser
\set user anguser
\set password '\'angproj\''
\set database angproj
\set promptvar ''
\prompt 'DROP USER [':user'] and DROP DATABASE [':database'] if existing (\\q or Ctrl-C to abort)?' promptvar
\prompt 'DROP ROLE [':user'] and DROP DATABASE [':database'] if existing (\\q or Ctrl-C to abort)?' promptvar
:promptvar
DROP DATABASE if exists :database;
DROP USER if exists :user;
DROP DATABASE if exists :database (FORCE);
DROP ROLE if exists :user;
\echo -------------------------------------
\echo passwort for user :user = :password
\echo password for user :user = :password
\echo -------------------------------------
\echo
\prompt 'CREATE USER [':user'] and DATABASE [':database'] (\\q or Ctrl-C to abort)?' promptvar
\prompt 'CREATE ROLE [':user'] and DATABASE [':database'] (\\q or Ctrl-C to abort)?' promptvar
:promptvar
CREATE USER :user WITH PASSWORD :password;
CREATE DATABASE :database WITH OWNER :user ENCODING 'UTF8';
\c :database :user
CREATE ROLE :user WITH LOGIN PASSWORD :password;
CREATE DATABASE :database WITH OWNER=:user ENCODING='UTF8';
-- specify encoding to match your files encoding, usually UTF8
-- valid values are: 'UTF8', 'LATIN1', 'WIN1252'
\encoding 'UTF8'
-- create extensions
-- connect to DB as superuser
\c -reuse-previous=on :database postgres
-- install extensions
\ir 1_extensions.sql
-- connect to DB as owner
\c -reuse-previous=on :database :user
-- create schema
\ir 2_schema.sql
......@@ -60,4 +65,3 @@ CREATE DATABASE :database WITH OWNER :user ENCODING 'UTF8';
\unset ECHO
-- demonstrate constraints in action
\ir 6_constraints_tests.sql
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment