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

Should "dbtoyaml -t TABLE" extract enum types as well #221

Open
andreypopp opened this issue Jul 8, 2020 · 1 comment
Open

Should "dbtoyaml -t TABLE" extract enum types as well #221

andreypopp opened this issue Jul 8, 2020 · 1 comment
Labels

Comments

@andreypopp
Copy link
Contributor

I understand that dbtoyaml is modelled after pg_dump and pg_dump doesn't extract enums if you supply -t but I'm wondering if dbtoyaml should diverge here? What do you think.

My use case is that I have a tool to build new pg databases out of existing ones and one of the features I want is to selectively to dump/restore (selectively as by specifying a subset of tables). pg_dump doesn't work for me (for the reason above) but I was wondering if I can use dbtoyaml instead for that.

@jmafc jmafc added the dbtoyaml label Jul 8, 2020
@jmafc
Copy link
Member

jmafc commented Jul 8, 2020

From a theoretical standpoint, I think dbtoyaml -t should output everything that's related to the requested table(s), but that is easier said than done. As I recall, one of the early issues was that if a table had a related sequence due to the use of SERIAL, dbtoyaml was only outputting the table so yamltodb would fail when it tried to ALTER TABLE to add the sequence. So that was fixed as a separate issue (there is a complicated if at the beginning of Sequence.to_map() that IIRC attests to that).
So, dbtoyaml -t doesn't currently output related types such as ENUMs (nor DOMAINs or TYPEs). I don't think we were trying to explicitly emulate pg_dump behavior (which also doesn't). Could it be done? I believe so, but it may not be as also outputting related SEQUENCEs. Since @dvarrazzo refactored Pyrseas for dependencies, we have dependency graphs for each object, so one could traverse the graph for a requested table and add to a list of "also needed" objects any data type that wouldn't normally be expected in a PG database. A quick and dirty (and more specific) solution would be to loop through the columns of a table, e.g., the film table in the pagila sample database, and add to a list of related objects any column type that's not in a list of "common" datatypes (INTEGER, TEXT, TSVECTOR, etc.), e.g., in the pagila case, the DOMAIN year and the ENUM mpaa_rating.

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

No branches or pull requests

2 participants