perseas / Pyrseas

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

Extension unaccent: duplication #218

Open vams1991 opened 4 years ago

vams1991 commented 4 years ago
extension unaccent:
  description: text search dictionary that removes accents
  owner: postgres
  schema: public
  version: '1.1'
text search dictionary unaccent:
    depends_on:
    - text search template unaccent
    options: rules = 'unaccent'
    owner: postgres
    template: unaccent
  text search template unaccent:
    init: public.unaccent_init
    lexize: public.unaccent_lexize

dbtoyaml seems to be be producing duplicate data(text search dictionary and template) which are already included in the extension.

Can we get a fix for this?

jmafc commented 4 years ago

My memory is quite rusty on this but I believe this may be fixed by tweaking the queries in pyrseas/dbobject/textsearch.py. If you grep -C1 "pg_depend" in that directory, you'll see a bunch of partial queries that read (for example),

AND o.oid NOT IN (
    SELECT objid FROM pg_depend WHERE deptype = 'e'
          AND classid = 'pg_opclass'::regclass)

I think similar clauses may have to be added to the textsearch.py queries to avoid the duplicates. [OTOH, I seem to recall someone criticizing these and suggesting a better way, but as I said, I'm rusty. @dvarrazzo @rmg Does this ring a bell?]

rmg commented 4 years ago

Not ringing any bells for me.

dvarrazzo commented 4 years ago

I remember pyrseas trying hard to avoid loading any object belonging to an extension, which means that every single query has to be special cased with a clause "and by the way, this shouldn't be fetched because belongs to an extension".

A simpler approach would be to load all the objects without caring if it belongs to an extension, and then prune away these objects down the line, and uniformly, replacing each object's dependency for an object into the extension with a dependency on the extension itself.

jmafc commented 4 years ago

Thanks Daniele. Yes, that's part of the reason why I had opened issue #185, but that's a major undertaking. So it seems that the only short term solution is adding yet more special case clauses fo the textsearch queries.