u
This commit is contained in:
@@ -88,6 +88,22 @@ function parseSchema(source) {
|
||||
});
|
||||
}
|
||||
|
||||
const alterAddColumnRegex =
|
||||
/ALTER TABLE\s+(\w+)\s+ADD\s+(\w+)\s+([\w]+(?:\([^)]*\))?)(?:\s+(NOT NULL|NULL))?\s*;/gi;
|
||||
let alterColumnMatch;
|
||||
|
||||
while ((alterColumnMatch = alterAddColumnRegex.exec(sqlBlock)) !== null) {
|
||||
const tableName = alterColumnMatch[1];
|
||||
const name = alterColumnMatch[2];
|
||||
const type = alterColumnMatch[3];
|
||||
const nullable = alterColumnMatch[4]?.toUpperCase() !== 'NOT NULL';
|
||||
|
||||
const table = tables.get(tableName);
|
||||
if (!table || table.columns.some((c) => c.name === name)) continue;
|
||||
|
||||
table.columns.push({ name, type, nullable, isPk: false });
|
||||
}
|
||||
|
||||
const alterFkRegex =
|
||||
/ALTER TABLE\s+(\w+)\s+ADD CONSTRAINT\s+(\w+)\s+FOREIGN KEY\s*\(([^)]+)\)\s+REFERENCES\s+(\w+)\(([^)]+)\)(?:\s+ON DELETE\s+([\w\s]+?))?\s*;/gi;
|
||||
let alterMatch;
|
||||
|
||||
Reference in New Issue
Block a user