local-lite 3.0.3 → 3.0.4
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.
|
@@ -273,8 +273,12 @@ function generateSqlDiff(prevSchema, nextSchema, dialect = 'mysql') {
|
|
|
273
273
|
const safeCol = !col.nullable && !col.defaultSql
|
|
274
274
|
? { ...col, nullable: true, defaultSql: 'NULL' }
|
|
275
275
|
: col;
|
|
276
|
-
up.push(
|
|
277
|
-
|
|
276
|
+
up.push(dialect === 'mysql'
|
|
277
|
+
? `ALTER TABLE ${qTable} ADD COLUMN IF NOT EXISTS ${formatColumnDef(colName, safeCol, dialect)};`
|
|
278
|
+
: `ALTER TABLE ${qTable} ADD COLUMN ${formatColumnDef(colName, safeCol, dialect)};`);
|
|
279
|
+
down.unshift(dialect === 'mysql'
|
|
280
|
+
? `ALTER TABLE ${qTable} DROP COLUMN IF EXISTS ${quoteIdent(colName, dialect)};`
|
|
281
|
+
: `ALTER TABLE ${qTable} DROP COLUMN ${quoteIdent(colName, dialect)};`);
|
|
278
282
|
}
|
|
279
283
|
else if (prevCol.sqlType !== col.sqlType) {
|
|
280
284
|
warnings.push(`Column type changed for ${tableName}.${colName} (${prevCol.sqlType} -> ${col.sqlType}); review manually before altering.`);
|
|
@@ -454,7 +458,7 @@ function applySqlStatement(tables, stmt) {
|
|
|
454
458
|
if (!table)
|
|
455
459
|
return;
|
|
456
460
|
for (const clause of splitTopLevel(alterMatch[2], ',')) {
|
|
457
|
-
const addCol = clause.match(/^ADD\s+(?:COLUMN\s+)?[`"]?(\w+)[`"]?\s+([\s\S]+)$/i);
|
|
461
|
+
const addCol = clause.match(/^ADD\s+(?:COLUMN\s+)?(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?\s+([\s\S]+)$/i);
|
|
458
462
|
if (addCol && !/^(?:UNIQUE|INDEX|KEY|CONSTRAINT|PRIMARY|FOREIGN)\b/i.test(addCol[1])) {
|
|
459
463
|
table.columns[addCol[1]] = {
|
|
460
464
|
sqlType: parseSqlType(addCol[2]),
|
|
@@ -463,7 +467,7 @@ function applySqlStatement(tables, stmt) {
|
|
|
463
467
|
};
|
|
464
468
|
continue;
|
|
465
469
|
}
|
|
466
|
-
const dropCol = clause.match(/^DROP\s+(?:COLUMN\s+)?[`"]?(\w+)[`"]?$/i);
|
|
470
|
+
const dropCol = clause.match(/^DROP\s+(?:COLUMN\s+)?(?:IF\s+EXISTS\s+)?[`"]?(\w+)[`"]?$/i);
|
|
467
471
|
if (dropCol) {
|
|
468
472
|
delete table.columns[dropCol[1]];
|
|
469
473
|
continue;
|
package/package.json
CHANGED