Skip to content

Commit

Permalink
FIX for bug 550: Kysely migrations fail because VercelPostgresDialect (
Browse files Browse the repository at this point in the history
…#567)

FIX for bug 550: Kysely migrations fail because VercelPostgresDialect incorrectly reports that transactions are supported (#551)

* dailect should say it doesn't support transactions

* added changeset

* fix eslint warnings

Co-authored-by: Jeff Wishnie <jeff@wishnie.org>
  • Loading branch information
correttojs and jwishnie committed Jan 16, 2024
1 parent 816845b commit f70264e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-pandas-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vercel/postgres-kysely": minor
---

Correct VercelPostgresDialect to return an adapter that reports that transactions are _not_ supported
28 changes: 26 additions & 2 deletions packages/postgres-kysely/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import type { DatabaseConnection, Dialect, Driver, KyselyConfig } from 'kysely';
import { PostgresDialect, PostgresDriver, Kysely } from 'kysely';
import type {
DatabaseConnection,
Dialect,
DialectAdapter,
Driver,
KyselyConfig,
} from 'kysely';
import {
PostgresDialect,
PostgresDriver,
Kysely,
PostgresAdapter,
} from 'kysely';
import type { Pool } from '@neondatabase/serverless';
import { createPool } from '@vercel/postgres';
import type { VercelPostgresPoolConfig } from '@vercel/postgres';
Expand All @@ -9,11 +20,24 @@ type VercelPostgresDialectConfig = VercelPostgresPoolConfig & {
pool: Pool;
};

class VercelPostgresAdapter extends PostgresAdapter {
// represented as readonly property to satisfy eslint rule:
// typescript-eslint/class-literal-property-style
private readonly _supportsTransactionalDdl = false;
public get supportsTransactionalDdl(): boolean {
return this._supportsTransactionalDdl;
}
}

class VercelPostgresDialect extends PostgresDialect implements Dialect {
constructor(private config: VercelPostgresDialectConfig) {
super(config);
}

createAdapter(): DialectAdapter {
return new VercelPostgresAdapter();
}

createDriver(): Driver {
return new VercelPostgresPoolDriver(this.config);
}
Expand Down

1 comment on commit f70264e

@vercel
Copy link

@vercel vercel bot commented on f70264e Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.