2013-12-23 04:24:40 +00:00
|
|
|
Promise = require 'bluebird'
|
2014-03-19 19:17:07 +00:00
|
|
|
Knex = require 'knex'
|
2013-12-14 05:18:20 +00:00
|
|
|
|
|
|
|
knex = Knex.initialize(
|
|
|
|
client: 'sqlite3'
|
|
|
|
connection:
|
2014-04-27 21:41:59 +00:00
|
|
|
filename: '/data/database.sqlite'
|
2013-12-14 05:18:20 +00:00
|
|
|
)
|
|
|
|
|
2014-08-19 17:21:44 +00:00
|
|
|
addColumn = (table, column, type) ->
|
|
|
|
knex.schema.hasColumn(table, column)
|
|
|
|
.then (exists) ->
|
|
|
|
if not exists
|
|
|
|
knex.schema.table table, (t) ->
|
|
|
|
t[type](column)
|
|
|
|
|
2013-12-23 04:24:40 +00:00
|
|
|
knex.init = Promise.all([
|
2014-03-19 19:17:07 +00:00
|
|
|
knex.schema.hasTable('config')
|
|
|
|
.then (exists) ->
|
2013-12-23 04:24:40 +00:00
|
|
|
if not exists
|
2014-03-19 19:17:07 +00:00
|
|
|
knex.schema.createTable 'config', (t) ->
|
2013-12-23 04:24:40 +00:00
|
|
|
t.string('key').primary()
|
|
|
|
t.string('value')
|
2014-03-19 19:17:07 +00:00
|
|
|
|
|
|
|
knex.schema.hasTable('app')
|
|
|
|
.then (exists) ->
|
2013-12-23 04:24:40 +00:00
|
|
|
if not exists
|
2014-03-19 19:17:07 +00:00
|
|
|
knex.schema.createTable 'app', (t) ->
|
2013-12-23 04:24:40 +00:00
|
|
|
t.increments('id').primary()
|
|
|
|
t.string('name')
|
|
|
|
t.string('containerId')
|
2014-07-19 02:24:01 +00:00
|
|
|
t.string('commit')
|
2013-12-23 04:24:40 +00:00
|
|
|
t.string('imageId')
|
2014-08-19 17:21:44 +00:00
|
|
|
t.string('appId')
|
2013-12-23 04:24:40 +00:00
|
|
|
t.boolean('privileged')
|
2014-04-03 17:16:37 +00:00
|
|
|
t.json('env')
|
2014-07-19 02:24:01 +00:00
|
|
|
else
|
2014-08-19 17:21:44 +00:00
|
|
|
Promise.all [
|
|
|
|
addColumn('app', 'commit', 'string')
|
|
|
|
addColumn('app', 'appId', 'string')
|
|
|
|
]
|
2014-07-19 02:24:01 +00:00
|
|
|
|
2016-05-11 14:44:05 +00:00
|
|
|
knex.schema.hasTable('image')
|
|
|
|
.then (exists) ->
|
|
|
|
if not exists
|
|
|
|
knex.schema.createTable 'image', (t) ->
|
|
|
|
t.increments('id').primary()
|
|
|
|
t.string('repoTag')
|
|
|
|
|
2013-12-23 04:24:40 +00:00
|
|
|
])
|
2013-12-14 05:18:20 +00:00
|
|
|
|
|
|
|
module.exports = knex
|