salsita / node-pg-migrate

Node.js database migration management for PostgreSQL
https://salsita.github.io/node-pg-migrate
MIT License
1.29k stars 177 forks source link

RunnerOption (RunnerOptionConfig) Type does not have an optional value for count? #754

Closed peterfargo2 closed 2 years ago

peterfargo2 commented 3 years ago

I am not sure if I am correct with my assumptions, but I am not sure where else to ask. When I want to provide a migrationRunner method that runs all necessary migrations without me knowing the count, would I just not provide a count value?

For example this runs all of the extra migrations I have just fine with count not provided.

import { Client, PoolConfig } from 'pg'
import path from 'path'
import migrationRunner, { RunnerOption } from 'node-pg-migrate'

export const runUpMigrations = async (pgConfig: PoolConfig) => {
const client = new Client(pgConfig)
const options: RunnerOption = {
    direction: 'up',
    // count: 1,
    dbClient: client,
    dir: path.resolve(__dirname, '../../migrations'),
    migrationsTable: 'migrations',
}

try {
    await client.connect()
    await migrationRunner(options)
    await client.end()

} catch (e) {
    await client.end()

}
}

Is this the correct way of handling migrations when I am not sure of how many need to be ran?

If so, I currently get the error

[COMPILER] src/db/migration-runner.ts(7,11): error TS2322: Type '{ direction: "up"; dbClient: Client; dir: string; migrationsTable: string; }' is not assignable to type 'RunnerOption'. [COMPILER] Type '{ direction: "up"; dbClient: Client; dir: string; migrationsTable: string; }' is not assignable to type. 'RunnerOptionConfig & RunnerOptionClient'. [COMPILER] Property 'count' is missing in type '{ direction: "up"; dbClient: Client; dir: string; migrationsTable: string; }' but required in type 'RunnerOptionConfig'.

So when looking at the type I see that count is not optional

export interface RunnerOptionConfig { migrationsTable: string; migrationsSchema?: string; schema?: string | string[]; dir: string; checkOrder?: boolean; direction: MigrationDirection; count: number; timestamp?: boolean; ignorePattern?: string; file?: string; dryRun?: boolean; createSchema?: boolean; createMigrationsSchema?: boolean; singleTransaction?: boolean; noLock?: boolean; fake?: boolean; decamelize?: boolean; log?: LogFn; logger?: Logger; verbose?: boolean; }

Thanks for creating an awesome package!

littlewhywhat commented 3 years ago

@peterfargo2 hi! thank you for submitting this ticket. We gonna try to improve it as it makes sense. As a quick workaround you can try to just provide Infinity to count and this will be the same behavior as the usual default one.