Andres Vargas - zodman

How Manage Scripts Applied to the Database

Ey pals, have you ever had the situation where you need to write a script for to perform some kind of operation over the database.

For examples:

Although the application doesn’t support a migrations. Like Prisma, Django, Rails and others. Therefore you are not able to execute migrate apply.

And it’s a struggle to have control over which scripts were executed and which ones were not.

On my work we have a list of scripts like:

scripts/DEV-XXX-create-new-categories.mjs
scripts/DEV-XXX-add-default-value-to-column.mjs

I need to know which scripts where applied to the DB and which didn’t.

For that I had created

ctrls

It’s a little python script to record which scripts were applied.

ctrls
Usage: ctrls [OPTIONS] COMMAND [ARGS]...

  🎛️   Ctrl-S - control scripts applied  by zodman

Options:
  --help  Show this message and exit.

Commands:
  add
  add-dir
  status

With the command add It store in a table called __ctrl_scripts_applied all scripts applied. and with status which ones didn’t.

This help me alot because my coworkers can create scripts and I can check which script I have locally missed.

the script is here:

https://github.com/zodman/ctrl-scripts