MS SQL Server: Renaming relationships

An existing relationship can be renamed as follows:

  • Head to Data -> [table-name] -> Relationships in the console
  • Drop the existing relationship
  • Recreate the relationship with the new name

You can rename a relationship by changing the relationship name in the tables.yaml file inside the metadata directory:

 - table:
     schema: public
     name: articles
   object_relationships:
   - name: author
     using:
       foreign_key_constraint_on: author_id
 - table:
     schema: public
     name: authors

Apply the metadata by running:

hasura metadata apply

You can rename a relationship by using the mssql_rename_relationship metadata API:

POST /v1/metadata HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
  "type": "mssql_rename_relationship",
  "args": {
    "table": "articles",
    "name": "article_details",
    "source": "default",
    "new_name": "article_detail"
  }
}

Note

You might not be allowed to drop a relationship if it has been referenced elsewhere (e.g. in a permissions rule).

In this case you will have to delete the references first, rename the relationship, and then re-add the references.