prisma-laravel-migrate 3.0.0 → 3.0.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.
|
@@ -7,6 +7,7 @@ export class ColumnDefinitionGenerator {
|
|
|
7
7
|
dmmf;
|
|
8
8
|
// private storage for each model’s column definitions
|
|
9
9
|
#columns = {};
|
|
10
|
+
#indexes = {};
|
|
10
11
|
// build a mapping from tableName → ColumnDefinition[]
|
|
11
12
|
#build() {
|
|
12
13
|
return this.dmmf.datamodel.models.reduce((map, model) => {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function buildCompositeFromIndexes(model) {
|
|
2
|
+
const raw = (model.indexes ?? []);
|
|
3
|
+
const isComposite = (i) => Array.isArray(i.fields) && i.fields.length > 1 && i.isDefinedOnField !== true;
|
|
4
|
+
const isPk = (i) => {
|
|
5
|
+
const t = (i.type || "").toLowerCase();
|
|
6
|
+
return t === "id" || t === "primary";
|
|
7
|
+
};
|
|
8
|
+
const isUnique = (i) => (typeof i.type === "string" && i.type.toLowerCase() === "unique") || i.isUnique === true;
|
|
9
|
+
const uniques = [];
|
|
10
|
+
const normals = [];
|
|
11
|
+
for (const i of raw) {
|
|
12
|
+
if (!isComposite(i) || isPk(i))
|
|
13
|
+
continue;
|
|
14
|
+
const spec = { fields: i.fields, name: i.name };
|
|
15
|
+
(isUnique(i) ? uniques : normals).push(spec);
|
|
16
|
+
}
|
|
17
|
+
// de-dupe by ordered field list (ignore name for dedupe)
|
|
18
|
+
const dedupe = (xs) => {
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
return xs.filter(x => {
|
|
21
|
+
const key = x.fields.join("|");
|
|
22
|
+
if (seen.has(key))
|
|
23
|
+
return false;
|
|
24
|
+
seen.add(key);
|
|
25
|
+
return true;
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
...model,
|
|
30
|
+
compositeUniques: dedupe(uniques),
|
|
31
|
+
compositeNormals: dedupe(normals),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Optional: build for all models in a DMMF document */
|
|
35
|
+
export function buildAllCompositeFromIndexes(doc) {
|
|
36
|
+
const out = {};
|
|
37
|
+
for (const m of doc.datamodel.models)
|
|
38
|
+
out[m.name] = buildCompositeFromIndexes(m);
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=model-definition.js.map
|
|
@@ -169,6 +169,10 @@ function runNormal(def, defaultMaps, snippet) {
|
|
|
169
169
|
? `, ${def.args.map(a => JSON.stringify(a)).join(", ")}`
|
|
170
170
|
: "";
|
|
171
171
|
let line = `$table->${def.migrationType}('${def.name}'${argsStr})`;
|
|
172
|
+
if (def.isUnique)
|
|
173
|
+
line += "->unique()";
|
|
174
|
+
if (def.isIndexed)
|
|
175
|
+
line += "->index()";
|
|
172
176
|
if (def.unsigned)
|
|
173
177
|
line += "->unsigned()";
|
|
174
178
|
if (def.nullable)
|
package/package.json
CHANGED
package/small.prisma
CHANGED
|
@@ -36,7 +36,7 @@ model Account {
|
|
|
36
36
|
email String? /// @fillable // now doubles as the FK to EmailOwner.email
|
|
37
37
|
user_id BigInt /// @fillable
|
|
38
38
|
type AccountType /// @fillable
|
|
39
|
-
password String /// @hidden @fillable
|
|
39
|
+
password String @unique /// @hidden @fillable
|
|
40
40
|
remember_token String? /// @hidden
|
|
41
41
|
|
|
42
42
|
// 2-factor
|
|
@@ -151,9 +151,9 @@ model Account {
|
|
|
151
151
|
|
|
152
152
|
labComments LabComment[]
|
|
153
153
|
|
|
154
|
-
@@unique([user_id, type]) // keep: one account per type per user
|
|
154
|
+
@@unique([user_id, type], map: "uniquw") // keep: one account per type per user
|
|
155
155
|
@@index([user_id, email]) // keep: fast guard-scoped lookups
|
|
156
|
-
@@index([
|
|
156
|
+
@@index([lang_id, email])
|
|
157
157
|
@@map("accounts")
|
|
158
158
|
}
|
|
159
159
|
|