keboola / db-writer-snowflake

Snowflake database writer
MIT License
0 stars 1 forks source link

Allow setting database constraints #62

Closed tomasfejfar closed 5 years ago

tomasfejfar commented 5 years ago

Snowflake allows users to set constraints on the data. The constraints are not checked or enforced, but can be used by tools accessing the database (Looker, Tableau) to automatically create models from the data.

Ideally user would be able to set a column in the table as a primary key, or set it as a foreign key referencing some other table's column.

Below is updated "tables" key in config.json

"tables": [
  {
    "tableId": "in.c-lepsimisto.v1_announcement_ListByCity",
    "dbName": "v1_announcement_ListByCity",
    "export": true,
    "items": [
      {
        "name": "id",
        "dbName": "id",
        "type": "int",
        "size": null,
        "nullable": null,
        "default": null
        "primaryKey": true <------ true/false, default false, not required
        "foreignKeyTable": "some_table_name" <---- string, not required, cannot be empty
        "foreignKeyColumn": "some_column_name" <---- string, not required, cannot be empty
         ^----- should be validated that both (table and column) or none are present
         ^----- I think that a column that is primary key and foreign key at the same time is valid
      }
    ]
  }
]

Keep in mind the solution should work with configRows as well as with implementation using CLONE instead of CREATE TABLE. Aso note, that dbName needs to be used in the actual constraints. It's not always a rule that name and dbName are the same ;)