Skip to content

Commit

Permalink
An accurate instruction for minor PG schema updates
Browse files Browse the repository at this point in the history
	modified:   docs/sdk/resources/persisting-data/typeorm.md
  • Loading branch information
abernatskiy committed Jan 7, 2025
1 parent 6d242f4 commit 3a9b2f4
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions docs/sdk/resources/persisting-data/typeorm.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,38 +98,44 @@ npx squid-typeorm-migration apply

In some rare cases it is possible to update the schema without dropping the database and restarting the squid from a blank state. The most important case is adding an index to an entity field. More complex changes are usually not feasible.

**1. Update schema.graphql**
Updating a running squid requires that you add an incremental migration.

**1. Ensure that your local database is running and has the same schema as the database of your Cloud squid**

In most situations re-creating the database container and applying existing migrations should be enough:
```bash
docker compose down
docker compose up -d
npx squid-typeorm-migration apply
```

**2. Update schema.graphql**

For example, [add an index](/sdk/reference/schema-file/indexes-and-constraints)

**2. Regenerate the model classes and build the code**
**3. Regenerate the model classes and build the code**

```bash
npx squid-typeorm-codegen
npm run build
```

**3. Create a new database migration**

Make sure the local database is running.
**4. Add a new database migration**

```bash
docker compose up -d
npx squid-typeorm-migration generate
```
This will create a new file in `db/migrations`. You may want to examine it before proceeding to the next step.

**4. Apply the database migration**
**5. Update the squid in Cloud**

Inspect the new migration in `db/migrations` and apply it:
If the squid is deployed to SQD Cloud, [update the deployed version](/squid-cli/deploy).

If you're self-hosting it, update your remote codebase and run
```bash
npx squid-typeorm-migration apply
```

**5. Update the squid in Cloud**

If the squid is deployed to SQD Cloud, [update the deployed version](/squid-cli/deploy).

### SQD Cloud deployment

By default, the TypeORM migrations are automatically applied by Cloud with the command `npx squid-typeorm-migration apply` before the squid services are started. For custom behavior, one can override the migration script using the optional `migrate:` section of [squid.yaml](/cloud/reference/manifest#deploy).
Expand Down

0 comments on commit 3a9b2f4

Please sign in to comment.