Skip to content

Commit

Permalink
Merged release/v0.1.1 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Drake Costa committed Dec 10, 2016
2 parents 13b2500 + e584b4e commit 4f34565
Show file tree
Hide file tree
Showing 52 changed files with 2,255 additions and 14 deletions.
11 changes: 11 additions & 0 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Project Changelog

> *[Return to Directory](README.md)*
## v0.1.1

- Fixed the outstanding errors with SQLite3 migrations. Because SQLite3 does not supposrt adding foreign keys after a table is created, foreign key creation is now conditionally added based on the environment.
- Another issue with migrations was fixed by moving all table definitions back to a subfolder, because Knex's migrations API doesn't seem to allow you to exclude files.
- Added some documentation, including a project Roadmap and a Changelog.
- Added missing dependency Winston-Loggly-Bulk.
- Removed leftover references to previous express server implementation in routes.
6 changes: 6 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Scribe Documentation

##<a name="contents"></a> Table of Contents

- [Project Roadmap](ROADMAP.md)
- [Changelog](CHANGELOG.md)
37 changes: 37 additions & 0 deletions doc/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Project Roadmap

> *[Return to Directory](README.md)*
## v0.2.0

- [ ] Refactor Types/Models to condense data schema into one place per table.
- [ ] Write basic project documentation (setup, getting started, etc) ie: [README](../README.md)
- [ ] Wire-up Hapi Routes
- [X] Troubleshoot remaining issues with SQLite Migrations / Knex schema
- [ ] Add pagination query arguments for lists

## v0.3.0

- [ ] Add remaining mutations to enable populating the database via the API
- [ ] Add private tables / type definitions
- [ ] Tables: Account, Collection, Binders, Decks, OwnedCards, misc
- [ ] Type definitions/queries/mutations for above

## v0.4.0

- [ ] Setup login/signup REST API
- [ ] Add authentication layer to GraphQL API for private Tables
- [ ] Add rate-limiting to public GraphQL API

## v0.5.0

- [ ] Add application state history table / frontend utility APIs
- [ ] Add trading API / services
- [ ] Create service to grab pricing data from public API sources
- [ ] Add GraphQL types/queries to expose pricing data
- [ ] Add tables / type definitions for Trading platform

## v0.6.0

- [ ] Refactor GraphQL resolvers to use batch SQL querying (speculative)
- [ ] ...?
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scribe",
"version": "0.1.0",
"version": "0.1.1",
"description": "A GraphQL Magic: The Gathering API Server",
"main": "src/app.js",
"productName": "Scribe",
Expand Down Expand Up @@ -67,6 +67,7 @@
"passport-oauth2": "^1.1.2",
"sqlite3": "^3.1.8",
"test-runner-config": "^0.5.0",
"winston": "^2.3.0"
"winston": "^2.3.0",
"winston-loggly-bulk": "^1.3.4"
}
}
12 changes: 7 additions & 5 deletions src/models/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path'
import glob from 'glob' // https://github.com/isaacs/node-glob
import config from '../config/server.config'

