Knex migration example

PHOTO EMBED

Wed Aug 25 2021 07:13:48 GMT+0000 (Coordinated Universal Time)

Saved by @ExplodeMilk #typescript #knex

import { Knex } from "knex";

export async function up(knex: Knex)  {
    if(!await knex.schema.hasTable("students")){
        await knex.schema.createTable("students",(table)=>{
            table.increments();
            table.string("name");
            table.string("level");
            table.date("date_of_birth");
            table.integer("teacher_id").unsigned();
            table.foreign('teacher_id').references('teachers.id');
            table.timestamps(false,true);
        });
    }
};

export async function down(knex: Knex){
    await knex.schema.dropTableIfExists("students");
};
content_copyCOPY

https://cms.tecky.io/mod/page/view.php?id