dbml icon indicating copy to clipboard operation
dbml copied to clipboard

Note not possible in index settings

Open Vanderhoof opened this issue 5 years ago • 3 comments

The Index example from the docs fails:

Table bookings {
  id integer
  country varchar
  booking_date date
  created_at timestamp

  indexes {
      (id, country) [pk] // composite primary key
      created_at [note: 'Date']
      booking_date
      (country, booking_date) [unique]
      booking_date [type: hash]
      (`id*2`)
      (`id*3`,`getdate()`)
      (`id*3`,id)
  }
}

Error message:

  ERROR: You have a syntax error at "table.dbml" line 9 column 19. Expected " ", "name:", "type:", "unique", PK, comment, or whitespace but "n" found.

Here we have a note in created_at index, which is not allowed by the syntax. According to the IndexSetting syntax, only "unique", name or type allowed in index settings.

Should either add note to possible index settings, or fix the example in docs

Vanderhoof avatar Apr 15 '20 10:04 Vanderhoof

Hi @Vanderhoof ,

Thanks for reporting the issue. This will be fixed in the next release of DBML.

phuongduyphan avatar Apr 16 '20 07:04 phuongduyphan

@phuongduyphan I hope you won't mind that I'm not creating a new issue for this (because I can't test it fully now):

It seems, that Project definition in docs is also incorrect:

Project project_name {
  database_type: 'PostgreSQL'
  Note: 'Description of the project'
}

Here the note is defined in ObjectNote syntax (without {}), but in the parser file only the ObjectNoteElement syntax (with {}) is allowed inside project. So in this example note wouldn't be considered as a note, but rather as another ProjectField.

Or is this intended? Because I see that a lot of other elements (in fact, all of them) possible inside project definition, which is not mentioned in the docs

Vanderhoof avatar Apr 17 '20 09:04 Vanderhoof

I have tried to put a note on an index field, and it didn't seem to come through:

Table permissions {
  id int [pk]
  user_id int [not null]
  role role [not null]
  entity entity [not null] 
  entity_id int [not null, note: 'stuff']
  note: '''
    stuff
  '''
  indexes {
    (user_id, entity, entity_id) [unique, name: 'permissions_index', note: 'role is missing from this index because a user can only have one role for a given entity']
  }
}

This is what I see on the dbdocs page: image

It is getting some of the settings, but not the notes: setting. I tried it for a non-composite key also, and it didn't work for that either.

Is this user error or is something broken?

charlesdeb avatar Apr 13 '22 13:04 charlesdeb