Skip to content

Commit

Permalink
Integrate Prettier (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
koistya committed Aug 3, 2017
1 parent b936e7a commit 7cf33ea
Show file tree
Hide file tree
Showing 24 changed files with 816 additions and 408 deletions.
7 changes: 0 additions & 7 deletions .eslintrc

This file was deleted.

29 changes: 29 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Node.js API Starter Kit (https://reactstarter.com/nodejs)
*
* Copyright © 2016-present Kriasoft, LLC. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/

module.exports = {
parser: 'babel-eslint',
extends: [
'airbnb-base',
'prettier',
],
plugins: [
'flowtype',
'prettier'
],
rules: {
'prettier/prettier': [
'error',
{
singleQuote: true,
trailingComma: 'all',
},
]
}
}
103 changes: 83 additions & 20 deletions migrations/201612010000_initial.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,32 @@

// Create database schema for storing user accounts, logins and authentication claims/tokens
// Source https://github.com/membership/membership.db
module.exports.up = async (db) => {
module.exports.up = async db => {
// User accounts
await db.schema.createTable('users', (table) => {
await db.schema.createTable('users', table => {
// UUID v1mc reduces the negative side effect of using random primary keys
// with respect to keyspace fragmentation on disk for the tables because it's time based
// https://www.postgresql.org/docs/current/static/uuid-ossp.html
table.uuid('id').notNullable().defaultTo(db.raw('uuid_generate_v1mc()')).primary();
table
.uuid('id')
.notNullable()
.defaultTo(db.raw('uuid_generate_v1mc()'))
.primary();
table.string('display_name', 100);
table.string('image_url', 200);
table.jsonb('emails').notNullable().defaultTo('[]');
table.timestamps(false, true);
});

// External logins with security tokens (e.g. Google, Facebook, Twitter)
await db.schema.createTable('logins', (table) => {
table.uuid('user_id').notNullable().references('id').inTable('users').onDelete('CASCADE').onUpdate('CASCADE');
await db.schema.createTable('logins', table => {
table
.uuid('user_id')
.notNullable()
.references('id')
.inTable('users')
.onDelete('CASCADE')
.onUpdate('CASCADE');
table.string('provider', 16).notNullable();
table.string('id', 36).notNullable();
table.string('username', 100);
Expand All @@ -34,38 +44,91 @@ module.exports.up = async (db) => {
table.primary(['provider', 'id']);
});

await db.schema.createTable('stories', (table) => {
table.uuid('id').notNullable().defaultTo(db.raw('uuid_generate_v1mc()')).primary();
table.uuid('author_id').notNullable().references('id').inTable('users').onDelete('CASCADE').onUpdate('CASCADE');
await db.schema.createTable('stories', table => {
table
.uuid('id')
.notNullable()
.defaultTo(db.raw('uuid_generate_v1mc()'))
.primary();
table
.uuid('author_id')
.notNullable()
.references('id')
.inTable('users')
.onDelete('CASCADE')
.onUpdate('CASCADE');
table.string('title', 80).notNullable();
table.string('url', 200);
table.text('text');
table.timestamps(false, true);
});

await db.schema.createTable('story_points', (table) => {
table.uuid('story_id').references('id').inTable('stories').onDelete('CASCADE').onUpdate('CASCADE');
table.uuid('user_id').notNullable().references('id').inTable('users').onDelete('CASCADE').onUpdate('CASCADE');
await db.schema.createTable('story_points', table => {
table
.uuid('story_id')
.references('id')
.inTable('stories')
.onDelete('CASCADE')
.onUpdate('CASCADE');
table
.uuid('user_id')
.notNullable()
.references('id')
.inTable('users')
.onDelete('CASCADE')
.onUpdate('CASCADE');
table.primary(['story_id', 'user_id']);
});

await db.schema.createTable('comments', (table) => {
table.uuid('id').notNullable().defaultTo(db.raw('uuid_generate_v1mc()')).primary();
table.uuid('story_id').notNullable().references('id').inTable('stories').onDelete('CASCADE').onUpdate('CASCADE');
table.uuid('parent_id').references('id').inTable('comments').onDelete('CASCADE').onUpdate('CASCADE');
table.uuid('author_id').notNullable().references('id').inTable('users').onDelete('CASCADE').onUpdate('CASCADE');
await db.schema.createTable('comments', table => {
table
.uuid('id')
.notNullable()
.defaultTo(db.raw('uuid_generate_v1mc()'))
.primary();
table
.uuid('story_id')
.notNullable()
.references('id')
.inTable('stories')
.onDelete('CASCADE')
.onUpdate('CASCADE');
table
.uuid('parent_id')
.references('id')
.inTable('comments')
.onDelete('CASCADE')
.onUpdate('CASCADE');
table
.uuid('author_id')
.notNullable()
.references('id')
.inTable('users')
.onDelete('CASCADE')
.onUpdate('CASCADE');
table.text('text');
table.timestamps(false, true);
});

await db.schema.createTable('comment_points', (table) => {
table.uuid('comment_id').references('id').inTable('comments').onDelete('CASCADE').onUpdate('CASCADE');
table.uuid('user_id').notNullable().references('id').inTable('users').onDelete('CASCADE').onUpdate('CASCADE');
await db.schema.createTable('comment_points', table => {
table
.uuid('comment_id')
.references('id')
.inTable('comments')
.onDelete('CASCADE')
.onUpdate('CASCADE');
table
.uuid('user_id')
.notNullable()
.references('id')
.inTable('users')
.onDelete('CASCADE')
.onUpdate('CASCADE');
table.primary(['comment_id', 'user_id']);
});
};

module.exports.down = async (db) => {
module.exports.down = async db => {
await db.schema.dropTableIfExists('comment_points');
await db.schema.dropTableIfExists('comments');
await db.schema.dropTableIfExists('story_points');
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@
"chokidar": "^1.7.0",
"eslint": "^4.3.0",
"eslint-config-airbnb-base": "^11.3.1",
"eslint-config-prettier": "^2.3.0",
"eslint-plugin-flowtype": "^2.35.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-prettier": "^2.1.2",
"flow-bin": "^0.51.1",
"mocha": "^3.5.0",
"prettier": "^1.5.3",
"rimraf": "^2.6.1"
},
"scripts": {
Expand Down
95 changes: 64 additions & 31 deletions seeds/data-sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,78 @@

const faker = require('faker');

module.exports.seed = async (db) => {
module.exports.seed = async db => {
// Create 10 random website users (as an example)
const users = Array.from({ length: 10 }).map(() => ({
display_name: faker.name.findName(),
image_url: faker.internet.avatar(),
emails: JSON.stringify([{ email: faker.internet.email().toLowerCase(), verified: false }]),
emails: JSON.stringify([
{ email: faker.internet.email().toLowerCase(), verified: false },
]),
}));

await Promise.all(users.map(user =>
db.table('users').insert(user).returning('id')
.then(rows => db.table('users').where('id', '=', rows[0]).first('*'))
.then(row => Object.assign(user, row))));
await Promise.all(
users.map(user =>
db
.table('users')
.insert(user)
.returning('id')
.then(rows => db.table('users').where('id', '=', rows[0]).first('*'))
.then(row => Object.assign(user, row)),
),
);

// Create 500 stories
const stories = Array.from({ length: 500 }).map(() => Object.assign(
{
author_id: users[faker.random.number({ min: 0, max: users.length - 1 })].id,
title: faker.lorem.sentence(faker.random.number({ min: 4, max: 7 }))
.slice(0, -1).substr(0, 80),
},
Math.random() > 0.3 ? { text: faker.lorem.text() } : { url: faker.internet.url() },
(date => ({ created_at: date, updated_at: date }))(faker.date.past())));

await Promise.all(stories.map(story =>
db.table('stories').insert(story).returning('id')
.then(rows => db.table('stories').where('id', '=', rows[0]).first('*'))
.then(row => Object.assign(story, row))));
const stories = Array.from({ length: 500 }).map(() =>
Object.assign(
{
author_id:
users[faker.random.number({ min: 0, max: users.length - 1 })].id,
title: faker.lorem
.sentence(faker.random.number({ min: 4, max: 7 }))
.slice(0, -1)
.substr(0, 80),
},
Math.random() > 0.3
? { text: faker.lorem.text() }
: { url: faker.internet.url() },
(date => ({ created_at: date, updated_at: date }))(faker.date.past()),
),
);

await Promise.all(
stories.map(story =>
db
.table('stories')
.insert(story)
.returning('id')
.then(rows => db.table('stories').where('id', '=', rows[0]).first('*'))
.then(row => Object.assign(story, row)),
),
);

// Create some user comments
const comments = Array.from({ length: 2000 }).map(() => Object.assign(
{
story_id: stories[faker.random.number({ min: 0, max: stories.length - 1 })].id,
author_id: users[faker.random.number({ min: 0, max: users.length - 1 })].id,
text: faker.lorem.sentences(faker.random.number({ min: 1, max: 10 })),
},
(date => ({ created_at: date, updated_at: date }))(faker.date.past())));

await Promise.all(comments.map(comment =>
db.table('comments').insert(comment).returning('id')
.then(rows => db.table('comments').where('id', '=', rows[0]).first('*'))
.then(row => Object.assign(comment, row))));
const comments = Array.from({ length: 2000 }).map(() =>
Object.assign(
{
story_id:
stories[faker.random.number({ min: 0, max: stories.length - 1 })].id,
author_id:
users[faker.random.number({ min: 0, max: users.length - 1 })].id,
text: faker.lorem.sentences(faker.random.number({ min: 1, max: 10 })),
},
(date => ({ created_at: date, updated_at: date }))(faker.date.past()),
),
);

await Promise.all(
comments.map(comment =>
db
.table('comments')
.insert(comment)
.returning('id')
.then(rows => db.table('comments').where('id', '=', rows[0]).first('*'))
.then(row => Object.assign(comment, row)),
),
);
};

0 comments on commit 7cf33ea

Please sign in to comment.