prisma-laravel-migrate 3.0.1 → 3.0.2
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ColumnDefinitionGenerator } from "./column-definition.js";
|
|
2
2
|
import { RuleResolver } from "./rule-definition.js";
|
|
3
|
-
import { isForMigrator, parseSilentDirective } from "../../utils/utils.js";
|
|
3
|
+
import { decorate, getConfig, isForMigrator, parseSilentDirective } from "../../utils/utils.js";
|
|
4
4
|
export class PrismaToLaravelMigrationGenerator {
|
|
5
5
|
dmmf;
|
|
6
6
|
columnGen;
|
|
@@ -62,6 +62,7 @@ export class PrismaToLaravelMigrationGenerator {
|
|
|
62
62
|
const isSilent = isForMigrator(parseSilentDirective(model.documentation ?? ""));
|
|
63
63
|
return {
|
|
64
64
|
tableName,
|
|
65
|
+
name: decorate(tableName, getConfig('migrator')),
|
|
65
66
|
isIgnored: isSilent,
|
|
66
67
|
local: isSilent,
|
|
67
68
|
definitions,
|
|
@@ -95,15 +95,15 @@ export async function generateLaravelSchema(options) {
|
|
|
95
95
|
let seq = idx + 1;
|
|
96
96
|
let timestamp = formatLaravelTimestamp(now, seq, padWidth);
|
|
97
97
|
// 3) Check for an existing file (old path before sort/repath)
|
|
98
|
-
const existingFile = readdirSync(baseOut).find(f => f.endsWith(`_create_${mig.
|
|
98
|
+
const existingFile = readdirSync(baseOut).find(f => f.endsWith(`_create_${mig.name}_table.php`));
|
|
99
99
|
const existingPath = existingFile ? path.join(baseOut, existingFile) : undefined;
|
|
100
100
|
// 4) If creating new, ensure uniqueness (re-runs within same second)
|
|
101
|
-
let fileName = existingFile ?? `${timestamp}_create_${mig.
|
|
101
|
+
let fileName = existingFile ?? `${timestamp}_create_${mig.name}_table.php`;
|
|
102
102
|
let filePath = path.join(baseOut, fileName);
|
|
103
103
|
while (!existingFile && existsSync(filePath)) {
|
|
104
104
|
seq += 1;
|
|
105
105
|
timestamp = formatLaravelTimestamp(now, seq, padWidth);
|
|
106
|
-
fileName = `${timestamp}_create_${mig.
|
|
106
|
+
fileName = `${timestamp}_create_${mig.name}_table.php`;
|
|
107
107
|
filePath = path.join(baseOut, fileName);
|
|
108
108
|
}
|
|
109
109
|
// 5) Generate and write (merge from old path, write to new path)
|
package/dist/utils/sort.js
CHANGED
|
@@ -6,10 +6,10 @@ export function sortMigrations(migrations) {
|
|
|
6
6
|
// ⬅️ NEW: drop migrations silenced for the migrator
|
|
7
7
|
migrations = migrations.filter(m => !m.local);
|
|
8
8
|
// 1) Build a map: tableName → Migration
|
|
9
|
-
const migMap = new Map(migrations.map(m => [m.
|
|
9
|
+
const migMap = new Map(migrations.map(m => [m.name, m]));
|
|
10
10
|
// 2) Collect “true” FKs only (skip back‐relation object fields)
|
|
11
11
|
const rawDeps = new Map();
|
|
12
|
-
for (const { tableName } of migrations) {
|
|
12
|
+
for (const { name: tableName } of migrations) {
|
|
13
13
|
rawDeps.set(tableName, new Set());
|
|
14
14
|
}
|
|
15
15
|
for (const m of migrations) {
|
|
@@ -24,9 +24,9 @@ export function sortMigrations(migrations) {
|
|
|
24
24
|
continue;
|
|
25
25
|
}
|
|
26
26
|
const parent = def.relationship.on;
|
|
27
|
-
if (!migMap.has(parent) || m.
|
|
27
|
+
if (!migMap.has(parent) || m.name === parent)
|
|
28
28
|
continue; // skip external/self
|
|
29
|
-
rawDeps.get(m.
|
|
29
|
+
rawDeps.get(m.name).add(parent);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
// 3) Build adjacency (parent → dependents) and in-degree (table → count)
|
|
@@ -62,8 +62,8 @@ export function sortMigrations(migrations) {
|
|
|
62
62
|
// 5) Cycle check
|
|
63
63
|
if (sorted.length !== migrations.length) {
|
|
64
64
|
const cycle = migrations
|
|
65
|
-
.map(m => m.
|
|
66
|
-
.filter(t => !sorted.some(s => s.
|
|
65
|
+
.map(m => m.name)
|
|
66
|
+
.filter(t => !sorted.some(s => s.name === t));
|
|
67
67
|
throw new Error(`Cycle detected in migration dependencies: ${cycle.join(' → ')}`);
|
|
68
68
|
}
|
|
69
69
|
console.log('\n📦 Sorted Migration Tables:\n' +
|