Skip to content

Commit

Permalink
Merge pull request cockroachdb#40 from crowdflux/dev/migrations
Browse files Browse the repository at this point in the history
pushing db migrations using knex
  • Loading branch information
himanshu144141 committed Oct 24, 2016
2 parents 5541a6c + b084e0c commit 3fb4a33
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ app/config/development.json

app/api/auther/prod.go

node_modules

### Windows ###
# Windows image file caches
Thumbs.db
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ $ go get -v
$ go get -t -v
```

- Migrate DB

One time setup: `$ npm install`

Migrate db to latest schema: `$ knex migrate:latest`

Push new schema change: `$ knex migrate:make <name_of_migration_file>`. This will be generated in `app/DAL/migrations`.
Refer the other migration files to learn how to write that.

- Install mongodb:

```
Expand Down Expand Up @@ -80,4 +89,4 @@ To start the server:
```
$ go install
$ $GOPATH/bin/angel
```
```
26 changes: 26 additions & 0 deletions app/DAL/migrations/20161023172412_add_config_column_in_step.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

exports.up = function (knex, Promise) {
return Promise.all([
knex
.schema
.table('step', t => {
t.specificType('config', 'jsonb')
.defaultTo('{}')
.notNullable()
t.string('label')
.notNullable()
.defaultTo('')
})
])
};

exports.down = function (knex, Promise) {
return Promise.all([
knex
.schema
.table('step', t=> {
t.dropColumn('config')
t.dropColumn('label')
})
])
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

exports.up = function (knex, Promise) {
return Promise.all([
knex
.schema
.table('routes', t => {
t.specificType('config', 'jsonb')
.defaultTo('{}')
.notNullable()
t.string('label')
.notNullable()
.defaultTo('')
})
])
};

exports.down = function (knex, Promise) {
return Promise.all([
knex
.schema
.table('routes', t=> {
t.dropColumn('config')
t.dropColumn('label')
})
])
};
28 changes: 28 additions & 0 deletions knexfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var Config = require('config-js');
var config = new Config('./app/config/##.json');

var connection = config.get('postgres')
connection.user = connection.username

var knexConfig = {
client: 'postgresql',
connection: connection,
migrations: {
directory: `${__dirname}/app/DAL/migrations`,
tableName: 'angel_knex_migrations'
},
seeds: {
directory: './app/db/seeds'
},
pool: {
min: 5,
max: 50
},
acquireConnectionTimeout: 60000
}

module.exports = {
development: knexConfig,
staging: knexConfig,
production: knexConfig
}
28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "angel",
"version": "1.0.0",
"description": "Playment's Angel ================",
"main": "knexfile.js",
"dependencies": {
"babel": "^6.5.2",
"co": "^4.6.0",
"babel-register": "^6.16.3",
"pg": "^6.1.0",
"config-js": "^1.1.9",
"knex": "^0.12.6"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/crowdflux/angel.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/crowdflux/angel/issues"
},
"homepage": "https://github.com/crowdflux/angel#readme"
}

0 comments on commit 3fb4a33

Please sign in to comment.