Skip to content

Commit

Permalink
fix(migrations): set config initial value (cross-seed#557)
Browse files Browse the repository at this point in the history
How to reproduce: on a clear environment run `cross-seed api-key`

```
migration file "02-timestamps" failed
migration failed with error: Cannot destructure property 'torznab' of 'getRuntimeConfig(...)' as it is undefined.
file:///usr/local/lib/node_modules/cross-seed/dist/migrations/02-timestamps.js:10
    const { torznab } = getRuntimeConfig();
            ^

TypeError: Cannot destructure property 'torznab' of 'getRuntimeConfig(...)' as it is undefined.
    at backfill (file:///usr/local/lib/node_modules/cross-seed/dist/migrations/02-timestamps.js:10:13)
    at Object.up (file:///usr/local/lib/node_modules/cross-seed/dist/migrations/02-timestamps.js:42:11)
    at async Migrator._runBatch (/usr/local/lib/node_modules/cross-seed/node_modules/knex/lib/migrations/migrate/Migrator.js:381:19)
```

The commands `api-key` and `reset-api-key` will fail when running the
migrations for the first time.

- `getRuntimeConfig` _needs_ to always return an object to the
destructure works.
- if `torznab` doesnt exist, `.length` will fail as well, optional
chaining protect us against undefined.
  • Loading branch information
fabricionaweb authored Dec 15, 2023
1 parent f498164 commit 5aa3d7f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/migrations/02-timestamps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function getApikey(url: string) {
}

async function backfill(knex: Knex.Knex) {
const { torznab } = getRuntimeConfig();
const torznab = getRuntimeConfig()?.torznab ?? [];

if (torznab.length > 0) {
await knex("indexer")
Expand Down

0 comments on commit 5aa3d7f

Please sign in to comment.