export function loadModels() {
let modelsArray = []
Expand Down Expand Up @@ -50,6 +51,7 @@ function create(knex, migrations) {
toBeCreated.push(
knex.schema.createTableIfNotExists(migration.name, (table) => {
migration.fields(table)
if(config.ENV === 'test' || config.ENV === 'development') migration.foreignKeys(table)
})
.then(() => {
console.log(`✓ Created table: ${migration.name}`)
Expand Down Expand Up @@ -108,24 +110,24 @@ function destroy(knex, migrations) {
// http://knexjs.org/#Migrations-API

export function up(knex, Promise) {
return knex.raw('SET foreign_key_checks = 0;')
return knex.raw(`${ config.ENV === 'production' ? 'SET foreign_key_checks = 0;' : 'PRAGMA foreign_keys = ON' }`)
.then(() => {
return Promise.all(loadMigrations(knex, create))
})
.then(() => {
return Promise.all(loadMigrations(knex, update))
if(config.ENV === 'production') return Promise.all(loadMigrations(knex, update))
})
.then(() => {
return knex.raw('SET foreign_key_checks = 1;')
if(config.ENV === 'production') return knex.raw('SET foreign_key_checks = 1;')
})
}

export function down(knex, Promise) {
return knex.raw('SET foreign_key_checks = 0;')
return knex.raw(`${ config.ENV === 'production' ? 'SET foreign_key_checks = 0;' : '' }`)
.then(() => {
return Promise.all(loadMigrations(knex, destroy))
})
.then(() => {
return knex.raw('SET foreign_key_checks = 1;')
if(config.ENV === 'production') return knex.raw('SET foreign_key_checks = 1;')
})
}
53 changes: 53 additions & 0 deletions src/models/tables/abilityType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import db from '../../config/bookshelf.config'

import Card from './card'
import AbilityTypes from './abilityTypes'
import AbilityTypeCards from './abilityTypeCards'

export default class abilityType extends db.Model {
get tableName() {
return 'abilitytype'
}

static fields(table) {
// Fields
table.bigIncrements(`id`)
.notNullable()
.primary()

table.string(`name`)
.comment(`The name of the ability type.`)
.notNullable()

table.text(`description`)
.comment(`Description of the ability type.`)

table.bigInteger(`cards`)
.comment(`The cards associated with this abilityType.`)
.notNullable()
.unsigned()
.index(`abilityType_cards`)

// Timestamps
table.timestamps()
}

static foreignKeys(table) {
table.foreign(`cards`)
.references(`abilitytype`)
.inTable(`abilitytypecards`)
.onDelete(`CASCADE`)
.onUpdate(`NO ACTION`)
}

abilityTypes() {
return this.belongsTo(AbilityTypes)
}

cards() {
return this.hasMany(Card, `card`)
.through(AbilityTypeCards)
}
}

export const AbilityType = new abilityType()
49 changes: 49 additions & 0 deletions src/models/tables/abilityTypeCards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import db from '../../config/bookshelf.config'

import Card from './card'
import AbilityType from './abilityType'

export default class abilityTypeCards extends db.Model {
get tableName() {
return 'abilitytypecards'
}

static fields(table) {
// Fields
table.bigInteger(`abilitytype`)
.comment(`The abilityType associated with this card.`)
.notNullable()
.unsigned()
.index(`abilityTypeCards_abilitytype`)

table.bigInteger(`card`)
.comment(`The card associated with this abilityType.`)
.notNullable()
.unsigned()
.index(`abilityTypeCards_card`)

// Timestamps
table.timestamps()

// Keys
table.primary([`abilitytype`, `card`])
}

static foreignKeys(table) {
table.foreign(`card`)
.references(`id`)
.inTable(`card`)
.onDelete(`NO ACTION`)
.onUpdate(`NO ACTION`)
}

abilityType() {
return this.belongsTo(AbilityType)
}

card() {
return this.hasMany(Card)
}
}

export const AbilityTypeCards = new abilityTypeCards()
49 changes: 49 additions & 0 deletions src/models/tables/abilityTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import db from '../../config/bookshelf.config'

import Card from './card'
import AbilityType from './abilityType'

export default class abilityTypes extends db.Model {
get tableName() {
return 'abilitytypes'
}

static fields(table) {
// Fields
table.bigInteger(`card`)
.comment(`The card associated with this abilityType.`)
.notNullable()
.unsigned()
.index(`abilitytypes_card`)

table.bigInteger(`abilitytype`)
.comment(`The abilityType associated with this card.`)
.notNullable()
.unsigned()
.index(`abilitytypes_abilitytype`)

// Timestamps
table.timestamps()

// Keys
table.primary([`card`, `abilitytype`])
}

static foreignKeys(table) {
table.foreign(`abilitytype`)
.references(`id`)
.inTable(`abilitytype`)
.onDelete(`NO ACTION`)
.onUpdate(`NO ACTION`)
}

abilityType() {
return this.belongsTo(AbilityType)
}

card() {
return this.hasMany(Card)
}
}

export const AbilityTypes = new abilityTypes()
52 changes: 52 additions & 0 deletions src/models/tables/artist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import db from '../../config/bookshelf.config'

import Card from './card'
import ArtistCards from './artistCards'

export default class artist extends db.Model {
get tableName() {
return `artist`
}

static fields(table) {
// Fields
table.bigIncrements(`id`)
.notNullable()
.primary()

table.string(`name`)
.comment(`The name of the artist.`)
.notNullable()

table.text(`website`)
.comment(`The website of the artist, if they have one.`)

table.bigInteger(`cards`)
.comment(`The cards associated with this artist.`)
.notNullable()
.unsigned()
.index(`artist_cards`)

// Timestamps
table.timestamps()
}

static foreignKeys(table) {
table.foreign(`cards`)
.references(`artist`)
.inTable(`artistcards`)
.onDelete(`CASCADE`)
.onUpdate(`NO ACTION`)
}

card() {
return this.belongsTo(Card, 'artist')
}

cards() {
return this.hasMany(Card, `card`)
.through(ArtistCards)
}
}

export const Artist = new artist()
49 changes: 49 additions & 0 deletions src/models/tables/artistCards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import db from '../../config/bookshelf.config'

import Card from './card'
import Artist from './artist'

export default class artistCards extends db.Model {
get tableName() {
return `artistcards`
}

static fields(table) {
// Fields
table.bigInteger(`artist`)
.comment(`The artist associated with this card.`)
.notNullable()
.unsigned()
.index(`artistCards_artist`)

table.bigInteger(`card`)
.comment(`The card associated with this artist.`)
.notNullable()
.unsigned()
.index(`artistCards_card`)

// Timestamps
table.timestamps()

// Keys
table.primary([`artist`, `card`])
}

static foreignKeys(table) {
table.foreign(`card`)
.references(`id`)
.inTable(`card`)
.onDelete(`NO ACTION`)
.onUpdate(`NO ACTION`)
}

artist() {
return this.belongsTo(Artist)
}

card() {
return this.hasMany(Card)
}
}

export const ArtistCards = new artistCards()
Loading

0 comments on commit 4f34565

Please sign in to comment.