new tests

This commit is contained in:
Mark Gregory
2026-10-19 10:08:40 +01:00
parent c9ebbb6406
commit 11a11d664f
+15 -4
View File
@@ -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 }