Data migrations are handled via the Knex migration system.

Migrations provide a managed and version-control-backed method for modifying the data structures that support the API.

Adding A Migration

yarn add-migration <newMigrationName>

creates a duplicate of migration.stub.ts that


-the needed module-alias import and

-a standard/initial TS up/down export setup.

Running A Migration

You’ll first need to build the app to compile the TypeScript migration into JavaScript, then run the migration.

yarn build
yarn db-latest

Data Structure Notes

Defining Primary Keys

In the Knex migration use the increments data type for a primary key field. For PostgreSQL this will be a serial data type, a 4-byte integer.

await knex.schema.createTable(tableName, (table) => {

Foreign Key => Primary Key References

For foreign key references, use the integer type which is also 4-bytes.

Adding a new column and making it a FK for it.