From 08a5f95b35687d146c26356b4a29336562d077c0 Mon Sep 17 00:00:00 2001 From: Haralan Dobrev Date: Tue, 22 Jun 2021 22:34:42 +0300 Subject: [PATCH 1/2] Copy seeds even when starting dev watching --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 882b0bca..34250807 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "postbuild": "cp -r src/seeds/parl-2021-04-04 dist/seeds/", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "start": "nest start", + "prestart:dev": "mkdir -p dist/seeds && cp -r src/seeds/parl-2021-04-04 dist/seeds/", "start:dev": "nest start --watch", "start:dev:db": "./scripts/start-dev-db.sh", "start:debug": "nest start --debug --watch", From e2298394fcd9b4b88f4bfad12f7ab76ed1da34f1 Mon Sep 17 00:00:00 2001 From: Haralan Dobrev Date: Tue, 22 Jun 2021 22:35:10 +0300 Subject: [PATCH 2/2] Warn instead of erroring out and exiting for missing streams CSV seed data --- src/seeds/1616992561879-AddStreams.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/seeds/1616992561879-AddStreams.ts b/src/seeds/1616992561879-AddStreams.ts index 48a1b620..7c0acb97 100644 --- a/src/seeds/1616992561879-AddStreams.ts +++ b/src/seeds/1616992561879-AddStreams.ts @@ -1,18 +1,23 @@ -import { csvToSql } from 'src/utils/csvToSql'; +import * as fs from 'fs'; import { MigrationInterface, QueryRunner } from 'typeorm'; import { ulid } from 'ulid'; +import { csvToSql } from 'src/utils/csvToSql'; export class AddStreams1616992561879 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { - ( - await csvToSql(__dirname + '/parl-2021-04-04/streams.csv', 'streams', { - emptyColumnCallback: () => { - return ulid(); - }, - }) - ) - .split(';') - .map(async (sql) => await queryRunner.query(sql)); + const streamsInput = __dirname + '/parl-2021-04-04/streams.csv'; + if (!fs.existsSync(streamsInput)) { + console.warn(`Missing streams seed input: ${streamsInput}`); + return; + } + + const sql = await csvToSql(streamsInput, 'streams', { + emptyColumnCallback: () => { + return ulid(); + }, + }); + + sql.split(';').forEach(async (sql) => await queryRunner.query(sql)); } public async down(queryRunner: QueryRunner): Promise {