@llmops/core 0.2.11-beta.4 → 0.2.12-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{bun-sqlite-dialect-DLqPd3F0.cjs → bun-sqlite-dialect-Bxz4B97L.cjs} +1 -2
- package/dist/{bun-sqlite-dialect-BiyQ5XmW.mjs → bun-sqlite-dialect-CHpTFgAo.mjs} +0 -1
- package/dist/db/index.cjs +4 -10
- package/dist/db/index.d.cts +2 -2
- package/dist/db/index.d.mts +2 -2
- package/dist/db/index.mjs +3 -4
- package/dist/{db-BIiDmOuQ.cjs → db-BOe6mM51.cjs} +94 -63
- package/dist/{db-CEHt_ysR.mjs → db-DohlAqJU.mjs} +94 -63
- package/dist/{index-C66pTe1n.d.cts → index-BO5Rse5J.d.mts} +60 -43
- package/dist/{index-BX96l072.d.mts → index-DwZhaRvQ.d.cts} +25 -8
- package/dist/index.cjs +5 -14
- package/dist/index.d.cts +226 -226
- package/dist/index.d.mts +493 -493
- package/dist/index.mjs +4 -8
- package/dist/neon-dialect-BQey5lUw.cjs +42 -0
- package/dist/neon-dialect-C0GZuGot.cjs +3 -0
- package/dist/neon-dialect-DySGBYUi.mjs +30 -0
- package/dist/neon-dialect-Hmo08nUq.mjs +3 -0
- package/dist/{node-sqlite-dialect-B3Mejscr.mjs → node-sqlite-dialect-B5oKhOm1.mjs} +0 -1
- package/dist/{node-sqlite-dialect-HRKgk8Ae.cjs → node-sqlite-dialect-N8j5UsT-.cjs} +1 -2
- package/package.json +7 -4
- package/dist/neon-dialect-C8y4ymaE.mjs +0 -4
- package/dist/neon-dialect-CTFuNy48.mjs +0 -4
- package/dist/neon-dialect-eEOfdvtN.cjs +0 -11
- package/dist/neon-dialect-js5JsNqM.cjs +0 -2
package/dist/db/index.cjs
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
require('../neon-dialect-js5JsNqM.cjs');
|
|
4
|
-
let kysely_neon = require("kysely-neon");
|
|
1
|
+
const require_db = require('../db-BOe6mM51.cjs');
|
|
2
|
+
const require_neon_dialect = require('../neon-dialect-BQey5lUw.cjs');
|
|
5
3
|
|
|
6
|
-
Object.defineProperty(exports, 'NeonDialect', {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return kysely_neon.NeonDialect;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
4
|
exports.SCHEMA_METADATA = require_db.SCHEMA_METADATA;
|
|
13
5
|
exports.configVariantsSchema = require_db.configVariantsSchema;
|
|
14
6
|
exports.configsSchema = require_db.configsSchema;
|
|
15
7
|
exports.createDatabase = require_db.createDatabase;
|
|
16
8
|
exports.createDatabaseFromConnection = require_db.createDatabaseFromConnection;
|
|
9
|
+
exports.createNeonDialect = require_neon_dialect.createNeonDialect;
|
|
17
10
|
exports.detectDatabaseType = require_db.detectDatabaseType;
|
|
18
11
|
exports.environmentSecretsSchema = require_db.environmentSecretsSchema;
|
|
19
12
|
exports.environmentsSchema = require_db.environmentsSchema;
|
|
13
|
+
exports.executeWithSchema = require_neon_dialect.executeWithSchema;
|
|
20
14
|
exports.getMigrations = require_db.getMigrations;
|
|
21
15
|
exports.llmRequestsSchema = require_db.llmRequestsSchema;
|
|
22
16
|
exports.matchType = require_db.matchType;
|
package/dist/db/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
export { Config, ConfigVariant, ConfigVariantsTable, ConfigsTable, Database, DatabaseConnection, DatabaseOptions, DatabaseType, Environment, EnvironmentSecret, EnvironmentSecretsTable, EnvironmentsTable, Insertable, LLMRequest, LLMRequestsTable, MigrationOptions, MigrationResult,
|
|
1
|
+
import { $ as variantsSchema, A as ProviderConfig, B as VariantVersionsTable, C as Environment, D as Insertable, E as EnvironmentsTable, F as TargetingRule, G as configsSchema, H as WorkspaceSettings, I as TargetingRulesTable, J as llmRequestsSchema, K as environmentSecretsSchema, L as Updateable, M as SCHEMA_METADATA, N as Selectable, O as LLMRequest, P as TableName, Q as variantVersionsSchema, R as Variant, S as Database, T as EnvironmentSecretsTable, U as WorkspaceSettingsTable, V as VariantsTable, W as configVariantsSchema, X as schemas, Y as providerConfigsSchema, Z as targetingRulesSchema, _ as validateTableData, a as createDatabaseFromConnection, b as ConfigVariantsTable, c as executeWithSchema, d as getMigrations, et as workspaceSettingsSchema, f as matchType, g as validatePartialTableData, h as parseTableData, i as createDatabase, j as ProviderConfigsTable, k as LLMRequestsTable, l as MigrationOptions, m as parsePartialTableData, n as DatabaseOptions, o as detectDatabaseType, p as runAutoMigrations, q as environmentsSchema, r as DatabaseType, s as createNeonDialect, t as DatabaseConnection, u as MigrationResult, v as Config, w as EnvironmentSecret, x as ConfigsTable, y as ConfigVariant, z as VariantVersion } from "../index-DwZhaRvQ.cjs";
|
|
2
|
+
export { Config, ConfigVariant, ConfigVariantsTable, ConfigsTable, Database, DatabaseConnection, DatabaseOptions, DatabaseType, Environment, EnvironmentSecret, EnvironmentSecretsTable, EnvironmentsTable, Insertable, LLMRequest, LLMRequestsTable, MigrationOptions, MigrationResult, ProviderConfig, ProviderConfigsTable, SCHEMA_METADATA, Selectable, TableName, TargetingRule, TargetingRulesTable, Updateable, Variant, VariantVersion, VariantVersionsTable, VariantsTable, WorkspaceSettings, WorkspaceSettingsTable, configVariantsSchema, configsSchema, createDatabase, createDatabaseFromConnection, createNeonDialect, detectDatabaseType, environmentSecretsSchema, environmentsSchema, executeWithSchema, getMigrations, llmRequestsSchema, matchType, parsePartialTableData, parseTableData, providerConfigsSchema, runAutoMigrations, schemas, targetingRulesSchema, validatePartialTableData, validateTableData, variantVersionsSchema, variantsSchema, workspaceSettingsSchema };
|
package/dist/db/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
export { Config, ConfigVariant, ConfigVariantsTable, ConfigsTable, Database, DatabaseConnection, DatabaseOptions, DatabaseType, Environment, EnvironmentSecret, EnvironmentSecretsTable, EnvironmentsTable, Insertable, LLMRequest, LLMRequestsTable, MigrationOptions, MigrationResult,
|
|
1
|
+
import { $ as variantsSchema, A as ProviderConfig, B as VariantVersionsTable, C as Environment, D as Insertable, E as EnvironmentsTable, F as TargetingRule, G as configsSchema, H as WorkspaceSettings, I as TargetingRulesTable, J as llmRequestsSchema, K as environmentSecretsSchema, L as Updateable, M as SCHEMA_METADATA, N as Selectable, O as LLMRequest, P as TableName, Q as variantVersionsSchema, R as Variant, S as Database, T as EnvironmentSecretsTable, U as WorkspaceSettingsTable, V as VariantsTable, W as configVariantsSchema, X as schemas, Y as providerConfigsSchema, Z as targetingRulesSchema, _ as validateTableData, a as createDatabaseFromConnection, b as ConfigVariantsTable, c as executeWithSchema, d as getMigrations, et as workspaceSettingsSchema, f as matchType, g as validatePartialTableData, h as parseTableData, i as createDatabase, j as ProviderConfigsTable, k as LLMRequestsTable, l as MigrationOptions, m as parsePartialTableData, n as DatabaseOptions, o as detectDatabaseType, p as runAutoMigrations, q as environmentsSchema, r as DatabaseType, s as createNeonDialect, t as DatabaseConnection, u as MigrationResult, v as Config, w as EnvironmentSecret, x as ConfigsTable, y as ConfigVariant, z as VariantVersion } from "../index-BO5Rse5J.mjs";
|
|
2
|
+
export { Config, ConfigVariant, ConfigVariantsTable, ConfigsTable, Database, DatabaseConnection, DatabaseOptions, DatabaseType, Environment, EnvironmentSecret, EnvironmentSecretsTable, EnvironmentsTable, Insertable, LLMRequest, LLMRequestsTable, MigrationOptions, MigrationResult, ProviderConfig, ProviderConfigsTable, SCHEMA_METADATA, Selectable, TableName, TargetingRule, TargetingRulesTable, Updateable, Variant, VariantVersion, VariantVersionsTable, VariantsTable, WorkspaceSettings, WorkspaceSettingsTable, configVariantsSchema, configsSchema, createDatabase, createDatabaseFromConnection, createNeonDialect, detectDatabaseType, environmentSecretsSchema, environmentsSchema, executeWithSchema, getMigrations, llmRequestsSchema, matchType, parsePartialTableData, parseTableData, providerConfigsSchema, runAutoMigrations, schemas, targetingRulesSchema, validatePartialTableData, validateTableData, variantVersionsSchema, variantsSchema, workspaceSettingsSchema };
|
package/dist/db/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { t as NeonDialect } from "../neon-dialect-C8y4ymaE.mjs";
|
|
1
|
+
import { C as variantsSchema, S as variantVersionsSchema, _ as environmentsSchema, a as matchType, b as schemas, d as validatePartialTableData, f as validateTableData, g as environmentSecretsSchema, h as configsSchema, i as getMigrations, l as parsePartialTableData, m as configVariantsSchema, n as createDatabaseFromConnection, o as runAutoMigrations, p as SCHEMA_METADATA, r as detectDatabaseType, t as createDatabase, u as parseTableData, v as llmRequestsSchema, w as workspaceSettingsSchema, x as targetingRulesSchema, y as providerConfigsSchema } from "../db-DohlAqJU.mjs";
|
|
2
|
+
import { n as executeWithSchema, t as createNeonDialect } from "../neon-dialect-DySGBYUi.mjs";
|
|
4
3
|
|
|
5
|
-
export {
|
|
4
|
+
export { SCHEMA_METADATA, configVariantsSchema, configsSchema, createDatabase, createDatabaseFromConnection, createNeonDialect, detectDatabaseType, environmentSecretsSchema, environmentsSchema, executeWithSchema, getMigrations, llmRequestsSchema, matchType, parsePartialTableData, parseTableData, providerConfigsSchema, runAutoMigrations, schemas, targetingRulesSchema, validatePartialTableData, validateTableData, variantVersionsSchema, variantsSchema, workspaceSettingsSchema };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use node";
|
|
2
1
|
//#region rolldown:runtime
|
|
3
2
|
var __create = Object.create;
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
@@ -13459,36 +13458,38 @@ const getAuthClientOptions = (options) => {
|
|
|
13459
13458
|
|
|
13460
13459
|
//#endregion
|
|
13461
13460
|
//#region src/db/migrations.ts
|
|
13461
|
+
const postgresMap = {
|
|
13462
|
+
uuid: [
|
|
13463
|
+
"character varying",
|
|
13464
|
+
"varchar",
|
|
13465
|
+
"text",
|
|
13466
|
+
"uuid"
|
|
13467
|
+
],
|
|
13468
|
+
text: [
|
|
13469
|
+
"character varying",
|
|
13470
|
+
"varchar",
|
|
13471
|
+
"text"
|
|
13472
|
+
],
|
|
13473
|
+
timestamp: [
|
|
13474
|
+
"timestamptz",
|
|
13475
|
+
"timestamp",
|
|
13476
|
+
"date"
|
|
13477
|
+
],
|
|
13478
|
+
jsonb: ["json", "jsonb"],
|
|
13479
|
+
integer: [
|
|
13480
|
+
"integer",
|
|
13481
|
+
"int4",
|
|
13482
|
+
"int",
|
|
13483
|
+
"smallint",
|
|
13484
|
+
"bigint",
|
|
13485
|
+
"int2",
|
|
13486
|
+
"int8"
|
|
13487
|
+
],
|
|
13488
|
+
boolean: ["boolean", "bool"]
|
|
13489
|
+
};
|
|
13462
13490
|
const typeMap = {
|
|
13463
|
-
postgres:
|
|
13464
|
-
|
|
13465
|
-
"character varying",
|
|
13466
|
-
"varchar",
|
|
13467
|
-
"text",
|
|
13468
|
-
"uuid"
|
|
13469
|
-
],
|
|
13470
|
-
text: [
|
|
13471
|
-
"character varying",
|
|
13472
|
-
"varchar",
|
|
13473
|
-
"text"
|
|
13474
|
-
],
|
|
13475
|
-
timestamp: [
|
|
13476
|
-
"timestamptz",
|
|
13477
|
-
"timestamp",
|
|
13478
|
-
"date"
|
|
13479
|
-
],
|
|
13480
|
-
jsonb: ["json", "jsonb"],
|
|
13481
|
-
integer: [
|
|
13482
|
-
"integer",
|
|
13483
|
-
"int4",
|
|
13484
|
-
"int",
|
|
13485
|
-
"smallint",
|
|
13486
|
-
"bigint",
|
|
13487
|
-
"int2",
|
|
13488
|
-
"int8"
|
|
13489
|
-
],
|
|
13490
|
-
boolean: ["boolean", "bool"]
|
|
13491
|
-
},
|
|
13491
|
+
postgres: postgresMap,
|
|
13492
|
+
neon: postgresMap,
|
|
13492
13493
|
mysql: {
|
|
13493
13494
|
text: ["varchar", "text"],
|
|
13494
13495
|
timestamp: [
|
|
@@ -13552,18 +13553,17 @@ async function ensurePostgresSchemaExists(db, schema) {
|
|
|
13552
13553
|
) as exists
|
|
13553
13554
|
`.execute(db)).rows[0]?.exists) {
|
|
13554
13555
|
logger.info(`Creating PostgreSQL schema: ${schema}`);
|
|
13555
|
-
await kysely.sql`CREATE SCHEMA IF NOT EXISTS ${kysely.sql.
|
|
13556
|
+
await kysely.sql`CREATE SCHEMA IF NOT EXISTS ${kysely.sql.id(schema)}`.execute(db);
|
|
13557
|
+
await kysely.sql`GRANT USAGE ON SCHEMA ${kysely.sql.id(schema)} TO PUBLIC`.execute(db);
|
|
13558
|
+
await kysely.sql`GRANT CREATE ON SCHEMA ${kysely.sql.id(schema)} TO PUBLIC`.execute(db);
|
|
13556
13559
|
}
|
|
13557
13560
|
} catch (error$47) {
|
|
13558
|
-
logger.warn(
|
|
13559
|
-
try {
|
|
13560
|
-
await kysely.sql`CREATE SCHEMA IF NOT EXISTS ${kysely.sql.ref(schema)}`.execute(db);
|
|
13561
|
-
} catch {}
|
|
13561
|
+
logger.warn({ error: error$47 }, "Failed to ensure PostgreSQL schema exists");
|
|
13562
13562
|
}
|
|
13563
13563
|
}
|
|
13564
13564
|
async function getMigrations(db, dbType, options) {
|
|
13565
13565
|
let currentSchema = "public";
|
|
13566
|
-
if (dbType === "postgres") {
|
|
13566
|
+
if (dbType === "postgres" || dbType === "neon") {
|
|
13567
13567
|
if (options?.schema) {
|
|
13568
13568
|
await ensurePostgresSchemaExists(db, options.schema);
|
|
13569
13569
|
currentSchema = options.schema;
|
|
@@ -13572,7 +13572,7 @@ async function getMigrations(db, dbType, options) {
|
|
|
13572
13572
|
}
|
|
13573
13573
|
const allTableMetadata = await db.introspection.getTables();
|
|
13574
13574
|
let tableMetadata = allTableMetadata;
|
|
13575
|
-
if (dbType === "postgres") try {
|
|
13575
|
+
if (dbType === "postgres" || dbType === "neon") try {
|
|
13576
13576
|
const tablesInSchema = await kysely.sql`
|
|
13577
13577
|
SELECT table_name
|
|
13578
13578
|
FROM information_schema.tables
|
|
@@ -13621,36 +13621,42 @@ async function getMigrations(db, dbType, options) {
|
|
|
13621
13621
|
return {
|
|
13622
13622
|
uuid: {
|
|
13623
13623
|
postgres: "uuid",
|
|
13624
|
+
neon: "uuid",
|
|
13624
13625
|
mysql: "varchar(36)",
|
|
13625
13626
|
sqlite: "text",
|
|
13626
13627
|
mssql: "varchar(36)"
|
|
13627
13628
|
},
|
|
13628
13629
|
text: {
|
|
13629
13630
|
postgres: "text",
|
|
13631
|
+
neon: "text",
|
|
13630
13632
|
mysql: fieldConfig.unique ? "varchar(255)" : "text",
|
|
13631
13633
|
sqlite: "text",
|
|
13632
13634
|
mssql: fieldConfig.unique ? "varchar(255)" : "varchar(8000)"
|
|
13633
13635
|
},
|
|
13634
13636
|
timestamp: {
|
|
13635
13637
|
postgres: "timestamptz",
|
|
13638
|
+
neon: "timestamptz",
|
|
13636
13639
|
mysql: "timestamp(3)",
|
|
13637
13640
|
sqlite: "date",
|
|
13638
13641
|
mssql: kysely.sql`datetime2(3)`
|
|
13639
13642
|
},
|
|
13640
13643
|
jsonb: {
|
|
13641
13644
|
postgres: "jsonb",
|
|
13645
|
+
neon: "jsonb",
|
|
13642
13646
|
mysql: "json",
|
|
13643
13647
|
sqlite: "text",
|
|
13644
13648
|
mssql: "varchar(8000)"
|
|
13645
13649
|
},
|
|
13646
13650
|
boolean: {
|
|
13647
13651
|
postgres: "boolean",
|
|
13652
|
+
neon: "boolean",
|
|
13648
13653
|
mysql: "boolean",
|
|
13649
13654
|
sqlite: "integer",
|
|
13650
13655
|
mssql: kysely.sql`bit`
|
|
13651
13656
|
},
|
|
13652
13657
|
integer: {
|
|
13653
13658
|
postgres: "integer",
|
|
13659
|
+
neon: "integer",
|
|
13654
13660
|
mysql: "integer",
|
|
13655
13661
|
sqlite: "integer",
|
|
13656
13662
|
mssql: "integer"
|
|
@@ -13658,7 +13664,8 @@ async function getMigrations(db, dbType, options) {
|
|
|
13658
13664
|
}[type]?.[dbType] || "text";
|
|
13659
13665
|
}
|
|
13660
13666
|
for (const table of toBeCreated) {
|
|
13661
|
-
|
|
13667
|
+
const qualifiedTableName = (dbType === "postgres" || dbType === "neon") && options?.schema ? `${options.schema}.${table.table}` : table.table;
|
|
13668
|
+
let builder = db.schema.createTable(qualifiedTableName);
|
|
13662
13669
|
for (const [fieldName, fieldConfig] of Object.entries(table.fields)) {
|
|
13663
13670
|
const type = getColumnType(fieldConfig, fieldName);
|
|
13664
13671
|
builder = builder.addColumn(fieldName, type, (col) => {
|
|
@@ -13679,24 +13686,35 @@ async function getMigrations(db, dbType, options) {
|
|
|
13679
13686
|
}
|
|
13680
13687
|
migrations.push(builder);
|
|
13681
13688
|
}
|
|
13682
|
-
for (const table of toBeAdded)
|
|
13683
|
-
const
|
|
13684
|
-
const
|
|
13685
|
-
|
|
13686
|
-
|
|
13687
|
-
|
|
13688
|
-
|
|
13689
|
-
|
|
13690
|
-
|
|
13691
|
-
|
|
13692
|
-
|
|
13693
|
-
|
|
13694
|
-
|
|
13695
|
-
|
|
13696
|
-
|
|
13697
|
-
|
|
13689
|
+
for (const table of toBeAdded) {
|
|
13690
|
+
const qualifiedTableName = (dbType === "postgres" || dbType === "neon") && options?.schema ? `${options.schema}.${table.table}` : table.table;
|
|
13691
|
+
for (const [fieldName, fieldConfig] of Object.entries(table.fields)) {
|
|
13692
|
+
const type = getColumnType(fieldConfig, fieldName);
|
|
13693
|
+
const builder = db.schema.alterTable(qualifiedTableName).addColumn(fieldName, type, (col) => {
|
|
13694
|
+
let c = col;
|
|
13695
|
+
if (!fieldConfig.nullable) c = c.notNull();
|
|
13696
|
+
if (fieldConfig.references) {
|
|
13697
|
+
const refTable = fieldConfig.references.table;
|
|
13698
|
+
const refColumn = fieldConfig.references.column;
|
|
13699
|
+
c = c.references(`${refTable}.${refColumn}`).onDelete("cascade");
|
|
13700
|
+
}
|
|
13701
|
+
if (fieldConfig.unique) c = c.unique();
|
|
13702
|
+
if (fieldConfig.default === "now()" && dbType !== "sqlite") if (dbType === "mysql") c = c.defaultTo(kysely.sql`CURRENT_TIMESTAMP(3)`);
|
|
13703
|
+
else c = c.defaultTo(kysely.sql`CURRENT_TIMESTAMP`);
|
|
13704
|
+
return c;
|
|
13705
|
+
});
|
|
13706
|
+
migrations.push(builder);
|
|
13707
|
+
}
|
|
13698
13708
|
}
|
|
13699
|
-
|
|
13709
|
+
if (dbType === "postgres") try {
|
|
13710
|
+
await kysely.sql`SET search_path TO "${options?.schema ?? "llmops"}"`.execute(db);
|
|
13711
|
+
} catch (error$47) {
|
|
13712
|
+
logger.warn({ error: error$47 }, "Failed to set search_path for Better Auth migrations");
|
|
13713
|
+
}
|
|
13714
|
+
const { toBeAdded: authChangesToBeAdded, toBeCreated: authChangesToBeCreated, runMigrations: runAuthMigrations } = await (0, better_auth_db.getMigrations)(getAuthClientOptions({ database: {
|
|
13715
|
+
db,
|
|
13716
|
+
type: dbType === "neon" ? "postgres" : dbType
|
|
13717
|
+
} }));
|
|
13700
13718
|
async function runMigrations() {
|
|
13701
13719
|
for (const migration of migrations) await migration.execute();
|
|
13702
13720
|
await runAuthMigrations();
|
|
@@ -13801,19 +13819,19 @@ function createDatabase(connection) {
|
|
|
13801
13819
|
* Auto-detect database type from connection object
|
|
13802
13820
|
*/
|
|
13803
13821
|
function detectDatabaseType(db) {
|
|
13804
|
-
if (!db || typeof db !== "object") return null;
|
|
13822
|
+
if (!db || typeof db !== "object" && typeof db !== "function") return null;
|
|
13805
13823
|
if ("createDriver" in db) {
|
|
13806
13824
|
if (db instanceof kysely.SqliteDialect) return "sqlite";
|
|
13807
13825
|
if (db instanceof kysely.MysqlDialect) return "mysql";
|
|
13808
13826
|
if (db instanceof kysely.PostgresDialect) return "postgres";
|
|
13809
13827
|
if (db instanceof kysely.MssqlDialect) return "mssql";
|
|
13810
13828
|
}
|
|
13829
|
+
if (typeof db === "function" && db.name === "templateFn") return "neon";
|
|
13811
13830
|
if ("aggregate" in db) return "sqlite";
|
|
13812
13831
|
if ("getConnection" in db) return "mysql";
|
|
13813
13832
|
if ("connect" in db) return "postgres";
|
|
13814
13833
|
if ("fileControl" in db) return "sqlite";
|
|
13815
13834
|
if ("open" in db && "close" in db && "prepare" in db) return "sqlite";
|
|
13816
|
-
if ("neon" in db) return "neon";
|
|
13817
13835
|
return null;
|
|
13818
13836
|
}
|
|
13819
13837
|
/**
|
|
@@ -13831,12 +13849,12 @@ async function createDatabaseFromConnection(rawConnection, options) {
|
|
|
13831
13849
|
case "sqlite":
|
|
13832
13850
|
if ("aggregate" in rawConnection && !("createSession" in rawConnection)) dialect = new kysely.SqliteDialect({ database: rawConnection });
|
|
13833
13851
|
else if ("fileControl" in rawConnection) {
|
|
13834
|
-
const { BunSqliteDialect } = await Promise.resolve().then(() => require("./bun-sqlite-dialect-
|
|
13852
|
+
const { BunSqliteDialect } = await Promise.resolve().then(() => require("./bun-sqlite-dialect-Bxz4B97L.cjs"));
|
|
13835
13853
|
dialect = new BunSqliteDialect({ database: rawConnection });
|
|
13836
13854
|
} else if ("createSession" in rawConnection && typeof window === "undefined") try {
|
|
13837
13855
|
const { DatabaseSync } = await import("node:sqlite");
|
|
13838
13856
|
if (rawConnection instanceof DatabaseSync) {
|
|
13839
|
-
const { NodeSqliteDialect } = await Promise.resolve().then(() => require("./node-sqlite-dialect-
|
|
13857
|
+
const { NodeSqliteDialect } = await Promise.resolve().then(() => require("./node-sqlite-dialect-N8j5UsT-.cjs"));
|
|
13840
13858
|
dialect = new NodeSqliteDialect({ database: rawConnection });
|
|
13841
13859
|
}
|
|
13842
13860
|
} catch {}
|
|
@@ -13852,13 +13870,26 @@ async function createDatabaseFromConnection(rawConnection, options) {
|
|
|
13852
13870
|
}
|
|
13853
13871
|
});
|
|
13854
13872
|
break;
|
|
13873
|
+
case "neon":
|
|
13874
|
+
if (schema && schema !== "public") {
|
|
13875
|
+
const { Pool, neonConfig } = await import("@neondatabase/serverless");
|
|
13876
|
+
const { default: ws } = await import("ws");
|
|
13877
|
+
neonConfig.webSocketConstructor = ws;
|
|
13878
|
+
const connectionString = typeof rawConnection === "string" ? rawConnection : process.env.NEON_PG_URL || "";
|
|
13879
|
+
dialect = new kysely.PostgresDialect({
|
|
13880
|
+
pool: new Pool({ connectionString: connectionString.includes("currentSchema") ? connectionString.split("currentSchema=")[1].split("&")[0] === "public" ? connectionString.replace(/currentSchema=[^&]*&?/, "") : connectionString : connectionString }),
|
|
13881
|
+
onCreateConnection: async (connection) => {
|
|
13882
|
+
await connection.executeQuery(kysely.CompiledQuery.raw(`SET search_path TO "${schema}"`));
|
|
13883
|
+
}
|
|
13884
|
+
});
|
|
13885
|
+
} else {
|
|
13886
|
+
const { createNeonDialect } = await Promise.resolve().then(() => require("./neon-dialect-C0GZuGot.cjs"));
|
|
13887
|
+
dialect = createNeonDialect(rawConnection);
|
|
13888
|
+
}
|
|
13889
|
+
break;
|
|
13855
13890
|
case "mssql":
|
|
13856
13891
|
if ("createDriver" in rawConnection) dialect = rawConnection;
|
|
13857
13892
|
break;
|
|
13858
|
-
case "neon":
|
|
13859
|
-
const { NeonDialect: NeonDialect$1 } = await Promise.resolve().then(() => require("./neon-dialect-eEOfdvtN.cjs"));
|
|
13860
|
-
dialect = new NeonDialect$1(rawConnection);
|
|
13861
|
-
break;
|
|
13862
13893
|
}
|
|
13863
13894
|
return dialect ? new kysely.Kysely({ dialect }) : null;
|
|
13864
13895
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use node";
|
|
2
1
|
import { CompiledQuery, Kysely, MssqlDialect, MysqlDialect, PostgresDialect, SqliteDialect, sql } from "kysely";
|
|
3
2
|
import { getMigrations } from "better-auth/db";
|
|
4
3
|
import pino from "pino";
|
|
@@ -13435,36 +13434,38 @@ const getAuthClientOptions = (options) => {
|
|
|
13435
13434
|
|
|
13436
13435
|
//#endregion
|
|
13437
13436
|
//#region src/db/migrations.ts
|
|
13437
|
+
const postgresMap = {
|
|
13438
|
+
uuid: [
|
|
13439
|
+
"character varying",
|
|
13440
|
+
"varchar",
|
|
13441
|
+
"text",
|
|
13442
|
+
"uuid"
|
|
13443
|
+
],
|
|
13444
|
+
text: [
|
|
13445
|
+
"character varying",
|
|
13446
|
+
"varchar",
|
|
13447
|
+
"text"
|
|
13448
|
+
],
|
|
13449
|
+
timestamp: [
|
|
13450
|
+
"timestamptz",
|
|
13451
|
+
"timestamp",
|
|
13452
|
+
"date"
|
|
13453
|
+
],
|
|
13454
|
+
jsonb: ["json", "jsonb"],
|
|
13455
|
+
integer: [
|
|
13456
|
+
"integer",
|
|
13457
|
+
"int4",
|
|
13458
|
+
"int",
|
|
13459
|
+
"smallint",
|
|
13460
|
+
"bigint",
|
|
13461
|
+
"int2",
|
|
13462
|
+
"int8"
|
|
13463
|
+
],
|
|
13464
|
+
boolean: ["boolean", "bool"]
|
|
13465
|
+
};
|
|
13438
13466
|
const typeMap = {
|
|
13439
|
-
postgres:
|
|
13440
|
-
|
|
13441
|
-
"character varying",
|
|
13442
|
-
"varchar",
|
|
13443
|
-
"text",
|
|
13444
|
-
"uuid"
|
|
13445
|
-
],
|
|
13446
|
-
text: [
|
|
13447
|
-
"character varying",
|
|
13448
|
-
"varchar",
|
|
13449
|
-
"text"
|
|
13450
|
-
],
|
|
13451
|
-
timestamp: [
|
|
13452
|
-
"timestamptz",
|
|
13453
|
-
"timestamp",
|
|
13454
|
-
"date"
|
|
13455
|
-
],
|
|
13456
|
-
jsonb: ["json", "jsonb"],
|
|
13457
|
-
integer: [
|
|
13458
|
-
"integer",
|
|
13459
|
-
"int4",
|
|
13460
|
-
"int",
|
|
13461
|
-
"smallint",
|
|
13462
|
-
"bigint",
|
|
13463
|
-
"int2",
|
|
13464
|
-
"int8"
|
|
13465
|
-
],
|
|
13466
|
-
boolean: ["boolean", "bool"]
|
|
13467
|
-
},
|
|
13467
|
+
postgres: postgresMap,
|
|
13468
|
+
neon: postgresMap,
|
|
13468
13469
|
mysql: {
|
|
13469
13470
|
text: ["varchar", "text"],
|
|
13470
13471
|
timestamp: [
|
|
@@ -13528,18 +13529,17 @@ async function ensurePostgresSchemaExists(db, schema) {
|
|
|
13528
13529
|
) as exists
|
|
13529
13530
|
`.execute(db)).rows[0]?.exists) {
|
|
13530
13531
|
logger.info(`Creating PostgreSQL schema: ${schema}`);
|
|
13531
|
-
await sql`CREATE SCHEMA IF NOT EXISTS ${sql.
|
|
13532
|
+
await sql`CREATE SCHEMA IF NOT EXISTS ${sql.id(schema)}`.execute(db);
|
|
13533
|
+
await sql`GRANT USAGE ON SCHEMA ${sql.id(schema)} TO PUBLIC`.execute(db);
|
|
13534
|
+
await sql`GRANT CREATE ON SCHEMA ${sql.id(schema)} TO PUBLIC`.execute(db);
|
|
13532
13535
|
}
|
|
13533
13536
|
} catch (error$47) {
|
|
13534
|
-
logger.warn(
|
|
13535
|
-
try {
|
|
13536
|
-
await sql`CREATE SCHEMA IF NOT EXISTS ${sql.ref(schema)}`.execute(db);
|
|
13537
|
-
} catch {}
|
|
13537
|
+
logger.warn({ error: error$47 }, "Failed to ensure PostgreSQL schema exists");
|
|
13538
13538
|
}
|
|
13539
13539
|
}
|
|
13540
13540
|
async function getMigrations$1(db, dbType, options) {
|
|
13541
13541
|
let currentSchema = "public";
|
|
13542
|
-
if (dbType === "postgres") {
|
|
13542
|
+
if (dbType === "postgres" || dbType === "neon") {
|
|
13543
13543
|
if (options?.schema) {
|
|
13544
13544
|
await ensurePostgresSchemaExists(db, options.schema);
|
|
13545
13545
|
currentSchema = options.schema;
|
|
@@ -13548,7 +13548,7 @@ async function getMigrations$1(db, dbType, options) {
|
|
|
13548
13548
|
}
|
|
13549
13549
|
const allTableMetadata = await db.introspection.getTables();
|
|
13550
13550
|
let tableMetadata = allTableMetadata;
|
|
13551
|
-
if (dbType === "postgres") try {
|
|
13551
|
+
if (dbType === "postgres" || dbType === "neon") try {
|
|
13552
13552
|
const tablesInSchema = await sql`
|
|
13553
13553
|
SELECT table_name
|
|
13554
13554
|
FROM information_schema.tables
|
|
@@ -13597,36 +13597,42 @@ async function getMigrations$1(db, dbType, options) {
|
|
|
13597
13597
|
return {
|
|
13598
13598
|
uuid: {
|
|
13599
13599
|
postgres: "uuid",
|
|
13600
|
+
neon: "uuid",
|
|
13600
13601
|
mysql: "varchar(36)",
|
|
13601
13602
|
sqlite: "text",
|
|
13602
13603
|
mssql: "varchar(36)"
|
|
13603
13604
|
},
|
|
13604
13605
|
text: {
|
|
13605
13606
|
postgres: "text",
|
|
13607
|
+
neon: "text",
|
|
13606
13608
|
mysql: fieldConfig.unique ? "varchar(255)" : "text",
|
|
13607
13609
|
sqlite: "text",
|
|
13608
13610
|
mssql: fieldConfig.unique ? "varchar(255)" : "varchar(8000)"
|
|
13609
13611
|
},
|
|
13610
13612
|
timestamp: {
|
|
13611
13613
|
postgres: "timestamptz",
|
|
13614
|
+
neon: "timestamptz",
|
|
13612
13615
|
mysql: "timestamp(3)",
|
|
13613
13616
|
sqlite: "date",
|
|
13614
13617
|
mssql: sql`datetime2(3)`
|
|
13615
13618
|
},
|
|
13616
13619
|
jsonb: {
|
|
13617
13620
|
postgres: "jsonb",
|
|
13621
|
+
neon: "jsonb",
|
|
13618
13622
|
mysql: "json",
|
|
13619
13623
|
sqlite: "text",
|
|
13620
13624
|
mssql: "varchar(8000)"
|
|
13621
13625
|
},
|
|
13622
13626
|
boolean: {
|
|
13623
13627
|
postgres: "boolean",
|
|
13628
|
+
neon: "boolean",
|
|
13624
13629
|
mysql: "boolean",
|
|
13625
13630
|
sqlite: "integer",
|
|
13626
13631
|
mssql: sql`bit`
|
|
13627
13632
|
},
|
|
13628
13633
|
integer: {
|
|
13629
13634
|
postgres: "integer",
|
|
13635
|
+
neon: "integer",
|
|
13630
13636
|
mysql: "integer",
|
|
13631
13637
|
sqlite: "integer",
|
|
13632
13638
|
mssql: "integer"
|
|
@@ -13634,7 +13640,8 @@ async function getMigrations$1(db, dbType, options) {
|
|
|
13634
13640
|
}[type]?.[dbType] || "text";
|
|
13635
13641
|
}
|
|
13636
13642
|
for (const table of toBeCreated) {
|
|
13637
|
-
|
|
13643
|
+
const qualifiedTableName = (dbType === "postgres" || dbType === "neon") && options?.schema ? `${options.schema}.${table.table}` : table.table;
|
|
13644
|
+
let builder = db.schema.createTable(qualifiedTableName);
|
|
13638
13645
|
for (const [fieldName, fieldConfig] of Object.entries(table.fields)) {
|
|
13639
13646
|
const type = getColumnType(fieldConfig, fieldName);
|
|
13640
13647
|
builder = builder.addColumn(fieldName, type, (col) => {
|
|
@@ -13655,24 +13662,35 @@ async function getMigrations$1(db, dbType, options) {
|
|
|
13655
13662
|
}
|
|
13656
13663
|
migrations.push(builder);
|
|
13657
13664
|
}
|
|
13658
|
-
for (const table of toBeAdded)
|
|
13659
|
-
const
|
|
13660
|
-
const
|
|
13661
|
-
|
|
13662
|
-
|
|
13663
|
-
|
|
13664
|
-
|
|
13665
|
-
|
|
13666
|
-
|
|
13667
|
-
|
|
13668
|
-
|
|
13669
|
-
|
|
13670
|
-
|
|
13671
|
-
|
|
13672
|
-
|
|
13673
|
-
|
|
13665
|
+
for (const table of toBeAdded) {
|
|
13666
|
+
const qualifiedTableName = (dbType === "postgres" || dbType === "neon") && options?.schema ? `${options.schema}.${table.table}` : table.table;
|
|
13667
|
+
for (const [fieldName, fieldConfig] of Object.entries(table.fields)) {
|
|
13668
|
+
const type = getColumnType(fieldConfig, fieldName);
|
|
13669
|
+
const builder = db.schema.alterTable(qualifiedTableName).addColumn(fieldName, type, (col) => {
|
|
13670
|
+
let c = col;
|
|
13671
|
+
if (!fieldConfig.nullable) c = c.notNull();
|
|
13672
|
+
if (fieldConfig.references) {
|
|
13673
|
+
const refTable = fieldConfig.references.table;
|
|
13674
|
+
const refColumn = fieldConfig.references.column;
|
|
13675
|
+
c = c.references(`${refTable}.${refColumn}`).onDelete("cascade");
|
|
13676
|
+
}
|
|
13677
|
+
if (fieldConfig.unique) c = c.unique();
|
|
13678
|
+
if (fieldConfig.default === "now()" && dbType !== "sqlite") if (dbType === "mysql") c = c.defaultTo(sql`CURRENT_TIMESTAMP(3)`);
|
|
13679
|
+
else c = c.defaultTo(sql`CURRENT_TIMESTAMP`);
|
|
13680
|
+
return c;
|
|
13681
|
+
});
|
|
13682
|
+
migrations.push(builder);
|
|
13683
|
+
}
|
|
13674
13684
|
}
|
|
13675
|
-
|
|
13685
|
+
if (dbType === "postgres") try {
|
|
13686
|
+
await sql`SET search_path TO "${options?.schema ?? "llmops"}"`.execute(db);
|
|
13687
|
+
} catch (error$47) {
|
|
13688
|
+
logger.warn({ error: error$47 }, "Failed to set search_path for Better Auth migrations");
|
|
13689
|
+
}
|
|
13690
|
+
const { toBeAdded: authChangesToBeAdded, toBeCreated: authChangesToBeCreated, runMigrations: runAuthMigrations } = await getMigrations(getAuthClientOptions({ database: {
|
|
13691
|
+
db,
|
|
13692
|
+
type: dbType === "neon" ? "postgres" : dbType
|
|
13693
|
+
} }));
|
|
13676
13694
|
async function runMigrations() {
|
|
13677
13695
|
for (const migration of migrations) await migration.execute();
|
|
13678
13696
|
await runAuthMigrations();
|
|
@@ -13777,19 +13795,19 @@ function createDatabase(connection) {
|
|
|
13777
13795
|
* Auto-detect database type from connection object
|
|
13778
13796
|
*/
|
|
13779
13797
|
function detectDatabaseType(db) {
|
|
13780
|
-
if (!db || typeof db !== "object") return null;
|
|
13798
|
+
if (!db || typeof db !== "object" && typeof db !== "function") return null;
|
|
13781
13799
|
if ("createDriver" in db) {
|
|
13782
13800
|
if (db instanceof SqliteDialect) return "sqlite";
|
|
13783
13801
|
if (db instanceof MysqlDialect) return "mysql";
|
|
13784
13802
|
if (db instanceof PostgresDialect) return "postgres";
|
|
13785
13803
|
if (db instanceof MssqlDialect) return "mssql";
|
|
13786
13804
|
}
|
|
13805
|
+
if (typeof db === "function" && db.name === "templateFn") return "neon";
|
|
13787
13806
|
if ("aggregate" in db) return "sqlite";
|
|
13788
13807
|
if ("getConnection" in db) return "mysql";
|
|
13789
13808
|
if ("connect" in db) return "postgres";
|
|
13790
13809
|
if ("fileControl" in db) return "sqlite";
|
|
13791
13810
|
if ("open" in db && "close" in db && "prepare" in db) return "sqlite";
|
|
13792
|
-
if ("neon" in db) return "neon";
|
|
13793
13811
|
return null;
|
|
13794
13812
|
}
|
|
13795
13813
|
/**
|
|
@@ -13807,12 +13825,12 @@ async function createDatabaseFromConnection(rawConnection, options) {
|
|
|
13807
13825
|
case "sqlite":
|
|
13808
13826
|
if ("aggregate" in rawConnection && !("createSession" in rawConnection)) dialect = new SqliteDialect({ database: rawConnection });
|
|
13809
13827
|
else if ("fileControl" in rawConnection) {
|
|
13810
|
-
const { BunSqliteDialect } = await import("./bun-sqlite-dialect-
|
|
13828
|
+
const { BunSqliteDialect } = await import("./bun-sqlite-dialect-CHpTFgAo.mjs");
|
|
13811
13829
|
dialect = new BunSqliteDialect({ database: rawConnection });
|
|
13812
13830
|
} else if ("createSession" in rawConnection && typeof window === "undefined") try {
|
|
13813
13831
|
const { DatabaseSync } = await import("node:sqlite");
|
|
13814
13832
|
if (rawConnection instanceof DatabaseSync) {
|
|
13815
|
-
const { NodeSqliteDialect } = await import("./node-sqlite-dialect-
|
|
13833
|
+
const { NodeSqliteDialect } = await import("./node-sqlite-dialect-B5oKhOm1.mjs");
|
|
13816
13834
|
dialect = new NodeSqliteDialect({ database: rawConnection });
|
|
13817
13835
|
}
|
|
13818
13836
|
} catch {}
|
|
@@ -13828,13 +13846,26 @@ async function createDatabaseFromConnection(rawConnection, options) {
|
|
|
13828
13846
|
}
|
|
13829
13847
|
});
|
|
13830
13848
|
break;
|
|
13849
|
+
case "neon":
|
|
13850
|
+
if (schema && schema !== "public") {
|
|
13851
|
+
const { Pool, neonConfig } = await import("@neondatabase/serverless");
|
|
13852
|
+
const { default: ws } = await import("ws");
|
|
13853
|
+
neonConfig.webSocketConstructor = ws;
|
|
13854
|
+
const connectionString = typeof rawConnection === "string" ? rawConnection : process.env.NEON_PG_URL || "";
|
|
13855
|
+
dialect = new PostgresDialect({
|
|
13856
|
+
pool: new Pool({ connectionString: connectionString.includes("currentSchema") ? connectionString.split("currentSchema=")[1].split("&")[0] === "public" ? connectionString.replace(/currentSchema=[^&]*&?/, "") : connectionString : connectionString }),
|
|
13857
|
+
onCreateConnection: async (connection) => {
|
|
13858
|
+
await connection.executeQuery(CompiledQuery.raw(`SET search_path TO "${schema}"`));
|
|
13859
|
+
}
|
|
13860
|
+
});
|
|
13861
|
+
} else {
|
|
13862
|
+
const { createNeonDialect } = await import("./neon-dialect-Hmo08nUq.mjs");
|
|
13863
|
+
dialect = createNeonDialect(rawConnection);
|
|
13864
|
+
}
|
|
13865
|
+
break;
|
|
13831
13866
|
case "mssql":
|
|
13832
13867
|
if ("createDriver" in rawConnection) dialect = rawConnection;
|
|
13833
13868
|
break;
|
|
13834
|
-
case "neon":
|
|
13835
|
-
const { NeonDialect: NeonDialect$1 } = await import("./neon-dialect-CTFuNy48.mjs");
|
|
13836
|
-
dialect = new NeonDialect$1(rawConnection);
|
|
13837
|
-
break;
|
|
13838
13869
|
}
|
|
13839
13870
|
return dialect ? new Kysely({ dialect }) : null;
|
|
13840
13871
|
}
|