diff --git a/.travis.yml b/.travis.yml index d1e1c394..d87eea19 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,23 +3,21 @@ node_js: '6' sudo: required dist: trusty addons: - firefox: 52.3.0 - postgresql: '9.4' + firefox: latest install: -- npm install + - npm install before_install: -- export DISPLAY=:99.0 -- sh -e /etc/init.d/xvfb start -- psql -c 'create database bitballs;' -U postgres + - 'export DISPLAY=:99.0' + - sh -e /etc/init.d/xvfb start script: -- sudo sh -c 'dbus-uuidgen > /etc/machine-id' + - sudo sh -c 'dbus-uuidgen > /etc/machine-id' before_deploy: -- git config --global user.email "justin@bitovi.com" -- git config --global user.name "bitballs deploy bot" -- node public/build -- git add public/dist/ --force -- git commit -m "Updating build." -- node_modules/.bin/firebase deploy --token "$FIREBASE_TOKEN" + - git config --global user.email "justin@bitovi.com" + - git config --global user.name "bitballs deploy bot" + - node public/build + - git add public/dist/ --force + - git commit -m "Updating build." + - node_modules/.bin/firebase deploy --token "$FIREBASE_TOKEN" deploy: skip_cleanup: true provider: heroku @@ -28,4 +26,4 @@ deploy: secure: "eQg48vbV7bfZ86eJ+e9oTt8hU18zS6frECUOr+v4J8paLEnBhSaKYnAAQolhAiS+aWfs9ZwAuvSbGtyKoDiTfdtlIfemFqufTRWVHVMJUUEcRpgTPZ8ooq1vkIMdVQUXEEnu1bO9cnLBJzxbDw84qOsFE7bNUyUeT0a6gnrGMleL0FRXNy9qNU5MO1DaQhOOA5JyOt666+W26bRyDnVnNNMrrB6fv4dY2M9oR40EYiQ0WcrzuXxSgpm/WHU+DPSfw/2rqbq0leOjpMZCJZh4XDTc02P9X31YgKAJhChI4OApdZbEpunbH7U2qu7VzN8pYxl0YqKM7/8he4IjO5bG+92Y1daVwmJ4gV0YjIrVrDaBs+n0El47ktY19IEuOBxkbDXJ9yNnREyEQx8DZofDOdfiWol6Ra0BORZowrcwssvFPA/ZDrqQTCKsAY7sPlaRMJqLPz0dJOyRVNlFXbnccvWHLuqDLQIiMnH0ZrfZ/Ggst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yyIHQyXq9ol9cFmHBkYdAYHd5Lo9NKpbHIjx2Fzb9qiFJq26MMBomgZT1l884TS9c9bwQHumzjJy0GZEyhNE/AReycNTEo33CkcD/OAQ7arNsU2c2/yVHVUcXUJSmIGDDbL/OC1/9tjTB/TWjMrkyxvv/5omO5pQpcdM0ed1aGjH2EBUhWlyjY5zivsyr3NlbYfeG/aLsjns6N0VDpcGtqRlvYhg2DQkjbTW4BIoDSBrxTM5k+ERnrRinI46FzPHObFt4i74o4TGlEsWTKLKnKxUhVWpfyiD2XItE7yF+Ol+guelvlYTNK/2J62aVURN5LZWKtsS98JeEOJS4TXt3d/osFxyBOFwIU/AHp09bg6sOTfaj6gZkz2n81TaezVwWR6Ly55AsACqbAWmSKO0X72OEGWDeT0kQ4CyrYV9XRRqzBpQB0EftBxAgLaUPilT7UMH7W8iU2zu06s931+KNSDdB4aUJuuSwpETWz1oQjo= \ No newline at end of file diff --git a/database.json b/database.json index 50745866..a7d77b21 100644 --- a/database.json +++ b/database.json @@ -1,5 +1,9 @@ { - "dev": "postgres://localhost:5432/bitballs", + "dev": { + "driver": "sqlite3", + "filename": "sqlite.db" + }, + "test": "postgres://localhost:5432/bitballs", "prod": { "ENV": "DATABASE_URL", "driver": "pg" diff --git a/migrations/20150801045523-players.js b/migrations/20150801045523-players.js index ba9cd05a..d89d28b5 100644 --- a/migrations/20150801045523-players.js +++ b/migrations/20150801045523-players.js @@ -1,7 +1,7 @@ exports.up = function(db, callback) { db.createTable('players', { id: { type: 'int', primaryKey: true, autoIncrement: true }, - name: 'string', + name: { type: 'string', notNull: true }, weight: 'int', height: 'int', birthday: 'date', diff --git a/migrations/20150804053921-add-stats.js b/migrations/20150804053921-add-stats.js index 1c8f2548..1069ecee 100644 --- a/migrations/20150804053921-add-stats.js +++ b/migrations/20150804053921-add-stats.js @@ -4,7 +4,7 @@ exports.up = function(db, callback) { async.series([ db.createTable.bind(db, 'tournaments', { id: { type: 'int', primaryKey: true, autoIncrement: true }, - date: 'date' + date: { type: 'date', notNull: true }, }), db.createTable.bind(db, 'teams', { id: { type: 'int', primaryKey: true, autoIncrement: true }, @@ -22,13 +22,15 @@ exports.up = function(db, callback) { round: 'string', court: 'string', videoUrl: 'string', - homeTeamId: 'string', - awayTeamId: 'string' + homeTeamId: 'int', + awayTeamId: 'int' }), db.createTable.bind(db, 'stats', { id: { type: 'int', primaryKey: true, autoIncrement: true }, gameId: 'int', playerId: 'int', + time: { type: 'int' }, + value: {type: 'int'}, type: 'string' }) ], callback); @@ -42,4 +44,3 @@ exports.down = function(db, callback) { db.dropTable.bind(db, 'stats') ], callback); }; - diff --git a/migrations/20150809023413-add-stats-time.js b/migrations/20150809023413-add-stats-time.js deleted file mode 100644 index 0e9bb4a1..00000000 --- a/migrations/20150809023413-add-stats-time.js +++ /dev/null @@ -1,15 +0,0 @@ -var async = require('async'); - -exports.up = function(db, callback) { - async.series([ - db.addColumn.bind(db, "stats","time",{type: 'int'}), - db.addColumn.bind(db, "stats","value",{type: 'int'}) - ], callback); -}; - -exports.down = function(db, callback) { - async.series([ - db.removeColumn.bind(db, "stats","time"), - db.removeColumn.bind(db, "stats","value") - ], callback); -}; diff --git a/migrations/20150816063154-add-users.js b/migrations/20150816063154-add-users.js index ac315bd2..9bed887f 100644 --- a/migrations/20150816063154-add-users.js +++ b/migrations/20150816063154-add-users.js @@ -2,8 +2,17 @@ exports.up = function(db, callback) { db.createTable('users', { id: { type: 'int', primaryKey: true, autoIncrement: true }, name: 'string', - password: 'string', + password: { type: 'string', notNull: true }, email: {type: 'string', unique: true}, + verificationHash: { + type: "string", + length: 100 + }, + verified: { + type: "boolean", + notNull: true, + defaultValue: false + }, isAdmin: 'boolean' }, callback); }; diff --git a/migrations/20160301185116-required-fields.js b/migrations/20160301185116-required-fields.js deleted file mode 100644 index f722c71f..00000000 --- a/migrations/20160301185116-required-fields.js +++ /dev/null @@ -1,31 +0,0 @@ -var async = require('async'); - -exports.up = function(db, callback) { - async.series([ - db.changeColumn.bind(db, 'players', 'name', { - notNull: true - }), - db.changeColumn.bind(db, 'users', 'password', { - notNull: true - }), - db.changeColumn.bind(db, 'tournaments', 'date', { - notNull: true - }) - ], - callback); -}; - -exports.down = function(db, callback) { - async.series([ - db.changeColumn.bind(db, 'players', 'name', { - notNull: false - }), - db.changeColumn.bind(db, 'users', 'password', { - notNull: false - }), - db.changeColumn.bind(db, 'tournaments', 'date', { - notNull: false - }) - ], - callback); -}; diff --git a/migrations/20160307152540-validate-emails.js b/migrations/20160307152540-validate-emails.js deleted file mode 100644 index 21c8c023..00000000 --- a/migrations/20160307152540-validate-emails.js +++ /dev/null @@ -1,24 +0,0 @@ -var async = require('async'); - -exports.up = function(db, callback) { - async.series([ - db.addColumn.bind(db, 'users', 'verified', { - type: "boolean", - notNull: true, - defaultValue: false - }), - db.addColumn.bind(db, 'users', 'verificationHash', { - type: "string", - length: 100 - }) - ], - callback); -}; - -exports.down = function(db, callback) { - async.series([ - db.removeColumn.bind(db, 'users', 'verified' ), - db.removeColumn.bind(db, 'users', 'verificationHash' ) - ], - callback); -}; diff --git a/migrations/20160313205522-team-ints.js b/migrations/20160313205522-team-ints.js deleted file mode 100644 index b8b8090c..00000000 --- a/migrations/20160313205522-team-ints.js +++ /dev/null @@ -1,21 +0,0 @@ -var async = require('async'); - -exports.up = function(db, callback) { - async.series([ - db.runSql.bind(db, 'ALTER TABLE games ALTER COLUMN "homeTeamId" TYPE integer USING "homeTeamId"::numeric'), - db.runSql.bind(db, 'ALTER TABLE games ALTER COLUMN "awayTeamId" TYPE integer USING "awayTeamId"::numeric') - ], - callback); -}; - -exports.down = function(db, callback) { - async.series([ - db.changeColumn.bind(db, 'games', 'homeTeamId', { - type: 'string' - }), - db.changeColumn.bind(db, 'games', 'awayTeamId', { - type: 'string' - }) - ], - callback); -}; diff --git a/models/bookshelf.js b/models/bookshelf.js index e27e7266..5b5e6255 100644 --- a/models/bookshelf.js +++ b/models/bookshelf.js @@ -7,8 +7,18 @@ var connectionString = typeof dbEnvironmentConfig === 'string' ? dbEnvironmentConfig : process.env[dbEnvironmentConfig.ENV]; +if (typeof dbEnvironmentConfig.filename === 'string') { + connectionString = { + filename: dbEnvironmentConfig.filename + }; + // Creates the database if needed + var driver = require(dbEnvironmentConfig.driver).verbose(); + new driver.Database(dbEnvironmentConfig.filename); +} + + var knex = require('knex')({ - client: 'pg', + client: dbEnvironmentConfig.driver, connection: connectionString });