|
1 | 1 | import { RDSData } from "@aws-sdk/client-rds-data"; |
2 | | -import { ColumnType, Generated, Kysely } from "kysely"; |
| 2 | +import { ColumnType, Generated, Kysely, Migrator, FileMigrationProvider } from "kysely"; |
3 | 3 | import { DataApiDialect } from "../src"; |
4 | 4 | import { DataApiDriverConfig } from "../src/data-api-driver"; |
5 | 5 | import path from "path"; |
| 6 | +import { promises as fs } from "fs"; |
6 | 7 |
|
7 | 8 | const TEST_DATABASE = "scratch"; |
8 | 9 |
|
@@ -71,7 +72,29 @@ export async function migrate() { |
71 | 72 | resourceArn: opts.resourceArn, |
72 | 73 | }); |
73 | 74 |
|
74 | | - await db.migration.migrateToLatest(path.resolve("./test/migrations")); |
| 75 | + const migrator = new Migrator({ |
| 76 | + db, |
| 77 | + provider: new FileMigrationProvider({ |
| 78 | + fs, |
| 79 | + path, |
| 80 | + migrationFolder: path.join(__dirname, "migrations"), |
| 81 | + }), |
| 82 | + }) |
| 83 | + |
| 84 | + const { error, results } = await migrator.migrateToLatest(); |
| 85 | + |
| 86 | + results?.forEach((it) => { |
| 87 | + if (it.status === "Success") { |
| 88 | + console.log(`migration "${it.migrationName}" was executed successfully`); |
| 89 | + } else if (it.status === "Error") { |
| 90 | + console.error(`failed to execute migration "${it.migrationName}"`); |
| 91 | + } |
| 92 | + }) |
| 93 | + |
| 94 | + if (error) { |
| 95 | + console.error("failed to migrate"); |
| 96 | + console.error(error); |
| 97 | + } |
75 | 98 | } |
76 | 99 |
|
77 | 100 | export async function reset() { |
|
0 commit comments