k1LoW / tbls

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

Enable to name Viewpoint files instead of indexes #591

Closed majimaccho closed 3 weeks ago

majimaccho commented 1 month ago

Hi. Big thank you as always for tbls and maintaining it.

It could be nicer if we can set custom names on each viewpoints.

This is because when I want to insert a new viewpoint above a existing viewpoint, all viewpoints under the new one renamed.

For example, when we have viewpoints like below,

viewpoint-1.md
viewpoint-2.md
viewpoint-3.md
.
.
.
viewpoint-n.md

then add add a new viewpoint right under viewpoint 1, all viewpoints below viewpoint 2 get renamed like below.

viewpoint-1.md
viewpoint-2.md <- new viewpoint
viewpoint-3.md <- previous viewpoint 2
viewpoint-4.md <- previous viewpoint 3
.
.
.
viewpoint-n+1.md <- previous viewpoint n

When viewpoint tbls.yaml would look like this.

 .tbls.yml

viewpoints:
  -
    name: comments on post
    id: comments-on-post # <- This should create `viewpoint-comments-on-post.md`
    desc: Users can comment on each post multiple times and put a star on each comment.
    tables:
      - users

I'm not sure id is the best name for this feature. If you have better naming or specs, I'm happy to listen to them. Thank you again!

k1LoW commented 1 month ago

@majimaccho Thank you for your request!

I too agree that file naming by index is not the best way to determine file names.

The first requirement is that the filename in viewpoint must be unique along with the other table markdowns.

Secondly, I do not want to require users to enter values other than the information needed for the documentation of the schema.

The id is information needed for tbls and has no effect on the documentation of the schema.

I want a solution that doesn't require unnecessary input from the user and that solves your problem.

majimaccho commented 1 month ago

@k1LoW Thank you for telling your idea.

The first requirement is that the filename in viewpoint must be unique along with the other table markdowns.

I agree with this point so I'm planning to do two things

  1. validate the id value as unique one
  2. add viewpoint to file name as a prefix.

Secondly, I do not want to require users to enter values other than the information needed for the documentation of the schema. The id is information needed for tbls and has no effect on the documentation of the schema.

I agree this point too.

My idea is to make id of viewpoint optional and if it's not set the index is used for file name as it does currently. So it would affect users who don't set id field of viewpoints.

Let me know what you think.

k1LoW commented 4 weeks ago

Would it be possible to solve your issue without entering an id, if possible?

I prefer to have settings that are not relevant to the schema as much as possible.

majimaccho commented 4 weeks ago

In that case, how about adding option to the config to set viewpoint name as file name like this?

# .tbls.yml

viewpointNameAsFileName: true # default: false. use index as default

When this parameter is set, viewpoint name must be unique.

k1LoW commented 4 weeks ago

If your first idea, the validation to make it unique if the id is specified, runs, it does not seem to be necessary.

I want to have a better effect now with zero-configuration (even if it is not 100%).

majimaccho commented 4 weeks ago

I suppose there could be multiple options between complete zero-configuratin and no breaking change as below.

Less Configurations ↑

  1. use viewpoint name as file name (Complete Zero-Configurations)
  2. use viewpoint name as file name by default but could be modified if wanted
  3. use index as file name by default but could be modified if wanted

Less Breaking Changes ↓


As a user myself, 2. use viewpoint name as file name by default but could be modified if wanted would make most sense since I want to have viewpoint name in Japanese but file name in English.

However, it goes richer configuration way than pure 1. use viewpoint name as file name.

The way to modify file names could be id or viewpointNameAsFileName either ways.

k1LoW commented 4 weeks ago

I prefer it to be zero-config, but using name: does not look good in Japanese.

I think we need to consider this a little more.

majimaccho commented 4 weeks ago

What if we can ignore non alpha-numeric string for file name?

Then, English users don't get affected and we can use it with zero config.

For example, when we have viewpoint nane: hogeほげ filename could be viewpoint_hoge.md. The non alphanumeric part ほげ is ignored.

k1LoW commented 3 weeks ago

Japanese-only patterns are likely to be common.

majimaccho commented 3 weeks ago

After thinking about this issue for a few days, in my perspective, the. first proposal seems the best solution for this issue.

If we cannot agree at this point I may close this issue.

Even if so, I can still use viewpoint by appending new one to existing list and sort in another PR that makes changes of each PR clear.