Skip to content

Commit

Permalink
Merge pull request #16 from EspadaV8/main
Browse files Browse the repository at this point in the history
Update readme examples to work with Kysely
  • Loading branch information
acro5piano committed Dec 19, 2023
2 parents 5e7ec44 + db9c912 commit f92ddee
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions README.md
Expand Up @@ -23,21 +23,36 @@ Create a migration script as shown below:
```typescript
// scripts/migrate.ts

import * as path from 'path'
import { promises as fs } from 'fs'
import pg from 'pg'
import { Kysely, Migrator, PostgresDialect, FileMigrationProvider } from 'kysely'
import { run } from 'kysely-migration-cli'

// For ESM environment
const migrationFolder = new URL('./migrations', import.meta.url).pathname

// For CJS environment
// const migrationFolder = path.join(__dirname, './migrations')

const db = new Kysely<any>({
dialect: new PostgresDialect({
connectionString: process.env.DATABASE_URL,
pool: new pg.Pool({
connectionString: process.env.DATABASE_URL,
}),
}),
})

const migrator = new Migrator({
db,
provider: new FileMigrationProvider('./migrations'),
provider: new FileMigrationProvider({
fs,
path,
migrationFolder,
}),
})

run(db, migrator)
run(db, migrator, migrationFolder)
```

Then run:
Expand Down

0 comments on commit f92ddee

Please sign in to comment.