knex-migrate-sql-file

Use sql files instead of `knex.schema` methods.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
knex-migrate-sql-file
1.0.34 years ago4 years agoMinified + gzip package size for knex-migrate-sql-file in KB

Readme

knex-migrate-sql-file
Use sql files instead of knex.schema methods.
Exports up and down functions whichs executes knex.raw() method on SQL files having same file name appended .up.sql and .down.sql.
Synopsis
  1. Create knex migration file
  2. Import this library in migration file
  3. Create SQL files

$ knex migrate:make add-user-table
Created Migration: /some/path/20180516163212_add-user-table.js

/some/path/20180516163212add-user-table.js
//                    Don't forget function call ⤵
module.exports = require("knex-migrate-sql-file")();

/some/path/20180516163212
add-user-table.up.sql

CREATE TABLE "user"

/some/path/20180516163212add-user-table.down.sql
DROP TABLE "user"

You can override up or down function according to your needs.
API

Functions

up(knex, Promise)

Reads .up.sql file and executes it using knex.raw() method.

down(knex, Promise)

Reads .down.sql file and executes it using knex.raw() method.


up(knex, Promise)

Reads .up.sql file and executes it using knex.raw() method.
Kind: global function
| Param | Type | Description | | --- | --- | --- | | knex | Knex | Knex object | | Promise | Promise | Promise |
Example
module.exports = require("knex-migrate-sql-file")();

down(knex, Promise)

Reads .down.sql file and executes it using knex.raw() method.
Kind: global function
| Param | Type | Description | | --- | --- | --- | | knex | Knex | Knex object | | Promise | Promise | Promise |
Example
module.exports = require("knex-migrate-sql-file")();