k1LoW / tbls

tbls is a CI-Friendly tool for document a database, written in Go.
MIT License
3.37k stars 165 forks source link

Add exclude option to tbls doc #437

Closed masaya-kato63 closed 1 year ago

masaya-kato63 commented 1 year ago

I would also like to see an exclusion setting for the tbls doc command. PostgreSQL extensions often automatically create schemas and tables over which the user has no control. (e.g. pg_repack). I would like to exclude those schemas and tables.

k1LoW commented 1 year ago

What about the --exclude option?

https://github.com/k1LoW/tbls/blob/e043006da266cbf918b3a8f4cff9e8bffd6f002d/cmd/doc.go#L236

av commented 1 year ago

--exclude seems to work as expected in such scenario, at least when specified in the tbls.yml:

exclude:
  # DB Schema owned by hasura
  - hdb_catalog.*

However, it doesn't exclude the stored procedures from being generated, which is probably relevant to this comment as well.

k1LoW commented 1 year ago

Perhaps I am not understanding what you are looking for. If you could give me an example of a "specific schema and the state you want to achieve" that would be helpful.

Should I use any extensions?

masaya-kato63 commented 1 year ago

@k1LoW @av Thank you for your confirmation. Sorry I missed the exclude option. Finally, I would like to ask about how to write exclude, is it possible to write exclude tables other than the public schema table? I don't want to list options like --exclude "repack.*" for each schema I want to exclude.

k1LoW commented 1 year ago

is it possible to write exclude tables other than the public schema table?

Try using --include 'public.*'

$ tbls out github://k1LoW/tbls/sample/postgres/schema.json -t json | jq .tables[].name
"public.users"
"public.user_options"
"public.posts"
"public.comments"
"public.comment_stars"
"public.logs"
"public.post_comments"
"public.post_comment_stars"
"public.CamelizeTable"
"public.hyphen-table"
"administrator.blogs"
"backup.blogs"
"backup.blog_options"
"time.bar"
"time.hyphenated-table"
"time.referencing"
$ tbls out github://k1LoW/tbls/sample/postgres/schema.json -t json --include 'public.*' | jq .tables[].name
"public.users"
"public.user_options"
"public.posts"
"public.comments"
"public.comment_stars"
"public.logs"
"public.post_comments"
"public.post_comment_stars"
"public.CamelizeTable"
"public.hyphen-table"
masaya-kato63 commented 1 year ago

Thank you for teaching me.