drizzle-kit 0.25.0-1f15bfd → 0.25.0-20acc2f
Sign up to get free protection for your applications and to get access to all the features.
- package/api.d.mts +82 -0
- package/api.d.ts +82 -0
- package/api.js +689 -98
- package/api.mjs +689 -98
- package/bin.cjs +772 -106
- package/package.json +1 -1
- package/utils.js +24 -6
- package/utils.mjs +24 -6
package/api.js
CHANGED
@@ -7376,7 +7376,7 @@ var init_lib = __esm({
|
|
7376
7376
|
});
|
7377
7377
|
|
7378
7378
|
// src/serializer/mysqlSchema.ts
|
7379
|
-
var index, fk, column, tableV3, compositePK, uniqueConstraint, tableV4, table, kitInternals, dialect, schemaHash, schemaInternalV3, schemaInternalV4, schemaInternalV5, schemaInternal, schemaV3, schemaV4, schemaV5, schema, tableSquashedV4, tableSquashed, schemaSquashed, schemaSquashedV4, MySqlSquasher, squashMysqlScheme, mysqlSchema, mysqlSchemaV5, mysqlSchemaSquashed, backwardCompatibleMysqlSchema, dryMySql;
|
7379
|
+
var index, fk, column, tableV3, compositePK, uniqueConstraint, checkConstraint, tableV4, table, kitInternals, dialect, schemaHash, schemaInternalV3, schemaInternalV4, schemaInternalV5, schemaInternal, schemaV3, schemaV4, schemaV5, schema, tableSquashedV4, tableSquashed, schemaSquashed, schemaSquashedV4, MySqlSquasher, squashMysqlScheme, mysqlSchema, mysqlSchemaV5, mysqlSchemaSquashed, backwardCompatibleMysqlSchema, dryMySql;
|
7380
7380
|
var init_mysqlSchema = __esm({
|
7381
7381
|
"src/serializer/mysqlSchema.ts"() {
|
7382
7382
|
"use strict";
|
@@ -7426,6 +7426,10 @@ var init_mysqlSchema = __esm({
|
|
7426
7426
|
name: stringType(),
|
7427
7427
|
columns: stringType().array()
|
7428
7428
|
}).strict();
|
7429
|
+
checkConstraint = objectType({
|
7430
|
+
name: stringType(),
|
7431
|
+
value: stringType()
|
7432
|
+
}).strict();
|
7429
7433
|
tableV4 = objectType({
|
7430
7434
|
name: stringType(),
|
7431
7435
|
schema: stringType().optional(),
|
@@ -7439,7 +7443,8 @@ var init_mysqlSchema = __esm({
|
|
7439
7443
|
indexes: recordType(stringType(), index),
|
7440
7444
|
foreignKeys: recordType(stringType(), fk),
|
7441
7445
|
compositePrimaryKeys: recordType(stringType(), compositePK),
|
7442
|
-
uniqueConstraints: recordType(stringType(), uniqueConstraint).default({})
|
7446
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint).default({}),
|
7447
|
+
checkConstraint: recordType(stringType(), checkConstraint).default({})
|
7443
7448
|
}).strict();
|
7444
7449
|
kitInternals = objectType({
|
7445
7450
|
tables: recordType(
|
@@ -7516,7 +7521,8 @@ var init_mysqlSchema = __esm({
|
|
7516
7521
|
indexes: recordType(stringType(), stringType()),
|
7517
7522
|
foreignKeys: recordType(stringType(), stringType()),
|
7518
7523
|
compositePrimaryKeys: recordType(stringType(), stringType()),
|
7519
|
-
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
7524
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({}),
|
7525
|
+
checkConstraints: recordType(stringType(), stringType()).default({})
|
7520
7526
|
}).strict();
|
7521
7527
|
schemaSquashed = objectType({
|
7522
7528
|
version: literalType("5"),
|
@@ -7583,6 +7589,13 @@ var init_mysqlSchema = __esm({
|
|
7583
7589
|
onDelete
|
7584
7590
|
});
|
7585
7591
|
return result;
|
7592
|
+
},
|
7593
|
+
squashCheck: (input) => {
|
7594
|
+
return `${input.name};${input.value}`;
|
7595
|
+
},
|
7596
|
+
unsquashCheck: (input) => {
|
7597
|
+
const [name2, value] = input.split(";");
|
7598
|
+
return { name: name2, value };
|
7586
7599
|
}
|
7587
7600
|
};
|
7588
7601
|
squashMysqlScheme = (json3) => {
|
@@ -7603,6 +7616,9 @@ var init_mysqlSchema = __esm({
|
|
7603
7616
|
return MySqlSquasher.squashUnique(unq);
|
7604
7617
|
}
|
7605
7618
|
);
|
7619
|
+
const squashedCheckConstraints = mapValues(it[1].checkConstraint, (check) => {
|
7620
|
+
return MySqlSquasher.squashCheck(check);
|
7621
|
+
});
|
7606
7622
|
return [
|
7607
7623
|
it[0],
|
7608
7624
|
{
|
@@ -7611,7 +7627,8 @@ var init_mysqlSchema = __esm({
|
|
7611
7627
|
indexes: squashedIndexes,
|
7612
7628
|
foreignKeys: squashedFKs,
|
7613
7629
|
compositePrimaryKeys: squashedPKs,
|
7614
|
-
uniqueConstraints: squashedUniqueConstraints
|
7630
|
+
uniqueConstraints: squashedUniqueConstraints,
|
7631
|
+
checkConstraints: squashedCheckConstraints
|
7615
7632
|
}
|
7616
7633
|
];
|
7617
7634
|
})
|
@@ -7661,7 +7678,7 @@ var init_vector = __esm({
|
|
7661
7678
|
});
|
7662
7679
|
|
7663
7680
|
// src/serializer/pgSchema.ts
|
7664
|
-
var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, sequenceSchema, sequenceSquashed, columnV7, column2, columnSquashed, tableV32, compositePK2, uniqueConstraint2, tableV42, tableV5, tableV6, tableV7, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaInternalV6, pgSchemaExternal, pgSchemaInternalV7, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashedV6, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchemaV6, pgSchemaV7, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
|
7681
|
+
var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, sequenceSchema, sequenceSquashed, columnV7, column2, checkConstraint2, columnSquashed, tableV32, compositePK2, uniqueConstraint2, tableV42, tableV5, tableV6, tableV7, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaInternalV6, pgSchemaExternal, pgSchemaInternalV7, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashedV6, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchemaV6, pgSchemaV7, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
|
7665
7682
|
var init_pgSchema = __esm({
|
7666
7683
|
"src/serializer/pgSchema.ts"() {
|
7667
7684
|
"use strict";
|
@@ -7825,6 +7842,10 @@ var init_pgSchema = __esm({
|
|
7825
7842
|
}).optional(),
|
7826
7843
|
identity: sequenceSchema.merge(objectType({ type: enumType(["always", "byDefault"]) })).optional()
|
7827
7844
|
}).strict();
|
7845
|
+
checkConstraint2 = objectType({
|
7846
|
+
name: stringType(),
|
7847
|
+
value: stringType()
|
7848
|
+
}).strict();
|
7828
7849
|
columnSquashed = objectType({
|
7829
7850
|
name: stringType(),
|
7830
7851
|
type: stringType(),
|
@@ -7897,7 +7918,8 @@ var init_pgSchema = __esm({
|
|
7897
7918
|
indexes: recordType(stringType(), index2),
|
7898
7919
|
foreignKeys: recordType(stringType(), fk2),
|
7899
7920
|
compositePrimaryKeys: recordType(stringType(), compositePK2),
|
7900
|
-
uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
|
7921
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({}),
|
7922
|
+
checkConstraints: recordType(stringType(), checkConstraint2).default({})
|
7901
7923
|
}).strict();
|
7902
7924
|
schemaHash2 = objectType({
|
7903
7925
|
id: stringType(),
|
@@ -8005,7 +8027,8 @@ var init_pgSchema = __esm({
|
|
8005
8027
|
indexes: recordType(stringType(), stringType()),
|
8006
8028
|
foreignKeys: recordType(stringType(), stringType()),
|
8007
8029
|
compositePrimaryKeys: recordType(stringType(), stringType()),
|
8008
|
-
uniqueConstraints: recordType(stringType(), stringType())
|
8030
|
+
uniqueConstraints: recordType(stringType(), stringType()),
|
8031
|
+
checkConstraints: recordType(stringType(), stringType())
|
8009
8032
|
}).strict();
|
8010
8033
|
tableSquashedV42 = objectType({
|
8011
8034
|
name: stringType(),
|
@@ -8187,6 +8210,16 @@ var init_pgSchema = __esm({
|
|
8187
8210
|
cache: splitted[6] !== "undefined" ? splitted[6] : void 0,
|
8188
8211
|
cycle: splitted[7] === "true"
|
8189
8212
|
};
|
8213
|
+
},
|
8214
|
+
squashCheck: (check) => {
|
8215
|
+
return `${check.name};${check.value}`;
|
8216
|
+
},
|
8217
|
+
unsquashCheck: (input) => {
|
8218
|
+
const [
|
8219
|
+
name2,
|
8220
|
+
value
|
8221
|
+
] = input.split(";");
|
8222
|
+
return { name: name2, value };
|
8190
8223
|
}
|
8191
8224
|
};
|
8192
8225
|
squashPgScheme = (json3, action) => {
|
@@ -8219,6 +8252,12 @@ var init_pgSchema = __esm({
|
|
8219
8252
|
return PgSquasher.squashUnique(unq);
|
8220
8253
|
}
|
8221
8254
|
);
|
8255
|
+
const squashedChecksContraints = mapValues(
|
8256
|
+
it[1].checkConstraints,
|
8257
|
+
(check) => {
|
8258
|
+
return PgSquasher.squashCheck(check);
|
8259
|
+
}
|
8260
|
+
);
|
8222
8261
|
return [
|
8223
8262
|
it[0],
|
8224
8263
|
{
|
@@ -8228,7 +8267,8 @@ var init_pgSchema = __esm({
|
|
8228
8267
|
indexes: squashedIndexes,
|
8229
8268
|
foreignKeys: squashedFKs,
|
8230
8269
|
compositePrimaryKeys: squashedPKs,
|
8231
|
-
uniqueConstraints: squashedUniqueConstraints
|
8270
|
+
uniqueConstraints: squashedUniqueConstraints,
|
8271
|
+
checkConstraints: squashedChecksContraints
|
8232
8272
|
}
|
8233
8273
|
];
|
8234
8274
|
})
|
@@ -8273,7 +8313,7 @@ var init_pgSchema = __esm({
|
|
8273
8313
|
});
|
8274
8314
|
|
8275
8315
|
// src/serializer/sqliteSchema.ts
|
8276
|
-
var index3, fk3, compositePK3, column3, tableV33, uniqueConstraint3, table3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, schemaInternalV52, kitInternals3, latestVersion, schemaInternal2, schemaV32, schemaV42, schemaV52, schema2, tableSquashed3, schemaSquashed2, SQLiteSquasher, squashSqliteScheme, drySQLite, sqliteSchemaV5, sqliteSchema, SQLiteSchemaSquashed, backwardCompatibleSqliteSchema;
|
8316
|
+
var index3, fk3, compositePK3, column3, tableV33, uniqueConstraint3, checkConstraint3, table3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, schemaInternalV52, kitInternals3, latestVersion, schemaInternal2, schemaV32, schemaV42, schemaV52, schema2, tableSquashed3, schemaSquashed2, SQLiteSquasher, squashSqliteScheme, drySQLite, sqliteSchemaV5, sqliteSchema, SQLiteSchemaSquashed, backwardCompatibleSqliteSchema;
|
8277
8317
|
var init_sqliteSchema = __esm({
|
8278
8318
|
"src/serializer/sqliteSchema.ts"() {
|
8279
8319
|
"use strict";
|
@@ -8320,13 +8360,18 @@ var init_sqliteSchema = __esm({
|
|
8320
8360
|
name: stringType(),
|
8321
8361
|
columns: stringType().array()
|
8322
8362
|
}).strict();
|
8363
|
+
checkConstraint3 = objectType({
|
8364
|
+
name: stringType(),
|
8365
|
+
value: stringType()
|
8366
|
+
}).strict();
|
8323
8367
|
table3 = objectType({
|
8324
8368
|
name: stringType(),
|
8325
8369
|
columns: recordType(stringType(), column3),
|
8326
8370
|
indexes: recordType(stringType(), index3),
|
8327
8371
|
foreignKeys: recordType(stringType(), fk3),
|
8328
8372
|
compositePrimaryKeys: recordType(stringType(), compositePK3),
|
8329
|
-
uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
|
8373
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({}),
|
8374
|
+
checkConstraints: recordType(stringType(), checkConstraint3).default({})
|
8330
8375
|
}).strict();
|
8331
8376
|
dialect2 = enumType(["sqlite"]);
|
8332
8377
|
schemaHash3 = objectType({
|
@@ -8388,7 +8433,8 @@ var init_sqliteSchema = __esm({
|
|
8388
8433
|
indexes: recordType(stringType(), stringType()),
|
8389
8434
|
foreignKeys: recordType(stringType(), stringType()),
|
8390
8435
|
compositePrimaryKeys: recordType(stringType(), stringType()),
|
8391
|
-
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
8436
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({}),
|
8437
|
+
checkConstraints: recordType(stringType(), stringType()).default({})
|
8392
8438
|
}).strict();
|
8393
8439
|
schemaSquashed2 = objectType({
|
8394
8440
|
version: latestVersion,
|
@@ -8470,6 +8516,16 @@ var init_sqliteSchema = __esm({
|
|
8470
8516
|
},
|
8471
8517
|
unsquashPK: (pk) => {
|
8472
8518
|
return pk.split(",");
|
8519
|
+
},
|
8520
|
+
squashCheck: (check) => {
|
8521
|
+
return `${check.name};${check.value}`;
|
8522
|
+
},
|
8523
|
+
unsquashCheck: (input) => {
|
8524
|
+
const [
|
8525
|
+
name2,
|
8526
|
+
value
|
8527
|
+
] = input.split(";");
|
8528
|
+
return { name: name2, value };
|
8473
8529
|
}
|
8474
8530
|
};
|
8475
8531
|
squashSqliteScheme = (json3, action) => {
|
@@ -8496,6 +8552,12 @@ var init_sqliteSchema = __esm({
|
|
8496
8552
|
return SQLiteSquasher.squashUnique(unq);
|
8497
8553
|
}
|
8498
8554
|
);
|
8555
|
+
const squashedCheckConstraints = mapValues(
|
8556
|
+
it[1].checkConstraints,
|
8557
|
+
(check) => {
|
8558
|
+
return SQLiteSquasher.squashCheck(check);
|
8559
|
+
}
|
8560
|
+
);
|
8499
8561
|
return [
|
8500
8562
|
it[0],
|
8501
8563
|
{
|
@@ -8504,7 +8566,8 @@ var init_sqliteSchema = __esm({
|
|
8504
8566
|
indexes: squashedIndexes,
|
8505
8567
|
foreignKeys: squashedFKs,
|
8506
8568
|
compositePrimaryKeys: squashedPKs,
|
8507
|
-
uniqueConstraints: squashedUniqueConstraints
|
8569
|
+
uniqueConstraints: squashedUniqueConstraints,
|
8570
|
+
checkConstraints: squashedCheckConstraints
|
8508
8571
|
}
|
8509
8572
|
];
|
8510
8573
|
})
|
@@ -11385,6 +11448,21 @@ var init_jsonDiffer = __esm({
|
|
11385
11448
|
return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
|
11386
11449
|
})
|
11387
11450
|
);
|
11451
|
+
const addedCheckConstraints = Object.fromEntries(
|
11452
|
+
Object.entries(table4.checkConstraints || {}).filter((it) => {
|
11453
|
+
return it[0].endsWith("__added");
|
11454
|
+
})
|
11455
|
+
);
|
11456
|
+
const deletedCheckConstraints = Object.fromEntries(
|
11457
|
+
Object.entries(table4.checkConstraints || {}).filter((it) => {
|
11458
|
+
return it[0].endsWith("__deleted");
|
11459
|
+
})
|
11460
|
+
);
|
11461
|
+
const alteredCheckConstraints = Object.fromEntries(
|
11462
|
+
Object.entries(table4.checkConstraints || {}).filter((it) => {
|
11463
|
+
return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
|
11464
|
+
})
|
11465
|
+
);
|
11388
11466
|
const mappedAltered = altered.map((it) => alternationsInColumn(it)).filter(Boolean);
|
11389
11467
|
return {
|
11390
11468
|
name: table4.name,
|
@@ -11401,7 +11479,10 @@ var init_jsonDiffer = __esm({
|
|
11401
11479
|
alteredCompositePKs,
|
11402
11480
|
addedUniqueConstraints,
|
11403
11481
|
deletedUniqueConstraints,
|
11404
|
-
alteredUniqueConstraints
|
11482
|
+
alteredUniqueConstraints,
|
11483
|
+
addedCheckConstraints,
|
11484
|
+
deletedCheckConstraints,
|
11485
|
+
alteredCheckConstraints
|
11405
11486
|
};
|
11406
11487
|
};
|
11407
11488
|
alternationsInColumn = (column4) => {
|
@@ -11655,6 +11736,32 @@ var init_jsonDiffer = __esm({
|
|
11655
11736
|
};
|
11656
11737
|
}
|
11657
11738
|
return it;
|
11739
|
+
}).map((it) => {
|
11740
|
+
if ("" in it) {
|
11741
|
+
return {
|
11742
|
+
...it,
|
11743
|
+
autoincrement: {
|
11744
|
+
type: "changed",
|
11745
|
+
old: it.autoincrement.__old,
|
11746
|
+
new: it.autoincrement.__new
|
11747
|
+
}
|
11748
|
+
};
|
11749
|
+
}
|
11750
|
+
if ("autoincrement__added" in it) {
|
11751
|
+
const { autoincrement__added, ...others } = it;
|
11752
|
+
return {
|
11753
|
+
...others,
|
11754
|
+
autoincrement: { type: "added", value: it.autoincrement__added }
|
11755
|
+
};
|
11756
|
+
}
|
11757
|
+
if ("autoincrement__deleted" in it) {
|
11758
|
+
const { autoincrement__deleted, ...others } = it;
|
11759
|
+
return {
|
11760
|
+
...others,
|
11761
|
+
autoincrement: { type: "deleted", value: it.autoincrement__deleted }
|
11762
|
+
};
|
11763
|
+
}
|
11764
|
+
return it;
|
11658
11765
|
}).filter(Boolean);
|
11659
11766
|
return result[0];
|
11660
11767
|
};
|
@@ -11675,7 +11782,7 @@ function fromJson(statements, dialect4, action, json22) {
|
|
11675
11782
|
}).filter((it) => it !== "");
|
11676
11783
|
return result;
|
11677
11784
|
}
|
11678
|
-
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, DropTypeEnumConvertor, AlterTypeAddValueConvertor, AlterTypeSetSchemaConvertor, AlterRenameTypeConvertor, AlterTypeDropValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
|
11785
|
+
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, PgAlterTableAddCheckConstraintConvertor, PgAlterTableDeleteCheckConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, MySqlAlterTableAddCheckConstraintConvertor, MySqlAlterTableDeleteCheckConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, DropTypeEnumConvertor, AlterTypeAddValueConvertor, AlterTypeSetSchemaConvertor, AlterRenameTypeConvertor, AlterTypeDropValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
|
11679
11786
|
var init_sqlgenerator = __esm({
|
11680
11787
|
"src/sqlgenerator.ts"() {
|
11681
11788
|
"use strict";
|
@@ -11736,7 +11843,7 @@ var init_sqlgenerator = __esm({
|
|
11736
11843
|
return statement.type === "create_table" && dialect4 === "postgresql";
|
11737
11844
|
}
|
11738
11845
|
convert(st) {
|
11739
|
-
const { tableName, schema: schema4, columns, compositePKs, uniqueConstraints } = st;
|
11846
|
+
const { tableName, schema: schema4, columns, compositePKs, uniqueConstraints, checkConstraints } = st;
|
11740
11847
|
let statement = "";
|
11741
11848
|
const name2 = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
|
11742
11849
|
statement += `CREATE TABLE IF NOT EXISTS ${name2} (
|
@@ -11769,6 +11876,13 @@ var init_sqlgenerator = __esm({
|
|
11769
11876
|
statement += ` CONSTRAINT "${unsquashedUnique.name}" UNIQUE${unsquashedUnique.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}("${unsquashedUnique.columns.join(`","`)}")`;
|
11770
11877
|
}
|
11771
11878
|
}
|
11879
|
+
if (typeof checkConstraints !== "undefined" && checkConstraints.length > 0) {
|
11880
|
+
for (const checkConstraint4 of checkConstraints) {
|
11881
|
+
statement += ",\n";
|
11882
|
+
const unsquashedCheck = PgSquasher.unsquashCheck(checkConstraint4);
|
11883
|
+
statement += ` CONSTRAINT "${unsquashedCheck.name}" CHECK (${unsquashedCheck.value})`;
|
11884
|
+
}
|
11885
|
+
}
|
11772
11886
|
statement += `
|
11773
11887
|
);`;
|
11774
11888
|
statement += `
|
@@ -11785,6 +11899,7 @@ var init_sqlgenerator = __esm({
|
|
11785
11899
|
tableName,
|
11786
11900
|
columns,
|
11787
11901
|
schema: schema4,
|
11902
|
+
checkConstraints,
|
11788
11903
|
compositePKs,
|
11789
11904
|
uniqueConstraints,
|
11790
11905
|
internals
|
@@ -11818,6 +11933,13 @@ var init_sqlgenerator = __esm({
|
|
11818
11933
|
statement += ` CONSTRAINT \`${unsquashedUnique.name}\` UNIQUE(${uniqueString})`;
|
11819
11934
|
}
|
11820
11935
|
}
|
11936
|
+
if (typeof checkConstraints !== "undefined" && checkConstraints.length > 0) {
|
11937
|
+
for (const checkConstraint4 of checkConstraints) {
|
11938
|
+
statement += ",\n";
|
11939
|
+
const unsquashedCheck = MySqlSquasher.unsquashCheck(checkConstraint4);
|
11940
|
+
statement += ` CONSTRAINT \`${unsquashedCheck.name}\` CHECK(${unsquashedCheck.value})`;
|
11941
|
+
}
|
11942
|
+
}
|
11821
11943
|
statement += `
|
11822
11944
|
);`;
|
11823
11945
|
statement += `
|
@@ -11835,7 +11957,8 @@ var init_sqlgenerator = __esm({
|
|
11835
11957
|
columns,
|
11836
11958
|
referenceData,
|
11837
11959
|
compositePKs,
|
11838
|
-
uniqueConstraints
|
11960
|
+
uniqueConstraints,
|
11961
|
+
checkConstraints
|
11839
11962
|
} = st;
|
11840
11963
|
let statement = "";
|
11841
11964
|
statement += `CREATE TABLE \`${tableName}\` (
|
@@ -11876,10 +11999,17 @@ var init_sqlgenerator = __esm({
|
|
11876
11999
|
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
11877
12000
|
for (const uniqueConstraint4 of uniqueConstraints) {
|
11878
12001
|
statement += ",\n";
|
11879
|
-
const unsquashedUnique =
|
12002
|
+
const unsquashedUnique = SQLiteSquasher.unsquashUnique(uniqueConstraint4);
|
11880
12003
|
statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
|
11881
12004
|
}
|
11882
12005
|
}
|
12006
|
+
if (typeof checkConstraints !== "undefined" && checkConstraints.length > 0) {
|
12007
|
+
for (const check of checkConstraints) {
|
12008
|
+
statement += ",\n";
|
12009
|
+
const { value, name: name2 } = SQLiteSquasher.unsquashCheck(check);
|
12010
|
+
statement += ` CONSTRAINT "${name2}" CHECK(${value})`;
|
12011
|
+
}
|
12012
|
+
}
|
11883
12013
|
statement += `
|
11884
12014
|
`;
|
11885
12015
|
statement += `);`;
|
@@ -11979,6 +12109,25 @@ var init_sqlgenerator = __esm({
|
|
11979
12109
|
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${unsquashed.name}";`;
|
11980
12110
|
}
|
11981
12111
|
};
|
12112
|
+
PgAlterTableAddCheckConstraintConvertor = class extends Convertor {
|
12113
|
+
can(statement, dialect4) {
|
12114
|
+
return statement.type === "create_check_constraint" && dialect4 === "postgresql";
|
12115
|
+
}
|
12116
|
+
convert(statement) {
|
12117
|
+
const unsquashed = PgSquasher.unsquashCheck(statement.data);
|
12118
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
12119
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" CHECK (${unsquashed.value});`;
|
12120
|
+
}
|
12121
|
+
};
|
12122
|
+
PgAlterTableDeleteCheckConstraintConvertor = class extends Convertor {
|
12123
|
+
can(statement, dialect4) {
|
12124
|
+
return statement.type === "delete_check_constraint" && dialect4 === "postgresql";
|
12125
|
+
}
|
12126
|
+
convert(statement) {
|
12127
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
12128
|
+
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${statement.constraintName}";`;
|
12129
|
+
}
|
12130
|
+
};
|
11982
12131
|
MySQLAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
11983
12132
|
can(statement, dialect4) {
|
11984
12133
|
return statement.type === "create_unique_constraint" && dialect4 === "mysql";
|
@@ -11997,6 +12146,25 @@ var init_sqlgenerator = __esm({
|
|
11997
12146
|
return `ALTER TABLE \`${statement.tableName}\` DROP INDEX \`${unsquashed.name}\`;`;
|
11998
12147
|
}
|
11999
12148
|
};
|
12149
|
+
MySqlAlterTableAddCheckConstraintConvertor = class extends Convertor {
|
12150
|
+
can(statement, dialect4) {
|
12151
|
+
return statement.type === "create_check_constraint" && dialect4 === "mysql";
|
12152
|
+
}
|
12153
|
+
convert(statement) {
|
12154
|
+
const unsquashed = MySqlSquasher.unsquashCheck(statement.data);
|
12155
|
+
const { tableName } = statement;
|
12156
|
+
return `ALTER TABLE \`${tableName}\` ADD CONSTRAINT \`${unsquashed.name}\` CHECK (${unsquashed.value});`;
|
12157
|
+
}
|
12158
|
+
};
|
12159
|
+
MySqlAlterTableDeleteCheckConstraintConvertor = class extends Convertor {
|
12160
|
+
can(statement, dialect4) {
|
12161
|
+
return statement.type === "delete_check_constraint" && dialect4 === "mysql";
|
12162
|
+
}
|
12163
|
+
convert(statement) {
|
12164
|
+
const { tableName } = statement;
|
12165
|
+
return `ALTER TABLE \`${tableName}\` DROP CONSTRAINT \`${statement.constraintName}\`;`;
|
12166
|
+
}
|
12167
|
+
};
|
12000
12168
|
CreatePgSequenceConvertor = class extends Convertor {
|
12001
12169
|
can(statement, dialect4) {
|
12002
12170
|
return statement.type === "create_sequence" && dialect4 === "postgresql";
|
@@ -12071,7 +12239,7 @@ var init_sqlgenerator = __esm({
|
|
12071
12239
|
convert(st) {
|
12072
12240
|
const { name: name2, schema: schema4 } = st;
|
12073
12241
|
const enumNameWithSchema = schema4 ? `"${schema4}"."${name2}"` : `"${name2}"`;
|
12074
|
-
let statement = `DROP TYPE ${enumNameWithSchema}
|
12242
|
+
let statement = `DROP TYPE ${enumNameWithSchema};`;
|
12075
12243
|
return statement;
|
12076
12244
|
}
|
12077
12245
|
};
|
@@ -12600,7 +12768,7 @@ var init_sqlgenerator = __esm({
|
|
12600
12768
|
};
|
12601
12769
|
LibSQLModifyColumn = class extends Convertor {
|
12602
12770
|
can(statement, dialect4) {
|
12603
|
-
return (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default") && dialect4 === "turso";
|
12771
|
+
return (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "create_check_constraint" || statement.type === "delete_check_constraint") && dialect4 === "turso";
|
12604
12772
|
}
|
12605
12773
|
convert(statement, json22) {
|
12606
12774
|
const { tableName, columnName } = statement;
|
@@ -13187,18 +13355,22 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13187
13355
|
return statement.type === "recreate_table" && dialect4 === "sqlite";
|
13188
13356
|
}
|
13189
13357
|
convert(statement) {
|
13190
|
-
const { tableName, columns, compositePKs, referenceData } = statement;
|
13358
|
+
const { tableName, columns, compositePKs, referenceData, checkConstraints } = statement;
|
13191
13359
|
const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
|
13192
13360
|
const newTableName = `__new_${tableName}`;
|
13193
13361
|
const sqlStatements = [];
|
13194
13362
|
sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
|
13363
|
+
const mappedCheckConstraints = checkConstraints.map(
|
13364
|
+
(it) => it.replaceAll(`"${tableName}".`, `"${newTableName}".`).replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`).replaceAll(`${tableName}.`, `${newTableName}.`).replaceAll(`'${tableName}'.`, `'${newTableName}'.`)
|
13365
|
+
);
|
13195
13366
|
sqlStatements.push(
|
13196
13367
|
new SQLiteCreateTableConvertor().convert({
|
13197
13368
|
type: "sqlite_create_table",
|
13198
13369
|
tableName: newTableName,
|
13199
13370
|
columns,
|
13200
13371
|
referenceData,
|
13201
|
-
compositePKs
|
13372
|
+
compositePKs,
|
13373
|
+
checkConstraints: mappedCheckConstraints
|
13202
13374
|
})
|
13203
13375
|
);
|
13204
13376
|
sqlStatements.push(
|
@@ -13229,10 +13401,13 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13229
13401
|
return statement.type === "recreate_table" && dialect4 === "turso";
|
13230
13402
|
}
|
13231
13403
|
convert(statement) {
|
13232
|
-
const { tableName, columns, compositePKs, referenceData } = statement;
|
13404
|
+
const { tableName, columns, compositePKs, referenceData, checkConstraints } = statement;
|
13233
13405
|
const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
|
13234
13406
|
const newTableName = `__new_${tableName}`;
|
13235
13407
|
const sqlStatements = [];
|
13408
|
+
const mappedCheckConstraints = checkConstraints.map(
|
13409
|
+
(it) => it.replaceAll(`"${tableName}".`, `"${newTableName}".`).replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`).replaceAll(`${tableName}.`, `${newTableName}.`).replaceAll(`'${tableName}'.`, `\`${newTableName}\`.`)
|
13410
|
+
);
|
13236
13411
|
sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
|
13237
13412
|
sqlStatements.push(
|
13238
13413
|
new SQLiteCreateTableConvertor().convert({
|
@@ -13240,7 +13415,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13240
13415
|
tableName: newTableName,
|
13241
13416
|
columns,
|
13242
13417
|
referenceData,
|
13243
|
-
compositePKs
|
13418
|
+
compositePKs,
|
13419
|
+
checkConstraints: mappedCheckConstraints
|
13244
13420
|
})
|
13245
13421
|
);
|
13246
13422
|
sqlStatements.push(
|
@@ -13301,6 +13477,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13301
13477
|
convertors.push(new PgAlterTableAlterColumnSetTypeConvertor());
|
13302
13478
|
convertors.push(new PgAlterTableAddUniqueConstraintConvertor());
|
13303
13479
|
convertors.push(new PgAlterTableDropUniqueConstraintConvertor());
|
13480
|
+
convertors.push(new PgAlterTableAddCheckConstraintConvertor());
|
13481
|
+
convertors.push(new PgAlterTableDeleteCheckConstraintConvertor());
|
13482
|
+
convertors.push(new MySqlAlterTableAddCheckConstraintConvertor());
|
13483
|
+
convertors.push(new MySqlAlterTableDeleteCheckConstraintConvertor());
|
13304
13484
|
convertors.push(new MySQLAlterTableAddUniqueConstraintConvertor());
|
13305
13485
|
convertors.push(new MySQLAlterTableDropUniqueConstraintConvertor());
|
13306
13486
|
convertors.push(new CreatePgIndexConvertor());
|
@@ -13390,6 +13570,10 @@ var init_sqlitePushUtils = __esm({
|
|
13390
13570
|
const compositePKs = Object.values(
|
13391
13571
|
json3.tables[tableName].compositePrimaryKeys
|
13392
13572
|
).map((it) => SQLiteSquasher.unsquashPK(it));
|
13573
|
+
const checkConstraints = Object.values(json3.tables[tableName].checkConstraints);
|
13574
|
+
const mappedCheckConstraints = checkConstraints.map(
|
13575
|
+
(it) => it.replaceAll(`"${tableName}".`, `"${newTableName}".`).replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`).replaceAll(`${tableName}.`, `${newTableName}.`).replaceAll(`'${tableName}'.`, `\`${newTableName}\`.`)
|
13576
|
+
);
|
13393
13577
|
const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
|
13394
13578
|
statements.push(
|
13395
13579
|
new SQLiteCreateTableConvertor().convert({
|
@@ -13397,7 +13581,8 @@ var init_sqlitePushUtils = __esm({
|
|
13397
13581
|
tableName: newTableName,
|
13398
13582
|
columns: tableColumns,
|
13399
13583
|
referenceData: fks,
|
13400
|
-
compositePKs
|
13584
|
+
compositePKs,
|
13585
|
+
checkConstraints: mappedCheckConstraints
|
13401
13586
|
})
|
13402
13587
|
);
|
13403
13588
|
if (!dataLoss) {
|
@@ -13609,7 +13794,7 @@ var init_sqlitePushUtils = __esm({
|
|
13609
13794
|
});
|
13610
13795
|
|
13611
13796
|
// src/jsonStatements.ts
|
13612
|
-
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumValues, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
|
13797
|
+
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumValues, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCheckConstraint, prepareDeleteCheckConstraint, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
|
13613
13798
|
var init_jsonStatements = __esm({
|
13614
13799
|
"src/jsonStatements.ts"() {
|
13615
13800
|
"use strict";
|
@@ -13620,7 +13805,7 @@ var init_jsonStatements = __esm({
|
|
13620
13805
|
init_pgSchema();
|
13621
13806
|
init_sqliteSchema();
|
13622
13807
|
preparePgCreateTableJson = (table4, json22) => {
|
13623
|
-
const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
13808
|
+
const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints, checkConstraints } = table4;
|
13624
13809
|
const tableKey2 = `${schema4 || "public"}.${name2}`;
|
13625
13810
|
const compositePkName = Object.values(compositePrimaryKeys).length > 0 ? json22.tables[tableKey2].compositePrimaryKeys[`${PgSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name}`].name : "";
|
13626
13811
|
return {
|
@@ -13630,11 +13815,12 @@ var init_jsonStatements = __esm({
|
|
13630
13815
|
columns: Object.values(columns),
|
13631
13816
|
compositePKs: Object.values(compositePrimaryKeys),
|
13632
13817
|
compositePkName,
|
13633
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
13818
|
+
uniqueConstraints: Object.values(uniqueConstraints),
|
13819
|
+
checkConstraints: Object.values(checkConstraints)
|
13634
13820
|
};
|
13635
13821
|
};
|
13636
13822
|
prepareMySqlCreateTableJson = (table4, json22, internals) => {
|
13637
|
-
const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
13823
|
+
const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints, checkConstraints } = table4;
|
13638
13824
|
return {
|
13639
13825
|
type: "create_table",
|
13640
13826
|
tableName: name2,
|
@@ -13643,11 +13829,12 @@ var init_jsonStatements = __esm({
|
|
13643
13829
|
compositePKs: Object.values(compositePrimaryKeys),
|
13644
13830
|
compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json22.tables[name2].compositePrimaryKeys[MySqlSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name].name : "",
|
13645
13831
|
uniqueConstraints: Object.values(uniqueConstraints),
|
13646
|
-
internals
|
13832
|
+
internals,
|
13833
|
+
checkConstraints: Object.values(checkConstraints)
|
13647
13834
|
};
|
13648
13835
|
};
|
13649
13836
|
prepareSQLiteCreateTable = (table4, action) => {
|
13650
|
-
const { name: name2, columns, uniqueConstraints } = table4;
|
13837
|
+
const { name: name2, columns, uniqueConstraints, checkConstraints } = table4;
|
13651
13838
|
const references2 = Object.values(table4.foreignKeys);
|
13652
13839
|
const composites = Object.values(table4.compositePrimaryKeys).map(
|
13653
13840
|
(it) => SQLiteSquasher.unsquashPK(it)
|
@@ -13661,7 +13848,8 @@ var init_jsonStatements = __esm({
|
|
13661
13848
|
columns: Object.values(columns),
|
13662
13849
|
referenceData: fks,
|
13663
13850
|
compositePKs: composites,
|
13664
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
13851
|
+
uniqueConstraints: Object.values(uniqueConstraints),
|
13852
|
+
checkConstraints: Object.values(checkConstraints)
|
13665
13853
|
};
|
13666
13854
|
};
|
13667
13855
|
prepareDropTableJson = (table4) => {
|
@@ -14925,6 +15113,26 @@ var init_jsonStatements = __esm({
|
|
14925
15113
|
};
|
14926
15114
|
});
|
14927
15115
|
};
|
15116
|
+
prepareAddCheckConstraint = (tableName, schema4, check) => {
|
15117
|
+
return Object.values(check).map((it) => {
|
15118
|
+
return {
|
15119
|
+
type: "create_check_constraint",
|
15120
|
+
tableName,
|
15121
|
+
data: it,
|
15122
|
+
schema: schema4
|
15123
|
+
};
|
15124
|
+
});
|
15125
|
+
};
|
15126
|
+
prepareDeleteCheckConstraint = (tableName, schema4, check) => {
|
15127
|
+
return Object.values(check).map((it) => {
|
15128
|
+
return {
|
15129
|
+
type: "delete_check_constraint",
|
15130
|
+
tableName,
|
15131
|
+
constraintName: PgSquasher.unsquashCheck(it).name,
|
15132
|
+
schema: schema4
|
15133
|
+
};
|
15134
|
+
});
|
15135
|
+
};
|
14928
15136
|
prepareAddCompositePrimaryKeyMySql = (tableName, pks, json1, json22) => {
|
14929
15137
|
const res = [];
|
14930
15138
|
for (const it of Object.values(pks)) {
|
@@ -14974,7 +15182,7 @@ var init_statementCombiner = __esm({
|
|
14974
15182
|
init_jsonStatements();
|
14975
15183
|
init_sqliteSchema();
|
14976
15184
|
prepareLibSQLRecreateTable = (table4, action) => {
|
14977
|
-
const { name: name2, columns, uniqueConstraints, indexes } = table4;
|
15185
|
+
const { name: name2, columns, uniqueConstraints, indexes, checkConstraints } = table4;
|
14978
15186
|
const composites = Object.values(table4.compositePrimaryKeys).map(
|
14979
15187
|
(it) => SQLiteSquasher.unsquashPK(it)
|
14980
15188
|
);
|
@@ -14989,7 +15197,8 @@ var init_statementCombiner = __esm({
|
|
14989
15197
|
columns: Object.values(columns),
|
14990
15198
|
compositePKs: composites,
|
14991
15199
|
referenceData: fks,
|
14992
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
15200
|
+
uniqueConstraints: Object.values(uniqueConstraints),
|
15201
|
+
checkConstraints: Object.values(checkConstraints)
|
14993
15202
|
}
|
14994
15203
|
];
|
14995
15204
|
if (Object.keys(indexes).length) {
|
@@ -14998,7 +15207,7 @@ var init_statementCombiner = __esm({
|
|
14998
15207
|
return statements;
|
14999
15208
|
};
|
15000
15209
|
prepareSQLiteRecreateTable = (table4, action) => {
|
15001
|
-
const { name: name2, columns, uniqueConstraints, indexes } = table4;
|
15210
|
+
const { name: name2, columns, uniqueConstraints, indexes, checkConstraints } = table4;
|
15002
15211
|
const composites = Object.values(table4.compositePrimaryKeys).map(
|
15003
15212
|
(it) => SQLiteSquasher.unsquashPK(it)
|
15004
15213
|
);
|
@@ -15013,7 +15222,8 @@ var init_statementCombiner = __esm({
|
|
15013
15222
|
columns: Object.values(columns),
|
15014
15223
|
compositePKs: composites,
|
15015
15224
|
referenceData: fks,
|
15016
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
15225
|
+
uniqueConstraints: Object.values(uniqueConstraints),
|
15226
|
+
checkConstraints: Object.values(checkConstraints)
|
15017
15227
|
}
|
15018
15228
|
];
|
15019
15229
|
if (Object.keys(indexes).length) {
|
@@ -15024,7 +15234,7 @@ var init_statementCombiner = __esm({
|
|
15024
15234
|
libSQLCombineStatements = (statements, json22, action) => {
|
15025
15235
|
const newStatements = {};
|
15026
15236
|
for (const statement of statements) {
|
15027
|
-
if (statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk" || statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk") {
|
15237
|
+
if (statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk" || statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk" || statement.type === "create_check_constraint" || statement.type === "delete_check_constraint") {
|
15028
15238
|
const tableName2 = statement.tableName;
|
15029
15239
|
const statementsForTable2 = newStatements[tableName2];
|
15030
15240
|
if (!statementsForTable2) {
|
@@ -15165,16 +15375,16 @@ var init_statementCombiner = __esm({
|
|
15165
15375
|
sqliteCombineStatements = (statements, json22, action) => {
|
15166
15376
|
const newStatements = {};
|
15167
15377
|
for (const statement of statements) {
|
15168
|
-
if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk" || statement.type === "delete_reference" || statement.type === "alter_reference" || statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk" || statement.type === "create_unique_constraint" || statement.type === "delete_unique_constraint") {
|
15378
|
+
if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk" || statement.type === "delete_reference" || statement.type === "alter_reference" || statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk" || statement.type === "create_unique_constraint" || statement.type === "delete_unique_constraint" || statement.type === "create_check_constraint" || statement.type === "delete_check_constraint") {
|
15169
15379
|
const tableName2 = statement.tableName;
|
15170
15380
|
const statementsForTable2 = newStatements[tableName2];
|
15171
15381
|
if (!statementsForTable2) {
|
15172
|
-
newStatements[tableName2] =
|
15382
|
+
newStatements[tableName2] = prepareSQLiteRecreateTable(json22.tables[tableName2], action);
|
15173
15383
|
continue;
|
15174
15384
|
}
|
15175
15385
|
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15176
15386
|
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15177
|
-
const preparedStatements =
|
15387
|
+
const preparedStatements = prepareSQLiteRecreateTable(json22.tables[tableName2], action);
|
15178
15388
|
if (wasRename) {
|
15179
15389
|
newStatements[tableName2].push(...preparedStatements);
|
15180
15390
|
} else {
|
@@ -15188,12 +15398,12 @@ var init_statementCombiner = __esm({
|
|
15188
15398
|
const tableName2 = statement.tableName;
|
15189
15399
|
const statementsForTable2 = newStatements[tableName2];
|
15190
15400
|
if (!statementsForTable2) {
|
15191
|
-
newStatements[tableName2] =
|
15401
|
+
newStatements[tableName2] = prepareSQLiteRecreateTable(json22.tables[tableName2], action);
|
15192
15402
|
continue;
|
15193
15403
|
}
|
15194
15404
|
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15195
15405
|
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15196
|
-
const preparedStatements =
|
15406
|
+
const preparedStatements = prepareSQLiteRecreateTable(json22.tables[tableName2], action);
|
15197
15407
|
if (wasRename) {
|
15198
15408
|
newStatements[tableName2].push(...preparedStatements);
|
15199
15409
|
} else {
|
@@ -15218,7 +15428,7 @@ var init_statementCombiner = __esm({
|
|
15218
15428
|
}
|
15219
15429
|
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15220
15430
|
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15221
|
-
const preparedStatements =
|
15431
|
+
const preparedStatements = prepareSQLiteRecreateTable(json22.tables[tableName2], action);
|
15222
15432
|
if (wasRename) {
|
15223
15433
|
newStatements[tableName2].push(...preparedStatements);
|
15224
15434
|
} else {
|
@@ -15387,7 +15597,8 @@ var init_snapshotsDiffer = __esm({
|
|
15387
15597
|
indexes: recordType(stringType(), stringType()),
|
15388
15598
|
foreignKeys: recordType(stringType(), stringType()),
|
15389
15599
|
compositePrimaryKeys: recordType(stringType(), stringType()).default({}),
|
15390
|
-
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
15600
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({}),
|
15601
|
+
checkConstraints: recordType(stringType(), stringType()).default({})
|
15391
15602
|
}).strict();
|
15392
15603
|
alteredTableScheme = objectType({
|
15393
15604
|
name: stringType(),
|
@@ -15428,6 +15639,21 @@ var init_snapshotsDiffer = __esm({
|
|
15428
15639
|
__new: stringType(),
|
15429
15640
|
__old: stringType()
|
15430
15641
|
})
|
15642
|
+
),
|
15643
|
+
addedCheckConstraints: recordType(
|
15644
|
+
stringType(),
|
15645
|
+
stringType()
|
15646
|
+
),
|
15647
|
+
deletedCheckConstraints: recordType(
|
15648
|
+
stringType(),
|
15649
|
+
stringType()
|
15650
|
+
),
|
15651
|
+
alteredCheckConstraints: recordType(
|
15652
|
+
stringType(),
|
15653
|
+
objectType({
|
15654
|
+
__new: stringType(),
|
15655
|
+
__old: stringType()
|
15656
|
+
})
|
15431
15657
|
)
|
15432
15658
|
}).strict();
|
15433
15659
|
diffResultScheme = objectType({
|
@@ -15768,6 +15994,8 @@ var init_snapshotsDiffer = __esm({
|
|
15768
15994
|
schemaTo: it.schemaTo || "public"
|
15769
15995
|
});
|
15770
15996
|
}
|
15997
|
+
const jsonDeletedCheckConstraints = [];
|
15998
|
+
const jsonCreatedCheckConstraints = [];
|
15771
15999
|
for (let it of alteredTables) {
|
15772
16000
|
let addedColumns = [];
|
15773
16001
|
for (const addedPkName of Object.keys(it.addedCompositePKs)) {
|
@@ -15807,6 +16035,8 @@ var init_snapshotsDiffer = __esm({
|
|
15807
16035
|
let addedUniqueConstraints = [];
|
15808
16036
|
let deletedUniqueConstraints = [];
|
15809
16037
|
let alteredUniqueConstraints = [];
|
16038
|
+
let createCheckConstraints = [];
|
16039
|
+
let deleteCheckConstraints = [];
|
15810
16040
|
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
15811
16041
|
it.name,
|
15812
16042
|
it.schema,
|
@@ -15831,6 +16061,24 @@ var init_snapshotsDiffer = __esm({
|
|
15831
16061
|
...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
|
15832
16062
|
);
|
15833
16063
|
}
|
16064
|
+
createCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
|
16065
|
+
deleteCheckConstraints = prepareDeleteCheckConstraint(
|
16066
|
+
it.name,
|
16067
|
+
it.schema,
|
16068
|
+
it.deletedCheckConstraints
|
16069
|
+
);
|
16070
|
+
if (it.alteredCheckConstraints && action !== "push") {
|
16071
|
+
const added = {};
|
16072
|
+
const deleted = {};
|
16073
|
+
for (const k of Object.keys(it.alteredCheckConstraints)) {
|
16074
|
+
added[k] = it.alteredCheckConstraints[k].__new;
|
16075
|
+
deleted[k] = it.alteredCheckConstraints[k].__old;
|
16076
|
+
}
|
16077
|
+
createCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
|
16078
|
+
deleteCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
|
16079
|
+
}
|
16080
|
+
jsonCreatedCheckConstraints.push(...createCheckConstraints);
|
16081
|
+
jsonDeletedCheckConstraints.push(...deleteCheckConstraints);
|
15834
16082
|
jsonAddedCompositePKs.push(...addedCompositePKs);
|
15835
16083
|
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
15836
16084
|
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
@@ -15987,6 +16235,7 @@ var init_snapshotsDiffer = __esm({
|
|
15987
16235
|
jsonStatements.push(...jsonRenameTables);
|
15988
16236
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
15989
16237
|
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
16238
|
+
jsonStatements.push(...jsonDeletedCheckConstraints);
|
15990
16239
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
15991
16240
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
15992
16241
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
@@ -16000,6 +16249,7 @@ var init_snapshotsDiffer = __esm({
|
|
16000
16249
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
16001
16250
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
16002
16251
|
jsonStatements.push(...jsonAddedUniqueConstraints);
|
16252
|
+
jsonStatements.push(...jsonCreatedCheckConstraints);
|
16003
16253
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16004
16254
|
jsonStatements.push(...jsonAlterEnumsWithDroppedValues);
|
16005
16255
|
jsonStatements.push(...dropEnums);
|
@@ -16022,7 +16272,17 @@ var init_snapshotsDiffer = __esm({
|
|
16022
16272
|
}
|
16023
16273
|
return true;
|
16024
16274
|
});
|
16025
|
-
const
|
16275
|
+
const filteredEnumsJsonStatements = filteredJsonStatements.filter((st) => {
|
16276
|
+
if (st.type === "alter_type_add_value") {
|
16277
|
+
if (jsonStatements.find(
|
16278
|
+
(it) => it.type === "alter_type_drop_value" && it.name === st.name && it.schema === st.schema
|
16279
|
+
)) {
|
16280
|
+
return false;
|
16281
|
+
}
|
16282
|
+
}
|
16283
|
+
return true;
|
16284
|
+
});
|
16285
|
+
const sqlStatements = fromJson(filteredEnumsJsonStatements, "postgresql");
|
16026
16286
|
const uniqueSqlStatements = [];
|
16027
16287
|
sqlStatements.forEach((ss) => {
|
16028
16288
|
if (!uniqueSqlStatements.includes(ss)) {
|
@@ -16038,7 +16298,7 @@ var init_snapshotsDiffer = __esm({
|
|
16038
16298
|
});
|
16039
16299
|
const _meta = prepareMigrationMeta(rSchemas, rTables, rColumns);
|
16040
16300
|
return {
|
16041
|
-
statements:
|
16301
|
+
statements: filteredEnumsJsonStatements,
|
16042
16302
|
sqlStatements: uniqueSqlStatements,
|
16043
16303
|
_meta
|
16044
16304
|
};
|
@@ -16164,6 +16424,8 @@ var init_snapshotsDiffer = __esm({
|
|
16164
16424
|
const jsonAddedUniqueConstraints = [];
|
16165
16425
|
const jsonDeletedUniqueConstraints = [];
|
16166
16426
|
const jsonAlteredUniqueConstraints = [];
|
16427
|
+
const jsonCreatedCheckConstraints = [];
|
16428
|
+
const jsonDeletedCheckConstraints = [];
|
16167
16429
|
const jsonRenameColumnsStatements = columnRenames.map((it) => prepareRenameColumns(it.table, "", it.renames)).flat();
|
16168
16430
|
const jsonAddColumnsStatemets = columnCreates.map((it) => _prepareAddColumns(it.table, "", it.columns)).flat();
|
16169
16431
|
const jsonDropColumnsStatemets = columnDeletes.map((it) => _prepareDropColumns(it.table, "", it.columns)).flat();
|
@@ -16202,6 +16464,8 @@ var init_snapshotsDiffer = __esm({
|
|
16202
16464
|
let addedUniqueConstraints = [];
|
16203
16465
|
let deletedUniqueConstraints = [];
|
16204
16466
|
let alteredUniqueConstraints = [];
|
16467
|
+
let createdCheckConstraints = [];
|
16468
|
+
let deletedCheckConstraints = [];
|
16205
16469
|
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
16206
16470
|
it.name,
|
16207
16471
|
it.schema,
|
@@ -16226,12 +16490,30 @@ var init_snapshotsDiffer = __esm({
|
|
16226
16490
|
...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
|
16227
16491
|
);
|
16228
16492
|
}
|
16493
|
+
createdCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
|
16494
|
+
deletedCheckConstraints = prepareDeleteCheckConstraint(
|
16495
|
+
it.name,
|
16496
|
+
it.schema,
|
16497
|
+
it.deletedCheckConstraints
|
16498
|
+
);
|
16499
|
+
if (it.alteredCheckConstraints && action !== "push") {
|
16500
|
+
const added = {};
|
16501
|
+
const deleted = {};
|
16502
|
+
for (const k of Object.keys(it.alteredCheckConstraints)) {
|
16503
|
+
added[k] = it.alteredCheckConstraints[k].__new;
|
16504
|
+
deleted[k] = it.alteredCheckConstraints[k].__old;
|
16505
|
+
}
|
16506
|
+
createdCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
|
16507
|
+
deletedCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
|
16508
|
+
}
|
16229
16509
|
jsonAddedCompositePKs.push(...addedCompositePKs);
|
16230
16510
|
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
16231
16511
|
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
16232
16512
|
jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
|
16233
16513
|
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
16234
16514
|
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
16515
|
+
jsonCreatedCheckConstraints.push(...createdCheckConstraints);
|
16516
|
+
jsonDeletedCheckConstraints.push(...deletedCheckConstraints);
|
16235
16517
|
});
|
16236
16518
|
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
16237
16519
|
const tableName = it.tableName;
|
@@ -16327,6 +16609,7 @@ var init_snapshotsDiffer = __esm({
|
|
16327
16609
|
jsonStatements.push(...jsonRenameTables);
|
16328
16610
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
16329
16611
|
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
16612
|
+
jsonStatements.push(...jsonDeletedCheckConstraints);
|
16330
16613
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
16331
16614
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
16332
16615
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
@@ -16337,11 +16620,11 @@ var init_snapshotsDiffer = __esm({
|
|
16337
16620
|
jsonStatements.push(...jsonAddColumnsStatemets);
|
16338
16621
|
jsonStatements.push(...jsonCreateReferencesForCreatedTables);
|
16339
16622
|
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
16623
|
+
jsonStatements.push(...jsonCreatedCheckConstraints);
|
16340
16624
|
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
16341
16625
|
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
16342
16626
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
16343
16627
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
16344
|
-
jsonStatements.push(...jsonAddedUniqueConstraints);
|
16345
16628
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16346
16629
|
const sqlStatements = fromJson(jsonStatements, "mysql");
|
16347
16630
|
const uniqueSqlStatements = [];
|
@@ -16469,6 +16752,8 @@ var init_snapshotsDiffer = __esm({
|
|
16469
16752
|
const jsonAddedUniqueConstraints = [];
|
16470
16753
|
const jsonDeletedUniqueConstraints = [];
|
16471
16754
|
const jsonAlteredUniqueConstraints = [];
|
16755
|
+
const jsonDeletedCheckConstraints = [];
|
16756
|
+
const jsonCreatedCheckConstraints = [];
|
16472
16757
|
allAltered.forEach((it) => {
|
16473
16758
|
let addedColumns = [];
|
16474
16759
|
for (const addedPkName of Object.keys(it.addedCompositePKs)) {
|
@@ -16525,12 +16810,56 @@ var init_snapshotsDiffer = __esm({
|
|
16525
16810
|
...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
|
16526
16811
|
);
|
16527
16812
|
}
|
16813
|
+
let createdCheckConstraints = [];
|
16814
|
+
let deletedCheckConstraints = [];
|
16815
|
+
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
16816
|
+
it.name,
|
16817
|
+
it.schema,
|
16818
|
+
it.addedUniqueConstraints
|
16819
|
+
);
|
16820
|
+
deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
|
16821
|
+
it.name,
|
16822
|
+
it.schema,
|
16823
|
+
it.deletedUniqueConstraints
|
16824
|
+
);
|
16825
|
+
if (it.alteredUniqueConstraints) {
|
16826
|
+
const added = {};
|
16827
|
+
const deleted = {};
|
16828
|
+
for (const k of Object.keys(it.alteredUniqueConstraints)) {
|
16829
|
+
added[k] = it.alteredUniqueConstraints[k].__new;
|
16830
|
+
deleted[k] = it.alteredUniqueConstraints[k].__old;
|
16831
|
+
}
|
16832
|
+
addedUniqueConstraints.push(
|
16833
|
+
...prepareAddUniqueConstraintPg(it.name, it.schema, added)
|
16834
|
+
);
|
16835
|
+
deletedUniqueConstraints.push(
|
16836
|
+
...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
|
16837
|
+
);
|
16838
|
+
}
|
16839
|
+
createdCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
|
16840
|
+
deletedCheckConstraints = prepareDeleteCheckConstraint(
|
16841
|
+
it.name,
|
16842
|
+
it.schema,
|
16843
|
+
it.deletedCheckConstraints
|
16844
|
+
);
|
16845
|
+
if (it.alteredCheckConstraints && action !== "push") {
|
16846
|
+
const added = {};
|
16847
|
+
const deleted = {};
|
16848
|
+
for (const k of Object.keys(it.alteredCheckConstraints)) {
|
16849
|
+
added[k] = it.alteredCheckConstraints[k].__new;
|
16850
|
+
deleted[k] = it.alteredCheckConstraints[k].__old;
|
16851
|
+
}
|
16852
|
+
createdCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
|
16853
|
+
deletedCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
|
16854
|
+
}
|
16528
16855
|
jsonAddedCompositePKs.push(...addedCompositePKs);
|
16529
16856
|
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
16530
16857
|
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
16531
16858
|
jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
|
16532
16859
|
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
16533
16860
|
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
16861
|
+
jsonCreatedCheckConstraints.push(...createdCheckConstraints);
|
16862
|
+
jsonDeletedCheckConstraints.push(...deletedCheckConstraints);
|
16534
16863
|
});
|
16535
16864
|
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
16536
16865
|
const tableName = it.tableName;
|
@@ -16615,6 +16944,7 @@ var init_snapshotsDiffer = __esm({
|
|
16615
16944
|
jsonStatements.push(...jsonRenameTables);
|
16616
16945
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
16617
16946
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
16947
|
+
jsonStatements.push(...jsonDeletedCheckConstraints);
|
16618
16948
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
16619
16949
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
16620
16950
|
jsonStatements.push(...jsonTableAlternations);
|
@@ -16622,6 +16952,7 @@ var init_snapshotsDiffer = __esm({
|
|
16622
16952
|
jsonStatements.push(...jsonAddColumnsStatemets);
|
16623
16953
|
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
16624
16954
|
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
16955
|
+
jsonStatements.push(...jsonCreatedCheckConstraints);
|
16625
16956
|
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
16626
16957
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
16627
16958
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
@@ -16765,6 +17096,8 @@ var init_snapshotsDiffer = __esm({
|
|
16765
17096
|
const jsonAddedUniqueConstraints = [];
|
16766
17097
|
const jsonDeletedUniqueConstraints = [];
|
16767
17098
|
const jsonAlteredUniqueConstraints = [];
|
17099
|
+
const jsonDeletedCheckConstraints = [];
|
17100
|
+
const jsonCreatedCheckConstraints = [];
|
16768
17101
|
allAltered.forEach((it) => {
|
16769
17102
|
let addedColumns = [];
|
16770
17103
|
for (const addedPkName of Object.keys(it.addedCompositePKs)) {
|
@@ -16797,6 +17130,8 @@ var init_snapshotsDiffer = __esm({
|
|
16797
17130
|
let addedUniqueConstraints = [];
|
16798
17131
|
let deletedUniqueConstraints = [];
|
16799
17132
|
let alteredUniqueConstraints = [];
|
17133
|
+
let createdCheckConstraints = [];
|
17134
|
+
let deletedCheckConstraints = [];
|
16800
17135
|
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
16801
17136
|
it.name,
|
16802
17137
|
it.schema,
|
@@ -16821,12 +17156,30 @@ var init_snapshotsDiffer = __esm({
|
|
16821
17156
|
...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
|
16822
17157
|
);
|
16823
17158
|
}
|
17159
|
+
createdCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
|
17160
|
+
deletedCheckConstraints = prepareDeleteCheckConstraint(
|
17161
|
+
it.name,
|
17162
|
+
it.schema,
|
17163
|
+
it.deletedCheckConstraints
|
17164
|
+
);
|
17165
|
+
if (it.alteredCheckConstraints && action !== "push") {
|
17166
|
+
const added = {};
|
17167
|
+
const deleted = {};
|
17168
|
+
for (const k of Object.keys(it.alteredCheckConstraints)) {
|
17169
|
+
added[k] = it.alteredCheckConstraints[k].__new;
|
17170
|
+
deleted[k] = it.alteredCheckConstraints[k].__old;
|
17171
|
+
}
|
17172
|
+
createdCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
|
17173
|
+
deletedCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
|
17174
|
+
}
|
16824
17175
|
jsonAddedCompositePKs.push(...addedCompositePKs);
|
16825
17176
|
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
16826
17177
|
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
16827
17178
|
jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
|
16828
17179
|
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
16829
17180
|
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
17181
|
+
jsonCreatedCheckConstraints.push(...createdCheckConstraints);
|
17182
|
+
jsonDeletedCheckConstraints.push(...deletedCheckConstraints);
|
16830
17183
|
});
|
16831
17184
|
const jsonTableAlternations = allAltered.map((it) => {
|
16832
17185
|
return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json22);
|
@@ -16904,6 +17257,7 @@ var init_snapshotsDiffer = __esm({
|
|
16904
17257
|
jsonStatements.push(...jsonRenameTables);
|
16905
17258
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
16906
17259
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
17260
|
+
jsonStatements.push(...jsonDeletedCheckConstraints);
|
16907
17261
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
16908
17262
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
16909
17263
|
jsonStatements.push(...jsonTableAlternations);
|
@@ -16911,6 +17265,7 @@ var init_snapshotsDiffer = __esm({
|
|
16911
17265
|
jsonStatements.push(...jsonAddColumnsStatemets);
|
16912
17266
|
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
16913
17267
|
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
17268
|
+
jsonStatements.push(...jsonCreatedCheckConstraints);
|
16914
17269
|
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
16915
17270
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
16916
17271
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
@@ -26028,6 +26383,7 @@ var init_pgSerializer = __esm({
|
|
26028
26383
|
const sequencesToReturn = {};
|
26029
26384
|
const indexesInSchema = {};
|
26030
26385
|
for (const table4 of tables) {
|
26386
|
+
const checksInTable = {};
|
26031
26387
|
const {
|
26032
26388
|
name: tableName,
|
26033
26389
|
columns,
|
@@ -26043,6 +26399,7 @@ var init_pgSerializer = __esm({
|
|
26043
26399
|
}
|
26044
26400
|
const columnsObject = {};
|
26045
26401
|
const indexesObject = {};
|
26402
|
+
const checksObject = {};
|
26046
26403
|
const foreignKeysObject = {};
|
26047
26404
|
const primaryKeysObject = {};
|
26048
26405
|
const uniqueConstraintObject = {};
|
@@ -26308,6 +26665,33 @@ ${withStyle.errorWarning(
|
|
26308
26665
|
with: value.config.with ?? {}
|
26309
26666
|
};
|
26310
26667
|
});
|
26668
|
+
checks.forEach((check) => {
|
26669
|
+
const checkName = check.name;
|
26670
|
+
if (typeof checksInTable[`"${schema4 ?? "public"}"."${tableName}"`] !== "undefined") {
|
26671
|
+
if (checksInTable[`"${schema4 ?? "public"}"."${tableName}"`].includes(check.name)) {
|
26672
|
+
console.log(
|
26673
|
+
`
|
26674
|
+
${withStyle.errorWarning(
|
26675
|
+
`We've found duplicated check constraint name across ${source_default.underline.blue(
|
26676
|
+
schema4 ?? "public"
|
26677
|
+
)} schema in ${source_default.underline.blue(
|
26678
|
+
tableName
|
26679
|
+
)}. Please rename your check constraint in either the ${source_default.underline.blue(
|
26680
|
+
tableName
|
26681
|
+
)} table or the table with the duplicated check contraint name`
|
26682
|
+
)}`
|
26683
|
+
);
|
26684
|
+
process.exit(1);
|
26685
|
+
}
|
26686
|
+
checksInTable[`"${schema4 ?? "public"}"."${tableName}"`].push(checkName);
|
26687
|
+
} else {
|
26688
|
+
checksInTable[`"${schema4 ?? "public"}"."${tableName}"`] = [check.name];
|
26689
|
+
}
|
26690
|
+
checksObject[checkName] = {
|
26691
|
+
name: checkName,
|
26692
|
+
value: dialect4.sqlToQuery(check.value).sql
|
26693
|
+
};
|
26694
|
+
});
|
26311
26695
|
const tableKey2 = `${schema4 ?? "public"}.${tableName}`;
|
26312
26696
|
result[tableKey2] = {
|
26313
26697
|
name: tableName,
|
@@ -26316,7 +26700,8 @@ ${withStyle.errorWarning(
|
|
26316
26700
|
indexes: indexesObject,
|
26317
26701
|
foreignKeys: foreignKeysObject,
|
26318
26702
|
compositePrimaryKeys: primaryKeysObject,
|
26319
|
-
uniqueConstraints: uniqueConstraintObject
|
26703
|
+
uniqueConstraints: uniqueConstraintObject,
|
26704
|
+
checkConstraints: checksObject
|
26320
26705
|
};
|
26321
26706
|
}
|
26322
26707
|
for (const sequence of sequences) {
|
@@ -26405,6 +26790,7 @@ ${withStyle.errorWarning(
|
|
26405
26790
|
let indexesCount = 0;
|
26406
26791
|
let foreignKeysCount = 0;
|
26407
26792
|
let tableCount = 0;
|
26793
|
+
let checksCount = 0;
|
26408
26794
|
const sequencesToReturn = {};
|
26409
26795
|
const seqWhere = schemaFilters.map((t) => `schemaname = '${t}'`).join(" or ");
|
26410
26796
|
const allSequences = await db.query(
|
@@ -26474,7 +26860,8 @@ ${withStyle.errorWarning(
|
|
26474
26860
|
const indexToReturn = {};
|
26475
26861
|
const foreignKeysToReturn = {};
|
26476
26862
|
const primaryKeys = {};
|
26477
|
-
const
|
26863
|
+
const uniqueConstraints = {};
|
26864
|
+
const checkConstraints = {};
|
26478
26865
|
const tableResponse = await db.query(
|
26479
26866
|
`SELECT a.attrelid::regclass::text, a.attname, is_nullable, a.attndims as array_dimensions
|
26480
26867
|
, CASE WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[])
|
@@ -26512,55 +26899,97 @@ ${withStyle.errorWarning(
|
|
26512
26899
|
ORDER BY a.attnum;`
|
26513
26900
|
);
|
26514
26901
|
const tableConstraints = await db.query(
|
26515
|
-
`SELECT c.column_name,
|
26516
|
-
|
26517
|
-
|
26518
|
-
|
26519
|
-
|
26520
|
-
|
26902
|
+
`SELECT c.column_name,
|
26903
|
+
c.data_type,
|
26904
|
+
tc.constraint_type,
|
26905
|
+
tc.constraint_name,
|
26906
|
+
tc.constraint_schema,
|
26907
|
+
pg_get_constraintdef(con.oid) AS check_constraint_definition
|
26908
|
+
FROM information_schema.table_constraints tc
|
26909
|
+
JOIN information_schema.constraint_column_usage AS ccu
|
26910
|
+
USING (constraint_schema, constraint_name)
|
26911
|
+
JOIN information_schema.columns AS c
|
26912
|
+
ON c.table_schema = tc.constraint_schema
|
26913
|
+
AND tc.table_name = c.table_name
|
26914
|
+
AND ccu.column_name = c.column_name
|
26915
|
+
JOIN pg_constraint con
|
26916
|
+
ON con.conname = tc.constraint_name
|
26917
|
+
AND con.conrelid = (
|
26918
|
+
SELECT oid
|
26919
|
+
FROM pg_class
|
26920
|
+
WHERE relname = tc.table_name
|
26921
|
+
AND relnamespace = (
|
26922
|
+
SELECT oid
|
26923
|
+
FROM pg_namespace
|
26924
|
+
WHERE nspname = tc.constraint_schema
|
26925
|
+
)
|
26926
|
+
)
|
26927
|
+
WHERE tc.table_name = '${tableName}' AND tc.constraint_schema = '${tableSchema}';`
|
26521
26928
|
);
|
26929
|
+
const tableChecks = await db.query(`SELECT
|
26930
|
+
tc.constraint_name,
|
26931
|
+
tc.constraint_type,
|
26932
|
+
pg_get_constraintdef(con.oid) AS constraint_definition
|
26933
|
+
FROM
|
26934
|
+
information_schema.table_constraints AS tc
|
26935
|
+
JOIN pg_constraint AS con
|
26936
|
+
ON tc.constraint_name = con.conname
|
26937
|
+
AND con.conrelid = (
|
26938
|
+
SELECT oid
|
26939
|
+
FROM pg_class
|
26940
|
+
WHERE relname = tc.table_name
|
26941
|
+
AND relnamespace = (
|
26942
|
+
SELECT oid
|
26943
|
+
FROM pg_namespace
|
26944
|
+
WHERE nspname = tc.constraint_schema
|
26945
|
+
)
|
26946
|
+
)
|
26947
|
+
WHERE
|
26948
|
+
tc.table_name = '${tableName}'
|
26949
|
+
AND tc.constraint_schema = '${tableSchema}'
|
26950
|
+
AND tc.constraint_type = 'CHECK';`);
|
26522
26951
|
columnsCount += tableResponse.length;
|
26523
26952
|
if (progressCallback) {
|
26524
26953
|
progressCallback("columns", columnsCount, "fetching");
|
26525
26954
|
}
|
26526
26955
|
const tableForeignKeys = await db.query(
|
26527
26956
|
`SELECT
|
26528
|
-
|
26529
|
-
|
26530
|
-
|
26531
|
-
|
26532
|
-
|
26533
|
-
|
26534
|
-
|
26535
|
-
|
26536
|
-
|
26537
|
-
|
26538
|
-
|
26539
|
-
|
26540
|
-
|
26541
|
-
|
26542
|
-
|
26543
|
-
|
26544
|
-
|
26545
|
-
|
26546
|
-
|
26547
|
-
|
26548
|
-
|
26549
|
-
|
26550
|
-
|
26551
|
-
|
26552
|
-
|
26553
|
-
|
26554
|
-
|
26555
|
-
|
26556
|
-
|
26557
|
-
|
26558
|
-
|
26559
|
-
|
26560
|
-
|
26561
|
-
|
26562
|
-
|
26563
|
-
|
26957
|
+
con.contype AS constraint_type,
|
26958
|
+
nsp.nspname AS constraint_schema,
|
26959
|
+
con.conname AS constraint_name,
|
26960
|
+
rel.relname AS table_name,
|
26961
|
+
att.attname AS column_name,
|
26962
|
+
fnsp.nspname AS foreign_table_schema,
|
26963
|
+
frel.relname AS foreign_table_name,
|
26964
|
+
fatt.attname AS foreign_column_name,
|
26965
|
+
CASE con.confupdtype
|
26966
|
+
WHEN 'a' THEN 'NO ACTION'
|
26967
|
+
WHEN 'r' THEN 'RESTRICT'
|
26968
|
+
WHEN 'n' THEN 'SET NULL'
|
26969
|
+
WHEN 'c' THEN 'CASCADE'
|
26970
|
+
WHEN 'd' THEN 'SET DEFAULT'
|
26971
|
+
END AS update_rule,
|
26972
|
+
CASE con.confdeltype
|
26973
|
+
WHEN 'a' THEN 'NO ACTION'
|
26974
|
+
WHEN 'r' THEN 'RESTRICT'
|
26975
|
+
WHEN 'n' THEN 'SET NULL'
|
26976
|
+
WHEN 'c' THEN 'CASCADE'
|
26977
|
+
WHEN 'd' THEN 'SET DEFAULT'
|
26978
|
+
END AS delete_rule
|
26979
|
+
FROM
|
26980
|
+
pg_catalog.pg_constraint con
|
26981
|
+
JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
|
26982
|
+
JOIN pg_catalog.pg_namespace nsp ON nsp.oid = con.connamespace
|
26983
|
+
LEFT JOIN pg_catalog.pg_attribute att ON att.attnum = ANY (con.conkey)
|
26984
|
+
AND att.attrelid = con.conrelid
|
26985
|
+
LEFT JOIN pg_catalog.pg_class frel ON frel.oid = con.confrelid
|
26986
|
+
LEFT JOIN pg_catalog.pg_namespace fnsp ON fnsp.oid = frel.relnamespace
|
26987
|
+
LEFT JOIN pg_catalog.pg_attribute fatt ON fatt.attnum = ANY (con.confkey)
|
26988
|
+
AND fatt.attrelid = con.confrelid
|
26989
|
+
WHERE
|
26990
|
+
nsp.nspname = '${tableSchema}'
|
26991
|
+
AND rel.relname = '${tableName}'
|
26992
|
+
AND con.contype IN ('f');`
|
26564
26993
|
);
|
26565
26994
|
foreignKeysCount += tableForeignKeys.length;
|
26566
26995
|
if (progressCallback) {
|
@@ -26602,16 +27031,29 @@ ${withStyle.errorWarning(
|
|
26602
27031
|
for (const unqs of uniqueConstrainsRows) {
|
26603
27032
|
const columnName = unqs.column_name;
|
26604
27033
|
const constraintName = unqs.constraint_name;
|
26605
|
-
if (typeof
|
26606
|
-
|
27034
|
+
if (typeof uniqueConstraints[constraintName] !== "undefined") {
|
27035
|
+
uniqueConstraints[constraintName].columns.push(columnName);
|
26607
27036
|
} else {
|
26608
|
-
|
27037
|
+
uniqueConstraints[constraintName] = {
|
26609
27038
|
columns: [columnName],
|
26610
27039
|
nullsNotDistinct: false,
|
26611
27040
|
name: constraintName
|
26612
27041
|
};
|
26613
27042
|
}
|
26614
27043
|
}
|
27044
|
+
checksCount += tableChecks.length;
|
27045
|
+
if (progressCallback) {
|
27046
|
+
progressCallback("checks", checksCount, "fetching");
|
27047
|
+
}
|
27048
|
+
for (const checks of tableChecks) {
|
27049
|
+
let checkValue = checks.constraint_definition;
|
27050
|
+
const constraintName = checks.constraint_name;
|
27051
|
+
checkValue = checkValue.replace(/^CHECK\s*\(\(/, "").replace(/\)\)\s*$/, "");
|
27052
|
+
checkConstraints[constraintName] = {
|
27053
|
+
name: constraintName,
|
27054
|
+
value: checkValue
|
27055
|
+
};
|
27056
|
+
}
|
26615
27057
|
for (const columnResponse of tableResponse) {
|
26616
27058
|
const columnName = columnResponse.attname;
|
26617
27059
|
const columnAdditionalDT = columnResponse.additional_dt;
|
@@ -26855,7 +27297,8 @@ ${withStyle.errorWarning(
|
|
26855
27297
|
indexes: indexToReturn,
|
26856
27298
|
foreignKeys: foreignKeysToReturn,
|
26857
27299
|
compositePrimaryKeys: primaryKeys,
|
26858
|
-
uniqueConstraints
|
27300
|
+
uniqueConstraints,
|
27301
|
+
checkConstraints
|
26859
27302
|
};
|
26860
27303
|
} catch (e) {
|
26861
27304
|
rej(e);
|
@@ -26873,6 +27316,7 @@ ${withStyle.errorWarning(
|
|
26873
27316
|
progressCallback("columns", columnsCount, "done");
|
26874
27317
|
progressCallback("indexes", indexesCount, "done");
|
26875
27318
|
progressCallback("fks", foreignKeysCount, "done");
|
27319
|
+
progressCallback("checks", checksCount, "done");
|
26876
27320
|
}
|
26877
27321
|
const schemasObject = Object.fromEntries([...schemas].map((it) => [it, it]));
|
26878
27322
|
return {
|
@@ -26944,6 +27388,8 @@ ${withStyle.errorWarning(
|
|
26944
27388
|
}
|
26945
27389
|
return columnDefaultAsString;
|
26946
27390
|
}
|
27391
|
+
} else if (column4.data_type.includes("numeric")) {
|
27392
|
+
return columnDefaultAsString.includes("'") ? columnDefaultAsString : `'${columnDefaultAsString}'`;
|
26947
27393
|
} else if (column4.data_type === "json" || column4.data_type === "jsonb") {
|
26948
27394
|
const jsonWithoutSpaces = JSON.stringify(JSON.parse(columnDefaultAsString.slice(1, -1)));
|
26949
27395
|
return `'${jsonWithoutSpaces}'::${column4.data_type}`;
|
@@ -30470,10 +30916,13 @@ var init_sqliteSerializer = __esm({
|
|
30470
30916
|
const foreignKeysObject = {};
|
30471
30917
|
const primaryKeysObject = {};
|
30472
30918
|
const uniqueConstraintObject = {};
|
30919
|
+
const checkConstraintObject = {};
|
30920
|
+
const checksInTable = {};
|
30473
30921
|
const {
|
30474
30922
|
name: tableName,
|
30475
30923
|
columns,
|
30476
30924
|
indexes,
|
30925
|
+
checks,
|
30477
30926
|
foreignKeys: tableForeignKeys,
|
30478
30927
|
primaryKeys,
|
30479
30928
|
uniqueConstraints
|
@@ -30649,13 +31098,39 @@ The unique constraint ${source_default.underline.blue(
|
|
30649
31098
|
columnsObject[getColumnCasing(it.columns[0], casing2)].primaryKey = true;
|
30650
31099
|
}
|
30651
31100
|
});
|
31101
|
+
checks.forEach((check) => {
|
31102
|
+
const checkName = check.name;
|
31103
|
+
if (typeof checksInTable[tableName] !== "undefined") {
|
31104
|
+
if (checksInTable[tableName].includes(check.name)) {
|
31105
|
+
console.log(
|
31106
|
+
`
|
31107
|
+
${withStyle.errorWarning(
|
31108
|
+
`We've found duplicated check constraint name in ${source_default.underline.blue(
|
31109
|
+
tableName
|
31110
|
+
)}. Please rename your check constraint in the ${source_default.underline.blue(
|
31111
|
+
tableName
|
31112
|
+
)} table`
|
31113
|
+
)}`
|
31114
|
+
);
|
31115
|
+
process.exit(1);
|
31116
|
+
}
|
31117
|
+
checksInTable[tableName].push(checkName);
|
31118
|
+
} else {
|
31119
|
+
checksInTable[tableName] = [check.name];
|
31120
|
+
}
|
31121
|
+
checkConstraintObject[checkName] = {
|
31122
|
+
name: checkName,
|
31123
|
+
value: dialect4.sqlToQuery(check.value).sql
|
31124
|
+
};
|
31125
|
+
});
|
30652
31126
|
result[tableName] = {
|
30653
31127
|
name: tableName,
|
30654
31128
|
columns: columnsObject,
|
30655
31129
|
indexes: indexesObject,
|
30656
31130
|
foreignKeys: foreignKeysObject,
|
30657
31131
|
compositePrimaryKeys: primaryKeysObject,
|
30658
|
-
uniqueConstraints: uniqueConstraintObject
|
31132
|
+
uniqueConstraints: uniqueConstraintObject,
|
31133
|
+
checkConstraints: checkConstraintObject
|
30659
31134
|
};
|
30660
31135
|
}
|
30661
31136
|
return {
|
@@ -30702,6 +31177,7 @@ The unique constraint ${source_default.underline.blue(
|
|
30702
31177
|
let tablesCount = /* @__PURE__ */ new Set();
|
30703
31178
|
let indexesCount = 0;
|
30704
31179
|
let foreignKeysCount = 0;
|
31180
|
+
let checksCount = 0;
|
30705
31181
|
const tableToPk = {};
|
30706
31182
|
let tableToGeneratedColumnsInfo = {};
|
30707
31183
|
for (const column4 of columns) {
|
@@ -30759,7 +31235,8 @@ The unique constraint ${source_default.underline.blue(
|
|
30759
31235
|
compositePrimaryKeys: {},
|
30760
31236
|
indexes: {},
|
30761
31237
|
foreignKeys: {},
|
30762
|
-
uniqueConstraints: {}
|
31238
|
+
uniqueConstraints: {},
|
31239
|
+
checkConstraints: {}
|
30763
31240
|
};
|
30764
31241
|
} else {
|
30765
31242
|
result[tableName].columns[columnName] = newColumn;
|
@@ -30873,6 +31350,56 @@ WHERE
|
|
30873
31350
|
progressCallback("indexes", indexesCount, "done");
|
30874
31351
|
progressCallback("enums", 0, "done");
|
30875
31352
|
}
|
31353
|
+
const namedCheckPattern = /CONSTRAINT\s*["']?(\w+)["']?\s*CHECK\s*\((.*?)\)/gi;
|
31354
|
+
const unnamedCheckPattern = /CHECK\s*\((.*?)\)/gi;
|
31355
|
+
let checkCounter = 0;
|
31356
|
+
const checkConstraints = {};
|
31357
|
+
const checks = await db.query(`SELECT name as "tableName", sql as "sql"
|
31358
|
+
FROM sqlite_master
|
31359
|
+
WHERE type = 'table' AND name != 'sqlite_sequence';`);
|
31360
|
+
for (const check of checks) {
|
31361
|
+
if (!tablesFilter(check.tableName)) continue;
|
31362
|
+
const { tableName, sql: sql2 } = check;
|
31363
|
+
let namedChecks = [...sql2.matchAll(namedCheckPattern)];
|
31364
|
+
if (namedChecks.length > 0) {
|
31365
|
+
namedChecks.forEach(([_2, checkName, checkValue]) => {
|
31366
|
+
checkConstraints[checkName] = {
|
31367
|
+
name: checkName,
|
31368
|
+
value: checkValue.trim()
|
31369
|
+
};
|
31370
|
+
});
|
31371
|
+
} else {
|
31372
|
+
let unnamedChecks = [...sql2.matchAll(unnamedCheckPattern)];
|
31373
|
+
unnamedChecks.forEach(([_2, checkValue]) => {
|
31374
|
+
let checkName = `${tableName}_check_${++checkCounter}`;
|
31375
|
+
checkConstraints[checkName] = {
|
31376
|
+
name: checkName,
|
31377
|
+
value: checkValue.trim()
|
31378
|
+
};
|
31379
|
+
});
|
31380
|
+
}
|
31381
|
+
checksCount += Object.values(checkConstraints).length;
|
31382
|
+
if (progressCallback) {
|
31383
|
+
progressCallback("checks", checksCount, "fetching");
|
31384
|
+
}
|
31385
|
+
const table4 = result[tableName];
|
31386
|
+
if (!table4) {
|
31387
|
+
result[tableName] = {
|
31388
|
+
name: tableName,
|
31389
|
+
columns: {},
|
31390
|
+
compositePrimaryKeys: {},
|
31391
|
+
indexes: {},
|
31392
|
+
foreignKeys: {},
|
31393
|
+
uniqueConstraints: {},
|
31394
|
+
checkConstraints
|
31395
|
+
};
|
31396
|
+
} else {
|
31397
|
+
result[tableName].checkConstraints = checkConstraints;
|
31398
|
+
}
|
31399
|
+
}
|
31400
|
+
if (progressCallback) {
|
31401
|
+
progressCallback("checks", checksCount, "done");
|
31402
|
+
}
|
30876
31403
|
return {
|
30877
31404
|
version: "6",
|
30878
31405
|
dialect: "sqlite",
|
@@ -35168,6 +35695,7 @@ var init_mysqlSerializer = __esm({
|
|
35168
35695
|
indexes,
|
35169
35696
|
foreignKeys,
|
35170
35697
|
schema: schema4,
|
35698
|
+
checks,
|
35171
35699
|
primaryKeys,
|
35172
35700
|
uniqueConstraints
|
35173
35701
|
} = getTableConfig3(table4);
|
@@ -35176,6 +35704,8 @@ var init_mysqlSerializer = __esm({
|
|
35176
35704
|
const foreignKeysObject = {};
|
35177
35705
|
const primaryKeysObject = {};
|
35178
35706
|
const uniqueConstraintObject = {};
|
35707
|
+
const checkConstraintObject = {};
|
35708
|
+
let checksInTable = {};
|
35179
35709
|
columns.forEach((column4) => {
|
35180
35710
|
const name2 = getColumnCasing(column4, casing2);
|
35181
35711
|
const notNull = column4.notNull;
|
@@ -35406,6 +35936,32 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
35406
35936
|
lock: value.config.lock
|
35407
35937
|
};
|
35408
35938
|
});
|
35939
|
+
checks.forEach((check) => {
|
35940
|
+
check;
|
35941
|
+
const checkName = check.name;
|
35942
|
+
if (typeof checksInTable[tableName] !== "undefined") {
|
35943
|
+
if (checksInTable[tableName].includes(check.name)) {
|
35944
|
+
console.log(
|
35945
|
+
`
|
35946
|
+
${withStyle.errorWarning(
|
35947
|
+
`We've found duplicated check constraint name in ${source_default.underline.blue(
|
35948
|
+
tableName
|
35949
|
+
)}. Please rename your check constraint in the ${source_default.underline.blue(
|
35950
|
+
tableName
|
35951
|
+
)} table`
|
35952
|
+
)}`
|
35953
|
+
);
|
35954
|
+
process.exit(1);
|
35955
|
+
}
|
35956
|
+
checksInTable[tableName].push(checkName);
|
35957
|
+
} else {
|
35958
|
+
checksInTable[tableName] = [check.name];
|
35959
|
+
}
|
35960
|
+
checkConstraintObject[checkName] = {
|
35961
|
+
name: checkName,
|
35962
|
+
value: dialect4.sqlToQuery(check.value).sql
|
35963
|
+
};
|
35964
|
+
});
|
35409
35965
|
if (!schema4) {
|
35410
35966
|
result[tableName] = {
|
35411
35967
|
name: tableName,
|
@@ -35413,7 +35969,8 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
35413
35969
|
indexes: indexesObject,
|
35414
35970
|
foreignKeys: foreignKeysObject,
|
35415
35971
|
compositePrimaryKeys: primaryKeysObject,
|
35416
|
-
uniqueConstraints: uniqueConstraintObject
|
35972
|
+
uniqueConstraints: uniqueConstraintObject,
|
35973
|
+
checkConstraint: checkConstraintObject
|
35417
35974
|
};
|
35418
35975
|
}
|
35419
35976
|
}
|
@@ -35440,6 +35997,7 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
35440
35997
|
let tablesCount = /* @__PURE__ */ new Set();
|
35441
35998
|
let indexesCount = 0;
|
35442
35999
|
let foreignKeysCount = 0;
|
36000
|
+
let checksCount = 0;
|
35443
36001
|
const idxs = await db.query(
|
35444
36002
|
`select * from INFORMATION_SCHEMA.STATISTICS
|
35445
36003
|
WHERE INFORMATION_SCHEMA.STATISTICS.TABLE_SCHEMA = '${inputSchema}' and INFORMATION_SCHEMA.STATISTICS.INDEX_NAME != 'PRIMARY';`
|
@@ -35534,7 +36092,8 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
35534
36092
|
compositePrimaryKeys: {},
|
35535
36093
|
indexes: {},
|
35536
36094
|
foreignKeys: {},
|
35537
|
-
uniqueConstraints: {}
|
36095
|
+
uniqueConstraints: {},
|
36096
|
+
checkConstraint: {}
|
35538
36097
|
};
|
35539
36098
|
} else {
|
35540
36099
|
result[tableName].columns[columnName] = newColumn;
|
@@ -35683,6 +36242,38 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
35683
36242
|
progressCallback("indexes", indexesCount, "done");
|
35684
36243
|
progressCallback("enums", 0, "done");
|
35685
36244
|
}
|
36245
|
+
const checkConstraints = await db.query(
|
36246
|
+
`SELECT
|
36247
|
+
tc.table_name,
|
36248
|
+
tc.constraint_name,
|
36249
|
+
cc.check_clause
|
36250
|
+
FROM
|
36251
|
+
information_schema.table_constraints tc
|
36252
|
+
JOIN
|
36253
|
+
information_schema.check_constraints cc
|
36254
|
+
ON tc.constraint_name = cc.constraint_name
|
36255
|
+
WHERE
|
36256
|
+
tc.constraint_schema = '${inputSchema}'
|
36257
|
+
AND
|
36258
|
+
tc.constraint_type = 'CHECK';`
|
36259
|
+
);
|
36260
|
+
checksCount += checkConstraints.length;
|
36261
|
+
if (progressCallback) {
|
36262
|
+
progressCallback("checks", checksCount, "fetching");
|
36263
|
+
}
|
36264
|
+
for (const checkConstraintRow of checkConstraints) {
|
36265
|
+
const constraintName = checkConstraintRow["CONSTRAINT_NAME"];
|
36266
|
+
const constraintValue = checkConstraintRow["CHECK_CLAUSE"];
|
36267
|
+
const tableName = checkConstraintRow["TABLE_NAME"];
|
36268
|
+
const tableInResult = result[tableName];
|
36269
|
+
tableInResult.checkConstraint[constraintName] = {
|
36270
|
+
name: constraintName,
|
36271
|
+
value: constraintValue
|
36272
|
+
};
|
36273
|
+
}
|
36274
|
+
if (progressCallback) {
|
36275
|
+
progressCallback("checks", checksCount, "done");
|
36276
|
+
}
|
35686
36277
|
return {
|
35687
36278
|
version: "5",
|
35688
36279
|
dialect: "mysql",
|