Skip to content

Instantly share code, notes, and snippets.

@Wonder2210
Created May 29, 2020 03:30
Show Gist options
  • Save Wonder2210/654dcf4f1a5dfee94499634d9d90aa3b to your computer and use it in GitHub Desktop.
Save Wonder2210/654dcf4f1a5dfee94499634d9d90aa3b to your computer and use it in GitHub Desktop.
Easy database Schema migration with knex
import * as Knex from "knex";
export async function up(knex: Knex): Promise<any> {
return knex.schema.createTable('users',(table:Knex.CreateTableBuilder)=>{
table.increments('id');
table.string('full_name',36);
table.integer('country_code');
table.timestamps(true,true);
})
.createTable('pets',(table:Knex.CreateTableBuilder)=>{
table.increments('id');
table.string('name');
table.integer('owner_id').references("users.id").onDelete("CASCADE");
table.string('specie');
table.timestamps(true,true);
})
}
export async function down(knex: Knex): Promise<any> {
}
@Wonder2210
Copy link
Author

Captura

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment