@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.
@@ -2110,7 +2110,12 @@ function generateCreateTableSQL(fullTableName, table) {
2110
2110
  const foreignKeys = table.foreignKeys || {};
2111
2111
  for (const [fkName, fkDef] of Object.entries(foreignKeys)) {
2112
2112
  const fk = fkDef;
2113
- const fkSQL = `ALTER TABLE "${schema}"."${tableName}" ADD CONSTRAINT "${fkName}" FOREIGN KEY (${fk.columnsFrom.map((c) => `"${c}"`).join(", ")}) REFERENCES "${fk.schemaTo || "public"}"."${fk.tableTo}" (${fk.columnsTo.map((c) => `"${c}"`).join(", ")})${fk.onDelete ? ` ON DELETE ${fk.onDelete}` : ""}${fk.onUpdate ? ` ON UPDATE ${fk.onUpdate}` : ""};`;
2113
+ const fkSQL = wrapConstraintCreationGuard(fkName, buildCreateForeignKeyBodySQL({
2114
+ ...fk,
2115
+ name: fkName,
2116
+ schemaFrom: schema,
2117
+ tableFrom: tableName
2118
+ }));
2114
2119
  fkSQLs.push(fkSQL);
2115
2120
  }
2116
2121
  return { tableSQL, fkSQLs };
@@ -2289,19 +2294,7 @@ function generateDropIndexSQL(index7) {
2289
2294
  return `DROP INDEX IF EXISTS "${indexName}";`;
2290
2295
  }
2291
2296
  function generateCreateForeignKeySQL(fk) {
2292
- const schemaFrom = fk.schemaFrom || "public";
2293
- const schemaTo = fk.schemaTo || "public";
2294
- const tableFrom = fk.tableFrom;
2295
- const columnsFrom = fk.columnsFrom.map((c) => `"${c}"`).join(", ");
2296
- const columnsTo = fk.columnsTo.map((c) => `"${c}"`).join(", ");
2297
- let sql22 = `ALTER TABLE "${schemaFrom}"."${tableFrom}" ADD CONSTRAINT "${fk.name}" FOREIGN KEY (${columnsFrom}) REFERENCES "${schemaTo}"."${fk.tableTo}" (${columnsTo})`;
2298
- if (fk.onDelete) {
2299
- sql22 += ` ON DELETE ${fk.onDelete}`;
2300
- }
2301
- if (fk.onUpdate) {
2302
- sql22 += ` ON UPDATE ${fk.onUpdate}`;
2303
- }
2304
- return `${sql22};`;
2297
+ return wrapConstraintCreationGuard(fk.name, buildCreateForeignKeyBodySQL(fk));
2305
2298
  }
2306
2299
  function generateDropForeignKeySQL(fk) {
2307
2300
  const [schema, tableName] = fk.tableFrom ? fk.tableFrom.includes(".") ? fk.tableFrom.split(".") : ["public", fk.tableFrom] : ["public", ""];
@@ -2336,6 +2329,25 @@ function generateDropCheckConstraintSQL(constraint) {
2336
2329
  const [schema, tableName] = table.includes(".") ? table.split(".") : ["public", table];
2337
2330
  return `ALTER TABLE "${schema}"."${tableName}" DROP CONSTRAINT "${constraint.name}";`;
2338
2331
  }
2332
+ function buildCreateForeignKeyBodySQL(fk) {
2333
+ const schemaFrom = fk.schemaFrom || "public";
2334
+ const schemaTo = fk.schemaTo || "public";
2335
+ const tableFrom = fk.tableFrom;
2336
+ const columnsFrom = fk.columnsFrom.map((c) => `"${c}"`).join(", ");
2337
+ const columnsTo = fk.columnsTo.map((c) => `"${c}"`).join(", ");
2338
+ let sql22 = `ALTER TABLE "${schemaFrom}"."${tableFrom}" ADD CONSTRAINT "${fk.name}" FOREIGN KEY (${columnsFrom}) REFERENCES "${schemaTo}"."${fk.tableTo}" (${columnsTo})`;
2339
+ if (fk.onDelete) {
2340
+ sql22 += ` ON DELETE ${fk.onDelete}`;
2341
+ }
2342
+ if (fk.onUpdate) {
2343
+ sql22 += ` ON UPDATE ${fk.onUpdate}`;
2344
+ }
2345
+ return sql22;
2346
+ }
2347
+ function wrapConstraintCreationGuard(constraintName, statement) {
2348
+ const escapedConstraintName = constraintName.replace(/'/g, "''");
2349
+ return `DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = '${escapedConstraintName}') THEN ${statement}; END IF; END $$;`;
2350
+ }
2339
2351
  var init_sql_generator = () => {};
2340
2352
 
2341
2353
  // runtime-migrator/extension-manager.ts
@@ -3155,11 +3167,11 @@ import {
3155
3167
  or,
3156
3168
  sql as sql27
3157
3169
  } from "drizzle-orm";
3158
- // node_modules/uuid/dist/native.js
3170
+ // ../../../node_modules/.bun/uuid@13.0.0/node_modules/uuid/dist/native.js
3159
3171
  var randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
3160
3172
  var native_default = { randomUUID };
3161
3173
 
3162
- // node_modules/uuid/dist/rng.js
3174
+ // ../../../node_modules/.bun/uuid@13.0.0/node_modules/uuid/dist/rng.js
3163
3175
  var getRandomValues;
3164
3176
  var rnds8 = new Uint8Array(16);
3165
3177
  function rng() {
@@ -3172,7 +3184,7 @@ function rng() {
3172
3184
  return getRandomValues(rnds8);
3173
3185
  }
3174
3186
 
3175
- // node_modules/uuid/dist/stringify.js
3187
+ // ../../../node_modules/.bun/uuid@13.0.0/node_modules/uuid/dist/stringify.js
3176
3188
  var byteToHex = [];
3177
3189
  for (let i = 0;i < 256; ++i) {
3178
3190
  byteToHex.push((i + 256).toString(16).slice(1));
@@ -3181,7 +3193,7 @@ function unsafeStringify(arr, offset = 0) {
3181
3193
  return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
3182
3194
  }
3183
3195
 
3184
- // node_modules/uuid/dist/v4.js
3196
+ // ../../../node_modules/.bun/uuid@13.0.0/node_modules/uuid/dist/v4.js
3185
3197
  function _v4(options, buf, offset) {
3186
3198
  options = options || {};
3187
3199
  const rnds = options.random ?? options.rng?.() ?? rng();
@@ -3681,7 +3693,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
3681
3693
  return [String(names)];
3682
3694
  }
3683
3695
  isValidUUID(value) {
3684
- return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value);
3696
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
3685
3697
  }
3686
3698
  normalizeWorldData(world) {
3687
3699
  const worldData = {
@@ -6708,5 +6720,5 @@ export {
6708
6720
  DatabaseMigrationService
6709
6721
  };
6710
6722
 
6711
- //# debugId=E44EA4F58C58A8D764756E2164756E21
6723
+ //# debugId=1C0FA995699E599E64756E2164756E21
6712
6724
  //# sourceMappingURL=index.browser.js.map