Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create schema of same name when user is created #171

Closed
joshlk opened this issue Jan 26, 2018 · 6 comments
Closed

Create schema of same name when user is created #171

joshlk opened this issue Jan 26, 2018 · 6 comments

Comments

@joshlk
Copy link

joshlk commented Jan 26, 2018

It common to have a schema that the same name as a user in a database. By default, postgres includes such a schema in its search_path automatically, see "section 5.8.3" in the docs.

It would be ace to have an option in ldap2pg that would create a schema of the same name when a user is newly created.

Thanks

@bersace
Copy link
Member

bersace commented Feb 13, 2018

Hi @joshlk actually, you can already do this by hacking the ACL mechanism :-) Just think grant as create and revoke as drop. This should look like:

acls:
  user_schema:
    type: datacl
    inspect: |
      SELECT NULL as "schema", rolname
      FROM pg_namespace n
      JOIN pg_authid ON rolname = nspname
    grant: |
      CREATE SCHEMA {role};
      ALTER USER {role} SET search_path {role},public;

sync_map:
- role: myuser
  grant:
    acl: user_schema
    database: mydb
    role: myuser

YMMV

@bersace bersace changed the title [Feature Request] Create schema of same name when user is created Create schema of same name when user is created Mar 1, 2018
@bersace
Copy link
Member

bersace commented May 13, 2019

I'm thinking of extending ldap2pg to help managing this case. Here is an idea:

- role:
    name: '{cn}'
    on_create: |
      CREATE SCHEMA {role};
    on_alter: |
      ALTER SCHEMA {old} RENAME TO {new};
    on_drop: |
      DROP SCHEMA {role} CASCADE;

What do you think of it ? Would you prefer global on_create, on_drop ? Thanks for the feedback.

@bersace
Copy link
Member

bersace commented Apr 3, 2020

Another solution would be the allows override of queries :

postgres:
  queries:
    role_create: |
      CREATE ROLE "{role}" WITH {options};
      COMMENT ON ROLE "{role}" IS '{comment}';
      CREATE SCHEMA "{role}";
      ALTER ROLE "{role}" SET search_path = "{role}",public;

@jeanpommier
Copy link
Contributor

I'm thinking of extending ldap2pg to help managing this case. Here is an idea:

- role:
    name: '{cn}'
    on_create: |
      CREATE SCHEMA {role};
    on_alter: |
      ALTER SCHEMA {old} RENAME TO {new};
    on_drop: |
      DROP SCHEMA {role} CASCADE;

@bersace, is it still considered ? This looks quite interesting. Would definitely be useful for me !

@alehaa
Copy link

alehaa commented May 30, 2022

Would you prefer global on_create, on_drop ? Thanks for the feedback.

I would like to see both. Some queries might be useful on a global level, others just for specific roles.

@bersace
Copy link
Member

bersace commented Oct 18, 2023

Closing in favor of #565.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants