Skip to content

Commit

Permalink
Warn instead of erroring out and exiting for missing streams CSV seed…
Browse files Browse the repository at this point in the history
… data
  • Loading branch information
hkdobrev committed Jun 22, 2021
1 parent 08a5f95 commit e229839
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/seeds/1616992561879-AddStreams.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
(
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<void> {
Expand Down

0 comments on commit e229839

Please sign in to comment.