Reset using connectionString instead of rootConnectionString?
See original GitHub issueI am trying to “start from scratch” using graphile/migrate to manage a database. I’m making strides, but I am pretty sure there are some issues with graphile-migrate reset
- it throws permissions errors when I reset the database. I’m trying to do things exactly as in starter
, just writing things from scratch. here are some samples:
BEGIN;
GRANT CONNECT ON DATABASE :DATABASE_NAME TO :DATABASE_OWNER;
GRANT CONNECT ON DATABASE :DATABASE_NAME TO :DATABASE_AUTHENTICATOR;
GRANT ALL ON DATABASE :DATABASE_NAME TO :DATABASE_OWNER;
-- Some extensions require superuser privileges, so we create them before migration time.
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public;
CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA public;
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
COMMIT;
export DATABASE_URL="postgresql://${DATABASE_AUTHENTICATOR}:${DATABASE_AUTHENTICATOR_PASSWORD}@${POSTGRES_HOST}:5432/${DATABASE_NAME}"
export SHADOW_DATABASE_URL="postgresql://${DATABASE_AUTHENTICATOR}:${DATABASE_AUTHENTICATOR_PASSWORD}@${POSTGRES_HOST}:5432/${DATABASE_NAME}_shadow"
export ROOT_DATABASE_URL="postgresql://${DATABASE_OWNER}:${DATABASE_OWNER_PASSWORD}@${POSTGRES_HOST}/${POSTGRES_DB}"
and this is the database initialization script:
await this.pg(`DROP DATABASE IF EXISTS "${env.DATABASE_NAME};"`);
await this.pg(`DROP DATABASE IF EXISTS "${env.DATABASE_NAME}_shadow";`);
await this.pg(`DROP DATABASE IF EXISTS "${env.DATABASE_NAME}_test";`);
await this.pg(`DROP ROLE IF EXISTS "${env.DATABASE_VISITOR}";`);
await this.pg(`DROP ROLE IF EXISTS "${env.DATABASE_AUTHENTICATOR}";`);
await this.pg(`DROP ROLE IF EXISTS "${env.DATABASE_OWNER}";`);
await this.pg(`CREATE ROLE "${env.DATABASE_OWNER}" WITH LOGIN PASSWORD '${env.DATABASE_OWNER_PASSWORD}' ${env.NODE_ENV == 'development' ? 'SUPERUSER' : ''};`);
await this.pg(`CREATE ROLE "${env.DATABASE_AUTHENTICATOR}" WITH LOGIN PASSWORD '${env.DATABASE_AUTHENTICATOR_PASSWORD}' NOINHERIT;`);
await this.pg(`CREATE ROLE "${env.DATABASE_VISITOR}";`);
await this.pg(`GRANT "${env.DATABASE_VISITOR}" TO "${env.DATABASE_AUTHENTICATOR}";`);
Everything works correctly if I do graphile-migrate reset
with connectionString being a superuser, but throws an error on “uuid-ossp” when it’s a non-superuser.
Knowing this, I can easily DATABASE_URL=$ROOT_DATABASE_URL graphile-migrate reset
, but it’d be good to reset using root (right?).
Tnanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Connection Strings and Configuration Files - ADO.NET
Learn how to store connection strings for ADO.NET applications in an application configuration file, as a best practice for security and ...
Read more >The ultimate guide to connection strings in web.config
Learn everything there is to know about connection strings in web.config. From setting up SQL Server using Windows Authentication to ...
Read more >Passing application's connection string down to a Repository ...
I am aware that when using EntityFramework the DbContext is already inejcted down to the repository class library. I am not using Entity...
Read more >MySQL connection strings - ConnectionStrings.com
Connection strings for MySQL. Connect using MySqlConnection, MySQLDriverCS, SevenObjects MySqlClient, ... From 6.2.1 use the SslMode option instead.
Read more >MySqlConnection.ConnectionString Property
Name Default Description
Initial Catalog. ‑or‑. Database mysql The name of the database to use intially
Password. ‑or‑. pwd The password for the MySQL account...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@benjie the docs actually clearly state this:
So, whoops! Sorry for the noise here.
Getting back on track for this issue: @dts in the context of migrate if
connectionString
is not superuser, then you cannot perform actions that require superuser privs. You can get around this by using a script (see my post above).I’ve standardized on:
postgraphile
:pgConfig
: non-superuser (DATABASE_AUTHENTICATOR
in language of the starter)ownerConnectionString
: superuser, with app databasemigrate
:connectionString
: non-superuser, a user that has all privs on the database, but is not a superuser. this is the same user my node js app uses to run manual queries.rootConnectionString
: superuser, with databasetemplate1
@abeluck Beware of using
rootConnectionString
withtemplate1
- if you accidentally install extensions there rather than reconnecting to your relevant database then all database created from then onwards will contain those extensions.