From 11a11d664f706846bf53fef90ef2d25817ca0eb9 Mon Sep 17 00:00:00 2001 From: Mark Gregory Date: Mon, 19 Oct 2026 10:08:40 +0100 Subject: [PATCH] new tests --- DBSyn/LaravelMigrationView.swift | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/DBSyn/LaravelMigrationView.swift b/DBSyn/LaravelMigrationView.swift index 88976d8..88c6cf9 100644 --- a/DBSyn/LaravelMigrationView.swift +++ b/DBSyn/LaravelMigrationView.swift @@ -23,13 +23,24 @@ enum LaravelMigrationGenerator { let item = definition.trimmingCharacters(in: .whitespacesAndNewlines) let upper = item.uppercased() if upper.hasPrefix("PRIMARY KEY") { - let cols = backtickNames(item) - if cols.count == 1 { lines.append(" $table->primary('\\(cols[0])');") } - else if !cols.isEmpty { lines.append(" $table->primary([" + cols.map { "'\\($0)'" }.joined(separator: ", ") + "]);" ) } + let columns = backtickNames(item) + if columns.count == 1 { + lines.append(" $table->primary('\(columns[0])');") + } else if !columns.isEmpty { + let quotedColumns = columns.map { "'\($0)'" }.joined(separator: ", ") + lines.append(" $table->primary([\(quotedColumns)]);") + } continue } if upper.hasPrefix("UNIQUE KEY") || upper.hasPrefix("UNIQUE INDEX") || upper.hasPrefix("KEY ") || upper.hasPrefix("INDEX ") { - let cols = backtickNames(item); if cols.count > 1 { lines.append(" $table->" + (upper.hasPrefix("UNIQUE") ? "unique" : "index") + "([" + cols.dropFirst().map { "'\\($0)'" }.joined(separator: ", ") + "]);") }; continue + let columns = backtickNames(item) + if columns.count > 1 { + let columnNames = Array(columns.dropFirst()) + let quotedColumns = columnNames.map { "'\($0)'" }.joined(separator: ", ") + let indexMethod = upper.hasPrefix("UNIQUE") ? "unique" : "index" + lines.append(" $table->\(indexMethod)([\(quotedColumns)]);") + } + continue } if upper.hasPrefix("CONSTRAINT") || upper.hasPrefix("FOREIGN KEY") || upper.hasPrefix("CHECK") { lines.append(" // Review manually: " + item.replacingOccurrences(of: "\n", with: " ")); continue } guard let column = item.range(of: #"^`?([A-Za-z_][\w]*)`?\s+"#, options: .regularExpression) else { continue }