Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Jira Legacy
serverSystem JiraJIRA
columnskey,summary,type,created,updated,due,assignee,reporter,priority,status,resolution
serverId01505d01-b853-3c2e-90f1-ee9b165564fc
keyMODDICONV-12

...

  • Constraints and indexes

    RMB does not directly support a foreign key inside the jsonb, but uses workaround to achieve referential integrity. If schema generator meats "foreignKeys" key in database configuration file (schema.json file in most of the cases), then it defines a separate column in a database table to store foreign key value, setup FK constraint on that field and create creates trigger to keep it sync with the value inside the jsonb. The trigger runs every time before insert or update the target table, so keep in mind that the table with FK may be a bottleneck considering database performance.

Here is a source of the trigger and it's related function to keep sync foreign keys of the "tickets" table:


Image AddedImage Added


    RMB provides 5 kinds of indexes: 

  • likeIndex - fields in the json will be queried using the LIKE;
  • ginIndex - allows for regex queries to run in an optimal manner;
  • uniqueIndex - create a unique index on a field in the json;
  • btree index - supports equality and range queries on data that can be sorted into some ordering;
  • fullTextIndex - full text index using teh tsvector features of Postgres;

   For more information about indexes read here.

Unique constraint

RMB does not support unique constraint "out of the box" but we can emulate it using unique index to prevent duplicate fields in jsonb. Inserting json with the same filed value you will get an error "duplicate key value violates unique constraint "<unique_index_name>"".

Check constraint

RMB does not support check constraint "out of the box" for jsonb fields, but we can apply check constraint in customSnippet, for example
ALTER TABLE persons ADD CONSTRAINT test_constraint CHECK(((jsonb ->> 'weight')::numeric) > 75).