ignore d1 system tables, deploy verified

This commit is contained in:
dswbx
2025-02-12 07:29:56 +01:00
parent 7a6321f4ce
commit 61d06973a4
4 changed files with 15 additions and 12 deletions

View File

@@ -12,7 +12,7 @@ export type D1ConnectionConfig = {
class CustomD1Dialect extends D1Dialect { class CustomD1Dialect extends D1Dialect {
override createIntrospector(db: Kysely<any>): DatabaseIntrospector { override createIntrospector(db: Kysely<any>): DatabaseIntrospector {
return new SqliteIntrospector(db, { return new SqliteIntrospector(db, {
excludeTables: [""] excludeTables: ["_cf_KV"]
}); });
} }
} }

View File

@@ -5,7 +5,7 @@ import type {
ExpressionBuilder, ExpressionBuilder,
Kysely, Kysely,
SchemaMetadata, SchemaMetadata,
TableMetadata, TableMetadata
} from "kysely"; } from "kysely";
import { DEFAULT_MIGRATION_LOCK_TABLE, DEFAULT_MIGRATION_TABLE, sql } from "kysely"; import { DEFAULT_MIGRATION_LOCK_TABLE, DEFAULT_MIGRATION_TABLE, sql } from "kysely";
import type { ConnectionIntrospector, IndexMetadata } from "./Connection"; import type { ConnectionIntrospector, IndexMetadata } from "./Connection";
@@ -62,7 +62,7 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro
seqno: number; seqno: number;
cid: number; cid: number;
name: string; name: string;
}>`pragma_index_info(${index})`.as("index_info"), }>`pragma_index_info(${index})`.as("index_info")
) )
.select(["seqno", "cid", "name"]) .select(["seqno", "cid", "name"])
.orderBy("cid") .orderBy("cid")
@@ -74,8 +74,8 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro
isUnique: isUnique, isUnique: isUnique,
columns: columns.map((col) => ({ columns: columns.map((col) => ({
name: col.name, name: col.name,
order: col.seqno, order: col.seqno
})), }))
}; };
} }
@@ -87,7 +87,7 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro
} }
async getTables( async getTables(
options: DatabaseMetadataOptions = { withInternalKyselyTables: false }, options: DatabaseMetadataOptions = { withInternalKyselyTables: false }
): Promise<TableMetadata[]> { ): Promise<TableMetadata[]> {
let query = this.#db let query = this.#db
.selectFrom("sqlite_master") .selectFrom("sqlite_master")
@@ -99,7 +99,7 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro
if (!options.withInternalKyselyTables) { if (!options.withInternalKyselyTables) {
query = query.where( query = query.where(
this.excludeTables([DEFAULT_MIGRATION_TABLE, DEFAULT_MIGRATION_LOCK_TABLE]), this.excludeTables([DEFAULT_MIGRATION_TABLE, DEFAULT_MIGRATION_LOCK_TABLE])
); );
} }
if (this._excludeTables.length > 0) { if (this._excludeTables.length > 0) {
@@ -107,17 +107,19 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro
} }
const tables = await query.execute(); const tables = await query.execute();
console.log("tables", tables);
return Promise.all(tables.map(({ name }) => this.#getTableMetadata(name))); return Promise.all(tables.map(({ name }) => this.#getTableMetadata(name)));
} }
async getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata> { async getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata> {
return { return {
tables: await this.getTables(options), tables: await this.getTables(options)
}; };
} }
async #getTableMetadata(table: string): Promise<TableMetadata> { async #getTableMetadata(table: string): Promise<TableMetadata> {
const db = this.#db; const db = this.#db;
console.log("get table metadata", table);
// Get the SQL that was used to create the table. // Get the SQL that was used to create the table.
const tableDefinition = await db const tableDefinition = await db
@@ -142,7 +144,7 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro
type: string; type: string;
notnull: 0 | 1; notnull: 0 | 1;
dflt_value: any; dflt_value: any;
}>`pragma_table_info(${table})`.as("table_info"), }>`pragma_table_info(${table})`.as("table_info")
) )
.select(["name", "type", "notnull", "dflt_value"]) .select(["name", "type", "notnull", "dflt_value"])
.orderBy("cid") .orderBy("cid")
@@ -157,8 +159,8 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro
isNullable: !col.notnull, isNullable: !col.notnull,
isAutoIncrementing: col.name === autoIncrementCol, isAutoIncrementing: col.name === autoIncrementCol,
hasDefaultValue: col.dflt_value != null, hasDefaultValue: col.dflt_value != null,
comment: undefined, comment: undefined
})), }))
}; };
} }
} }

View File

@@ -3,6 +3,7 @@
import { serve } from "bknd/adapter/cloudflare"; import { serve } from "bknd/adapter/cloudflare";
export default serve({ export default serve({
mode: "fresh",
onBuilt: async (app) => { onBuilt: async (app) => {
app.modules.server.get("/custom", (c) => c.json({ hello: "world" })); app.modules.server.get("/custom", (c) => c.json({ hello: "world" }));
} }

View File

@@ -1,7 +1,7 @@
#:schema node_modules/wrangler/config-schema.json #:schema node_modules/wrangler/config-schema.json
name = "bknd-cf-worker-example" name = "bknd-cf-worker-example"
main = "src/index.ts" main = "src/index.ts"
compatibility_date = "2024-11-06" compatibility_date = "2025-02-04"
compatibility_flags = ["nodejs_compat"] compatibility_flags = ["nodejs_compat"]
workers_dev = true workers_dev = true
minify = true minify = true