perseas / Pyrseas

Provides utilities for Postgres database schema versioning.
https://perseas.github.io/
BSD 3-Clause "New" or "Revised" License
397 stars 67 forks source link

Inconsistent quoting of user names in privilege information #192

Open olvidio opened 6 years ago

olvidio commented 6 years ago

from issue #191.

My process is: from database create yaml, and from that compare with other database and create sql.

The problem is sql: ALTER TABLE xxx OWNER H-dlb no put quotes in owner. First Modified /dbobject/init.py to add quotes in sql statement. Now I see the error was in yaml file. All references to schemas, grantor etc are with quotes, but not owner. If I add quotes in owner in yaml file, the sql file is correct.

jmafc commented 6 years ago

I'm afraid what you're stating is incorrect. If a table is owned by user H-dlb it should be shown in the YAML file in that manner, i.e., without any quotes, just as if the user had been named h_dlb which doesn't require quotes in any circumstance. As I mentioned in #191, I believe this has been fixed in the master branch. I will confirm this later today and let you know.

olvidio commented 6 years ago

well, I don't know... But why different owner/grantor? Here paste a table example of my scenario:

table d_matriculas_activ_dl:
    columns:
    - id_schema:
        default: public.idschema('H-dlbv'::text)
        inherited: true
        not_null: true
        type: integer
    - id_activ:
        inherited: true
        not_null: true
        type: bigint
    - id_asignatura:
        inherited: true
        not_null: true
        type: integer
    - id_nom:
        inherited: true
        not_null: true
        privileges:
        - orbixv:
          - select
        type: integer
    - id_situacion:
        inherited: true
        type: smallint
    - preceptor:
        default: 'false'
        inherited: true
        type: boolean
- id_nivel:
        inherited: true
        type: integer
    - nota_num:
        inherited: true
        type: numeric(3,1)
    - nota_max:
        inherited: true
        type: smallint
    - id_preceptor:
        inherited: true
        type: integer
    depends_on:
    - function idschema(r_dl text)
    indexes:
      d_matriculas_dl_id_activ_idx:
        keys:
        - id_activ
      d_matriculas_dl_id_nom_idx:
        keys:
        - id_nom
      d_matriculas_dl_id_situacion_idx:
        access_method: hash
        keys:
        - id_situacion
    inherits:
    - publicv.d_matriculas_activ
    owner: H-dlbv
    privileges:
    - '"H-dlbv"':
        grantor: '"H-dlbv"'
        privs:
        - all
    - orbixv:
        grantor: '"H-dlbv"'
        privs:
        - insert
        - select
        - update
jmafc commented 6 years ago

Would you mind editing the comment so that it's easier to read: just add three backticks and "yaml" (``` yaml) on a line by itself before the copied text, and finish it off with three backticks. You can click the Preview button to verify the formatting. Thanks.

jmafc commented 6 years ago

I've verified the problem and changed the title accordingly. AFAIK the inconsistency is because the privilege information was added separately and late in the development of Pyrseas. FWIW, Postgres itself has the same inconsistent display. If I use \dt in psql on a table owned by user www-data, it shows everything without quotes:

 Schema | Name | Type  |  Owner   
--------+------+-------+----------
 test-1 | t1   | table | www-data

If I use \dp on the same table, it shows:

 Schema | Name | Type  |       Access privileges       | Column privileges | Policies 
--------+------+-------+-------------------------------+-------------------+----------
 test-1 | t1   | table | "www-data"=arwdDxt/"www-data" |                   | 

I'll see if it's not too difficult to fix the inconsistency on our side.

jmafc commented 6 years ago

@olvidio I'm afraid I haven't made much to resolve this issue. Please see https://pyrseas.wordpress.com/2018/09/12/the-future-of-pyrseas-revisited/ and let me know if you'd like to keep this open.