I've been extensively searching for a few hours now and I feel like I've tried everything but I'm still getting that the 'relation does not exist', from both my code in Go, and also from dumping the output of the PSQL database.
when logged in as the default postgres user:
from \du
, all of the users are there and it says that it owns the correct database from \dn
, all of the schemas are there
though when I changer user, e.g.
\c myapp_db myapp_admin
running \du
, \dn
, etc. I get nothing
show search_path
also displays as 'myapp', which is correct. everything seems to be correct but the relation is not there, what gives?
Here is my .sql file which I loaded like so:
psql
\i thefile.sql
... runs and everything works granted, created, altered, etc.
\c myapp_db myapp_admin
then I run
\dt
and no bueno! there are no relations!
The SQL file in question:
CREATE USER myapp_admin WITH ENCRYPTED PASSWORD 'admin';
CREATE USER myapp_manager WITH ENCRYPTED PASSWORD 'manager';
CREATE USER myapp_user WITH ENCRYPTED PASSWORD 'user';
GRANT myapp_user TO myapp_manager;
GRANT myapp_manager TO myapp_admin;
CREATE DATABASE myapp_db;
REVOKE ALL ON DATABASE myapp_db FROM PUBLIC;
GRANT CONNECT ON DATABASE myapp_db to myapp_user;
CREATE SCHEMA myapp AUTHORIZATION myapp_admin;
SET search_path = myapp;
ALTER ROLE myapp_admin IN DATABASE myapp_db SET search_path = myapp;
ALTER ROLE myapp_manager IN DATABASE myapp_db SET search_path = myapp;
ALTER ROLE myapp_user IN DATABASE myapp_db SET search_path = myapp;
GRANT USAGE ON SCHEMA myapp to myapp_user;
GRANT CREATE ON SCHEMA myapp to myapp_admin;
CREATE TABLE myapp.account (
id bigserial primary key not null,
);
ALTER DEFAULT PRIVILEGES FOR ROLE myapp_admin
GRANT SELECT ON TABLES TO myapp_user; -- only read
ALTER DEFAULT PRIVILEGES FOR ROLE myapp_admin
GRANT INSERT, UPDATE, DELETE, TRUNCATE ON TABLES TO myapp_manager; -- + write, truncate
ALTER DEFAULT PRIVILEGES FOR ROLE myapp_admin
GRANT USAGE, SELECT, UPDATE ON SEQUENCES TO myapp_manager;
Any ideas what's going on here? I'm starting to think it's some error with my PostgreSQL installation.