Skip to content

Commit

Permalink
refactor: move migrating models content to its own page (#910)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanharris authored Dec 5, 2024
1 parent fb7c011 commit 8d508b0
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 36 deletions.
44 changes: 44 additions & 0 deletions docs/content/modeling/migrating/migrating-models.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: 'Model Migrations'
slug: /modeling/migrating/migrating-models
sidebar_position: 1
---

import { DocumentationNotice, ProductName, ProductNameFormat, IntroCard, CardGrid, CardBox} from '@components/Docs';

<DocumentationNotice />

You can think of model migrations for <ProductName format={ProductNameFormat.ShortForm}/> in the same way as you think about relational database migrations. You can perform migrations with or without downtime for both, and for some changes, doing them without downtime is harder.

| <ProductName format={ProductNameFormat.ShortForm}/> | Relational Databases |
|-----------------------------------------------------|-----------------------|
| Add a type | Add a table |
| Remove a type | Remove a table |
| Rename a type | Rename a table |
| Add a relation | Add a nullable column |
| Rename a relation | Rename a column |
| Delete a relation | Delete a column |

When thinking about migrations, keep in mind that:

- [Models are immutable](../../getting-started/immutable-models.mdx).
- The tuples that are not valid according to the specified model, are ignored when evaluating queries.

## To add a type or relation

1. Add the type or relation to the authorization model, and write the model to the store. This will generate a new model ID.
2. If you have tuples to write for the new types/relations, write them.
3. Update the application code to start using those new types/relations.
4. Configure the application to start using the new model ID.

## To delete a type or relation

1. Delete the type or relation to the authorization model, and write the model to the store. This will generate a new model ID.
2. Update the application code to stops using the deleted types/relations.
3. Configure the application to start using the new model ID.
4. Delete the tuples for the deleted type/relations. While not required, doing so can improve performance. Invalid tuples will be ignored during query evaluation, but their presence may slow down the process if they need to be retrieved.

## To rename a type or relation

- [This document](./migrating-relations.mdx) describes an end-to-end example for that use case.

54 changes: 18 additions & 36 deletions docs/content/modeling/migrating/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ slug: /modeling/migrating
sidebar_position: 0
---

import { DocumentationNotice, ProductName, ProductNameFormat, IntroCard, CardGrid } from '@components/Docs';
import { DocumentationNotice, IntroCard, CardGrid } from '@components/Docs';

<DocumentationNotice />

Expand All @@ -15,41 +15,23 @@ This section has guides that focus on migrating models and relations.
title="When to use"
description="The content in this section is useful:"
listItems={[
`If you want to introduce changes to your existing authorization model or upgrade it to the new schema version.`,
`If you want to introduce changes to your existing authorization model or upgrade it to a new schema version.`,
]}
/>

You can think of model migrations for <ProductName format={ProductNameFormat.ShortForm}/> in the same way as you think about relational database migrations. You can perform migrations with or without downtime for both, and for some changes, doing them without downtime is harder.

| <ProductName format={ProductNameFormat.ShortForm}/> | Relational Databases |
|-----------------------------------------------------|-----------------------|
| Add a type | Add a table |
| Remove a type | Remove a table |
| Rename a type | Rename a table |
| Add a relation | Add a nullable column |
| Rename a relation | Rename a column |
| Delete a relation | Delete a column |

When thinking about migrations, keep in mind that:

- [Models are immutable](../../getting-started/immutable-models.mdx).
- The tuples that are not valid according to the specified model, are ignored when evaluating queries.

## To add a type or relation

1. Add the type or relation to the authorization model, and write the model to the store. This will generate a new model ID.
2. If you have tuples to write for the new types/relations, write them.
3. Update the application code to start using those new types/relations.
4. Configure the application to start using the new model ID.

## To delete a type or relation

1. Delete the type or relation to the authorization model, and write the model to the store. This will generate a new model ID.
2. Update the application code to stops using the deleted types/relations.
3. Configure the application to start using the new model ID.
4. Delete the tuples for the deleted type/relations. While not required, doing so can improve performance. Invalid tuples will be ignored during query evaluation, but their presence may slow down the process if they need to be retrieved.

## To rename a type or relation

- [This document](./migrating-relations.mdx) describes an end-to-end example for that use case.

# Content

<CardGrid
middle={[
{
title: 'Migrating Relations',
description: 'A end-to-end example on renaming a relation.',
to: 'migrating/migrating-relations',
},
{
title: 'Migrating Models',
description: 'Learn how to safely update your model.',
to: 'migrating/migrating-models',
},
]}
/>
5 changes: 5 additions & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ const sidebars = {
label: 'Migrating Relations',
id: 'content/modeling/migrating/migrating-relations',
},
{
type: 'doc',
label: 'Migrating Models',
id: 'content/modeling/migrating/migrating-models',
},
],
},
],
Expand Down

0 comments on commit 8d508b0

Please sign in to comment.