working server with migrations as defined

BOOM BABY!!!
This commit is contained in:
2020-06-16 01:54:12 -06:00
parent 3505b16169
commit d212d3b36c
15 changed files with 133 additions and 20 deletions

View File

@ -4,7 +4,7 @@
"private": true,
"scripts": {
"start": "yarn build && node --inspect ./build/bin/www",
"typescript": "tsc && cp -R ./src/views ./build/ && cp -R ./src/public ./build/",
"typescript": "tsc && cp -R ./src/views ./build/ && cp -R ./src/public ./build/ && cp ./src/migrationJobs/*.sql ./build/migrationJobs/",
"build": "yarn typescript",
"dist": "yarn build && cp -R ./build ./dist/ && cp -R ./node_modules ./dist/"
},
@ -23,6 +23,7 @@
"morgan": "~1.9.1",
"passport": "^0.4.1",
"passport-oauth2": "^1.5.0",
"passport-oauth2-refresh": "^2.0.0"
"passport-oauth2-refresh": "^2.0.0",
"path": "^0.12.7"
}
}

View File

@ -29,7 +29,7 @@ var strategy = new OAuth2Strategy({
},
function(accessToken, refreshToken, params, _, cb) {
console.log(params);
userService.findOrCreate(params.profile).then((user) => {
userService.findOrCreate(params.profile).then((user: any) => {
user.refreshToken = refreshToken;
user.accessToken = accessToken;
return cb(null, user);

View File

@ -1,6 +1,6 @@
import { Database } from './db/db';
import { Mapper } from './db/Mapper';
import { Altitude, Job } from './db/migrations/Altitude';
import { Altitude, Job } from './db/Altitude';
import jobs from './migrationJobs';
let db = new Database({

View File

@ -1,4 +1,4 @@
import { Mapper } from '../Mapper';
import { Mapper } from './Mapper';
class Altitude {
private migrations: Job[];

View File

@ -1,4 +1,4 @@
import { Database } from '../db/db';
import { Database } from './db';
class Mapper {
constructor(public database: Database) {}

View File

@ -1,2 +1,2 @@
import { config } from 'dotenv';
config({ silent: true })
config();

View File

@ -1,11 +1,29 @@
import { Job } from '../db/migrations/Altitude';
import { Job } from '../db/Altitude';
import * as fs from 'fs';
import * as path from 'path';
let jobs: Job[] = [];
jobs.push({
creator: 'Mason Payne',
name: 'initializeDB',
query: `CREATE TABLE Users (sub VARCHAR(36) NOT NULL UNIQUE, email VARCHAR(255) NOT NULL UNIQUE, accessToken VARCHAR(255), refreshToken VARCHAR(255), CreationTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (sub));`
});
let files = fs.readdirSync(path.join(__dirname)).filter(file => file !== 'index.js');
for (let i in files) {
try {
var data = fs.readFileSync(path.join(__dirname, files[i]), 'utf8');
let parts = data.split('--down').filter(part => part.indexOf('--up') !== -1);
if (parts.length) {
// there is an up command in this file
let upParts = parts[0].split('--up');
jobs.push({
creator: 'system',
name: files[i],
query: upParts[1].split('\n').join('')
});
}
} catch(e) {
console.log('Error:', e.stack);
}
}
console.log(jobs);
// SYSTEM-BUILDER-jobs.push

View File

@ -534,6 +534,14 @@ path-to-regexp@0.1.7:
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"
integrity sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=
path@^0.12.7:
version "0.12.7"
resolved "https://registry.yarnpkg.com/path/-/path-0.12.7.tgz#d4dc2a506c4ce2197eb481ebfcd5b36c0140b10f"
integrity sha1-1NwqUGxM4hl+tIHr/NWzbAFAsQ8=
dependencies:
process "^0.11.1"
util "^0.10.3"
pause@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/pause/-/pause-0.0.1.tgz#1d408b3fdb76923b9543d96fb4c9dfd535d9cb5d"
@ -544,6 +552,11 @@ process-nextick-args@~2.0.0:
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==
process@^0.11.1:
version "0.11.10"
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI=
proxy-addr@~2.0.4:
version "2.0.6"
resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.6.tgz#fdc2336505447d3f2f2c638ed272caf614bbb2bf"
@ -701,6 +714,13 @@ util-deprecate@~1.0.1:
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=
util@^0.10.3:
version "0.10.4"
resolved "https://registry.yarnpkg.com/util/-/util-0.10.4.tgz#3aa0125bfe668a4672de58857d3ace27ecb76901"
integrity sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==
dependencies:
inherits "2.0.3"
utils-merge@1.0.1, utils-merge@1.x.x:
version "1.0.1"
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"