【问题标题】:Flyway grants via sql migrations - not working通过 sql 迁移授予 Flyway 授权 - 不起作用
【发布时间】:2020-07-03 20:05:20
【问题描述】:

conf 属性值:

flyway.defaultSchema= discussions
flyway.schemas= discussions

迁移如下:

+-----------+---------+------------------------------+--------+---------------------+---------+
| Category  | Version | Description                  | Type   | Installed On        | State   |
+-----------+---------+------------------------------+--------+---------------------+---------+
|           |         | << Flyway Schema Creation >> | SCHEMA | 2020-03-23 15:55:38 | Success |
| Versioned | 1       | INITIAL SETUP                | SQL    | 2020-03-23 15:55:38 | Success |
| Versioned | 2       | R INITIAL SETUP              | SQL    |                     | Pending |
| Versioned | 3       | R1 INITIAL SETUP             | SQL    |                     | Pending |
| Versioned | 4       | CREATE TABLE TEMPLATE        | SQL    |                     | Pending |

初始设置将创建表空间

create tablespace tablespace_dts location 'E:\Tablespace\tablespace_dts';

    create tablespace tablespace_mtd location 'E:\Tablespace\tablespace_mtd';

    create tablespace tablespace_ind location 'E:\Tablespace\tablespace_ind';

    create tablespace tablespace_out location 'E:\Tablespace\tablespace_out';

    create tablespace tablespace_temp location 'E:\Tablespace\tablespace_temp';

v2 将执行以下操作

begin

for c  in select 1 where not exists (select 1 from pg_user where  usename = 'app_user' ) loop
    raise notice 'in app_user';
    execute ' create user app_user with password ''adept''';

end loop;       

for c  in select 1 where exists (select 1 from pg_tablespace,pg_user where  spcname = 'tablespace_dts' and usename = 'app_user') loop
    raise notice 'in grant create on tablespace_dts to app_user';
    execute 'grant create on tablespace tablespace_dts to app_user with grant option';

end loop;   

for c  in select 1 where exists (select 1 from pg_tablespace,pg_user where  spcname = 'tablespace_mtd' and usename = 'app_user') loop
    raise notice 'in grant create on tablespace_mtd to app_user';
    execute 'grant create on tablespace tablespace_mtd to app_user with grant option';

end loop;

for c  in select 1 where exists (select 1 from pg_tablespace,pg_user where  spcname = 'tablespace_ind' and usename = 'app_user') loop
    raise notice 'in grant create on tablespace_ind to app_user';
    execute 'grant create on tablespace tablespace_ind to app_user with grant option';

end loop;


for c  in select 1 where exists (select 1 from pg_tablespace,pg_user where  spcname = 'tablespace_out' and usename = 'app_user') loop
    raise notice 'in grant create on tablespace_out to app_user';
    execute 'grant create on tablespace tablespace_out to app_user with grant option';

end loop;


for c  in select 1 where exists (select 1 from pg_tablespace,pg_user where  spcname = 'tablespace_temp' and usename = 'app_user') loop
    raise notice 'in grant create on tablespace_temp to app_user';
    execute 'grant create on tablespace tablespace_temp to app_user with grant option';

end loop;   

请注意,这里授予作品

v3 将执行以下操作:


grant usage on schema discussions to app_user;

grant select on all tables in schema discussions to app_user;   

grant update on all tables in schema discussions to app_user;

grant insert on all tables in schema discussions to app_user;

grant create on schema discussions to app_user with grant option;

v4 创建表让我们说 webhook_certificate

因此,当我尝试在架构讨论中从 app_user 查询表 webhook_certificate 时。 它说,权限被拒绝,尽管我在 v3 中授予了权限。

如果手动执行相同的 v3,它可以工作并允许访问 Discussions.webhook_certificate。 请注意:v3 被标记为成功,在 flyway 迁移期间没有失败。 那为什么赠款不起作用。

请帮忙。

【问题讨论】:

    标签: postgresql flyway migrate


    【解决方案1】:

    我已经想通了。 感谢大家的支持。

    创建表的V4应该在V3(授权脚本)之前执行。

    在现有对象上提供授权。 因此,在每次迁移时,我都需要在最后运行授权脚本。 为此,我可以使用 afterMigrate - 在成功迁移后运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-24
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-12
      相关资源
      最近更新 更多