Database migration scripts¶
A migration script changes the structure or the data of your databases : add a column, backfill a value, create an index. It is code of the account, kept in Git, and API Maker runs each script once per environment, in order.
| Page | Utility → Database Migration : name, label, order, timeout in minutes, active, and the code. |
| Runs | After a Git pull and after a deployment hook : the active scripts not yet executed on this environment, by order. Or by hand : Execute script, Execute Selected Migration. |
| Remembers | The names of the scripts executed, per environment. Mark as executed skips one without running it ; a script already run shows Script executed. |
| Code | async function main(g: T.IAMGlobal) with the same g as a custom API. Test it on the API testing page. |
A script¶
- Get table meta tells what is there, execute plain query runs any SQL or MongoDB command, create indexes adds indexes the same way on every database. Data moves with
g.sys.db. - Write scripts which can run twice without harm, like the one above : a script which fails half way is run again after the fix.
Order and timeout¶
ordersorts the scripts ; the pull runs them from the lowest. Use it for a script which needs the column another one adds.Timeout in minutesstops a script which runs too long (10when empty).- A script which throws stops with its error, shown by View error on its row ; the next scripts still run.
The Index Maker script¶
am_index_makeris managed by Index Maker : it holds the indexes decided by the automatic mode, the suggestions and the index form as a JSON list, runs on every deploy, and can not be deleted while Index Maker uses it. Edit the code outside the marked region as you like.