Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jwilm/knex-migrate
A migration generator for the knex query builder
https://github.com/jwilm/knex-migrate
Last synced: 7 days ago
JSON representation
A migration generator for the knex query builder
- Host: GitHub
- URL: https://github.com/jwilm/knex-migrate
- Owner: jwilm
- License: mit
- Created: 2013-12-07T18:57:10.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-03-07T17:07:05.000Z (over 10 years ago)
- Last Synced: 2024-10-17T10:06:50.569Z (21 days ago)
- Language: CoffeeScript
- Size: 152 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
knex-migrate
============A migration generator for the knex query builder.
This is a WIP - no workable code yet.
## Features
The knex generator interface is inspired from the rails migration generator, and if you are familiar with the latter, you should be immediately comfortable with this generator for knex. Migration files are output using CoffeeScript.
## Syntax
`knex-migrate migration_name [column:type[:index]]` Will produce a migration name `YYYYMMDDHHmmSS_migration_name.coffee`. There are several special cases for migration_name which migrations will be automatically generated:
- `AddXXXtoYYY` and `RemoveXXXfromYYY`
- Generate a change migration
- Columns specified like `name:type` are automatically added to the migration
- `name:type:index` will also add an index to the column if possible
- `CreateXXX`
- Generates table named XXX
- add columns as specified above
- `DropXXX`
- Drop table XXX. If there are references associated with the table, be sure to modify the migration to clean those up.
- `AddXXXRefToYYY`
- add xxx ref to yyy table
- `CreateJoinTableXXXYYY`
- Create a join table for the tables XXX and YYYThere are some utilities for running the migrations:
- `knex-migrate up`: run pending migrations
- `knex-migrate rollback`: rollback last migration
- `knex-migrate status`: show pending migrations## Examples
Create a table for books with a few fields.
```shell
knex-migrate create_user_table name:string:index password:string
```Creates migration file `YYYYMMDDHHmmSS_create_user_table.coffee`:
```coffee-script
module.exports =
up: (knex, Promise) ->
knex.schema.createTable 'user', (t) ->
t.increments('id').primary()t.string('name').index()
t.string('password')t.timestamps()
down: (knex, Promise) ->
knex.schema.dropTable 'user'
```