/plushcap/analysis/neon/neon-migrating-schemas

Migrating Schemas Across Many Neon Projects Using DrizzleORM

What's this blog post about?

This blog post explains how to manage multiple databases using the same schema with DrizzleORM, GitHub Actions, Neon API, and custom template scripts. The Database Per Tenant model is an architectural approach where each tenant (user, client, or project) has its own dedicated database instance sharing the same schema. This method requires new customers to be created using the same schema, and any changes to the database schema must be rolled out to all individual databases simultaneously. The workflow involves three scripts: create, generate, and migrate. The create script automates creating new Neon projects via the Neon API, while the generate script lists all projects in the Neon account, creates DrizzleORM configuration files if they don't exist, generates migration files using Drizzle Kit, creates a GitHub secret for the database connection string, and updates the GitHub Action workflow to include the new secret. The migrate script is automatically triggered by the GitHub Action, running schema migrations for all projects by reading their DrizzleORM config files. This approach can be used for any new projects/customers or when changes to schema are made and works well for database-per-tenant architectures.

Company
Neon

Date published
Nov. 21, 2024

Author(s)
Paul Scanlon

Word count
1560

Language
English

Hacker News points
None found.


By Matt Makai. 2021-2024.