关系不存在(golang / mac OS)

时间:2018-12-27 13:42:08

标签: database postgresql go psql

我已经搜索了几个小时,我觉得我已经尝试了所有方法,但是从Go的代码以及转储的代码中,我仍然发现“关系不存在”。 PSQL数据库的输出。

以默认的postgres用户身份登录时:

来自\du的所有用户都在那,并且说它拥有正确的数据库 来自\dn的所有模式都在那里

尽管当我更改用户时,例如

\c myapp_db myapp_admin

运行\du\dn等,我什么也没得到

show search_path

也显示为“ myapp”,这是正确的。一切似乎都是正确的,但这种关系并不存在,这有什么用?

这是我加载的.sql文件,如下所示:

psql
\i thefile.sql
... runs and everything works granted, created, altered, etc.
\c myapp_db myapp_admin

然后我跑步

\dt

没有布宜诺斯艾利斯!没有关系!

有问题的SQL文件:

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;

有什么想法吗?我开始认为我的PostgreSQL安装有一些错误。

0 个答案:

没有答案