Any of your databases
getTableMeta reads the columns of a table, executeQuery runs SQL or a MongoDB command, and g.sys.db moves data with the usual APIs.
API Maker
The framework for AI era
Team & delivery
Change the structure and data of every environment with TypeScript scripts that run once, in order.
A migration script is TypeScript with g: it reads table metadata, runs SQL or MongoDB commands on any of your databases, and moves data. Scripts go to Git with the rest of the project. After a deployment, the ones an environment has not run yet run one by one, in your order.
Step through it, slow it down, or open the full canvas.
A migration is a script in order. TypeScript run in the sandbox with g: read metadata, run SQL on any of your databases, import data. Each script has a number that sets its turn.
TypeScript run in the sandbox with g: read metadata, run SQL on any of your databases, import data. Each script has a number that sets its turn.
After a Git pull is committed, the scripts not executed yet on this account run one by one, in order. create-tables and seed-countries ran before, add-description is pending.
It reads the columns of order_transactions: description is missing, so it runs ALTER TABLE and adds it after qty, then the script is marked done. A script that fails is reported and runs again next time.
The next pull finds nothing pending. Even run by hand, the script sees the column already there and changes nothing.
getTableMeta reads the columns of a table, executeQuery runs SQL or a MongoDB command, and g.sys.db moves data with the usual APIs.
Scripts are part of the project in Git. Pull a branch on a server and its pending scripts run after the pull commits.
API Maker records which scripts ran on each account, so every script runs once, following its order number.
A script that fails is reported and not marked as done: it runs again the next time.
The admin panel shows the scripts still pending, and you can run the ones you pick.
Scripts run in the sandbox like the rest of your code, with your packages. lodash and moment come with every sandbox.
A feature needs a description column. The developer writes the script next to the API that uses it, and when QA, UAT and production pull the branch, each server adds the column before the new code serves its first request.
import * as T from 'types';import * as _ from 'lodash';async function main(g: T.IAMGlobal) { const columns = await g.sys.system.getTableMeta({ instance: 'mysql8', database: 'inventory', table: 'order_transactions', }); if (_.find(columns, { name: 'description' })) return 'already there'; await g.sys.system.executeQuery({ instance: 'mysql8', query: 'ALTER TABLE `inventory`.`order_transactions` ADD COLUMN `description` varchar(255) NULL AFTER `qty`', }); return 'added';}module.exports = main;Any instance of the account: MongoDB, MySQL, MariaDB, PostgreSQL, SQL Server or Oracle.
Up to 10 minutes each when run after a pull.
Documentation