@famgia/omnify-laravel 0.0.16 → 0.0.17
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/{chunk-CAWNYSF3.js → chunk-52JAFQBQ.js} +37 -6
- package/dist/chunk-52JAFQBQ.js.map +1 -0
- package/dist/index.cjs +36 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/plugin.cjs +36 -5
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-CAWNYSF3.js.map +0 -1
package/dist/index.js
CHANGED
package/dist/plugin.cjs
CHANGED
|
@@ -239,7 +239,7 @@ function generateForeignKey(propertyName, property, allSchemas) {
|
|
|
239
239
|
method = "string";
|
|
240
240
|
}
|
|
241
241
|
const modifiers = [];
|
|
242
|
-
if (assocProp.nullable
|
|
242
|
+
if (assocProp.nullable === true) {
|
|
243
243
|
modifiers.push({ method: "nullable" });
|
|
244
244
|
}
|
|
245
245
|
if (assocProp.default !== void 0 && assocProp.default !== null) {
|
|
@@ -300,36 +300,67 @@ function schemaToBlueprint(schema, allSchemas) {
|
|
|
300
300
|
columns.push(generateSoftDeleteColumn());
|
|
301
301
|
}
|
|
302
302
|
if (schema.options?.indexes) {
|
|
303
|
+
const propToColName = (propName) => {
|
|
304
|
+
const colName = toColumnName(propName);
|
|
305
|
+
const prop = schema.properties?.[propName];
|
|
306
|
+
if (prop?.type === "Association") {
|
|
307
|
+
const assoc = prop;
|
|
308
|
+
if ((assoc.relation === "ManyToOne" || assoc.relation === "OneToOne") && !assoc.mappedBy) {
|
|
309
|
+
return colName + "_id";
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return colName;
|
|
313
|
+
};
|
|
303
314
|
for (const index of schema.options.indexes) {
|
|
304
315
|
if (typeof index === "string") {
|
|
305
316
|
indexes.push({
|
|
306
|
-
columns: [
|
|
317
|
+
columns: [propToColName(index)],
|
|
307
318
|
unique: false
|
|
308
319
|
});
|
|
309
320
|
} else {
|
|
310
321
|
indexes.push({
|
|
311
322
|
name: index.name,
|
|
312
|
-
columns: index.columns.map(
|
|
323
|
+
columns: index.columns.map(propToColName),
|
|
313
324
|
unique: index.unique ?? false
|
|
314
325
|
});
|
|
315
326
|
}
|
|
316
327
|
}
|
|
317
328
|
}
|
|
318
329
|
if (schema.options?.unique) {
|
|
330
|
+
const propToColName = (propName) => {
|
|
331
|
+
const colName = toColumnName(propName);
|
|
332
|
+
const prop = schema.properties?.[propName];
|
|
333
|
+
if (prop?.type === "Association") {
|
|
334
|
+
const assoc = prop;
|
|
335
|
+
if ((assoc.relation === "ManyToOne" || assoc.relation === "OneToOne") && !assoc.mappedBy) {
|
|
336
|
+
return colName + "_id";
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return colName;
|
|
340
|
+
};
|
|
319
341
|
const uniqueConstraints = Array.isArray(schema.options.unique[0]) ? schema.options.unique : [schema.options.unique];
|
|
320
342
|
for (const constraint of uniqueConstraints) {
|
|
321
343
|
indexes.push({
|
|
322
|
-
columns: constraint.map(
|
|
344
|
+
columns: constraint.map(propToColName),
|
|
323
345
|
unique: true
|
|
324
346
|
});
|
|
325
347
|
}
|
|
326
348
|
}
|
|
349
|
+
const seenIndexes = /* @__PURE__ */ new Set();
|
|
350
|
+
const uniqueIndexes = indexes.filter((idx) => {
|
|
351
|
+
const key = idx.columns.join(",") + (idx.unique ? ":unique" : "");
|
|
352
|
+
if (seenIndexes.has(key)) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
seenIndexes.add(key);
|
|
356
|
+
return true;
|
|
357
|
+
});
|
|
327
358
|
return {
|
|
328
359
|
tableName,
|
|
329
360
|
columns,
|
|
330
361
|
primaryKey: ["id"],
|
|
331
362
|
foreignKeys,
|
|
332
|
-
indexes
|
|
363
|
+
indexes: uniqueIndexes
|
|
333
364
|
};
|
|
334
365
|
}
|
|
335
366
|
function formatColumnMethod(column) {
|