Skip to content

Commit

Permalink
Merge pull request #57 from ti-broish/seed-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hkdobrev authored Jun 22, 2021
2 parents 00d1913 + e229839 commit 38d9399
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
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 38d9399

Please sign in to comment.