node-backend-example/migrations/20240112194240_first.js

28 lines
690 B
JavaScript

// These functions needed to be changed to `async`.
// not necessary, but very helpful!
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
// if table alreay
if (await knex.schema.hasTable("note")) return;
await knex.schema.createTable("note", (table) => {
table.increments("id");
table.string("title");
table.string("text");
table.datetime("created");
});
};
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
if (! (await knex.schema.hasTable("note"))) return;
await knex.schema.dropTable("note");
};