API Maker

The backend engine for the AI era

MigrationsEpisode 32 7:17 11 chapters November 2026

Database Migrations in TypeScript or Python, Once per Environment

Changes to your databases that run once in every environment, in order, in the language of your team. Write a migration in TypeScript and one in Python, test it first, run the pending scripts from the dialog or from every deploy, and see what each server remembers.

In the playlists The complete course Migrations & tenants

Chapters

What you will learn

  • The Database Migration page
  • A script in TypeScript, and one in Python
  • Test it first
  • The dialog of the scripts to run, and what changed
  • Changes made in the panel, recorded into a migration script for every server
  • Every environment, each server remembering what ran
  • Run by every deploy, with deploy hooks
In the docsDatabase migration
Transcript976 words · click a time to play from there

Intro

A migration is a change to your databases. It runs once in every environment, in order, in the language your team uses. In this video, we look at the database migrations of API Maker.

Migrations, the usual way

Database changes usually cause trouble. SQL scripts are run by hand, from someone's laptop. They are forgotten on staging, or run twice on production. And nobody knows for sure which ones ran where. With API Maker, ordered scripts live in Git with the project. Each one runs once in each environment, and every server remembers what it ran. They come in eight languages, with the same g as your APIs.

In this video: the Database Migration page, a script in TypeScript, a script in Python, a test before the real run, the dialog of the scripts to run, changes recorded from the panel, and deploys.

The Database Migration page

Open Database Migration. One script is already here: am_index_maker, from the last video. The green dot says it ran on this server. Index Maker owns it, so it cannot be removed.

A script in TypeScript

Customers will earn loyalty points, so their table needs a new column. Click Add New. The name is add_loyalty_points. It cannot change later. Add a label for the list. Set order two. Scripts run from the lowest order. Set a time limit of five minutes. Now the code, in TypeScript. g.sys.system.executeQuery adds the column on PostgreSQL, if it is not there yet. So a second run changes nothing. It returns how many customers there are.

Save it. It is listed, but it has not run here yet.

A script in Python

Here is a second script, by someone who writes Python. Open the language picker, and pick Python. Name it recompute_ratings, give it a label, order three, and five minutes. We get the Python template, and we write the change. The rating of each product becomes the average of its reviews. It runs one aggregate on MongoDB, then one update for each product. Save it.

Test, then run

Before the real run, we test it. Each script has Test API. It opens API Testing, in the category Database Migration Scripts. Send. Thirty six products, and thirty three ratings changed. Send again, and zero changed. So it is safe to run twice. And a test run does not count as executed. Now load any page. The panel lists the scripts that have not run on this server yet, from the lowest order.

The same dialog opens on every environment where a pull brings new scripts. Tick both, and click Execute. They run in their order, and the page reloads. On Database Migration, both are now executed here. In API Testing, pick postgres, then crm, then customers, and Get all. Every customer has loyalty points, set to zero. The test already changed the ratings, so the real run found nothing to change.

Recorded from the panel

A script can also write itself, while you change your tables in the panel. Calm Home starts referrals. Pick postgres, then crm. The tables card says that changes are not recorded yet. Design a new table. Name it referrals, add an email, and the times it was made and changed. The pill at the bottom says where this change goes: a new script, named add_referrals, with a label. Click Done.

Click Create table. The table is made here, and the change is recorded into add_referrals. Its schema can wait. The tables card says the next changes go there too. Now open Database Migration. add_referrals shows its count: one change, made here, where it was designed. It holds the statement that ran, exactly as it ran. add_referrals is code, like any script. Between two markers is the list of changes. Each statement sits between backticks, colored as SQL.

When you type, it suggests the tables of crm and their columns. Next to each change, you see what happened to it on this server: made here, and when. The script is a list of changes, and one call: g.sys.system.applyRecordedChanges. On every server that deploys the project, each change runs once, in its order. What a server already made is skipped, so the list can grow. The changes name each database the way your account names it.

On every server, database name masking finds the real one. If a change fails, the ones after it stop, and the next run starts again from it.

Deploys

The scripts live in Git with the project, with their order. What ran is kept by each server, never in Git. A deployment hook pulls the branch, then runs what has not run there yet, in order. It answers with any migration errors. A script that fails is not marked as executed, so the next deploy runs it again.

Good to know

Good to know. There are eight languages, with the same g as your custom APIs. This is new in the Rust edition. Mark as executed records a script without running it, for a server that already has the change. A column added by a script comes back in full answers. Add it to the schema of the table, so a select can name it. And a name is for good.

A new script with the name of a deleted one counts as already executed.

Built on standards

Every change to a database is a reviewed script in Git, with an order. Each environment runs it once, and knows it did. So a change written by an AI assistant goes through the same review and the same order. It is never run by hand on production.

Recap

To sum up. Ordered scripts live in Git. Each runs once per environment, and each server remembers it. You can write them in TypeScript, Python, and six more languages. Test them first, and make them safe to run twice. Changes made in the panel are recorded for every server. And they run from the dialog, or with every deploy. Next: multi tenant APIs. API Maker. Build faster, spend smarter, deliver better.