-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
database: Initial setup for storing jobs
- Loading branch information
Showing
7 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Knex = require 'knex' | ||
config = require './config' | ||
url = require 'url' | ||
|
||
# Parse DB URL | ||
dbConfig = url.parse config.database.url | ||
connection = | ||
charset: 'utf8' | ||
|
||
# Normalize config | ||
switch dbConfig.protocol | ||
when 'postgres:' | ||
provider = 'pg' | ||
[user, pass] = dbConfig.auth.split ':' | ||
connection.host = dbConfig.hostname | ||
connection.user = user | ||
connection.password = pass | ||
connection.database = dbConfig.path.substr 1 | ||
connection.port = dbConfig.port | ||
|
||
module.exports = Knex | ||
client: provider | ||
connection: connection | ||
pool: | ||
min: 1 | ||
max: 4 | ||
useNullAsDefault: true | ||
# debug: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
config = require './config' | ||
url = require 'url' | ||
|
||
dbConfig = url.parse config.database.url | ||
[user, pass] = dbConfig.auth.split ':' | ||
switch dbConfig.protocol | ||
when 'postgres:' | ||
cfg = | ||
client: 'postgresql' | ||
connection: | ||
host: dbConfig.hostname | ||
port: dbConfig.port | ||
database: dbConfig.path.substr 1 | ||
user: user | ||
password: pass | ||
pool: | ||
min: 2 | ||
max: 10 | ||
migrations: | ||
tableName: 'knex_migrations' | ||
|
||
module.exports = | ||
development: cfg | ||
staging: cfg | ||
production: cfg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
exports.up = (knex, Promise) -> | ||
knex.schema.createTable 'jobs', (t) -> | ||
# Job UUID | ||
t.uuid('id').primary() | ||
|
||
# Timestamp info | ||
t.timestamps() | ||
# When whole job completed | ||
t.timestamp('completed_at').index() | ||
# When whole job failed | ||
t.timestamp('failed_at').index() | ||
|
||
# Data associated with this job | ||
# XXX: a bit quick & dirty | ||
# Normally one would have a separate table for the images, with a foreign key referring the job | ||
t.jsonb('data') | ||
|
||
exports.down = (knex, Promise) -> | ||
knex.schema.dropTableIfExists 'jobs' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters