Tuesday 31 March 2020

Knex.js migrations, does each table has its own migration?

Im currently learning Knex.js and try to create a basic todo REST API.I have these SQL tables here``` CREATE TABLE IF NOT EXISTS users ( id INTEGER AUTO_INCREMENT, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, role_id INT, PRIMARY KEY(id) );CREATE TABLE IF NOT EXISTS todos ( id INT AUTO_INCREMENT, todo VARCHAR(255) NOT NULL, done BOOLEAN NOT NULL DEFUALT false, FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, PRIMARY KEY(id) ) ENGINE = InnoDB; ```How would I go about implementing them with Knex.js migration? Does each table have its own migration file, like: knex migrate:make create_users and knex migrate:make create_todos or should it only be on a project level like knex migrate:make create_tables?And what if i now have two migration files, would the command knex migrate:latest only take the latest file timestamp based, or include both tables based on the name?

Submitted March 31, 2020 at 03:02PM by Tanckom

No comments:

Post a Comment