Back to Graphql Engine

MS SQL Server: Rename Relationships

docs/docs/schema/ms-sql-server/table-relationships/rename.mdx

2.48.162.1 KB
Original Source

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import Thumbnail from '@site/src/components/Thumbnail';

MS SQL Server: Rename Relationships

An existing relationship can be renamed as follows:

<Tabs groupId="user-preference" className="api-tabs"> <TabItem value="console" label="Console">

Renaming Local Relationships

  • Head to Data -> [table-name] -> Relationships in the Console
  • Click on the Rename option for the relationship in question.
<Thumbnail src="/img/schema/rename-local-rel-step-1.png" alt="Fill the relationship details" width="700px" />
  • This will open up a pop-up widget which will allow you to rename and save the relationship
<Thumbnail src="/img/schema/rename-local-rel-step-2.png" alt="Fill the relationship details" width="700px" />

Renaming Remote Relationships

Remote relationships cannot be renamed. They have to dropped and created again with the new name.

</TabItem> <TabItem value="cli" label="CLI">

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

yaml
- 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:

bash
hasura metadata apply
</TabItem> <TabItem value="api" label="API">

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

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

{
  "type": "mssql_rename_relationship",
  "args": {
    "source": "<db_name>",
    "table": "articles",
    "name": "article_details",
    "new_name": "article_detail"
  }
}
</TabItem> </Tabs>

:::info 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.

:::