@harnessflex/migration-builder

A Eloquent inspired migration builder for Harness Flex and DB Migrate.

Usage no npm install needed!

<script type="module">
  import harnessflexMigrationBuilder from 'https://cdn.skypack.dev/@harnessflex/migration-builder';
</script>

README

Migration Builder

A Laravel inspired migration builder for Harness Flex and DB Migrate.

Install

This package is automatically installed with the Harness Flex Framework.

npm i @harnessflex/migration-builder

Basic Usage

Migration Builder works both on imba based projects and JavaScript based projects.

Harness Flex

const { id, string, columns, timestamps } = require '@harnessflex/migration-builder'

exports.up = do(db, callback)
    db.createTable 'blogs', columns [
        id!
        foreign('user_id').references('id').on('users').onDelete('cascade')
        foreign('category_id').references('id').on('categories')
        longText 'body'
        string('tags').nullable!
        timestamps!
    ], callback

JavaScript

const { id, string, columns, timestamps } = require('@harnessflex/migration-builder')

exports.up = function (db, callback) {
    db.createTable('blogs', columns([
        id(),
        foreign('user_id').references('id').on('users').onDelete('cascade'),
        foreign('category_id').references('id').on('categories'),
        longText('body'),
        string('tags').nullable(),
        timestamps(),
    ], callback)
}

Columns

Column Params Type
bigInteger name: string Column
binary name: string Column
blob name: string Column
boolean name: string Column
char name: string Column
date name: string Column
dateTime name: string Column
decimal name: string Column
foreign name: string ForeignColumn
id Column
integer name: string Column
longText name: string Column
real name: string Column
smallInteger name: string Column
string name: string Column
text name: string Column
time name: string Column
timestamp name: string Column
timestamps currentTimeStamp: boolean Object

Other

Method Params Description
columns columns: array A collection of columns.

API


ForeignColumn

Method Params Description
references column: string Reference column of another table.
on table: string Reference table.
onDelete rule: string Add onDelete rule.
onUpdate rule: string Add onUpdate rule.

Imba and JavaScript

foreign('user_id').references('id').on('users').onDelete('cascade')

Column

Method Params Description
length length: integer Set column length.
primary primary: boolean Set column as primary key.
autoIncrement increment: boolean Add auto increment attribute.
nullable nullable: boolean Mark column nullable.
unique isUnique: boolean Mark column unique.
unsigned isUnsigned: boolean Mark column unsigned.
default value: mixed Set column default value.

Imba

db.createTable 'users', columns [
    id!
    string 'name'
    string('email').unique()
    string 'password'
    timestamp('email_verified_at').nullable!
    timetamps!
]

JavaScript

db.createTable('users', columns([
    id(),
    string('name'),
    string('email').unique(),
    string('password'),
    timestamp('email_verified_at').nullable(),
    timetamps(),
]))

Security

If you discover any security related issues, please email mjfold76@gmail.com instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.