prisma-laravel-migrate 3.0.2 → 3.0.3
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/README.md
CHANGED
|
@@ -57,7 +57,8 @@ module.exports = {
|
|
|
57
57
|
{ stubFile: "audit.stub", tables: ["logs","audit_trails"] }
|
|
58
58
|
],
|
|
59
59
|
outputEnumDir: "app/Enums",
|
|
60
|
-
overwriteExisting: true
|
|
60
|
+
overwriteExisting: true,
|
|
61
|
+
allowedPivotExtraFields: ["scope"]
|
|
61
62
|
}
|
|
62
63
|
};
|
|
63
64
|
```
|
|
@@ -191,6 +192,8 @@ export interface ModelConfigOverride extends LaravelGeneratorConfig {
|
|
|
191
192
|
outputEnumDir?: string;
|
|
192
193
|
/** use awobaz/compoships */
|
|
193
194
|
awobaz?: boolean;
|
|
195
|
+
/** Extra fields allowed on pivot models */
|
|
196
|
+
allowedPivotExtraFields?: string[];
|
|
194
197
|
}
|
|
195
198
|
```
|
|
196
199
|
|
|
@@ -47,6 +47,7 @@ export async function generateLaravelModels(options) {
|
|
|
47
47
|
enumStubPath: pick('enumStubPath'),
|
|
48
48
|
modelStubPath: pick('modelStubPath'),
|
|
49
49
|
noEmit: pick('noEmit', false),
|
|
50
|
+
allowedPivotExtraFields: pick('allowedPivotExtraFields', []),
|
|
50
51
|
namespace: pick("namespace", "App")
|
|
51
52
|
};
|
|
52
53
|
addToConfig('model', cfg);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { objRels, scalarNames, getModel, dbNameOf, conventionalPivotName, getPrimaryKeyFields, hasIntersection, isUniqueOn, PIVOT_SCALAR_WHITELIST, } from "./types.js";
|
|
2
2
|
import { detectMorphToRelations, parseMorphOwnerDirectives } from "./morph.js";
|
|
3
|
-
import { isForModel, parseLocalDirective } from "../../../utils/utils.js";
|
|
3
|
+
import { getConfig, isForModel, parseLocalDirective } from "../../../utils/utils.js";
|
|
4
4
|
/* ------------------ pivot relevance (explicit M:N) ----------------------- */
|
|
5
5
|
const pivotOtherEndpointFor = (thisModelName, candidate) => {
|
|
6
6
|
const rels = objRels(candidate);
|
|
@@ -17,7 +17,20 @@ const pivotOtherEndpointFor = (thisModelName, candidate) => {
|
|
|
17
17
|
if (hasIntersection(fkA, fkB))
|
|
18
18
|
return undefined;
|
|
19
19
|
const fkUnion = new Set([...fkA, ...fkB]);
|
|
20
|
-
|
|
20
|
+
// May be: ["id", "meta", "created_at", ...] from your config
|
|
21
|
+
const extrasFromConfigRaw = getConfig("model", "allowedPivotExtraFields");
|
|
22
|
+
// Normalise to string[]
|
|
23
|
+
const extrasFromConfig = Array.isArray(extrasFromConfigRaw)
|
|
24
|
+
? extrasFromConfigRaw
|
|
25
|
+
: extrasFromConfigRaw
|
|
26
|
+
? [extrasFromConfigRaw]
|
|
27
|
+
: [];
|
|
28
|
+
// Combined whitelist: hard-coded + config
|
|
29
|
+
const allowedPivotScalars = new Set([
|
|
30
|
+
...PIVOT_SCALAR_WHITELIST,
|
|
31
|
+
...extrasFromConfig,
|
|
32
|
+
]);
|
|
33
|
+
const extras = scalarNames(candidate).filter((n) => !fkUnion.has(n) && !allowedPivotScalars.has(n));
|
|
21
34
|
if (extras.length > 0)
|
|
22
35
|
return undefined;
|
|
23
36
|
return relOther.type; // self-join allowed
|