k1LoW / tbls

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

Filter database name in generated docs #454

Closed woidda closed 1 year ago

woidda commented 1 year ago

I could not find a option to remove the database / schema name from the generated output.

I have configured the db similar to:

# .tbls.yml
dsn: postgres://user:pwd@localhost:5432/mydb

Without the database name in the URL the connection fails.

In the generated output I have always the "public" prefix, such as [public.user] generated. This is actually not ideal as it is obvious information and takes up space.

Am I missing something here? It has been a long day. So this request might sound stupid. In this case my apologies in advance.

Btw. thanks for this awesome tool. It is exactly something I have been looking for for a long time.

k1LoW commented 1 year ago

@woidda Thank you for your report!

Without the database name in the URL the connection fails.

Yes, tbls is a tool to document a single database, so the database name is always required.

In the generated output I have always the "public" prefix, such as [public.user] generated. This is actually not ideal as it is obvious information and takes up space.

PostgreSQL has a layer of "schema" within the database.

For example, it is possible to have more than one schema in a database.

So, the public schema prefix exists almost as a default, but I don't think it is obvious.

k1LoW commented 1 year ago

And actually, the public schema is not the default. It seems to be only a search_path setting.

woidda commented 1 year ago

The thing is I end up with table descriptions as follows:

Name Columns Comment Type
public.auth_session 6 BASE TABLE
public.document 4 BASE TABLE
public.organization 6 BASE TABLE
public.user 7 BASE TABLE
... ... BASE TABLE

It would be great just to be able to remove the "public." prefix as it is the same for all and in generated ERDs it takes up too much space.

The public prefix is actually just standing for the "standard public schema" which all postgres databases have (additionally to information_schema and pg_catalog).

5.9.2. The Public Schema

In the previous sections we created tables without specifying any schema names. By default such tables (and other objects) are automatically put into a schema named “public”. Every new database contains such a schema. Thus, the following are equivalent:

CREATE TABLE products ( ... );

and:

CREATE TABLE public.products ( ... );

From the docs. Same as you referenced the search_path.

For me the ideal solution would be to just drop the public prefix as it is the default when creating new tables and most likely the same name for 90% of all postgres databases. With standard web frameworks, such as rails, django, laravel, spring boot, etc. (with their respective standard ORMs) I have not seen a single app in the last ten years that used another schema then the public one -- even it would make sense in order to organize the db into different domains when people start with a monolith.

See also in slightly simpler words than the Postgres docs: https://www.postgresqltutorial.com/postgresql-administration/postgresql-schema/

k1LoW commented 1 year ago

In the past, we have made a decision to display the information as is, as long as it is not 100% accurate.

We do not plan to make that correction at this time, although it will not meet your expectations.

woidda commented 1 year ago

Ah, OK. Thanks.