Skip to content

Commit

Permalink
fix: allow migrate js by using config
Browse files Browse the repository at this point in the history
  • Loading branch information
ScopeSV committed Nov 28, 2023
1 parent fa153ef commit 9276464
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/handlers/migrateMigrationsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export const migrateMigrationsHandler = (direction: Direction) => () => {
console.error('Database creds not found in config')
process.exit(1)
}
const migrator = new Migrator(cfg)
const migrator = new Migrator(cfg, configParser)
migrator.migrate(direction)
}
17 changes: 14 additions & 3 deletions src/migrator/migrator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config } from '../config-file/ConfigParser'
import { Config, ConfigParser } from '../config-file/ConfigParser'
import ts from 'typescript'
import {
Kysely,
Expand All @@ -19,7 +19,10 @@ export class Migrator {
#db: Kysely<any>
#migrator: KyselyMigrator

constructor(public cfg: Config) {
constructor(
public cfg: Config,
public configParser: ConfigParser
) {
this.#db = this.#createDbConnector()
this.#migrator = this.#createDbMigrator()
}
Expand All @@ -32,13 +35,20 @@ export class Migrator {
})
}

#getMigrationDir = () => {
if (this.cfg.useJsExtension) {
return this.configParser.getMigrationDir()
}
return path.resolve('tempMigrations')
}

#createDbMigrator = () => {
return new KyselyMigrator({
db: this.#db,
provider: new FileMigrationProvider({
fs,
path,
migrationFolder: path.resolve('tempMigrations'),
migrationFolder: this.#getMigrationDir(),
}),
})
}
Expand All @@ -58,6 +68,7 @@ export class Migrator {
}
}
#deleteDirectory() {
if (!fileSys.existsSync(this.#tempFileDir)) return
this.#deleteDirectoryContents()
fileSys.rmdirSync(this.#tempFileDir)
}
Expand Down

0 comments on commit 9276464

Please sign in to comment.