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

Casts depending on extensions are not excluded #209

Open
declaresub opened this issue Nov 1, 2019 · 3 comments
Open

Casts depending on extensions are not excluded #209

declaresub opened this issue Nov 1, 2019 · 3 comments
Labels
extensions Problems caused by PG extensions

Comments

@declaresub
Copy link

Casts depending on extensions are not excluded. So sql generated for a database that should drop an extension like hstore looks like

BEGIN;
DROP EXTENSION hstore;
DROP CAST (public.hstore AS jsonb);
DROP CAST (public.hstore AS json);
DROP CAST (text[] AS public.hstore);
COMMIT;

Then once the extension is dropped, the next drop cast statement fails

This could be resolved, I think, either by updating the statement in Cast.query, or by emitting DROP CAST IF EXISTS statements.

@jmafc
Copy link
Member

jmafc commented Nov 3, 2019

I think maybe the way to fix this is in Cast.get_implied_deps or in Extension.get_implied_deps. @dvarrazzo your input would be appreciated.

@dvarrazzo
Copy link
Contributor

I think the treatment of the objects inside extensions, and the relative dependencies, can use some love.

Pretty much all the queries to read types from the system tables have grown some clause such as

              AND p.oid NOT IN (
                  SELECT objid FROM pg_depend WHERE deptype = 'e'

to avoid dealing with objects belonging to an extension. This results in the dependencies to these objects to be missed, and as a consequence missing the fact the object depend on the extension. We get by probably by creating the extension before pretty much everything else, but that doesn't feel correct.

Probably we should do something like:

  • load from the database all the objects, including the ones belonging to extensions.
  • create a complete graph of the dependencies
  • postprocess the graph: if A -> B is an arc saying that object A depends on B:
    • if A is in an extension, drop the arc from the graph
    • if B is in an extension E, then replace the arc with A -> E
    • (what if A belongs to E1 and B belongs to E2? Probably that should become E1 -> E2?)
  • by now no object in an extension should be explicitly represented in the graph
  • when dumping, avoid dumping objects from extensions

Now, I don't know exactly the problem behind this wrong drop order, but I feel like that the missing information of the dependency from the cast to the function is a cause. That dependency should be returned by Cast.get_implied_deps (it is probably ignored because the function, being part of an extension, is discarded) and transformed into a dependency of the cast on the extension.

@jmafc
Copy link
Member

jmafc commented Nov 5, 2019

I knew I could depend (pun intended) on you for a thoughtful response. Yes, unfortunately, Pyrseas suffers from some premature optimizations (after all, it was going to only deal with simple stuff like schemas/tables/columns and maybe functions and not all the rest of the PG objects). Loading all objects would also be applicable for #185. Alas, I haven't been using it much lately, so aside from thanking you Daniele, I don't what else to say.

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

No branches or pull requests

3 participants