@elizaos/plugin-sql 2.0.0-alpha.16 → 2.0.0-alpha.18
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/node/index.node.js
CHANGED
|
@@ -2259,7 +2259,12 @@ function generateCreateTableSQL(fullTableName, table) {
|
|
|
2259
2259
|
const foreignKeys = table.foreignKeys || {};
|
|
2260
2260
|
for (const [fkName, fkDef] of Object.entries(foreignKeys)) {
|
|
2261
2261
|
const fk = fkDef;
|
|
2262
|
-
const fkSQL =
|
|
2262
|
+
const fkSQL = wrapConstraintCreationGuard(fkName, buildCreateForeignKeyBodySQL({
|
|
2263
|
+
...fk,
|
|
2264
|
+
name: fkName,
|
|
2265
|
+
schemaFrom: schema,
|
|
2266
|
+
tableFrom: tableName
|
|
2267
|
+
}));
|
|
2263
2268
|
fkSQLs.push(fkSQL);
|
|
2264
2269
|
}
|
|
2265
2270
|
return { tableSQL, fkSQLs };
|
|
@@ -2438,19 +2443,7 @@ function generateDropIndexSQL(index7) {
|
|
|
2438
2443
|
return `DROP INDEX IF EXISTS "${indexName}";`;
|
|
2439
2444
|
}
|
|
2440
2445
|
function generateCreateForeignKeySQL(fk) {
|
|
2441
|
-
|
|
2442
|
-
const schemaTo = fk.schemaTo || "public";
|
|
2443
|
-
const tableFrom = fk.tableFrom;
|
|
2444
|
-
const columnsFrom = fk.columnsFrom.map((c) => `"${c}"`).join(", ");
|
|
2445
|
-
const columnsTo = fk.columnsTo.map((c) => `"${c}"`).join(", ");
|
|
2446
|
-
let sql22 = `ALTER TABLE "${schemaFrom}"."${tableFrom}" ADD CONSTRAINT "${fk.name}" FOREIGN KEY (${columnsFrom}) REFERENCES "${schemaTo}"."${fk.tableTo}" (${columnsTo})`;
|
|
2447
|
-
if (fk.onDelete) {
|
|
2448
|
-
sql22 += ` ON DELETE ${fk.onDelete}`;
|
|
2449
|
-
}
|
|
2450
|
-
if (fk.onUpdate) {
|
|
2451
|
-
sql22 += ` ON UPDATE ${fk.onUpdate}`;
|
|
2452
|
-
}
|
|
2453
|
-
return `${sql22};`;
|
|
2446
|
+
return wrapConstraintCreationGuard(fk.name, buildCreateForeignKeyBodySQL(fk));
|
|
2454
2447
|
}
|
|
2455
2448
|
function generateDropForeignKeySQL(fk) {
|
|
2456
2449
|
const [schema, tableName] = fk.tableFrom ? fk.tableFrom.includes(".") ? fk.tableFrom.split(".") : ["public", fk.tableFrom] : ["public", ""];
|
|
@@ -2485,6 +2478,25 @@ function generateDropCheckConstraintSQL(constraint) {
|
|
|
2485
2478
|
const [schema, tableName] = table.includes(".") ? table.split(".") : ["public", table];
|
|
2486
2479
|
return `ALTER TABLE "${schema}"."${tableName}" DROP CONSTRAINT "${constraint.name}";`;
|
|
2487
2480
|
}
|
|
2481
|
+
function buildCreateForeignKeyBodySQL(fk) {
|
|
2482
|
+
const schemaFrom = fk.schemaFrom || "public";
|
|
2483
|
+
const schemaTo = fk.schemaTo || "public";
|
|
2484
|
+
const tableFrom = fk.tableFrom;
|
|
2485
|
+
const columnsFrom = fk.columnsFrom.map((c) => `"${c}"`).join(", ");
|
|
2486
|
+
const columnsTo = fk.columnsTo.map((c) => `"${c}"`).join(", ");
|
|
2487
|
+
let sql22 = `ALTER TABLE "${schemaFrom}"."${tableFrom}" ADD CONSTRAINT "${fk.name}" FOREIGN KEY (${columnsFrom}) REFERENCES "${schemaTo}"."${fk.tableTo}" (${columnsTo})`;
|
|
2488
|
+
if (fk.onDelete) {
|
|
2489
|
+
sql22 += ` ON DELETE ${fk.onDelete}`;
|
|
2490
|
+
}
|
|
2491
|
+
if (fk.onUpdate) {
|
|
2492
|
+
sql22 += ` ON UPDATE ${fk.onUpdate}`;
|
|
2493
|
+
}
|
|
2494
|
+
return sql22;
|
|
2495
|
+
}
|
|
2496
|
+
function wrapConstraintCreationGuard(constraintName, statement) {
|
|
2497
|
+
const escapedConstraintName = constraintName.replace(/'/g, "''");
|
|
2498
|
+
return `DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = '${escapedConstraintName}') THEN ${statement}; END IF; END $$;`;
|
|
2499
|
+
}
|
|
2488
2500
|
var init_sql_generator = () => {};
|
|
2489
2501
|
|
|
2490
2502
|
// runtime-migrator/extension-manager.ts
|
|
@@ -3778,7 +3790,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
3778
3790
|
return [String(names)];
|
|
3779
3791
|
}
|
|
3780
3792
|
isValidUUID(value) {
|
|
3781
|
-
return /^[0-9a-f]{8}-[0-9a-f]{4}-[
|
|
3793
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
3782
3794
|
}
|
|
3783
3795
|
normalizeWorldData(world) {
|
|
3784
3796
|
const worldData = {
|
|
@@ -7091,5 +7103,5 @@ export {
|
|
|
7091
7103
|
DatabaseMigrationService
|
|
7092
7104
|
};
|
|
7093
7105
|
|
|
7094
|
-
//# debugId=
|
|
7106
|
+
//# debugId=11DF3BC6739C08E664756E2164756E21
|
|
7095
7107
|
//# sourceMappingURL=index.node.js.map
|