drizzle-kit 0.25.0-22c3e40 → 0.25.0-503ee01
Sign up to get free protection for your applications and to get access to all the features.
- package/api.d.mts +801 -0
- package/api.d.ts +801 -0
- package/api.js +2504 -385
- package/api.mjs +2504 -385
- package/bin.cjs +2613 -432
- package/package.json +1 -1
- package/utils.js +105 -18
- package/utils.mjs +105 -18
package/api.mjs
CHANGED
@@ -567,7 +567,7 @@ function is(value, type) {
|
|
567
567
|
`Class "${type.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`
|
568
568
|
);
|
569
569
|
}
|
570
|
-
let cls = value.constructor;
|
570
|
+
let cls = Object.getPrototypeOf(value).constructor;
|
571
571
|
if (cls) {
|
572
572
|
while (cls) {
|
573
573
|
if (entityKind in cls && cls[entityKind] === type[entityKind]) {
|
@@ -3415,8 +3415,8 @@ var require_hanji = __commonJS({
|
|
3415
3415
|
};
|
3416
3416
|
exports.deferred = deferred;
|
3417
3417
|
var Terminal = class {
|
3418
|
-
constructor(
|
3419
|
-
this.view =
|
3418
|
+
constructor(view4, stdin, stdout, closable) {
|
3419
|
+
this.view = view4;
|
3420
3420
|
this.stdin = stdin;
|
3421
3421
|
this.stdout = stdout;
|
3422
3422
|
this.closable = closable;
|
@@ -3454,7 +3454,7 @@ var require_hanji = __commonJS({
|
|
3454
3454
|
this.resolve({ status: "submitted", data: this.view.result() });
|
3455
3455
|
return;
|
3456
3456
|
}
|
3457
|
-
|
3457
|
+
view4.input(str, key);
|
3458
3458
|
};
|
3459
3459
|
this.stdin.on("keypress", keypress);
|
3460
3460
|
this.view.attach(this);
|
@@ -3516,8 +3516,8 @@ var require_hanji = __commonJS({
|
|
3516
3516
|
};
|
3517
3517
|
exports.TaskView = TaskView2;
|
3518
3518
|
var TaskTerminal = class {
|
3519
|
-
constructor(
|
3520
|
-
this.view =
|
3519
|
+
constructor(view4, stdout) {
|
3520
|
+
this.view = view4;
|
3521
3521
|
this.stdout = stdout;
|
3522
3522
|
this.text = "";
|
3523
3523
|
this.view.attach(this);
|
@@ -3536,22 +3536,22 @@ var require_hanji = __commonJS({
|
|
3536
3536
|
}
|
3537
3537
|
};
|
3538
3538
|
exports.TaskTerminal = TaskTerminal;
|
3539
|
-
function render6(
|
3539
|
+
function render6(view4) {
|
3540
3540
|
const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)();
|
3541
|
-
if (
|
3542
|
-
const terminal = new Terminal(
|
3541
|
+
if (view4 instanceof Prompt3) {
|
3542
|
+
const terminal = new Terminal(view4, stdin, stdout, closable);
|
3543
3543
|
terminal.requestLayout();
|
3544
3544
|
return terminal.result();
|
3545
3545
|
}
|
3546
|
-
stdout.write(`${
|
3546
|
+
stdout.write(`${view4}
|
3547
3547
|
`);
|
3548
3548
|
closable.close();
|
3549
3549
|
return;
|
3550
3550
|
}
|
3551
3551
|
exports.render = render6;
|
3552
|
-
function renderWithTask4(
|
3552
|
+
function renderWithTask4(view4, task) {
|
3553
3553
|
return __awaiter(this, void 0, void 0, function* () {
|
3554
|
-
const terminal = new TaskTerminal(
|
3554
|
+
const terminal = new TaskTerminal(view4, process.stdout);
|
3555
3555
|
terminal.requestLayout();
|
3556
3556
|
const result = yield task;
|
3557
3557
|
terminal.clear();
|
@@ -5878,8 +5878,8 @@ var init_lib = __esm({
|
|
5878
5878
|
unknownKeys: "strict",
|
5879
5879
|
...message !== void 0 ? {
|
5880
5880
|
errorMap: (issue, ctx) => {
|
5881
|
-
var _a324, _b233,
|
5882
|
-
const defaultError = (
|
5881
|
+
var _a324, _b233, _c11, _d5;
|
5882
|
+
const defaultError = (_c11 = (_b233 = (_a324 = this._def).errorMap) === null || _b233 === void 0 ? void 0 : _b233.call(_a324, issue, ctx).message) !== null && _c11 !== void 0 ? _c11 : ctx.defaultError;
|
5883
5883
|
if (issue.code === "unrecognized_keys")
|
5884
5884
|
return {
|
5885
5885
|
message: (_d5 = errorUtil.errToObj(message).message) !== null && _d5 !== void 0 ? _d5 : defaultError
|
@@ -7381,7 +7381,7 @@ var init_lib = __esm({
|
|
7381
7381
|
});
|
7382
7382
|
|
7383
7383
|
// src/serializer/mysqlSchema.ts
|
7384
|
-
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;
|
7384
|
+
var index, fk, column, tableV3, compositePK, uniqueConstraint, checkConstraint, tableV4, table, viewMeta, view, kitInternals, dialect, schemaHash, schemaInternalV3, schemaInternalV4, schemaInternalV5, schemaInternal, schemaV3, schemaV4, schemaV5, schema, tableSquashedV4, tableSquashed, viewSquashed, schemaSquashed, schemaSquashedV4, MySqlSquasher, squashMysqlScheme, mysqlSchema, mysqlSchemaV5, mysqlSchemaSquashed, backwardCompatibleMysqlSchema, dryMySql;
|
7385
7385
|
var init_mysqlSchema = __esm({
|
7386
7386
|
"src/serializer/mysqlSchema.ts"() {
|
7387
7387
|
"use strict";
|
@@ -7431,6 +7431,10 @@ var init_mysqlSchema = __esm({
|
|
7431
7431
|
name: stringType(),
|
7432
7432
|
columns: stringType().array()
|
7433
7433
|
}).strict();
|
7434
|
+
checkConstraint = objectType({
|
7435
|
+
name: stringType(),
|
7436
|
+
value: stringType()
|
7437
|
+
}).strict();
|
7434
7438
|
tableV4 = objectType({
|
7435
7439
|
name: stringType(),
|
7436
7440
|
schema: stringType().optional(),
|
@@ -7444,8 +7448,20 @@ var init_mysqlSchema = __esm({
|
|
7444
7448
|
indexes: recordType(stringType(), index),
|
7445
7449
|
foreignKeys: recordType(stringType(), fk),
|
7446
7450
|
compositePrimaryKeys: recordType(stringType(), compositePK),
|
7447
|
-
uniqueConstraints: recordType(stringType(), uniqueConstraint).default({})
|
7451
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint).default({}),
|
7452
|
+
checkConstraint: recordType(stringType(), checkConstraint).default({})
|
7453
|
+
}).strict();
|
7454
|
+
viewMeta = objectType({
|
7455
|
+
algorithm: enumType(["undefined", "merge", "temptable"]),
|
7456
|
+
sqlSecurity: enumType(["definer", "invoker"]),
|
7457
|
+
withCheckOption: enumType(["local", "cascaded"]).optional()
|
7448
7458
|
}).strict();
|
7459
|
+
view = objectType({
|
7460
|
+
name: stringType(),
|
7461
|
+
columns: recordType(stringType(), column),
|
7462
|
+
definition: stringType().optional(),
|
7463
|
+
isExisting: booleanType()
|
7464
|
+
}).strict().merge(viewMeta);
|
7449
7465
|
kitInternals = objectType({
|
7450
7466
|
tables: recordType(
|
7451
7467
|
stringType(),
|
@@ -7498,6 +7514,7 @@ var init_mysqlSchema = __esm({
|
|
7498
7514
|
version: literalType("5"),
|
7499
7515
|
dialect,
|
7500
7516
|
tables: recordType(stringType(), table),
|
7517
|
+
views: recordType(stringType(), view),
|
7501
7518
|
_meta: objectType({
|
7502
7519
|
tables: recordType(stringType(), stringType()),
|
7503
7520
|
columns: recordType(stringType(), stringType())
|
@@ -7521,12 +7538,19 @@ var init_mysqlSchema = __esm({
|
|
7521
7538
|
indexes: recordType(stringType(), stringType()),
|
7522
7539
|
foreignKeys: recordType(stringType(), stringType()),
|
7523
7540
|
compositePrimaryKeys: recordType(stringType(), stringType()),
|
7524
|
-
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
7541
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({}),
|
7542
|
+
checkConstraints: recordType(stringType(), stringType()).default({})
|
7525
7543
|
}).strict();
|
7544
|
+
viewSquashed = view.omit({
|
7545
|
+
algorithm: true,
|
7546
|
+
sqlSecurity: true,
|
7547
|
+
withCheckOption: true
|
7548
|
+
}).extend({ meta: stringType() });
|
7526
7549
|
schemaSquashed = objectType({
|
7527
7550
|
version: literalType("5"),
|
7528
7551
|
dialect,
|
7529
|
-
tables: recordType(stringType(), tableSquashed)
|
7552
|
+
tables: recordType(stringType(), tableSquashed),
|
7553
|
+
views: recordType(stringType(), viewSquashed)
|
7530
7554
|
}).strict();
|
7531
7555
|
schemaSquashedV4 = objectType({
|
7532
7556
|
version: literalType("4"),
|
@@ -7588,6 +7612,25 @@ var init_mysqlSchema = __esm({
|
|
7588
7612
|
onDelete
|
7589
7613
|
});
|
7590
7614
|
return result;
|
7615
|
+
},
|
7616
|
+
squashCheck: (input) => {
|
7617
|
+
return `${input.name};${input.value}`;
|
7618
|
+
},
|
7619
|
+
unsquashCheck: (input) => {
|
7620
|
+
const [name2, value] = input.split(";");
|
7621
|
+
return { name: name2, value };
|
7622
|
+
},
|
7623
|
+
squashView: (view4) => {
|
7624
|
+
return `${view4.algorithm};${view4.sqlSecurity};${view4.withCheckOption}`;
|
7625
|
+
},
|
7626
|
+
unsquashView: (meta) => {
|
7627
|
+
const [algorithm, sqlSecurity, withCheckOption] = meta.split(";");
|
7628
|
+
const toReturn = {
|
7629
|
+
algorithm,
|
7630
|
+
sqlSecurity,
|
7631
|
+
withCheckOption: withCheckOption !== "undefined" ? withCheckOption : void 0
|
7632
|
+
};
|
7633
|
+
return viewMeta.parse(toReturn);
|
7591
7634
|
}
|
7592
7635
|
};
|
7593
7636
|
squashMysqlScheme = (json3) => {
|
@@ -7608,6 +7651,9 @@ var init_mysqlSchema = __esm({
|
|
7608
7651
|
return MySqlSquasher.squashUnique(unq);
|
7609
7652
|
}
|
7610
7653
|
);
|
7654
|
+
const squashedCheckConstraints = mapValues(it[1].checkConstraint, (check) => {
|
7655
|
+
return MySqlSquasher.squashCheck(check);
|
7656
|
+
});
|
7611
7657
|
return [
|
7612
7658
|
it[0],
|
7613
7659
|
{
|
@@ -7616,15 +7662,29 @@ var init_mysqlSchema = __esm({
|
|
7616
7662
|
indexes: squashedIndexes,
|
7617
7663
|
foreignKeys: squashedFKs,
|
7618
7664
|
compositePrimaryKeys: squashedPKs,
|
7619
|
-
uniqueConstraints: squashedUniqueConstraints
|
7665
|
+
uniqueConstraints: squashedUniqueConstraints,
|
7666
|
+
checkConstraints: squashedCheckConstraints
|
7620
7667
|
}
|
7621
7668
|
];
|
7622
7669
|
})
|
7623
7670
|
);
|
7671
|
+
const mappedViews = Object.fromEntries(
|
7672
|
+
Object.entries(json3.views).map(([key, value]) => {
|
7673
|
+
const meta = MySqlSquasher.squashView(value);
|
7674
|
+
return [key, {
|
7675
|
+
name: value.name,
|
7676
|
+
isExisting: value.isExisting,
|
7677
|
+
columns: value.columns,
|
7678
|
+
definition: value.definition,
|
7679
|
+
meta
|
7680
|
+
}];
|
7681
|
+
})
|
7682
|
+
);
|
7624
7683
|
return {
|
7625
7684
|
version: "5",
|
7626
7685
|
dialect: json3.dialect,
|
7627
|
-
tables: mappedTables
|
7686
|
+
tables: mappedTables,
|
7687
|
+
views: mappedViews
|
7628
7688
|
};
|
7629
7689
|
};
|
7630
7690
|
mysqlSchema = schema;
|
@@ -7638,6 +7698,7 @@ var init_mysqlSchema = __esm({
|
|
7638
7698
|
prevId: "",
|
7639
7699
|
tables: {},
|
7640
7700
|
schemas: {},
|
7701
|
+
views: {},
|
7641
7702
|
_meta: {
|
7642
7703
|
schemas: {},
|
7643
7704
|
tables: {},
|
@@ -7666,7 +7727,7 @@ var init_vector = __esm({
|
|
7666
7727
|
});
|
7667
7728
|
|
7668
7729
|
// src/serializer/pgSchema.ts
|
7669
|
-
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;
|
7730
|
+
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, viewWithOption, matViewWithOption, mergedViewWithOption, view2, 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;
|
7670
7731
|
var init_pgSchema = __esm({
|
7671
7732
|
"src/serializer/pgSchema.ts"() {
|
7672
7733
|
"use strict";
|
@@ -7830,6 +7891,10 @@ var init_pgSchema = __esm({
|
|
7830
7891
|
}).optional(),
|
7831
7892
|
identity: sequenceSchema.merge(objectType({ type: enumType(["always", "byDefault"]) })).optional()
|
7832
7893
|
}).strict();
|
7894
|
+
checkConstraint2 = objectType({
|
7895
|
+
name: stringType(),
|
7896
|
+
value: stringType()
|
7897
|
+
}).strict();
|
7833
7898
|
columnSquashed = objectType({
|
7834
7899
|
name: stringType(),
|
7835
7900
|
type: stringType(),
|
@@ -7861,6 +7926,44 @@ var init_pgSchema = __esm({
|
|
7861
7926
|
columns: stringType().array(),
|
7862
7927
|
nullsNotDistinct: booleanType()
|
7863
7928
|
}).strict();
|
7929
|
+
viewWithOption = objectType({
|
7930
|
+
checkOption: enumType(["local", "cascaded"]).optional(),
|
7931
|
+
securityBarrier: booleanType().optional(),
|
7932
|
+
securityInvoker: booleanType().optional()
|
7933
|
+
}).strict();
|
7934
|
+
matViewWithOption = objectType({
|
7935
|
+
fillfactor: numberType().optional(),
|
7936
|
+
toastTupleTarget: numberType().optional(),
|
7937
|
+
parallelWorkers: numberType().optional(),
|
7938
|
+
autovacuumEnabled: booleanType().optional(),
|
7939
|
+
vacuumIndexCleanup: enumType(["auto", "off", "on"]).optional(),
|
7940
|
+
vacuumTruncate: booleanType().optional(),
|
7941
|
+
autovacuumVacuumThreshold: numberType().optional(),
|
7942
|
+
autovacuumVacuumScaleFactor: numberType().optional(),
|
7943
|
+
autovacuumVacuumCostDelay: numberType().optional(),
|
7944
|
+
autovacuumVacuumCostLimit: numberType().optional(),
|
7945
|
+
autovacuumFreezeMinAge: numberType().optional(),
|
7946
|
+
autovacuumFreezeMaxAge: numberType().optional(),
|
7947
|
+
autovacuumFreezeTableAge: numberType().optional(),
|
7948
|
+
autovacuumMultixactFreezeMinAge: numberType().optional(),
|
7949
|
+
autovacuumMultixactFreezeMaxAge: numberType().optional(),
|
7950
|
+
autovacuumMultixactFreezeTableAge: numberType().optional(),
|
7951
|
+
logAutovacuumMinDuration: numberType().optional(),
|
7952
|
+
userCatalogTable: booleanType().optional()
|
7953
|
+
}).strict();
|
7954
|
+
mergedViewWithOption = viewWithOption.merge(matViewWithOption).strict();
|
7955
|
+
view2 = objectType({
|
7956
|
+
name: stringType(),
|
7957
|
+
schema: stringType(),
|
7958
|
+
columns: recordType(stringType(), column2),
|
7959
|
+
definition: stringType().optional(),
|
7960
|
+
materialized: booleanType(),
|
7961
|
+
with: mergedViewWithOption.optional(),
|
7962
|
+
isExisting: booleanType(),
|
7963
|
+
withNoData: booleanType().optional(),
|
7964
|
+
using: stringType().optional(),
|
7965
|
+
tablespace: stringType().optional()
|
7966
|
+
}).strict();
|
7864
7967
|
tableV42 = objectType({
|
7865
7968
|
name: stringType(),
|
7866
7969
|
schema: stringType(),
|
@@ -7902,7 +8005,8 @@ var init_pgSchema = __esm({
|
|
7902
8005
|
indexes: recordType(stringType(), index2),
|
7903
8006
|
foreignKeys: recordType(stringType(), fk2),
|
7904
8007
|
compositePrimaryKeys: recordType(stringType(), compositePK2),
|
7905
|
-
uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
|
8008
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({}),
|
8009
|
+
checkConstraints: recordType(stringType(), checkConstraint2).default({})
|
7906
8010
|
}).strict();
|
7907
8011
|
schemaHash2 = objectType({
|
7908
8012
|
id: stringType(),
|
@@ -7995,6 +8099,7 @@ var init_pgSchema = __esm({
|
|
7995
8099
|
tables: recordType(stringType(), table2),
|
7996
8100
|
enums: recordType(stringType(), enumSchema),
|
7997
8101
|
schemas: recordType(stringType(), stringType()),
|
8102
|
+
views: recordType(stringType(), view2).default({}),
|
7998
8103
|
sequences: recordType(stringType(), sequenceSchema).default({}),
|
7999
8104
|
_meta: objectType({
|
8000
8105
|
schemas: recordType(stringType(), stringType()),
|
@@ -8010,7 +8115,8 @@ var init_pgSchema = __esm({
|
|
8010
8115
|
indexes: recordType(stringType(), stringType()),
|
8011
8116
|
foreignKeys: recordType(stringType(), stringType()),
|
8012
8117
|
compositePrimaryKeys: recordType(stringType(), stringType()),
|
8013
|
-
uniqueConstraints: recordType(stringType(), stringType())
|
8118
|
+
uniqueConstraints: recordType(stringType(), stringType()),
|
8119
|
+
checkConstraints: recordType(stringType(), stringType())
|
8014
8120
|
}).strict();
|
8015
8121
|
tableSquashedV42 = objectType({
|
8016
8122
|
name: stringType(),
|
@@ -8039,6 +8145,7 @@ var init_pgSchema = __esm({
|
|
8039
8145
|
tables: recordType(stringType(), tableSquashed2),
|
8040
8146
|
enums: recordType(stringType(), enumSchema),
|
8041
8147
|
schemas: recordType(stringType(), stringType()),
|
8148
|
+
views: recordType(stringType(), view2),
|
8042
8149
|
sequences: recordType(stringType(), sequenceSquashed)
|
8043
8150
|
}).strict();
|
8044
8151
|
pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
|
@@ -8192,6 +8299,16 @@ var init_pgSchema = __esm({
|
|
8192
8299
|
cache: splitted[6] !== "undefined" ? splitted[6] : void 0,
|
8193
8300
|
cycle: splitted[7] === "true"
|
8194
8301
|
};
|
8302
|
+
},
|
8303
|
+
squashCheck: (check) => {
|
8304
|
+
return `${check.name};${check.value}`;
|
8305
|
+
},
|
8306
|
+
unsquashCheck: (input) => {
|
8307
|
+
const [
|
8308
|
+
name2,
|
8309
|
+
value
|
8310
|
+
] = input.split(";");
|
8311
|
+
return { name: name2, value };
|
8195
8312
|
}
|
8196
8313
|
};
|
8197
8314
|
squashPgScheme = (json3, action) => {
|
@@ -8224,6 +8341,12 @@ var init_pgSchema = __esm({
|
|
8224
8341
|
return PgSquasher.squashUnique(unq);
|
8225
8342
|
}
|
8226
8343
|
);
|
8344
|
+
const squashedChecksContraints = mapValues(
|
8345
|
+
it[1].checkConstraints,
|
8346
|
+
(check) => {
|
8347
|
+
return PgSquasher.squashCheck(check);
|
8348
|
+
}
|
8349
|
+
);
|
8227
8350
|
return [
|
8228
8351
|
it[0],
|
8229
8352
|
{
|
@@ -8233,7 +8356,8 @@ var init_pgSchema = __esm({
|
|
8233
8356
|
indexes: squashedIndexes,
|
8234
8357
|
foreignKeys: squashedFKs,
|
8235
8358
|
compositePrimaryKeys: squashedPKs,
|
8236
|
-
uniqueConstraints: squashedUniqueConstraints
|
8359
|
+
uniqueConstraints: squashedUniqueConstraints,
|
8360
|
+
checkConstraints: squashedChecksContraints
|
8237
8361
|
}
|
8238
8362
|
];
|
8239
8363
|
})
|
@@ -8256,6 +8380,7 @@ var init_pgSchema = __esm({
|
|
8256
8380
|
tables: mappedTables,
|
8257
8381
|
enums: json3.enums,
|
8258
8382
|
schemas: json3.schemas,
|
8383
|
+
views: json3.views,
|
8259
8384
|
sequences: mappedSequences
|
8260
8385
|
};
|
8261
8386
|
};
|
@@ -8278,7 +8403,7 @@ var init_pgSchema = __esm({
|
|
8278
8403
|
});
|
8279
8404
|
|
8280
8405
|
// src/serializer/sqliteSchema.ts
|
8281
|
-
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;
|
8406
|
+
var index3, fk3, compositePK3, column3, tableV33, uniqueConstraint3, checkConstraint3, table3, view3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, schemaInternalV52, kitInternals3, latestVersion, schemaInternal2, schemaV32, schemaV42, schemaV52, schema2, tableSquashed3, schemaSquashed2, SQLiteSquasher, squashSqliteScheme, drySQLite, sqliteSchemaV5, sqliteSchema, SQLiteSchemaSquashed, backwardCompatibleSqliteSchema;
|
8282
8407
|
var init_sqliteSchema = __esm({
|
8283
8408
|
"src/serializer/sqliteSchema.ts"() {
|
8284
8409
|
"use strict";
|
@@ -8325,13 +8450,24 @@ var init_sqliteSchema = __esm({
|
|
8325
8450
|
name: stringType(),
|
8326
8451
|
columns: stringType().array()
|
8327
8452
|
}).strict();
|
8453
|
+
checkConstraint3 = objectType({
|
8454
|
+
name: stringType(),
|
8455
|
+
value: stringType()
|
8456
|
+
}).strict();
|
8328
8457
|
table3 = objectType({
|
8329
8458
|
name: stringType(),
|
8330
8459
|
columns: recordType(stringType(), column3),
|
8331
8460
|
indexes: recordType(stringType(), index3),
|
8332
8461
|
foreignKeys: recordType(stringType(), fk3),
|
8333
8462
|
compositePrimaryKeys: recordType(stringType(), compositePK3),
|
8334
|
-
uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
|
8463
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({}),
|
8464
|
+
checkConstraints: recordType(stringType(), checkConstraint3).default({})
|
8465
|
+
}).strict();
|
8466
|
+
view3 = objectType({
|
8467
|
+
name: stringType(),
|
8468
|
+
columns: recordType(stringType(), column3),
|
8469
|
+
definition: stringType().optional(),
|
8470
|
+
isExisting: booleanType()
|
8335
8471
|
}).strict();
|
8336
8472
|
dialect2 = enumType(["sqlite"]);
|
8337
8473
|
schemaHash3 = objectType({
|
@@ -8348,6 +8484,7 @@ var init_sqliteSchema = __esm({
|
|
8348
8484
|
version: literalType("4"),
|
8349
8485
|
dialect: dialect2,
|
8350
8486
|
tables: recordType(stringType(), table3),
|
8487
|
+
views: recordType(stringType(), view3),
|
8351
8488
|
enums: objectType({})
|
8352
8489
|
}).strict();
|
8353
8490
|
schemaInternalV52 = objectType({
|
@@ -8376,6 +8513,7 @@ var init_sqliteSchema = __esm({
|
|
8376
8513
|
version: latestVersion,
|
8377
8514
|
dialect: dialect2,
|
8378
8515
|
tables: recordType(stringType(), table3),
|
8516
|
+
views: recordType(stringType(), view3),
|
8379
8517
|
enums: objectType({}),
|
8380
8518
|
_meta: objectType({
|
8381
8519
|
tables: recordType(stringType(), stringType()),
|
@@ -8393,12 +8531,14 @@ var init_sqliteSchema = __esm({
|
|
8393
8531
|
indexes: recordType(stringType(), stringType()),
|
8394
8532
|
foreignKeys: recordType(stringType(), stringType()),
|
8395
8533
|
compositePrimaryKeys: recordType(stringType(), stringType()),
|
8396
|
-
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
8534
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({}),
|
8535
|
+
checkConstraints: recordType(stringType(), stringType()).default({})
|
8397
8536
|
}).strict();
|
8398
8537
|
schemaSquashed2 = objectType({
|
8399
8538
|
version: latestVersion,
|
8400
8539
|
dialect: dialect2,
|
8401
8540
|
tables: recordType(stringType(), tableSquashed3),
|
8541
|
+
views: recordType(stringType(), view3),
|
8402
8542
|
enums: anyType()
|
8403
8543
|
}).strict();
|
8404
8544
|
SQLiteSquasher = {
|
@@ -8475,6 +8615,16 @@ var init_sqliteSchema = __esm({
|
|
8475
8615
|
},
|
8476
8616
|
unsquashPK: (pk) => {
|
8477
8617
|
return pk.split(",");
|
8618
|
+
},
|
8619
|
+
squashCheck: (check) => {
|
8620
|
+
return `${check.name};${check.value}`;
|
8621
|
+
},
|
8622
|
+
unsquashCheck: (input) => {
|
8623
|
+
const [
|
8624
|
+
name2,
|
8625
|
+
value
|
8626
|
+
] = input.split(";");
|
8627
|
+
return { name: name2, value };
|
8478
8628
|
}
|
8479
8629
|
};
|
8480
8630
|
squashSqliteScheme = (json3, action) => {
|
@@ -8501,6 +8651,12 @@ var init_sqliteSchema = __esm({
|
|
8501
8651
|
return SQLiteSquasher.squashUnique(unq);
|
8502
8652
|
}
|
8503
8653
|
);
|
8654
|
+
const squashedCheckConstraints = mapValues(
|
8655
|
+
it[1].checkConstraints,
|
8656
|
+
(check) => {
|
8657
|
+
return SQLiteSquasher.squashCheck(check);
|
8658
|
+
}
|
8659
|
+
);
|
8504
8660
|
return [
|
8505
8661
|
it[0],
|
8506
8662
|
{
|
@@ -8509,7 +8665,8 @@ var init_sqliteSchema = __esm({
|
|
8509
8665
|
indexes: squashedIndexes,
|
8510
8666
|
foreignKeys: squashedFKs,
|
8511
8667
|
compositePrimaryKeys: squashedPKs,
|
8512
|
-
uniqueConstraints: squashedUniqueConstraints
|
8668
|
+
uniqueConstraints: squashedUniqueConstraints,
|
8669
|
+
checkConstraints: squashedCheckConstraints
|
8513
8670
|
}
|
8514
8671
|
];
|
8515
8672
|
})
|
@@ -8518,6 +8675,7 @@ var init_sqliteSchema = __esm({
|
|
8518
8675
|
version: "6",
|
8519
8676
|
dialect: json3.dialect,
|
8520
8677
|
tables: mappedTables,
|
8678
|
+
views: json3.views,
|
8521
8679
|
enums: json3.enums
|
8522
8680
|
};
|
8523
8681
|
};
|
@@ -8527,6 +8685,7 @@ var init_sqliteSchema = __esm({
|
|
8527
8685
|
id: originUUID,
|
8528
8686
|
prevId: "",
|
8529
8687
|
tables: {},
|
8688
|
+
views: {},
|
8530
8689
|
enums: {},
|
8531
8690
|
_meta: {
|
8532
8691
|
tables: {},
|
@@ -11222,6 +11381,7 @@ function applyJsonDiff(json1, json22) {
|
|
11222
11381
|
difference.tables = difference.tables || {};
|
11223
11382
|
difference.enums = difference.enums || {};
|
11224
11383
|
difference.sequences = difference.sequences || {};
|
11384
|
+
difference.views = difference.views || {};
|
11225
11385
|
const schemaKeys = Object.keys(difference.schemas);
|
11226
11386
|
for (let key of schemaKeys) {
|
11227
11387
|
if (key.endsWith("__added") || key.endsWith("__deleted")) {
|
@@ -11277,6 +11437,70 @@ function applyJsonDiff(json1, json22) {
|
|
11277
11437
|
const alteredSequences = sequencesEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted")) && "values" in it[1]).map((it) => {
|
11278
11438
|
return json22.sequences[it[0]];
|
11279
11439
|
});
|
11440
|
+
const viewsEntries = Object.entries(difference.views);
|
11441
|
+
const alteredViews = viewsEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted"))).map(
|
11442
|
+
([nameWithSchema, view4]) => {
|
11443
|
+
const deletedWithOption = view4.with__deleted;
|
11444
|
+
const addedWithOption = view4.with__added;
|
11445
|
+
const deletedWith = Object.fromEntries(
|
11446
|
+
Object.entries(view4.with || {}).filter((it) => it[0].endsWith("__deleted")).map(([key, value]) => {
|
11447
|
+
return [key.replace("__deleted", ""), value];
|
11448
|
+
})
|
11449
|
+
);
|
11450
|
+
const addedWith = Object.fromEntries(
|
11451
|
+
Object.entries(view4.with || {}).filter((it) => it[0].endsWith("__added")).map(([key, value]) => {
|
11452
|
+
return [key.replace("__added", ""), value];
|
11453
|
+
})
|
11454
|
+
);
|
11455
|
+
const alterWith = Object.fromEntries(
|
11456
|
+
Object.entries(view4.with || {}).filter(
|
11457
|
+
(it) => typeof it[1].__old !== "undefined" && typeof it[1].__new !== "undefined"
|
11458
|
+
).map(
|
11459
|
+
(it) => {
|
11460
|
+
return [it[0], it[1].__new];
|
11461
|
+
}
|
11462
|
+
)
|
11463
|
+
);
|
11464
|
+
const alteredSchema = view4.schema;
|
11465
|
+
const alteredDefinition = view4.definition;
|
11466
|
+
const alteredExisting = view4.isExisting;
|
11467
|
+
const addedTablespace = view4.tablespace__added;
|
11468
|
+
const droppedTablespace = view4.tablespace__deleted;
|
11469
|
+
const alterTablespaceTo = view4.tablespace;
|
11470
|
+
let alteredTablespace;
|
11471
|
+
if (addedTablespace) alteredTablespace = { __new: addedTablespace, __old: "pg_default" };
|
11472
|
+
if (droppedTablespace) alteredTablespace = { __new: "pg_default", __old: droppedTablespace };
|
11473
|
+
if (alterTablespaceTo) alteredTablespace = alterTablespaceTo;
|
11474
|
+
const addedUsing = view4.using__added;
|
11475
|
+
const droppedUsing = view4.using__deleted;
|
11476
|
+
const alterUsingTo = view4.using;
|
11477
|
+
let alteredUsing;
|
11478
|
+
if (addedUsing) alteredUsing = { __new: addedUsing, __old: "heap" };
|
11479
|
+
if (droppedUsing) alteredUsing = { __new: "heap", __old: droppedUsing };
|
11480
|
+
if (alterUsingTo) alteredUsing = alterUsingTo;
|
11481
|
+
const alteredMeta = view4.meta;
|
11482
|
+
return Object.fromEntries(
|
11483
|
+
Object.entries({
|
11484
|
+
name: json22.views[nameWithSchema].name,
|
11485
|
+
schema: json22.views[nameWithSchema].schema,
|
11486
|
+
// pg
|
11487
|
+
deletedWithOption,
|
11488
|
+
addedWithOption,
|
11489
|
+
deletedWith: Object.keys(deletedWith).length ? deletedWith : void 0,
|
11490
|
+
addedWith: Object.keys(addedWith).length ? addedWith : void 0,
|
11491
|
+
alteredWith: Object.keys(alterWith).length ? alterWith : void 0,
|
11492
|
+
alteredSchema,
|
11493
|
+
alteredTablespace,
|
11494
|
+
alteredUsing,
|
11495
|
+
// mysql
|
11496
|
+
alteredMeta,
|
11497
|
+
// common
|
11498
|
+
alteredDefinition,
|
11499
|
+
alteredExisting
|
11500
|
+
}).filter(([_2, value]) => value !== void 0)
|
11501
|
+
);
|
11502
|
+
}
|
11503
|
+
);
|
11280
11504
|
const alteredTablesWithColumns = Object.values(difference.tables).map(
|
11281
11505
|
(table4) => {
|
11282
11506
|
return findAlternationsInTable(table4);
|
@@ -11285,7 +11509,8 @@ function applyJsonDiff(json1, json22) {
|
|
11285
11509
|
return {
|
11286
11510
|
alteredTablesWithColumns,
|
11287
11511
|
alteredEnums,
|
11288
|
-
alteredSequences
|
11512
|
+
alteredSequences,
|
11513
|
+
alteredViews
|
11289
11514
|
};
|
11290
11515
|
}
|
11291
11516
|
var import_json_diff, mapArraysDiff, findAlternationsInTable, alternationsInColumn;
|
@@ -11390,6 +11615,21 @@ var init_jsonDiffer = __esm({
|
|
11390
11615
|
return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
|
11391
11616
|
})
|
11392
11617
|
);
|
11618
|
+
const addedCheckConstraints = Object.fromEntries(
|
11619
|
+
Object.entries(table4.checkConstraints || {}).filter((it) => {
|
11620
|
+
return it[0].endsWith("__added");
|
11621
|
+
})
|
11622
|
+
);
|
11623
|
+
const deletedCheckConstraints = Object.fromEntries(
|
11624
|
+
Object.entries(table4.checkConstraints || {}).filter((it) => {
|
11625
|
+
return it[0].endsWith("__deleted");
|
11626
|
+
})
|
11627
|
+
);
|
11628
|
+
const alteredCheckConstraints = Object.fromEntries(
|
11629
|
+
Object.entries(table4.checkConstraints || {}).filter((it) => {
|
11630
|
+
return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
|
11631
|
+
})
|
11632
|
+
);
|
11393
11633
|
const mappedAltered = altered.map((it) => alternationsInColumn(it)).filter(Boolean);
|
11394
11634
|
return {
|
11395
11635
|
name: table4.name,
|
@@ -11406,7 +11646,10 @@ var init_jsonDiffer = __esm({
|
|
11406
11646
|
alteredCompositePKs,
|
11407
11647
|
addedUniqueConstraints,
|
11408
11648
|
deletedUniqueConstraints,
|
11409
|
-
alteredUniqueConstraints
|
11649
|
+
alteredUniqueConstraints,
|
11650
|
+
addedCheckConstraints,
|
11651
|
+
deletedCheckConstraints,
|
11652
|
+
alteredCheckConstraints
|
11410
11653
|
};
|
11411
11654
|
};
|
11412
11655
|
alternationsInColumn = (column4) => {
|
@@ -11660,6 +11903,32 @@ var init_jsonDiffer = __esm({
|
|
11660
11903
|
};
|
11661
11904
|
}
|
11662
11905
|
return it;
|
11906
|
+
}).map((it) => {
|
11907
|
+
if ("" in it) {
|
11908
|
+
return {
|
11909
|
+
...it,
|
11910
|
+
autoincrement: {
|
11911
|
+
type: "changed",
|
11912
|
+
old: it.autoincrement.__old,
|
11913
|
+
new: it.autoincrement.__new
|
11914
|
+
}
|
11915
|
+
};
|
11916
|
+
}
|
11917
|
+
if ("autoincrement__added" in it) {
|
11918
|
+
const { autoincrement__added, ...others } = it;
|
11919
|
+
return {
|
11920
|
+
...others,
|
11921
|
+
autoincrement: { type: "added", value: it.autoincrement__added }
|
11922
|
+
};
|
11923
|
+
}
|
11924
|
+
if ("autoincrement__deleted" in it) {
|
11925
|
+
const { autoincrement__deleted, ...others } = it;
|
11926
|
+
return {
|
11927
|
+
...others,
|
11928
|
+
autoincrement: { type: "deleted", value: it.autoincrement__deleted }
|
11929
|
+
};
|
11930
|
+
}
|
11931
|
+
return it;
|
11663
11932
|
}).filter(Boolean);
|
11664
11933
|
return result[0];
|
11665
11934
|
};
|
@@ -11680,7 +11949,7 @@ function fromJson(statements, dialect4, action, json22) {
|
|
11680
11949
|
}).filter((it) => it !== "");
|
11681
11950
|
return result;
|
11682
11951
|
}
|
11683
|
-
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;
|
11952
|
+
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgCreateViewConvertor, MySqlCreateViewConvertor, SqliteCreateViewConvertor, PgDropViewConvertor, MySqlDropViewConvertor, SqliteDropViewConvertor, MySqlAlterViewConvertor, PgRenameViewConvertor, MySqlRenameViewConvertor, PgAlterViewSchemaConvertor, PgAlterViewAddWithOptionConvertor, PgAlterViewDropWithOptionConvertor, PgAlterViewAlterTablespaceConvertor, PgAlterViewAlterUsingConvertor, 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;
|
11684
11953
|
var init_sqlgenerator = __esm({
|
11685
11954
|
"src/sqlgenerator.ts"() {
|
11686
11955
|
"use strict";
|
@@ -11741,7 +12010,7 @@ var init_sqlgenerator = __esm({
|
|
11741
12010
|
return statement.type === "create_table" && dialect4 === "postgresql";
|
11742
12011
|
}
|
11743
12012
|
convert(st) {
|
11744
|
-
const { tableName, schema: schema4, columns, compositePKs, uniqueConstraints } = st;
|
12013
|
+
const { tableName, schema: schema4, columns, compositePKs, uniqueConstraints, checkConstraints } = st;
|
11745
12014
|
let statement = "";
|
11746
12015
|
const name2 = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
|
11747
12016
|
statement += `CREATE TABLE IF NOT EXISTS ${name2} (
|
@@ -11774,6 +12043,13 @@ var init_sqlgenerator = __esm({
|
|
11774
12043
|
statement += ` CONSTRAINT "${unsquashedUnique.name}" UNIQUE${unsquashedUnique.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}("${unsquashedUnique.columns.join(`","`)}")`;
|
11775
12044
|
}
|
11776
12045
|
}
|
12046
|
+
if (typeof checkConstraints !== "undefined" && checkConstraints.length > 0) {
|
12047
|
+
for (const checkConstraint4 of checkConstraints) {
|
12048
|
+
statement += ",\n";
|
12049
|
+
const unsquashedCheck = PgSquasher.unsquashCheck(checkConstraint4);
|
12050
|
+
statement += ` CONSTRAINT "${unsquashedCheck.name}" CHECK (${unsquashedCheck.value})`;
|
12051
|
+
}
|
12052
|
+
}
|
11777
12053
|
statement += `
|
11778
12054
|
);`;
|
11779
12055
|
statement += `
|
@@ -11790,6 +12066,7 @@ var init_sqlgenerator = __esm({
|
|
11790
12066
|
tableName,
|
11791
12067
|
columns,
|
11792
12068
|
schema: schema4,
|
12069
|
+
checkConstraints,
|
11793
12070
|
compositePKs,
|
11794
12071
|
uniqueConstraints,
|
11795
12072
|
internals
|
@@ -11823,6 +12100,13 @@ var init_sqlgenerator = __esm({
|
|
11823
12100
|
statement += ` CONSTRAINT \`${unsquashedUnique.name}\` UNIQUE(${uniqueString})`;
|
11824
12101
|
}
|
11825
12102
|
}
|
12103
|
+
if (typeof checkConstraints !== "undefined" && checkConstraints.length > 0) {
|
12104
|
+
for (const checkConstraint4 of checkConstraints) {
|
12105
|
+
statement += ",\n";
|
12106
|
+
const unsquashedCheck = MySqlSquasher.unsquashCheck(checkConstraint4);
|
12107
|
+
statement += ` CONSTRAINT \`${unsquashedCheck.name}\` CHECK(${unsquashedCheck.value})`;
|
12108
|
+
}
|
12109
|
+
}
|
11826
12110
|
statement += `
|
11827
12111
|
);`;
|
11828
12112
|
statement += `
|
@@ -11840,7 +12124,8 @@ var init_sqlgenerator = __esm({
|
|
11840
12124
|
columns,
|
11841
12125
|
referenceData,
|
11842
12126
|
compositePKs,
|
11843
|
-
uniqueConstraints
|
12127
|
+
uniqueConstraints,
|
12128
|
+
checkConstraints
|
11844
12129
|
} = st;
|
11845
12130
|
let statement = "";
|
11846
12131
|
statement += `CREATE TABLE \`${tableName}\` (
|
@@ -11881,10 +12166,17 @@ var init_sqlgenerator = __esm({
|
|
11881
12166
|
if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
|
11882
12167
|
for (const uniqueConstraint4 of uniqueConstraints) {
|
11883
12168
|
statement += ",\n";
|
11884
|
-
const unsquashedUnique =
|
12169
|
+
const unsquashedUnique = SQLiteSquasher.unsquashUnique(uniqueConstraint4);
|
11885
12170
|
statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
|
11886
12171
|
}
|
11887
12172
|
}
|
12173
|
+
if (typeof checkConstraints !== "undefined" && checkConstraints.length > 0) {
|
12174
|
+
for (const check of checkConstraints) {
|
12175
|
+
statement += ",\n";
|
12176
|
+
const { value, name: name2 } = SQLiteSquasher.unsquashCheck(check);
|
12177
|
+
statement += ` CONSTRAINT "${name2}" CHECK(${value})`;
|
12178
|
+
}
|
12179
|
+
}
|
11888
12180
|
statement += `
|
11889
12181
|
`;
|
11890
12182
|
statement += `);`;
|
@@ -11893,6 +12185,187 @@ var init_sqlgenerator = __esm({
|
|
11893
12185
|
return statement;
|
11894
12186
|
}
|
11895
12187
|
};
|
12188
|
+
PgCreateViewConvertor = class extends Convertor {
|
12189
|
+
can(statement, dialect4) {
|
12190
|
+
return statement.type === "create_view" && dialect4 === "postgresql";
|
12191
|
+
}
|
12192
|
+
convert(st) {
|
12193
|
+
const { definition, name: viewName, schema: schema4, with: withOption, materialized, withNoData, tablespace, using } = st;
|
12194
|
+
const name2 = schema4 ? `"${schema4}"."${viewName}"` : `"${viewName}"`;
|
12195
|
+
let statement = materialized ? `CREATE MATERIALIZED VIEW ${name2}` : `CREATE VIEW ${name2}`;
|
12196
|
+
if (using) statement += ` USING "${using}"`;
|
12197
|
+
const options = [];
|
12198
|
+
if (withOption) {
|
12199
|
+
statement += ` WITH (`;
|
12200
|
+
Object.entries(withOption).forEach(([key, value]) => {
|
12201
|
+
if (typeof value === "undefined") return;
|
12202
|
+
options.push(`${key.snake_case()} = ${value}`);
|
12203
|
+
});
|
12204
|
+
statement += options.join(", ");
|
12205
|
+
statement += `)`;
|
12206
|
+
}
|
12207
|
+
if (tablespace) statement += ` TABLESPACE ${tablespace}`;
|
12208
|
+
statement += ` AS (${definition})`;
|
12209
|
+
if (withNoData) statement += ` WITH NO DATA`;
|
12210
|
+
statement += `;`;
|
12211
|
+
return statement;
|
12212
|
+
}
|
12213
|
+
};
|
12214
|
+
MySqlCreateViewConvertor = class extends Convertor {
|
12215
|
+
can(statement, dialect4) {
|
12216
|
+
return statement.type === "mysql_create_view" && dialect4 === "mysql";
|
12217
|
+
}
|
12218
|
+
convert(st) {
|
12219
|
+
const { definition, name: name2, algorithm, sqlSecurity, withCheckOption, replace } = st;
|
12220
|
+
let statement = `CREATE `;
|
12221
|
+
statement += replace ? `OR REPLACE ` : "";
|
12222
|
+
statement += algorithm ? `ALGORITHM = ${algorithm}
|
12223
|
+
` : "";
|
12224
|
+
statement += sqlSecurity ? `SQL SECURITY ${sqlSecurity}
|
12225
|
+
` : "";
|
12226
|
+
statement += `VIEW \`${name2}\` AS (${definition})`;
|
12227
|
+
statement += withCheckOption ? `
|
12228
|
+
WITH ${withCheckOption} CHECK OPTION` : "";
|
12229
|
+
statement += ";";
|
12230
|
+
return statement;
|
12231
|
+
}
|
12232
|
+
};
|
12233
|
+
SqliteCreateViewConvertor = class extends Convertor {
|
12234
|
+
can(statement, dialect4) {
|
12235
|
+
return statement.type === "sqlite_create_view" && (dialect4 === "sqlite" || dialect4 === "turso");
|
12236
|
+
}
|
12237
|
+
convert(st) {
|
12238
|
+
const { definition, name: name2 } = st;
|
12239
|
+
return `CREATE VIEW \`${name2}\` AS ${definition};`;
|
12240
|
+
}
|
12241
|
+
};
|
12242
|
+
PgDropViewConvertor = class extends Convertor {
|
12243
|
+
can(statement, dialect4) {
|
12244
|
+
return statement.type === "drop_view" && dialect4 === "postgresql";
|
12245
|
+
}
|
12246
|
+
convert(st) {
|
12247
|
+
const { name: viewName, schema: schema4, materialized } = st;
|
12248
|
+
const name2 = schema4 ? `"${schema4}"."${viewName}"` : `"${viewName}"`;
|
12249
|
+
return `DROP${materialized ? " MATERIALIZED" : ""} VIEW ${name2};`;
|
12250
|
+
}
|
12251
|
+
};
|
12252
|
+
MySqlDropViewConvertor = class extends Convertor {
|
12253
|
+
can(statement, dialect4) {
|
12254
|
+
return statement.type === "drop_view" && dialect4 === "mysql";
|
12255
|
+
}
|
12256
|
+
convert(st) {
|
12257
|
+
const { name: name2 } = st;
|
12258
|
+
return `DROP VIEW \`${name2}\`;`;
|
12259
|
+
}
|
12260
|
+
};
|
12261
|
+
SqliteDropViewConvertor = class extends Convertor {
|
12262
|
+
can(statement, dialect4) {
|
12263
|
+
return statement.type === "drop_view" && (dialect4 === "sqlite" || dialect4 === "turso");
|
12264
|
+
}
|
12265
|
+
convert(st) {
|
12266
|
+
const { name: name2 } = st;
|
12267
|
+
return `DROP VIEW \`${name2}\`;`;
|
12268
|
+
}
|
12269
|
+
};
|
12270
|
+
MySqlAlterViewConvertor = class extends Convertor {
|
12271
|
+
can(statement, dialect4) {
|
12272
|
+
return statement.type === "alter_mysql_view" && dialect4 === "mysql";
|
12273
|
+
}
|
12274
|
+
convert(st) {
|
12275
|
+
const { name: name2, algorithm, definition, sqlSecurity, withCheckOption } = st;
|
12276
|
+
let statement = `ALTER `;
|
12277
|
+
statement += algorithm ? `ALGORITHM = ${algorithm}
|
12278
|
+
` : "";
|
12279
|
+
statement += sqlSecurity ? `SQL SECURITY ${sqlSecurity}
|
12280
|
+
` : "";
|
12281
|
+
statement += `VIEW \`${name2}\` AS ${definition}`;
|
12282
|
+
statement += withCheckOption ? `
|
12283
|
+
WITH ${withCheckOption} CHECK OPTION` : "";
|
12284
|
+
statement += ";";
|
12285
|
+
return statement;
|
12286
|
+
}
|
12287
|
+
};
|
12288
|
+
PgRenameViewConvertor = class extends Convertor {
|
12289
|
+
can(statement, dialect4) {
|
12290
|
+
return statement.type === "rename_view" && dialect4 === "postgresql";
|
12291
|
+
}
|
12292
|
+
convert(st) {
|
12293
|
+
const { nameFrom: from, nameTo: to, schema: schema4, materialized } = st;
|
12294
|
+
const nameFrom = `"${schema4}"."${from}"`;
|
12295
|
+
return `ALTER${materialized ? " MATERIALIZED" : ""} VIEW ${nameFrom} RENAME TO "${to}";`;
|
12296
|
+
}
|
12297
|
+
};
|
12298
|
+
MySqlRenameViewConvertor = class extends Convertor {
|
12299
|
+
can(statement, dialect4) {
|
12300
|
+
return statement.type === "rename_view" && dialect4 === "mysql";
|
12301
|
+
}
|
12302
|
+
convert(st) {
|
12303
|
+
const { nameFrom: from, nameTo: to } = st;
|
12304
|
+
return `RENAME TABLE \`${from}\` RENAME TO \`${to}\`;`;
|
12305
|
+
}
|
12306
|
+
};
|
12307
|
+
PgAlterViewSchemaConvertor = class extends Convertor {
|
12308
|
+
can(statement, dialect4) {
|
12309
|
+
return statement.type === "alter_view_alter_schema" && dialect4 === "postgresql";
|
12310
|
+
}
|
12311
|
+
convert(st) {
|
12312
|
+
const { fromSchema, toSchema, name: name2, materialized } = st;
|
12313
|
+
const statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${fromSchema}"."${name2}" SET SCHEMA "${toSchema}";`;
|
12314
|
+
return statement;
|
12315
|
+
}
|
12316
|
+
};
|
12317
|
+
PgAlterViewAddWithOptionConvertor = class extends Convertor {
|
12318
|
+
can(statement, dialect4) {
|
12319
|
+
return statement.type === "alter_view_add_with_option" && dialect4 === "postgresql";
|
12320
|
+
}
|
12321
|
+
convert(st) {
|
12322
|
+
const { schema: schema4, with: withOption, name: name2, materialized } = st;
|
12323
|
+
let statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${schema4}"."${name2}" SET (`;
|
12324
|
+
const options = [];
|
12325
|
+
Object.entries(withOption).forEach(([key, value]) => {
|
12326
|
+
options.push(`${key.snake_case()} = ${value}`);
|
12327
|
+
});
|
12328
|
+
statement += options.join(", ");
|
12329
|
+
statement += `);`;
|
12330
|
+
return statement;
|
12331
|
+
}
|
12332
|
+
};
|
12333
|
+
PgAlterViewDropWithOptionConvertor = class extends Convertor {
|
12334
|
+
can(statement, dialect4) {
|
12335
|
+
return statement.type === "alter_view_drop_with_option" && dialect4 === "postgresql";
|
12336
|
+
}
|
12337
|
+
convert(st) {
|
12338
|
+
const { schema: schema4, name: name2, materialized, with: withOptions } = st;
|
12339
|
+
let statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${schema4}"."${name2}" RESET (`;
|
12340
|
+
const options = [];
|
12341
|
+
Object.entries(withOptions).forEach(([key, value]) => {
|
12342
|
+
options.push(`${key.snake_case()}`);
|
12343
|
+
});
|
12344
|
+
statement += options.join(", ");
|
12345
|
+
statement += ");";
|
12346
|
+
return statement;
|
12347
|
+
}
|
12348
|
+
};
|
12349
|
+
PgAlterViewAlterTablespaceConvertor = class extends Convertor {
|
12350
|
+
can(statement, dialect4) {
|
12351
|
+
return statement.type === "alter_view_alter_tablespace" && dialect4 === "postgresql";
|
12352
|
+
}
|
12353
|
+
convert(st) {
|
12354
|
+
const { schema: schema4, name: name2, toTablespace } = st;
|
12355
|
+
const statement = `ALTER MATERIALIZED VIEW "${schema4}"."${name2}" SET TABLESPACE ${toTablespace};`;
|
12356
|
+
return statement;
|
12357
|
+
}
|
12358
|
+
};
|
12359
|
+
PgAlterViewAlterUsingConvertor = class extends Convertor {
|
12360
|
+
can(statement, dialect4) {
|
12361
|
+
return statement.type === "alter_view_alter_using" && dialect4 === "postgresql";
|
12362
|
+
}
|
12363
|
+
convert(st) {
|
12364
|
+
const { schema: schema4, name: name2, toUsing } = st;
|
12365
|
+
const statement = `ALTER MATERIALIZED VIEW "${schema4}"."${name2}" SET ACCESS METHOD "${toUsing}";`;
|
12366
|
+
return statement;
|
12367
|
+
}
|
12368
|
+
};
|
11896
12369
|
PgAlterTableAlterColumnSetGenerated = class extends Convertor {
|
11897
12370
|
can(statement, dialect4) {
|
11898
12371
|
return statement.type === "alter_table_alter_column_set_identity" && dialect4 === "postgresql";
|
@@ -11984,6 +12457,25 @@ var init_sqlgenerator = __esm({
|
|
11984
12457
|
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${unsquashed.name}";`;
|
11985
12458
|
}
|
11986
12459
|
};
|
12460
|
+
PgAlterTableAddCheckConstraintConvertor = class extends Convertor {
|
12461
|
+
can(statement, dialect4) {
|
12462
|
+
return statement.type === "create_check_constraint" && dialect4 === "postgresql";
|
12463
|
+
}
|
12464
|
+
convert(statement) {
|
12465
|
+
const unsquashed = PgSquasher.unsquashCheck(statement.data);
|
12466
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
12467
|
+
return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" CHECK (${unsquashed.value});`;
|
12468
|
+
}
|
12469
|
+
};
|
12470
|
+
PgAlterTableDeleteCheckConstraintConvertor = class extends Convertor {
|
12471
|
+
can(statement, dialect4) {
|
12472
|
+
return statement.type === "delete_check_constraint" && dialect4 === "postgresql";
|
12473
|
+
}
|
12474
|
+
convert(statement) {
|
12475
|
+
const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
|
12476
|
+
return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${statement.constraintName}";`;
|
12477
|
+
}
|
12478
|
+
};
|
11987
12479
|
MySQLAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
11988
12480
|
can(statement, dialect4) {
|
11989
12481
|
return statement.type === "create_unique_constraint" && dialect4 === "mysql";
|
@@ -12002,6 +12494,25 @@ var init_sqlgenerator = __esm({
|
|
12002
12494
|
return `ALTER TABLE \`${statement.tableName}\` DROP INDEX \`${unsquashed.name}\`;`;
|
12003
12495
|
}
|
12004
12496
|
};
|
12497
|
+
MySqlAlterTableAddCheckConstraintConvertor = class extends Convertor {
|
12498
|
+
can(statement, dialect4) {
|
12499
|
+
return statement.type === "create_check_constraint" && dialect4 === "mysql";
|
12500
|
+
}
|
12501
|
+
convert(statement) {
|
12502
|
+
const unsquashed = MySqlSquasher.unsquashCheck(statement.data);
|
12503
|
+
const { tableName } = statement;
|
12504
|
+
return `ALTER TABLE \`${tableName}\` ADD CONSTRAINT \`${unsquashed.name}\` CHECK (${unsquashed.value});`;
|
12505
|
+
}
|
12506
|
+
};
|
12507
|
+
MySqlAlterTableDeleteCheckConstraintConvertor = class extends Convertor {
|
12508
|
+
can(statement, dialect4) {
|
12509
|
+
return statement.type === "delete_check_constraint" && dialect4 === "mysql";
|
12510
|
+
}
|
12511
|
+
convert(statement) {
|
12512
|
+
const { tableName } = statement;
|
12513
|
+
return `ALTER TABLE \`${tableName}\` DROP CONSTRAINT \`${statement.constraintName}\`;`;
|
12514
|
+
}
|
12515
|
+
};
|
12005
12516
|
CreatePgSequenceConvertor = class extends Convertor {
|
12006
12517
|
can(statement, dialect4) {
|
12007
12518
|
return statement.type === "create_sequence" && dialect4 === "postgresql";
|
@@ -12605,7 +13116,7 @@ var init_sqlgenerator = __esm({
|
|
12605
13116
|
};
|
12606
13117
|
LibSQLModifyColumn = class extends Convertor {
|
12607
13118
|
can(statement, dialect4) {
|
12608
|
-
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";
|
13119
|
+
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";
|
12609
13120
|
}
|
12610
13121
|
convert(statement, json22) {
|
12611
13122
|
const { tableName, columnName } = statement;
|
@@ -13192,18 +13703,22 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13192
13703
|
return statement.type === "recreate_table" && dialect4 === "sqlite";
|
13193
13704
|
}
|
13194
13705
|
convert(statement) {
|
13195
|
-
const { tableName, columns, compositePKs, referenceData } = statement;
|
13706
|
+
const { tableName, columns, compositePKs, referenceData, checkConstraints } = statement;
|
13196
13707
|
const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
|
13197
13708
|
const newTableName = `__new_${tableName}`;
|
13198
13709
|
const sqlStatements = [];
|
13199
13710
|
sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
|
13711
|
+
const mappedCheckConstraints = checkConstraints.map(
|
13712
|
+
(it) => it.replaceAll(`"${tableName}".`, `"${newTableName}".`).replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`).replaceAll(`${tableName}.`, `${newTableName}.`).replaceAll(`'${tableName}'.`, `'${newTableName}'.`)
|
13713
|
+
);
|
13200
13714
|
sqlStatements.push(
|
13201
13715
|
new SQLiteCreateTableConvertor().convert({
|
13202
13716
|
type: "sqlite_create_table",
|
13203
13717
|
tableName: newTableName,
|
13204
13718
|
columns,
|
13205
13719
|
referenceData,
|
13206
|
-
compositePKs
|
13720
|
+
compositePKs,
|
13721
|
+
checkConstraints: mappedCheckConstraints
|
13207
13722
|
})
|
13208
13723
|
);
|
13209
13724
|
sqlStatements.push(
|
@@ -13234,10 +13749,13 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13234
13749
|
return statement.type === "recreate_table" && dialect4 === "turso";
|
13235
13750
|
}
|
13236
13751
|
convert(statement) {
|
13237
|
-
const { tableName, columns, compositePKs, referenceData } = statement;
|
13752
|
+
const { tableName, columns, compositePKs, referenceData, checkConstraints } = statement;
|
13238
13753
|
const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
|
13239
13754
|
const newTableName = `__new_${tableName}`;
|
13240
13755
|
const sqlStatements = [];
|
13756
|
+
const mappedCheckConstraints = checkConstraints.map(
|
13757
|
+
(it) => it.replaceAll(`"${tableName}".`, `"${newTableName}".`).replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`).replaceAll(`${tableName}.`, `${newTableName}.`).replaceAll(`'${tableName}'.`, `\`${newTableName}\`.`)
|
13758
|
+
);
|
13241
13759
|
sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
|
13242
13760
|
sqlStatements.push(
|
13243
13761
|
new SQLiteCreateTableConvertor().convert({
|
@@ -13245,7 +13763,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13245
13763
|
tableName: newTableName,
|
13246
13764
|
columns,
|
13247
13765
|
referenceData,
|
13248
|
-
compositePKs
|
13766
|
+
compositePKs,
|
13767
|
+
checkConstraints: mappedCheckConstraints
|
13249
13768
|
})
|
13250
13769
|
);
|
13251
13770
|
sqlStatements.push(
|
@@ -13277,6 +13796,20 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13277
13796
|
convertors.push(new SQLiteCreateTableConvertor());
|
13278
13797
|
convertors.push(new SQLiteRecreateTableConvertor());
|
13279
13798
|
convertors.push(new LibSQLRecreateTableConvertor());
|
13799
|
+
convertors.push(new PgCreateViewConvertor());
|
13800
|
+
convertors.push(new PgDropViewConvertor());
|
13801
|
+
convertors.push(new PgRenameViewConvertor());
|
13802
|
+
convertors.push(new PgAlterViewSchemaConvertor());
|
13803
|
+
convertors.push(new PgAlterViewAddWithOptionConvertor());
|
13804
|
+
convertors.push(new PgAlterViewDropWithOptionConvertor());
|
13805
|
+
convertors.push(new PgAlterViewAlterTablespaceConvertor());
|
13806
|
+
convertors.push(new PgAlterViewAlterUsingConvertor());
|
13807
|
+
convertors.push(new MySqlCreateViewConvertor());
|
13808
|
+
convertors.push(new MySqlDropViewConvertor());
|
13809
|
+
convertors.push(new MySqlRenameViewConvertor());
|
13810
|
+
convertors.push(new MySqlAlterViewConvertor());
|
13811
|
+
convertors.push(new SqliteCreateViewConvertor());
|
13812
|
+
convertors.push(new SqliteDropViewConvertor());
|
13280
13813
|
convertors.push(new CreateTypeEnumConvertor());
|
13281
13814
|
convertors.push(new DropTypeEnumConvertor());
|
13282
13815
|
convertors.push(new AlterTypeAddValueConvertor());
|
@@ -13306,6 +13839,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13306
13839
|
convertors.push(new PgAlterTableAlterColumnSetTypeConvertor());
|
13307
13840
|
convertors.push(new PgAlterTableAddUniqueConstraintConvertor());
|
13308
13841
|
convertors.push(new PgAlterTableDropUniqueConstraintConvertor());
|
13842
|
+
convertors.push(new PgAlterTableAddCheckConstraintConvertor());
|
13843
|
+
convertors.push(new PgAlterTableDeleteCheckConstraintConvertor());
|
13844
|
+
convertors.push(new MySqlAlterTableAddCheckConstraintConvertor());
|
13845
|
+
convertors.push(new MySqlAlterTableDeleteCheckConstraintConvertor());
|
13309
13846
|
convertors.push(new MySQLAlterTableAddUniqueConstraintConvertor());
|
13310
13847
|
convertors.push(new MySQLAlterTableDropUniqueConstraintConvertor());
|
13311
13848
|
convertors.push(new CreatePgIndexConvertor());
|
@@ -13395,6 +13932,10 @@ var init_sqlitePushUtils = __esm({
|
|
13395
13932
|
const compositePKs = Object.values(
|
13396
13933
|
json3.tables[tableName].compositePrimaryKeys
|
13397
13934
|
).map((it) => SQLiteSquasher.unsquashPK(it));
|
13935
|
+
const checkConstraints = Object.values(json3.tables[tableName].checkConstraints);
|
13936
|
+
const mappedCheckConstraints = checkConstraints.map(
|
13937
|
+
(it) => it.replaceAll(`"${tableName}".`, `"${newTableName}".`).replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`).replaceAll(`${tableName}.`, `${newTableName}.`).replaceAll(`'${tableName}'.`, `\`${newTableName}\`.`)
|
13938
|
+
);
|
13398
13939
|
const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
|
13399
13940
|
statements.push(
|
13400
13941
|
new SQLiteCreateTableConvertor().convert({
|
@@ -13402,7 +13943,8 @@ var init_sqlitePushUtils = __esm({
|
|
13402
13943
|
tableName: newTableName,
|
13403
13944
|
columns: tableColumns,
|
13404
13945
|
referenceData: fks,
|
13405
|
-
compositePKs
|
13946
|
+
compositePKs,
|
13947
|
+
checkConstraints: mappedCheckConstraints
|
13406
13948
|
})
|
13407
13949
|
);
|
13408
13950
|
if (!dataLoss) {
|
@@ -13614,7 +14156,7 @@ var init_sqlitePushUtils = __esm({
|
|
13614
14156
|
});
|
13615
14157
|
|
13616
14158
|
// src/jsonStatements.ts
|
13617
|
-
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;
|
14159
|
+
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, preparePgCreateViewJson, prepareMySqlCreateViewJson, prepareSqliteCreateViewJson, prepareDropViewJson, prepareRenameViewJson, preparePgAlterViewAlterSchemaJson, preparePgAlterViewAddWithOptionJson, preparePgAlterViewDropWithOptionJson, preparePgAlterViewAlterTablespaceJson, preparePgAlterViewAlterUsingJson, prepareMySqlAlterView;
|
13618
14160
|
var init_jsonStatements = __esm({
|
13619
14161
|
"src/jsonStatements.ts"() {
|
13620
14162
|
"use strict";
|
@@ -13625,7 +14167,7 @@ var init_jsonStatements = __esm({
|
|
13625
14167
|
init_pgSchema();
|
13626
14168
|
init_sqliteSchema();
|
13627
14169
|
preparePgCreateTableJson = (table4, json22) => {
|
13628
|
-
const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
14170
|
+
const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints, checkConstraints } = table4;
|
13629
14171
|
const tableKey2 = `${schema4 || "public"}.${name2}`;
|
13630
14172
|
const compositePkName = Object.values(compositePrimaryKeys).length > 0 ? json22.tables[tableKey2].compositePrimaryKeys[`${PgSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name}`].name : "";
|
13631
14173
|
return {
|
@@ -13635,11 +14177,12 @@ var init_jsonStatements = __esm({
|
|
13635
14177
|
columns: Object.values(columns),
|
13636
14178
|
compositePKs: Object.values(compositePrimaryKeys),
|
13637
14179
|
compositePkName,
|
13638
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
14180
|
+
uniqueConstraints: Object.values(uniqueConstraints),
|
14181
|
+
checkConstraints: Object.values(checkConstraints)
|
13639
14182
|
};
|
13640
14183
|
};
|
13641
14184
|
prepareMySqlCreateTableJson = (table4, json22, internals) => {
|
13642
|
-
const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
14185
|
+
const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints, checkConstraints } = table4;
|
13643
14186
|
return {
|
13644
14187
|
type: "create_table",
|
13645
14188
|
tableName: name2,
|
@@ -13648,11 +14191,12 @@ var init_jsonStatements = __esm({
|
|
13648
14191
|
compositePKs: Object.values(compositePrimaryKeys),
|
13649
14192
|
compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json22.tables[name2].compositePrimaryKeys[MySqlSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name].name : "",
|
13650
14193
|
uniqueConstraints: Object.values(uniqueConstraints),
|
13651
|
-
internals
|
14194
|
+
internals,
|
14195
|
+
checkConstraints: Object.values(checkConstraints)
|
13652
14196
|
};
|
13653
14197
|
};
|
13654
14198
|
prepareSQLiteCreateTable = (table4, action) => {
|
13655
|
-
const { name: name2, columns, uniqueConstraints } = table4;
|
14199
|
+
const { name: name2, columns, uniqueConstraints, checkConstraints } = table4;
|
13656
14200
|
const references2 = Object.values(table4.foreignKeys);
|
13657
14201
|
const composites = Object.values(table4.compositePrimaryKeys).map(
|
13658
14202
|
(it) => SQLiteSquasher.unsquashPK(it)
|
@@ -13666,7 +14210,8 @@ var init_jsonStatements = __esm({
|
|
13666
14210
|
columns: Object.values(columns),
|
13667
14211
|
referenceData: fks,
|
13668
14212
|
compositePKs: composites,
|
13669
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
14213
|
+
uniqueConstraints: Object.values(uniqueConstraints),
|
14214
|
+
checkConstraints: Object.values(checkConstraints)
|
13670
14215
|
};
|
13671
14216
|
};
|
13672
14217
|
prepareDropTableJson = (table4) => {
|
@@ -14930,6 +15475,26 @@ var init_jsonStatements = __esm({
|
|
14930
15475
|
};
|
14931
15476
|
});
|
14932
15477
|
};
|
15478
|
+
prepareAddCheckConstraint = (tableName, schema4, check) => {
|
15479
|
+
return Object.values(check).map((it) => {
|
15480
|
+
return {
|
15481
|
+
type: "create_check_constraint",
|
15482
|
+
tableName,
|
15483
|
+
data: it,
|
15484
|
+
schema: schema4
|
15485
|
+
};
|
15486
|
+
});
|
15487
|
+
};
|
15488
|
+
prepareDeleteCheckConstraint = (tableName, schema4, check) => {
|
15489
|
+
return Object.values(check).map((it) => {
|
15490
|
+
return {
|
15491
|
+
type: "delete_check_constraint",
|
15492
|
+
tableName,
|
15493
|
+
constraintName: PgSquasher.unsquashCheck(it).name,
|
15494
|
+
schema: schema4
|
15495
|
+
};
|
15496
|
+
});
|
15497
|
+
};
|
14933
15498
|
prepareAddCompositePrimaryKeyMySql = (tableName, pks, json1, json22) => {
|
14934
15499
|
const res = [];
|
14935
15500
|
for (const it of Object.values(pks)) {
|
@@ -14968,6 +15533,103 @@ var init_jsonStatements = __esm({
|
|
14968
15533
|
};
|
14969
15534
|
});
|
14970
15535
|
};
|
15536
|
+
preparePgCreateViewJson = (name2, schema4, definition, materialized, withNoData = false, withOption, using, tablespace) => {
|
15537
|
+
return {
|
15538
|
+
type: "create_view",
|
15539
|
+
name: name2,
|
15540
|
+
schema: schema4,
|
15541
|
+
definition,
|
15542
|
+
with: withOption,
|
15543
|
+
materialized,
|
15544
|
+
withNoData,
|
15545
|
+
using,
|
15546
|
+
tablespace
|
15547
|
+
};
|
15548
|
+
};
|
15549
|
+
prepareMySqlCreateViewJson = (name2, definition, meta, replace = false) => {
|
15550
|
+
const { algorithm, sqlSecurity, withCheckOption } = MySqlSquasher.unsquashView(meta);
|
15551
|
+
return {
|
15552
|
+
type: "mysql_create_view",
|
15553
|
+
name: name2,
|
15554
|
+
definition,
|
15555
|
+
algorithm,
|
15556
|
+
sqlSecurity,
|
15557
|
+
withCheckOption,
|
15558
|
+
replace
|
15559
|
+
};
|
15560
|
+
};
|
15561
|
+
prepareSqliteCreateViewJson = (name2, definition) => {
|
15562
|
+
return {
|
15563
|
+
type: "sqlite_create_view",
|
15564
|
+
name: name2,
|
15565
|
+
definition
|
15566
|
+
};
|
15567
|
+
};
|
15568
|
+
prepareDropViewJson = (name2, schema4, materialized) => {
|
15569
|
+
const resObject = { name: name2, type: "drop_view" };
|
15570
|
+
if (schema4) resObject["schema"] = schema4;
|
15571
|
+
if (materialized) resObject["materialized"] = materialized;
|
15572
|
+
return resObject;
|
15573
|
+
};
|
15574
|
+
prepareRenameViewJson = (to, from, schema4, materialized) => {
|
15575
|
+
const resObject = {
|
15576
|
+
type: "rename_view",
|
15577
|
+
nameTo: to,
|
15578
|
+
nameFrom: from
|
15579
|
+
};
|
15580
|
+
if (schema4) resObject["schema"] = schema4;
|
15581
|
+
if (materialized) resObject["materialized"] = materialized;
|
15582
|
+
return resObject;
|
15583
|
+
};
|
15584
|
+
preparePgAlterViewAlterSchemaJson = (to, from, name2, materialized) => {
|
15585
|
+
const returnObject = {
|
15586
|
+
type: "alter_view_alter_schema",
|
15587
|
+
fromSchema: from,
|
15588
|
+
toSchema: to,
|
15589
|
+
name: name2
|
15590
|
+
};
|
15591
|
+
if (materialized) returnObject["materialized"] = materialized;
|
15592
|
+
return returnObject;
|
15593
|
+
};
|
15594
|
+
preparePgAlterViewAddWithOptionJson = (name2, schema4, materialized, withOption) => {
|
15595
|
+
return {
|
15596
|
+
type: "alter_view_add_with_option",
|
15597
|
+
name: name2,
|
15598
|
+
schema: schema4,
|
15599
|
+
materialized,
|
15600
|
+
with: withOption
|
15601
|
+
};
|
15602
|
+
};
|
15603
|
+
preparePgAlterViewDropWithOptionJson = (name2, schema4, materialized, withOption) => {
|
15604
|
+
return {
|
15605
|
+
type: "alter_view_drop_with_option",
|
15606
|
+
name: name2,
|
15607
|
+
schema: schema4,
|
15608
|
+
materialized,
|
15609
|
+
with: withOption
|
15610
|
+
};
|
15611
|
+
};
|
15612
|
+
preparePgAlterViewAlterTablespaceJson = (name2, schema4, materialized, to) => {
|
15613
|
+
return {
|
15614
|
+
type: "alter_view_alter_tablespace",
|
15615
|
+
name: name2,
|
15616
|
+
schema: schema4,
|
15617
|
+
materialized,
|
15618
|
+
toTablespace: to
|
15619
|
+
};
|
15620
|
+
};
|
15621
|
+
preparePgAlterViewAlterUsingJson = (name2, schema4, materialized, to) => {
|
15622
|
+
return {
|
15623
|
+
type: "alter_view_alter_using",
|
15624
|
+
name: name2,
|
15625
|
+
schema: schema4,
|
15626
|
+
materialized,
|
15627
|
+
toUsing: to
|
15628
|
+
};
|
15629
|
+
};
|
15630
|
+
prepareMySqlAlterView = (view4) => {
|
15631
|
+
return { type: "alter_mysql_view", ...view4 };
|
15632
|
+
};
|
14971
15633
|
}
|
14972
15634
|
});
|
14973
15635
|
|
@@ -14979,7 +15641,7 @@ var init_statementCombiner = __esm({
|
|
14979
15641
|
init_jsonStatements();
|
14980
15642
|
init_sqliteSchema();
|
14981
15643
|
prepareLibSQLRecreateTable = (table4, action) => {
|
14982
|
-
const { name: name2, columns, uniqueConstraints, indexes } = table4;
|
15644
|
+
const { name: name2, columns, uniqueConstraints, indexes, checkConstraints } = table4;
|
14983
15645
|
const composites = Object.values(table4.compositePrimaryKeys).map(
|
14984
15646
|
(it) => SQLiteSquasher.unsquashPK(it)
|
14985
15647
|
);
|
@@ -14994,7 +15656,8 @@ var init_statementCombiner = __esm({
|
|
14994
15656
|
columns: Object.values(columns),
|
14995
15657
|
compositePKs: composites,
|
14996
15658
|
referenceData: fks,
|
14997
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
15659
|
+
uniqueConstraints: Object.values(uniqueConstraints),
|
15660
|
+
checkConstraints: Object.values(checkConstraints)
|
14998
15661
|
}
|
14999
15662
|
];
|
15000
15663
|
if (Object.keys(indexes).length) {
|
@@ -15003,7 +15666,7 @@ var init_statementCombiner = __esm({
|
|
15003
15666
|
return statements;
|
15004
15667
|
};
|
15005
15668
|
prepareSQLiteRecreateTable = (table4, action) => {
|
15006
|
-
const { name: name2, columns, uniqueConstraints, indexes } = table4;
|
15669
|
+
const { name: name2, columns, uniqueConstraints, indexes, checkConstraints } = table4;
|
15007
15670
|
const composites = Object.values(table4.compositePrimaryKeys).map(
|
15008
15671
|
(it) => SQLiteSquasher.unsquashPK(it)
|
15009
15672
|
);
|
@@ -15018,7 +15681,8 @@ var init_statementCombiner = __esm({
|
|
15018
15681
|
columns: Object.values(columns),
|
15019
15682
|
compositePKs: composites,
|
15020
15683
|
referenceData: fks,
|
15021
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
15684
|
+
uniqueConstraints: Object.values(uniqueConstraints),
|
15685
|
+
checkConstraints: Object.values(checkConstraints)
|
15022
15686
|
}
|
15023
15687
|
];
|
15024
15688
|
if (Object.keys(indexes).length) {
|
@@ -15029,7 +15693,7 @@ var init_statementCombiner = __esm({
|
|
15029
15693
|
libSQLCombineStatements = (statements, json22, action) => {
|
15030
15694
|
const newStatements = {};
|
15031
15695
|
for (const statement of statements) {
|
15032
|
-
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") {
|
15696
|
+
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") {
|
15033
15697
|
const tableName2 = statement.tableName;
|
15034
15698
|
const statementsForTable2 = newStatements[tableName2];
|
15035
15699
|
if (!statementsForTable2) {
|
@@ -15170,16 +15834,16 @@ var init_statementCombiner = __esm({
|
|
15170
15834
|
sqliteCombineStatements = (statements, json22, action) => {
|
15171
15835
|
const newStatements = {};
|
15172
15836
|
for (const statement of statements) {
|
15173
|
-
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") {
|
15837
|
+
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") {
|
15174
15838
|
const tableName2 = statement.tableName;
|
15175
15839
|
const statementsForTable2 = newStatements[tableName2];
|
15176
15840
|
if (!statementsForTable2) {
|
15177
|
-
newStatements[tableName2] =
|
15841
|
+
newStatements[tableName2] = prepareSQLiteRecreateTable(json22.tables[tableName2], action);
|
15178
15842
|
continue;
|
15179
15843
|
}
|
15180
15844
|
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15181
15845
|
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15182
|
-
const preparedStatements =
|
15846
|
+
const preparedStatements = prepareSQLiteRecreateTable(json22.tables[tableName2], action);
|
15183
15847
|
if (wasRename) {
|
15184
15848
|
newStatements[tableName2].push(...preparedStatements);
|
15185
15849
|
} else {
|
@@ -15193,12 +15857,12 @@ var init_statementCombiner = __esm({
|
|
15193
15857
|
const tableName2 = statement.tableName;
|
15194
15858
|
const statementsForTable2 = newStatements[tableName2];
|
15195
15859
|
if (!statementsForTable2) {
|
15196
|
-
newStatements[tableName2] =
|
15860
|
+
newStatements[tableName2] = prepareSQLiteRecreateTable(json22.tables[tableName2], action);
|
15197
15861
|
continue;
|
15198
15862
|
}
|
15199
15863
|
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15200
15864
|
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15201
|
-
const preparedStatements =
|
15865
|
+
const preparedStatements = prepareSQLiteRecreateTable(json22.tables[tableName2], action);
|
15202
15866
|
if (wasRename) {
|
15203
15867
|
newStatements[tableName2].push(...preparedStatements);
|
15204
15868
|
} else {
|
@@ -15223,7 +15887,7 @@ var init_statementCombiner = __esm({
|
|
15223
15887
|
}
|
15224
15888
|
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15225
15889
|
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15226
|
-
const preparedStatements =
|
15890
|
+
const preparedStatements = prepareSQLiteRecreateTable(json22.tables[tableName2], action);
|
15227
15891
|
if (wasRename) {
|
15228
15892
|
newStatements[tableName2].push(...preparedStatements);
|
15229
15893
|
} else {
|
@@ -15255,6 +15919,7 @@ var init_statementCombiner = __esm({
|
|
15255
15919
|
// src/snapshotsDiffer.ts
|
15256
15920
|
var snapshotsDiffer_exports = {};
|
15257
15921
|
__export(snapshotsDiffer_exports, {
|
15922
|
+
alteredPgViewSchema: () => alteredPgViewSchema,
|
15258
15923
|
alteredTableScheme: () => alteredTableScheme,
|
15259
15924
|
applyLibSQLSnapshotsDiff: () => applyLibSQLSnapshotsDiff,
|
15260
15925
|
applyMysqlSnapshotsDiff: () => applyMysqlSnapshotsDiff,
|
@@ -15266,7 +15931,7 @@ __export(snapshotsDiffer_exports, {
|
|
15266
15931
|
makePatched: () => makePatched,
|
15267
15932
|
makeSelfOrPatched: () => makeSelfOrPatched
|
15268
15933
|
});
|
15269
|
-
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
|
15934
|
+
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, alteredViewCommon, alteredPgViewSchema, alteredMySqlViewSchema, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
|
15270
15935
|
var init_snapshotsDiffer = __esm({
|
15271
15936
|
"src/snapshotsDiffer.ts"() {
|
15272
15937
|
"use strict";
|
@@ -15392,7 +16057,8 @@ var init_snapshotsDiffer = __esm({
|
|
15392
16057
|
indexes: recordType(stringType(), stringType()),
|
15393
16058
|
foreignKeys: recordType(stringType(), stringType()),
|
15394
16059
|
compositePrimaryKeys: recordType(stringType(), stringType()).default({}),
|
15395
|
-
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
16060
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({}),
|
16061
|
+
checkConstraints: recordType(stringType(), stringType()).default({})
|
15396
16062
|
}).strict();
|
15397
16063
|
alteredTableScheme = objectType({
|
15398
16064
|
name: stringType(),
|
@@ -15433,20 +16099,79 @@ var init_snapshotsDiffer = __esm({
|
|
15433
16099
|
__new: stringType(),
|
15434
16100
|
__old: stringType()
|
15435
16101
|
})
|
16102
|
+
),
|
16103
|
+
addedCheckConstraints: recordType(
|
16104
|
+
stringType(),
|
16105
|
+
stringType()
|
16106
|
+
),
|
16107
|
+
deletedCheckConstraints: recordType(
|
16108
|
+
stringType(),
|
16109
|
+
stringType()
|
16110
|
+
),
|
16111
|
+
alteredCheckConstraints: recordType(
|
16112
|
+
stringType(),
|
16113
|
+
objectType({
|
16114
|
+
__new: stringType(),
|
16115
|
+
__old: stringType()
|
16116
|
+
})
|
15436
16117
|
)
|
15437
16118
|
}).strict();
|
16119
|
+
alteredViewCommon = objectType({
|
16120
|
+
name: stringType(),
|
16121
|
+
alteredDefinition: objectType({
|
16122
|
+
__old: stringType(),
|
16123
|
+
__new: stringType()
|
16124
|
+
}).strict().optional(),
|
16125
|
+
alteredExisting: objectType({
|
16126
|
+
__old: booleanType(),
|
16127
|
+
__new: booleanType()
|
16128
|
+
}).strict().optional()
|
16129
|
+
});
|
16130
|
+
alteredPgViewSchema = alteredViewCommon.merge(
|
16131
|
+
objectType({
|
16132
|
+
schema: stringType(),
|
16133
|
+
deletedWithOption: mergedViewWithOption.optional(),
|
16134
|
+
addedWithOption: mergedViewWithOption.optional(),
|
16135
|
+
addedWith: mergedViewWithOption.optional(),
|
16136
|
+
deletedWith: mergedViewWithOption.optional(),
|
16137
|
+
alteredWith: mergedViewWithOption.optional(),
|
16138
|
+
alteredSchema: objectType({
|
16139
|
+
__old: stringType(),
|
16140
|
+
__new: stringType()
|
16141
|
+
}).strict().optional(),
|
16142
|
+
alteredTablespace: objectType({
|
16143
|
+
__old: stringType(),
|
16144
|
+
__new: stringType()
|
16145
|
+
}).strict().optional(),
|
16146
|
+
alteredUsing: objectType({
|
16147
|
+
__old: stringType(),
|
16148
|
+
__new: stringType()
|
16149
|
+
}).strict().optional()
|
16150
|
+
}).strict()
|
16151
|
+
);
|
16152
|
+
alteredMySqlViewSchema = alteredViewCommon.merge(
|
16153
|
+
objectType({
|
16154
|
+
alteredMeta: objectType({
|
16155
|
+
__old: stringType(),
|
16156
|
+
__new: stringType()
|
16157
|
+
}).strict().optional()
|
16158
|
+
}).strict()
|
16159
|
+
);
|
15438
16160
|
diffResultScheme = objectType({
|
15439
16161
|
alteredTablesWithColumns: alteredTableScheme.array(),
|
15440
16162
|
alteredEnums: changedEnumSchema.array(),
|
15441
|
-
alteredSequences: sequenceSquashed.array()
|
16163
|
+
alteredSequences: sequenceSquashed.array(),
|
16164
|
+
alteredViews: alteredPgViewSchema.array()
|
15442
16165
|
}).strict();
|
15443
16166
|
diffResultSchemeMysql = objectType({
|
15444
16167
|
alteredTablesWithColumns: alteredTableScheme.array(),
|
15445
|
-
alteredEnums: neverType().array()
|
16168
|
+
alteredEnums: neverType().array(),
|
16169
|
+
alteredViews: alteredMySqlViewSchema.array()
|
15446
16170
|
});
|
15447
16171
|
diffResultSchemeSQLite = objectType({
|
15448
16172
|
alteredTablesWithColumns: alteredTableScheme.array(),
|
15449
|
-
alteredEnums: neverType().array()
|
16173
|
+
alteredEnums: neverType().array(),
|
16174
|
+
alteredViews: alteredViewCommon.array()
|
15450
16175
|
});
|
15451
16176
|
schemaChangeFor = (table4, renamedSchemas) => {
|
15452
16177
|
for (let ren of renamedSchemas) {
|
@@ -15493,7 +16218,7 @@ var init_snapshotsDiffer = __esm({
|
|
15493
16218
|
}
|
15494
16219
|
return column4;
|
15495
16220
|
};
|
15496
|
-
applyPgSnapshotsDiff = async (json1, json22, schemasResolver2, enumsResolver2, sequencesResolver2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
16221
|
+
applyPgSnapshotsDiff = async (json1, json22, schemasResolver2, enumsResolver2, sequencesResolver2, tablesResolver2, columnsResolver2, viewsResolver2, prevFull, curFull, action) => {
|
15497
16222
|
const schemasDiff = diffSchemasOrTables(json1.schemas, json22.schemas);
|
15498
16223
|
const {
|
15499
16224
|
created: createdSchemas,
|
@@ -15721,7 +16446,39 @@ var init_snapshotsDiffer = __esm({
|
|
15721
16446
|
return [tableKey2, tableValue];
|
15722
16447
|
}
|
15723
16448
|
);
|
15724
|
-
const
|
16449
|
+
const viewsDiff = diffSchemasOrTables(json1.views, json22.views);
|
16450
|
+
const {
|
16451
|
+
created: createdViews,
|
16452
|
+
deleted: deletedViews,
|
16453
|
+
renamed: renamedViews,
|
16454
|
+
moved: movedViews
|
16455
|
+
} = await viewsResolver2({
|
16456
|
+
created: viewsDiff.added,
|
16457
|
+
deleted: viewsDiff.deleted
|
16458
|
+
});
|
16459
|
+
const renamesViewDic = {};
|
16460
|
+
renamedViews.forEach((it) => {
|
16461
|
+
renamesViewDic[`${it.from.schema}.${it.from.name}`] = { to: it.to.name, from: it.from.name };
|
16462
|
+
});
|
16463
|
+
const movedViewDic = {};
|
16464
|
+
movedViews.forEach((it) => {
|
16465
|
+
movedViewDic[`${it.schemaFrom}.${it.name}`] = { to: it.schemaTo, from: it.schemaFrom };
|
16466
|
+
});
|
16467
|
+
const viewsPatchedSnap1 = copy(columnsPatchedSnap1);
|
16468
|
+
viewsPatchedSnap1.views = mapEntries(
|
16469
|
+
viewsPatchedSnap1.views,
|
16470
|
+
(viewKey, viewValue) => {
|
16471
|
+
const rename = renamesViewDic[`${viewValue.schema}.${viewValue.name}`];
|
16472
|
+
const moved = movedViewDic[`${viewValue.schema}.${viewValue.name}`];
|
16473
|
+
if (rename) {
|
16474
|
+
viewValue.name = rename.to;
|
16475
|
+
viewKey = `${viewValue.schema}.${viewValue.name}`;
|
16476
|
+
}
|
16477
|
+
if (moved) viewKey = `${moved.to}.${viewValue.name}`;
|
16478
|
+
return [viewKey, viewValue];
|
16479
|
+
}
|
16480
|
+
);
|
16481
|
+
const diffResult = applyJsonDiff(viewsPatchedSnap1, json22);
|
15725
16482
|
const typedResult = diffResultScheme.parse(diffResult);
|
15726
16483
|
const jsonStatements = [];
|
15727
16484
|
const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
|
@@ -15773,6 +16530,8 @@ var init_snapshotsDiffer = __esm({
|
|
15773
16530
|
schemaTo: it.schemaTo || "public"
|
15774
16531
|
});
|
15775
16532
|
}
|
16533
|
+
const jsonDeletedCheckConstraints = [];
|
16534
|
+
const jsonCreatedCheckConstraints = [];
|
15776
16535
|
for (let it of alteredTables) {
|
15777
16536
|
let addedColumns = [];
|
15778
16537
|
for (const addedPkName of Object.keys(it.addedCompositePKs)) {
|
@@ -15812,6 +16571,8 @@ var init_snapshotsDiffer = __esm({
|
|
15812
16571
|
let addedUniqueConstraints = [];
|
15813
16572
|
let deletedUniqueConstraints = [];
|
15814
16573
|
let alteredUniqueConstraints = [];
|
16574
|
+
let createCheckConstraints = [];
|
16575
|
+
let deleteCheckConstraints = [];
|
15815
16576
|
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
15816
16577
|
it.name,
|
15817
16578
|
it.schema,
|
@@ -15836,6 +16597,24 @@ var init_snapshotsDiffer = __esm({
|
|
15836
16597
|
...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
|
15837
16598
|
);
|
15838
16599
|
}
|
16600
|
+
createCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
|
16601
|
+
deleteCheckConstraints = prepareDeleteCheckConstraint(
|
16602
|
+
it.name,
|
16603
|
+
it.schema,
|
16604
|
+
it.deletedCheckConstraints
|
16605
|
+
);
|
16606
|
+
if (it.alteredCheckConstraints && action !== "push") {
|
16607
|
+
const added = {};
|
16608
|
+
const deleted = {};
|
16609
|
+
for (const k of Object.keys(it.alteredCheckConstraints)) {
|
16610
|
+
added[k] = it.alteredCheckConstraints[k].__new;
|
16611
|
+
deleted[k] = it.alteredCheckConstraints[k].__old;
|
16612
|
+
}
|
16613
|
+
createCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
|
16614
|
+
deleteCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
|
16615
|
+
}
|
16616
|
+
jsonCreatedCheckConstraints.push(...createCheckConstraints);
|
16617
|
+
jsonDeletedCheckConstraints.push(...deleteCheckConstraints);
|
15839
16618
|
jsonAddedCompositePKs.push(...addedCompositePKs);
|
15840
16619
|
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
15841
16620
|
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
@@ -15976,6 +16755,137 @@ var init_snapshotsDiffer = __esm({
|
|
15976
16755
|
const createTables = createdTables.map((it) => {
|
15977
16756
|
return preparePgCreateTableJson(it, curFull);
|
15978
16757
|
});
|
16758
|
+
const createViews = [];
|
16759
|
+
const dropViews = [];
|
16760
|
+
const renameViews = [];
|
16761
|
+
const alterViews = [];
|
16762
|
+
createViews.push(
|
16763
|
+
...createdViews.filter((it) => !it.isExisting).map((it) => {
|
16764
|
+
return preparePgCreateViewJson(
|
16765
|
+
it.name,
|
16766
|
+
it.schema,
|
16767
|
+
it.definition,
|
16768
|
+
it.materialized,
|
16769
|
+
it.withNoData,
|
16770
|
+
it.with,
|
16771
|
+
it.using,
|
16772
|
+
it.tablespace
|
16773
|
+
);
|
16774
|
+
})
|
16775
|
+
);
|
16776
|
+
dropViews.push(
|
16777
|
+
...deletedViews.filter((it) => !it.isExisting).map((it) => {
|
16778
|
+
return prepareDropViewJson(it.name, it.schema, it.materialized);
|
16779
|
+
})
|
16780
|
+
);
|
16781
|
+
renameViews.push(
|
16782
|
+
...renamedViews.filter((it) => !it.to.isExisting && !json1.views[`${it.from.schema}.${it.from.name}`].isExisting).map((it) => {
|
16783
|
+
return prepareRenameViewJson(it.to.name, it.from.name, it.to.schema, it.to.materialized);
|
16784
|
+
})
|
16785
|
+
);
|
16786
|
+
alterViews.push(
|
16787
|
+
...movedViews.filter(
|
16788
|
+
(it) => !json22.views[`${it.schemaTo}.${it.name}`].isExisting && !json1.views[`${it.schemaFrom}.${it.name}`].isExisting
|
16789
|
+
).map((it) => {
|
16790
|
+
return preparePgAlterViewAlterSchemaJson(
|
16791
|
+
it.schemaTo,
|
16792
|
+
it.schemaFrom,
|
16793
|
+
it.name,
|
16794
|
+
json22.views[`${it.schemaTo}.${it.name}`].materialized
|
16795
|
+
);
|
16796
|
+
})
|
16797
|
+
);
|
16798
|
+
const alteredViews = typedResult.alteredViews.filter((it) => !json22.views[`${it.schema}.${it.name}`].isExisting);
|
16799
|
+
for (const alteredView of alteredViews) {
|
16800
|
+
const viewKey = `${alteredView.schema}.${alteredView.name}`;
|
16801
|
+
const { materialized, with: withOption, definition, withNoData, using, tablespace } = json22.views[viewKey];
|
16802
|
+
if (alteredView.alteredExisting || alteredView.alteredDefinition && action !== "push") {
|
16803
|
+
dropViews.push(prepareDropViewJson(alteredView.name, alteredView.schema, materialized));
|
16804
|
+
createViews.push(
|
16805
|
+
preparePgCreateViewJson(
|
16806
|
+
alteredView.name,
|
16807
|
+
alteredView.schema,
|
16808
|
+
definition,
|
16809
|
+
materialized,
|
16810
|
+
withNoData,
|
16811
|
+
withOption,
|
16812
|
+
using,
|
16813
|
+
tablespace
|
16814
|
+
)
|
16815
|
+
);
|
16816
|
+
continue;
|
16817
|
+
}
|
16818
|
+
if (alteredView.addedWithOption) {
|
16819
|
+
alterViews.push(
|
16820
|
+
preparePgAlterViewAddWithOptionJson(
|
16821
|
+
alteredView.name,
|
16822
|
+
alteredView.schema,
|
16823
|
+
materialized,
|
16824
|
+
alteredView.addedWithOption
|
16825
|
+
)
|
16826
|
+
);
|
16827
|
+
}
|
16828
|
+
if (alteredView.deletedWithOption) {
|
16829
|
+
alterViews.push(
|
16830
|
+
preparePgAlterViewDropWithOptionJson(
|
16831
|
+
alteredView.name,
|
16832
|
+
alteredView.schema,
|
16833
|
+
materialized,
|
16834
|
+
alteredView.deletedWithOption
|
16835
|
+
)
|
16836
|
+
);
|
16837
|
+
}
|
16838
|
+
if (alteredView.addedWith) {
|
16839
|
+
alterViews.push(
|
16840
|
+
preparePgAlterViewAddWithOptionJson(
|
16841
|
+
alteredView.name,
|
16842
|
+
alteredView.schema,
|
16843
|
+
materialized,
|
16844
|
+
alteredView.addedWith
|
16845
|
+
)
|
16846
|
+
);
|
16847
|
+
}
|
16848
|
+
if (alteredView.deletedWith) {
|
16849
|
+
alterViews.push(
|
16850
|
+
preparePgAlterViewDropWithOptionJson(
|
16851
|
+
alteredView.name,
|
16852
|
+
alteredView.schema,
|
16853
|
+
materialized,
|
16854
|
+
alteredView.deletedWith
|
16855
|
+
)
|
16856
|
+
);
|
16857
|
+
}
|
16858
|
+
if (alteredView.alteredWith) {
|
16859
|
+
alterViews.push(
|
16860
|
+
preparePgAlterViewAddWithOptionJson(
|
16861
|
+
alteredView.name,
|
16862
|
+
alteredView.schema,
|
16863
|
+
materialized,
|
16864
|
+
alteredView.alteredWith
|
16865
|
+
)
|
16866
|
+
);
|
16867
|
+
}
|
16868
|
+
if (alteredView.alteredTablespace) {
|
16869
|
+
alterViews.push(
|
16870
|
+
preparePgAlterViewAlterTablespaceJson(
|
16871
|
+
alteredView.name,
|
16872
|
+
alteredView.schema,
|
16873
|
+
materialized,
|
16874
|
+
alteredView.alteredTablespace.__new
|
16875
|
+
)
|
16876
|
+
);
|
16877
|
+
}
|
16878
|
+
if (alteredView.alteredUsing) {
|
16879
|
+
alterViews.push(
|
16880
|
+
preparePgAlterViewAlterUsingJson(
|
16881
|
+
alteredView.name,
|
16882
|
+
alteredView.schema,
|
16883
|
+
materialized,
|
16884
|
+
alteredView.alteredUsing.__new
|
16885
|
+
)
|
16886
|
+
);
|
16887
|
+
}
|
16888
|
+
}
|
15979
16889
|
jsonStatements.push(...createSchemas);
|
15980
16890
|
jsonStatements.push(...renameSchemas);
|
15981
16891
|
jsonStatements.push(...createEnums);
|
@@ -15987,11 +16897,15 @@ var init_snapshotsDiffer = __esm({
|
|
15987
16897
|
jsonStatements.push(...renameSequences);
|
15988
16898
|
jsonStatements.push(...jsonAlterSequences);
|
15989
16899
|
jsonStatements.push(...createTables);
|
16900
|
+
jsonStatements.push(...dropViews);
|
16901
|
+
jsonStatements.push(...renameViews);
|
16902
|
+
jsonStatements.push(...alterViews);
|
15990
16903
|
jsonStatements.push(...jsonDropTables);
|
15991
16904
|
jsonStatements.push(...jsonSetTableSchemas);
|
15992
16905
|
jsonStatements.push(...jsonRenameTables);
|
15993
16906
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
15994
16907
|
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
16908
|
+
jsonStatements.push(...jsonDeletedCheckConstraints);
|
15995
16909
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
15996
16910
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
15997
16911
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
@@ -16005,8 +16919,10 @@ var init_snapshotsDiffer = __esm({
|
|
16005
16919
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
16006
16920
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
16007
16921
|
jsonStatements.push(...jsonAddedUniqueConstraints);
|
16922
|
+
jsonStatements.push(...jsonCreatedCheckConstraints);
|
16008
16923
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16009
16924
|
jsonStatements.push(...jsonAlterEnumsWithDroppedValues);
|
16925
|
+
jsonStatements.push(...createViews);
|
16010
16926
|
jsonStatements.push(...dropEnums);
|
16011
16927
|
jsonStatements.push(...dropSequences);
|
16012
16928
|
jsonStatements.push(...dropSchemas);
|
@@ -16058,7 +16974,7 @@ var init_snapshotsDiffer = __esm({
|
|
16058
16974
|
_meta
|
16059
16975
|
};
|
16060
16976
|
};
|
16061
|
-
applyMysqlSnapshotsDiff = async (json1, json22, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
16977
|
+
applyMysqlSnapshotsDiff = async (json1, json22, tablesResolver2, columnsResolver2, viewsResolver2, prevFull, curFull, action) => {
|
16062
16978
|
for (const tableName in json1.tables) {
|
16063
16979
|
const table4 = json1.tables[tableName];
|
16064
16980
|
for (const indexName2 in table4.indexes) {
|
@@ -16155,7 +17071,33 @@ var init_snapshotsDiffer = __esm({
|
|
16155
17071
|
return [tableKey2, tableValue];
|
16156
17072
|
}
|
16157
17073
|
);
|
16158
|
-
const
|
17074
|
+
const viewsDiff = diffSchemasOrTables(json1.views, json22.views);
|
17075
|
+
const {
|
17076
|
+
created: createdViews,
|
17077
|
+
deleted: deletedViews,
|
17078
|
+
renamed: renamedViews
|
17079
|
+
// renamed or moved
|
17080
|
+
} = await viewsResolver2({
|
17081
|
+
created: viewsDiff.added,
|
17082
|
+
deleted: viewsDiff.deleted
|
17083
|
+
});
|
17084
|
+
const renamesViewDic = {};
|
17085
|
+
renamedViews.forEach((it) => {
|
17086
|
+
renamesViewDic[it.from.name] = { to: it.to.name, from: it.from.name };
|
17087
|
+
});
|
17088
|
+
const viewsPatchedSnap1 = copy(columnsPatchedSnap1);
|
17089
|
+
viewsPatchedSnap1.views = mapEntries(
|
17090
|
+
viewsPatchedSnap1.views,
|
17091
|
+
(viewKey, viewValue) => {
|
17092
|
+
const rename = renamesViewDic[viewValue.name];
|
17093
|
+
if (rename) {
|
17094
|
+
viewValue.name = rename.to;
|
17095
|
+
viewKey = rename.to;
|
17096
|
+
}
|
17097
|
+
return [viewKey, viewValue];
|
17098
|
+
}
|
17099
|
+
);
|
17100
|
+
const diffResult = applyJsonDiff(viewsPatchedSnap1, json22);
|
16159
17101
|
const typedResult = diffResultSchemeMysql.parse(diffResult);
|
16160
17102
|
const jsonStatements = [];
|
16161
17103
|
const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
|
@@ -16179,6 +17121,8 @@ var init_snapshotsDiffer = __esm({
|
|
16179
17121
|
const jsonAddedUniqueConstraints = [];
|
16180
17122
|
const jsonDeletedUniqueConstraints = [];
|
16181
17123
|
const jsonAlteredUniqueConstraints = [];
|
17124
|
+
const jsonCreatedCheckConstraints = [];
|
17125
|
+
const jsonDeletedCheckConstraints = [];
|
16182
17126
|
const jsonRenameColumnsStatements = columnRenames.map((it) => prepareRenameColumns(it.table, "", it.renames)).flat();
|
16183
17127
|
const jsonAddColumnsStatemets = columnCreates.map((it) => _prepareAddColumns(it.table, "", it.columns)).flat();
|
16184
17128
|
const jsonDropColumnsStatemets = columnDeletes.map((it) => _prepareDropColumns(it.table, "", it.columns)).flat();
|
@@ -16217,6 +17161,8 @@ var init_snapshotsDiffer = __esm({
|
|
16217
17161
|
let addedUniqueConstraints = [];
|
16218
17162
|
let deletedUniqueConstraints = [];
|
16219
17163
|
let alteredUniqueConstraints = [];
|
17164
|
+
let createdCheckConstraints = [];
|
17165
|
+
let deletedCheckConstraints = [];
|
16220
17166
|
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
16221
17167
|
it.name,
|
16222
17168
|
it.schema,
|
@@ -16241,12 +17187,30 @@ var init_snapshotsDiffer = __esm({
|
|
16241
17187
|
...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
|
16242
17188
|
);
|
16243
17189
|
}
|
17190
|
+
createdCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
|
17191
|
+
deletedCheckConstraints = prepareDeleteCheckConstraint(
|
17192
|
+
it.name,
|
17193
|
+
it.schema,
|
17194
|
+
it.deletedCheckConstraints
|
17195
|
+
);
|
17196
|
+
if (it.alteredCheckConstraints && action !== "push") {
|
17197
|
+
const added = {};
|
17198
|
+
const deleted = {};
|
17199
|
+
for (const k of Object.keys(it.alteredCheckConstraints)) {
|
17200
|
+
added[k] = it.alteredCheckConstraints[k].__new;
|
17201
|
+
deleted[k] = it.alteredCheckConstraints[k].__old;
|
17202
|
+
}
|
17203
|
+
createdCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
|
17204
|
+
deletedCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
|
17205
|
+
}
|
16244
17206
|
jsonAddedCompositePKs.push(...addedCompositePKs);
|
16245
17207
|
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
16246
17208
|
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
16247
17209
|
jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
|
16248
17210
|
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
16249
17211
|
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
17212
|
+
jsonCreatedCheckConstraints.push(...createdCheckConstraints);
|
17213
|
+
jsonDeletedCheckConstraints.push(...deletedCheckConstraints);
|
16250
17214
|
});
|
16251
17215
|
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
16252
17216
|
const tableName = it.tableName;
|
@@ -16337,11 +17301,70 @@ var init_snapshotsDiffer = __esm({
|
|
16337
17301
|
curFull.internal
|
16338
17302
|
);
|
16339
17303
|
});
|
17304
|
+
const createViews = [];
|
17305
|
+
const dropViews = [];
|
17306
|
+
const renameViews = [];
|
17307
|
+
const alterViews = [];
|
17308
|
+
createViews.push(
|
17309
|
+
...createdViews.filter((it) => !it.isExisting).map((it) => {
|
17310
|
+
return prepareMySqlCreateViewJson(
|
17311
|
+
it.name,
|
17312
|
+
it.definition,
|
17313
|
+
it.meta
|
17314
|
+
);
|
17315
|
+
})
|
17316
|
+
);
|
17317
|
+
dropViews.push(
|
17318
|
+
...deletedViews.filter((it) => !it.isExisting).map((it) => {
|
17319
|
+
return prepareDropViewJson(it.name);
|
17320
|
+
})
|
17321
|
+
);
|
17322
|
+
renameViews.push(
|
17323
|
+
...renamedViews.filter((it) => !it.to.isExisting && !json1.views[it.from.name].isExisting).map((it) => {
|
17324
|
+
return prepareRenameViewJson(it.to.name, it.from.name);
|
17325
|
+
})
|
17326
|
+
);
|
17327
|
+
const alteredViews = typedResult.alteredViews.filter((it) => !json22.views[it.name].isExisting);
|
17328
|
+
for (const alteredView of alteredViews) {
|
17329
|
+
const { definition, meta } = json22.views[alteredView.name];
|
17330
|
+
if (alteredView.alteredExisting) {
|
17331
|
+
dropViews.push(prepareDropViewJson(alteredView.name));
|
17332
|
+
createViews.push(
|
17333
|
+
prepareMySqlCreateViewJson(
|
17334
|
+
alteredView.name,
|
17335
|
+
definition,
|
17336
|
+
meta
|
17337
|
+
)
|
17338
|
+
);
|
17339
|
+
continue;
|
17340
|
+
}
|
17341
|
+
if (alteredView.alteredDefinition && action !== "push") {
|
17342
|
+
createViews.push(
|
17343
|
+
prepareMySqlCreateViewJson(
|
17344
|
+
alteredView.name,
|
17345
|
+
definition,
|
17346
|
+
meta,
|
17347
|
+
true
|
17348
|
+
)
|
17349
|
+
);
|
17350
|
+
continue;
|
17351
|
+
}
|
17352
|
+
if (alteredView.alteredMeta) {
|
17353
|
+
const view4 = curFull["views"][alteredView.name];
|
17354
|
+
alterViews.push(
|
17355
|
+
prepareMySqlAlterView(view4)
|
17356
|
+
);
|
17357
|
+
}
|
17358
|
+
}
|
16340
17359
|
jsonStatements.push(...jsonMySqlCreateTables);
|
16341
17360
|
jsonStatements.push(...jsonDropTables);
|
16342
17361
|
jsonStatements.push(...jsonRenameTables);
|
16343
17362
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
17363
|
+
jsonStatements.push(...dropViews);
|
17364
|
+
jsonStatements.push(...renameViews);
|
17365
|
+
jsonStatements.push(...alterViews);
|
16344
17366
|
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
17367
|
+
jsonStatements.push(...jsonDeletedCheckConstraints);
|
16345
17368
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
16346
17369
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
16347
17370
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
@@ -16352,11 +17375,12 @@ var init_snapshotsDiffer = __esm({
|
|
16352
17375
|
jsonStatements.push(...jsonAddColumnsStatemets);
|
16353
17376
|
jsonStatements.push(...jsonCreateReferencesForCreatedTables);
|
16354
17377
|
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
17378
|
+
jsonStatements.push(...jsonCreatedCheckConstraints);
|
16355
17379
|
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
16356
17380
|
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
16357
17381
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
16358
17382
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
16359
|
-
jsonStatements.push(...
|
17383
|
+
jsonStatements.push(...createViews);
|
16360
17384
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16361
17385
|
const sqlStatements = fromJson(jsonStatements, "mysql");
|
16362
17386
|
const uniqueSqlStatements = [];
|
@@ -16375,7 +17399,7 @@ var init_snapshotsDiffer = __esm({
|
|
16375
17399
|
_meta
|
16376
17400
|
};
|
16377
17401
|
};
|
16378
|
-
applySqliteSnapshotsDiff = async (json1, json22, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
17402
|
+
applySqliteSnapshotsDiff = async (json1, json22, tablesResolver2, columnsResolver2, viewsResolver2, prevFull, curFull, action) => {
|
16379
17403
|
const tablesDiff = diffSchemasOrTables(json1.tables, json22.tables);
|
16380
17404
|
const {
|
16381
17405
|
created: createdTables,
|
@@ -16445,7 +17469,32 @@ var init_snapshotsDiffer = __esm({
|
|
16445
17469
|
return [tableKey2, tableValue];
|
16446
17470
|
}
|
16447
17471
|
);
|
16448
|
-
const
|
17472
|
+
const viewsDiff = diffSchemasOrTables(json1.views, json22.views);
|
17473
|
+
const {
|
17474
|
+
created: createdViews,
|
17475
|
+
deleted: deletedViews,
|
17476
|
+
renamed: renamedViews
|
17477
|
+
// renamed or moved
|
17478
|
+
} = await viewsResolver2({
|
17479
|
+
created: viewsDiff.added,
|
17480
|
+
deleted: viewsDiff.deleted
|
17481
|
+
});
|
17482
|
+
const renamesViewDic = {};
|
17483
|
+
renamedViews.forEach((it) => {
|
17484
|
+
renamesViewDic[it.from.name] = { to: it.to.name, from: it.from.name };
|
17485
|
+
});
|
17486
|
+
const viewsPatchedSnap1 = copy(columnsPatchedSnap1);
|
17487
|
+
viewsPatchedSnap1.views = mapEntries(
|
17488
|
+
viewsPatchedSnap1.views,
|
17489
|
+
(viewKey, viewValue) => {
|
17490
|
+
const rename = renamesViewDic[viewValue.name];
|
17491
|
+
if (rename) {
|
17492
|
+
viewValue.name = rename.to;
|
17493
|
+
}
|
17494
|
+
return [viewKey, viewValue];
|
17495
|
+
}
|
17496
|
+
);
|
17497
|
+
const diffResult = applyJsonDiff(viewsPatchedSnap1, json22);
|
16449
17498
|
const typedResult = diffResultSchemeSQLite.parse(diffResult);
|
16450
17499
|
const tablesMap = {};
|
16451
17500
|
typedResult.alteredTablesWithColumns.forEach((obj) => {
|
@@ -16484,6 +17533,8 @@ var init_snapshotsDiffer = __esm({
|
|
16484
17533
|
const jsonAddedUniqueConstraints = [];
|
16485
17534
|
const jsonDeletedUniqueConstraints = [];
|
16486
17535
|
const jsonAlteredUniqueConstraints = [];
|
17536
|
+
const jsonDeletedCheckConstraints = [];
|
17537
|
+
const jsonCreatedCheckConstraints = [];
|
16487
17538
|
allAltered.forEach((it) => {
|
16488
17539
|
let addedColumns = [];
|
16489
17540
|
for (const addedPkName of Object.keys(it.addedCompositePKs)) {
|
@@ -16540,12 +17591,56 @@ var init_snapshotsDiffer = __esm({
|
|
16540
17591
|
...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
|
16541
17592
|
);
|
16542
17593
|
}
|
17594
|
+
let createdCheckConstraints = [];
|
17595
|
+
let deletedCheckConstraints = [];
|
17596
|
+
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
17597
|
+
it.name,
|
17598
|
+
it.schema,
|
17599
|
+
it.addedUniqueConstraints
|
17600
|
+
);
|
17601
|
+
deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
|
17602
|
+
it.name,
|
17603
|
+
it.schema,
|
17604
|
+
it.deletedUniqueConstraints
|
17605
|
+
);
|
17606
|
+
if (it.alteredUniqueConstraints) {
|
17607
|
+
const added = {};
|
17608
|
+
const deleted = {};
|
17609
|
+
for (const k of Object.keys(it.alteredUniqueConstraints)) {
|
17610
|
+
added[k] = it.alteredUniqueConstraints[k].__new;
|
17611
|
+
deleted[k] = it.alteredUniqueConstraints[k].__old;
|
17612
|
+
}
|
17613
|
+
addedUniqueConstraints.push(
|
17614
|
+
...prepareAddUniqueConstraintPg(it.name, it.schema, added)
|
17615
|
+
);
|
17616
|
+
deletedUniqueConstraints.push(
|
17617
|
+
...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
|
17618
|
+
);
|
17619
|
+
}
|
17620
|
+
createdCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
|
17621
|
+
deletedCheckConstraints = prepareDeleteCheckConstraint(
|
17622
|
+
it.name,
|
17623
|
+
it.schema,
|
17624
|
+
it.deletedCheckConstraints
|
17625
|
+
);
|
17626
|
+
if (it.alteredCheckConstraints && action !== "push") {
|
17627
|
+
const added = {};
|
17628
|
+
const deleted = {};
|
17629
|
+
for (const k of Object.keys(it.alteredCheckConstraints)) {
|
17630
|
+
added[k] = it.alteredCheckConstraints[k].__new;
|
17631
|
+
deleted[k] = it.alteredCheckConstraints[k].__old;
|
17632
|
+
}
|
17633
|
+
createdCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
|
17634
|
+
deletedCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
|
17635
|
+
}
|
16543
17636
|
jsonAddedCompositePKs.push(...addedCompositePKs);
|
16544
17637
|
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
16545
17638
|
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
16546
17639
|
jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
|
16547
17640
|
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
16548
17641
|
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
17642
|
+
jsonCreatedCheckConstraints.push(...createdCheckConstraints);
|
17643
|
+
jsonDeletedCheckConstraints.push(...deletedCheckConstraints);
|
16549
17644
|
});
|
16550
17645
|
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
16551
17646
|
const tableName = it.tableName;
|
@@ -16624,12 +17719,51 @@ var init_snapshotsDiffer = __esm({
|
|
16624
17719
|
const jsonDroppedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
16625
17720
|
(t) => t.type === "delete_reference"
|
16626
17721
|
);
|
17722
|
+
const createViews = [];
|
17723
|
+
const dropViews = [];
|
17724
|
+
createViews.push(
|
17725
|
+
...createdViews.filter((it) => !it.isExisting).map((it) => {
|
17726
|
+
return prepareSqliteCreateViewJson(
|
17727
|
+
it.name,
|
17728
|
+
it.definition
|
17729
|
+
);
|
17730
|
+
})
|
17731
|
+
);
|
17732
|
+
dropViews.push(
|
17733
|
+
...deletedViews.filter((it) => !it.isExisting).map((it) => {
|
17734
|
+
return prepareDropViewJson(it.name);
|
17735
|
+
})
|
17736
|
+
);
|
17737
|
+
dropViews.push(
|
17738
|
+
...renamedViews.filter((it) => !it.to.isExisting).map((it) => {
|
17739
|
+
return prepareDropViewJson(it.from.name);
|
17740
|
+
})
|
17741
|
+
);
|
17742
|
+
createViews.push(
|
17743
|
+
...renamedViews.filter((it) => !it.to.isExisting).map((it) => {
|
17744
|
+
return prepareSqliteCreateViewJson(it.to.name, it.to.definition);
|
17745
|
+
})
|
17746
|
+
);
|
17747
|
+
const alteredViews = typedResult.alteredViews.filter((it) => !json22.views[it.name].isExisting);
|
17748
|
+
for (const alteredView of alteredViews) {
|
17749
|
+
const { definition } = json22.views[alteredView.name];
|
17750
|
+
if (alteredView.alteredExisting || alteredView.alteredDefinition && action !== "push") {
|
17751
|
+
dropViews.push(prepareDropViewJson(alteredView.name));
|
17752
|
+
createViews.push(
|
17753
|
+
prepareSqliteCreateViewJson(
|
17754
|
+
alteredView.name,
|
17755
|
+
definition
|
17756
|
+
)
|
17757
|
+
);
|
17758
|
+
}
|
17759
|
+
}
|
16627
17760
|
const jsonStatements = [];
|
16628
17761
|
jsonStatements.push(...jsonCreateTables);
|
16629
17762
|
jsonStatements.push(...jsonDropTables);
|
16630
17763
|
jsonStatements.push(...jsonRenameTables);
|
16631
17764
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
16632
17765
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
17766
|
+
jsonStatements.push(...jsonDeletedCheckConstraints);
|
16633
17767
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
16634
17768
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
16635
17769
|
jsonStatements.push(...jsonTableAlternations);
|
@@ -16637,10 +17771,13 @@ var init_snapshotsDiffer = __esm({
|
|
16637
17771
|
jsonStatements.push(...jsonAddColumnsStatemets);
|
16638
17772
|
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
16639
17773
|
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
17774
|
+
jsonStatements.push(...jsonCreatedCheckConstraints);
|
16640
17775
|
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
16641
17776
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
16642
17777
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
16643
17778
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
17779
|
+
jsonStatements.push(...dropViews);
|
17780
|
+
jsonStatements.push(...createViews);
|
16644
17781
|
const combinedJsonStatements = sqliteCombineStatements(jsonStatements, json22, action);
|
16645
17782
|
const sqlStatements = fromJson(combinedJsonStatements, "sqlite");
|
16646
17783
|
const uniqueSqlStatements = [];
|
@@ -16659,7 +17796,7 @@ var init_snapshotsDiffer = __esm({
|
|
16659
17796
|
_meta
|
16660
17797
|
};
|
16661
17798
|
};
|
16662
|
-
applyLibSQLSnapshotsDiff = async (json1, json22, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
17799
|
+
applyLibSQLSnapshotsDiff = async (json1, json22, tablesResolver2, columnsResolver2, viewsResolver2, prevFull, curFull, action) => {
|
16663
17800
|
const tablesDiff = diffSchemasOrTables(json1.tables, json22.tables);
|
16664
17801
|
const {
|
16665
17802
|
created: createdTables,
|
@@ -16729,7 +17866,32 @@ var init_snapshotsDiffer = __esm({
|
|
16729
17866
|
return [tableKey2, tableValue];
|
16730
17867
|
}
|
16731
17868
|
);
|
16732
|
-
const
|
17869
|
+
const viewsDiff = diffSchemasOrTables(json1.views, json22.views);
|
17870
|
+
const {
|
17871
|
+
created: createdViews,
|
17872
|
+
deleted: deletedViews,
|
17873
|
+
renamed: renamedViews
|
17874
|
+
// renamed or moved
|
17875
|
+
} = await viewsResolver2({
|
17876
|
+
created: viewsDiff.added,
|
17877
|
+
deleted: viewsDiff.deleted
|
17878
|
+
});
|
17879
|
+
const renamesViewDic = {};
|
17880
|
+
renamedViews.forEach((it) => {
|
17881
|
+
renamesViewDic[it.from.name] = { to: it.to.name, from: it.from.name };
|
17882
|
+
});
|
17883
|
+
const viewsPatchedSnap1 = copy(columnsPatchedSnap1);
|
17884
|
+
viewsPatchedSnap1.views = mapEntries(
|
17885
|
+
viewsPatchedSnap1.views,
|
17886
|
+
(viewKey, viewValue) => {
|
17887
|
+
const rename = renamesViewDic[viewValue.name];
|
17888
|
+
if (rename) {
|
17889
|
+
viewValue.name = rename.to;
|
17890
|
+
}
|
17891
|
+
return [viewKey, viewValue];
|
17892
|
+
}
|
17893
|
+
);
|
17894
|
+
const diffResult = applyJsonDiff(viewsPatchedSnap1, json22);
|
16733
17895
|
const typedResult = diffResultSchemeSQLite.parse(diffResult);
|
16734
17896
|
const tablesMap = {};
|
16735
17897
|
typedResult.alteredTablesWithColumns.forEach((obj) => {
|
@@ -16780,6 +17942,8 @@ var init_snapshotsDiffer = __esm({
|
|
16780
17942
|
const jsonAddedUniqueConstraints = [];
|
16781
17943
|
const jsonDeletedUniqueConstraints = [];
|
16782
17944
|
const jsonAlteredUniqueConstraints = [];
|
17945
|
+
const jsonDeletedCheckConstraints = [];
|
17946
|
+
const jsonCreatedCheckConstraints = [];
|
16783
17947
|
allAltered.forEach((it) => {
|
16784
17948
|
let addedColumns = [];
|
16785
17949
|
for (const addedPkName of Object.keys(it.addedCompositePKs)) {
|
@@ -16812,6 +17976,8 @@ var init_snapshotsDiffer = __esm({
|
|
16812
17976
|
let addedUniqueConstraints = [];
|
16813
17977
|
let deletedUniqueConstraints = [];
|
16814
17978
|
let alteredUniqueConstraints = [];
|
17979
|
+
let createdCheckConstraints = [];
|
17980
|
+
let deletedCheckConstraints = [];
|
16815
17981
|
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
16816
17982
|
it.name,
|
16817
17983
|
it.schema,
|
@@ -16836,12 +18002,30 @@ var init_snapshotsDiffer = __esm({
|
|
16836
18002
|
...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
|
16837
18003
|
);
|
16838
18004
|
}
|
18005
|
+
createdCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
|
18006
|
+
deletedCheckConstraints = prepareDeleteCheckConstraint(
|
18007
|
+
it.name,
|
18008
|
+
it.schema,
|
18009
|
+
it.deletedCheckConstraints
|
18010
|
+
);
|
18011
|
+
if (it.alteredCheckConstraints && action !== "push") {
|
18012
|
+
const added = {};
|
18013
|
+
const deleted = {};
|
18014
|
+
for (const k of Object.keys(it.alteredCheckConstraints)) {
|
18015
|
+
added[k] = it.alteredCheckConstraints[k].__new;
|
18016
|
+
deleted[k] = it.alteredCheckConstraints[k].__old;
|
18017
|
+
}
|
18018
|
+
createdCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
|
18019
|
+
deletedCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
|
18020
|
+
}
|
16839
18021
|
jsonAddedCompositePKs.push(...addedCompositePKs);
|
16840
18022
|
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
16841
18023
|
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
16842
18024
|
jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
|
16843
18025
|
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
16844
18026
|
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
18027
|
+
jsonCreatedCheckConstraints.push(...createdCheckConstraints);
|
18028
|
+
jsonDeletedCheckConstraints.push(...deletedCheckConstraints);
|
16845
18029
|
});
|
16846
18030
|
const jsonTableAlternations = allAltered.map((it) => {
|
16847
18031
|
return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json22);
|
@@ -16913,12 +18097,51 @@ var init_snapshotsDiffer = __esm({
|
|
16913
18097
|
const jsonDroppedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
16914
18098
|
(t) => t.type === "delete_reference"
|
16915
18099
|
);
|
18100
|
+
const createViews = [];
|
18101
|
+
const dropViews = [];
|
18102
|
+
createViews.push(
|
18103
|
+
...createdViews.filter((it) => !it.isExisting).map((it) => {
|
18104
|
+
return prepareSqliteCreateViewJson(
|
18105
|
+
it.name,
|
18106
|
+
it.definition
|
18107
|
+
);
|
18108
|
+
})
|
18109
|
+
);
|
18110
|
+
dropViews.push(
|
18111
|
+
...deletedViews.filter((it) => !it.isExisting).map((it) => {
|
18112
|
+
return prepareDropViewJson(it.name);
|
18113
|
+
})
|
18114
|
+
);
|
18115
|
+
dropViews.push(
|
18116
|
+
...renamedViews.filter((it) => !it.to.isExisting).map((it) => {
|
18117
|
+
return prepareDropViewJson(it.from.name);
|
18118
|
+
})
|
18119
|
+
);
|
18120
|
+
createViews.push(
|
18121
|
+
...renamedViews.filter((it) => !it.to.isExisting).map((it) => {
|
18122
|
+
return prepareSqliteCreateViewJson(it.to.name, it.to.definition);
|
18123
|
+
})
|
18124
|
+
);
|
18125
|
+
const alteredViews = typedResult.alteredViews.filter((it) => !json22.views[it.name].isExisting);
|
18126
|
+
for (const alteredView of alteredViews) {
|
18127
|
+
const { definition } = json22.views[alteredView.name];
|
18128
|
+
if (alteredView.alteredExisting || alteredView.alteredDefinition && action !== "push") {
|
18129
|
+
dropViews.push(prepareDropViewJson(alteredView.name));
|
18130
|
+
createViews.push(
|
18131
|
+
prepareSqliteCreateViewJson(
|
18132
|
+
alteredView.name,
|
18133
|
+
definition
|
18134
|
+
)
|
18135
|
+
);
|
18136
|
+
}
|
18137
|
+
}
|
16916
18138
|
const jsonStatements = [];
|
16917
18139
|
jsonStatements.push(...jsonCreateTables);
|
16918
18140
|
jsonStatements.push(...jsonDropTables);
|
16919
18141
|
jsonStatements.push(...jsonRenameTables);
|
16920
18142
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
16921
18143
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
18144
|
+
jsonStatements.push(...jsonDeletedCheckConstraints);
|
16922
18145
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
16923
18146
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
16924
18147
|
jsonStatements.push(...jsonTableAlternations);
|
@@ -16926,6 +18149,9 @@ var init_snapshotsDiffer = __esm({
|
|
16926
18149
|
jsonStatements.push(...jsonAddColumnsStatemets);
|
16927
18150
|
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
16928
18151
|
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
18152
|
+
jsonStatements.push(...jsonCreatedCheckConstraints);
|
18153
|
+
jsonStatements.push(...dropViews);
|
18154
|
+
jsonStatements.push(...createViews);
|
16929
18155
|
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
16930
18156
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
16931
18157
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
@@ -17088,7 +18314,7 @@ var init_outputs = __esm({
|
|
17088
18314
|
});
|
17089
18315
|
|
17090
18316
|
// src/cli/commands/migrate.ts
|
17091
|
-
var import_hanji2, schemasResolver, tablesResolver, sequencesResolver, enumsResolver, columnsResolver, promptColumnsConflicts, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT;
|
18317
|
+
var import_hanji2, schemasResolver, tablesResolver, viewsResolver, mySqlViewsResolver, sqliteViewsResolver, sequencesResolver, enumsResolver, columnsResolver, promptColumnsConflicts, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT;
|
17092
18318
|
var init_migrate = __esm({
|
17093
18319
|
"src/cli/commands/migrate.ts"() {
|
17094
18320
|
"use strict";
|
@@ -17133,6 +18359,60 @@ var init_migrate = __esm({
|
|
17133
18359
|
throw e;
|
17134
18360
|
}
|
17135
18361
|
};
|
18362
|
+
viewsResolver = async (input) => {
|
18363
|
+
try {
|
18364
|
+
const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
|
18365
|
+
input.created,
|
18366
|
+
input.deleted,
|
18367
|
+
"view"
|
18368
|
+
);
|
18369
|
+
return {
|
18370
|
+
created,
|
18371
|
+
deleted,
|
18372
|
+
moved,
|
18373
|
+
renamed
|
18374
|
+
};
|
18375
|
+
} catch (e) {
|
18376
|
+
console.error(e);
|
18377
|
+
throw e;
|
18378
|
+
}
|
18379
|
+
};
|
18380
|
+
mySqlViewsResolver = async (input) => {
|
18381
|
+
try {
|
18382
|
+
const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
|
18383
|
+
input.created,
|
18384
|
+
input.deleted,
|
18385
|
+
"view"
|
18386
|
+
);
|
18387
|
+
return {
|
18388
|
+
created,
|
18389
|
+
deleted,
|
18390
|
+
moved,
|
18391
|
+
renamed
|
18392
|
+
};
|
18393
|
+
} catch (e) {
|
18394
|
+
console.error(e);
|
18395
|
+
throw e;
|
18396
|
+
}
|
18397
|
+
};
|
18398
|
+
sqliteViewsResolver = async (input) => {
|
18399
|
+
try {
|
18400
|
+
const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
|
18401
|
+
input.created,
|
18402
|
+
input.deleted,
|
18403
|
+
"view"
|
18404
|
+
);
|
18405
|
+
return {
|
18406
|
+
created,
|
18407
|
+
deleted,
|
18408
|
+
moved,
|
18409
|
+
renamed
|
18410
|
+
};
|
18411
|
+
} catch (e) {
|
18412
|
+
console.error(e);
|
18413
|
+
throw e;
|
18414
|
+
}
|
18415
|
+
};
|
17136
18416
|
sequencesResolver = async (input) => {
|
17137
18417
|
try {
|
17138
18418
|
const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
|
@@ -19208,7 +20488,7 @@ function fillPlaceholders(params, values) {
|
|
19208
20488
|
return p;
|
19209
20489
|
});
|
19210
20490
|
}
|
19211
|
-
var _a20, FakePrimitiveParam, _a21, StringChunk, _a22, _SQL, SQL, _a23, Name, noopDecoder, noopEncoder, noopMapper, _a24, Param, _a25, Placeholder, _a26, _b10,
|
20491
|
+
var _a20, FakePrimitiveParam, _a21, StringChunk, _a22, _SQL, SQL, _a23, Name, noopDecoder, noopEncoder, noopMapper, _a24, Param, _a25, Placeholder, _a26, _b10, View3;
|
19212
20492
|
var init_sql = __esm({
|
19213
20493
|
"../drizzle-orm/dist/sql/sql.js"() {
|
19214
20494
|
"use strict";
|
@@ -19311,7 +20591,7 @@ var init_sql = __esm({
|
|
19311
20591
|
}
|
19312
20592
|
return { sql: escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName), params: [] };
|
19313
20593
|
}
|
19314
|
-
if (is(chunk,
|
20594
|
+
if (is(chunk, View3)) {
|
19315
20595
|
const schemaName = chunk[ViewBaseConfig].schema;
|
19316
20596
|
const viewName = chunk[ViewBaseConfig].name;
|
19317
20597
|
return {
|
@@ -19530,7 +20810,7 @@ var init_sql = __esm({
|
|
19530
20810
|
};
|
19531
20811
|
__publicField(Placeholder, _a25, "Placeholder");
|
19532
20812
|
_b10 = entityKind, _a26 = ViewBaseConfig;
|
19533
|
-
|
20813
|
+
View3 = class {
|
19534
20814
|
constructor({ name: name2, schema: schema4, selectedFields, query }) {
|
19535
20815
|
/** @internal */
|
19536
20816
|
__publicField(this, _a26);
|
@@ -19548,7 +20828,7 @@ var init_sql = __esm({
|
|
19548
20828
|
return new SQL([this]);
|
19549
20829
|
}
|
19550
20830
|
};
|
19551
|
-
__publicField(
|
20831
|
+
__publicField(View3, _b10, "View");
|
19552
20832
|
Column2.prototype.getSQL = function() {
|
19553
20833
|
return new SQL([this]);
|
19554
20834
|
};
|
@@ -19699,7 +20979,7 @@ var init_errors = __esm({
|
|
19699
20979
|
|
19700
20980
|
// ../drizzle-orm/dist/sql/expressions/conditions.js
|
19701
20981
|
function bindIfParam(value, column4) {
|
19702
|
-
if (isDriverValueEncoder(column4) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column2) && !is(value, Table) && !is(value,
|
20982
|
+
if (isDriverValueEncoder(column4) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column2) && !is(value, Table) && !is(value, View3)) {
|
19703
20983
|
return new Param(value, column4);
|
19704
20984
|
}
|
19705
20985
|
return value;
|
@@ -20070,7 +21350,7 @@ function getTableColumns(table4) {
|
|
20070
21350
|
return table4[Table.Symbol.Columns];
|
20071
21351
|
}
|
20072
21352
|
function getTableLikeName(table4) {
|
20073
|
-
return is(table4, Subquery) ? table4._.alias : is(table4,
|
21353
|
+
return is(table4, Subquery) ? table4._.alias : is(table4, View3) ? table4[ViewBaseConfig].name : is(table4, SQL) ? void 0 : table4[Table.Symbol.IsAlias] ? table4[Table.Symbol.Name] : table4[Table.Symbol.BaseName];
|
20074
21354
|
}
|
20075
21355
|
function getColumnNameAndConfig(a, b) {
|
20076
21356
|
return {
|
@@ -20988,23 +22268,23 @@ function hexToBytes(hex) {
|
|
20988
22268
|
}
|
20989
22269
|
function bytesToFloat64(bytes, offset) {
|
20990
22270
|
const buffer = new ArrayBuffer(8);
|
20991
|
-
const
|
22271
|
+
const view4 = new DataView(buffer);
|
20992
22272
|
for (let i = 0; i < 8; i++) {
|
20993
|
-
|
22273
|
+
view4.setUint8(i, bytes[offset + i]);
|
20994
22274
|
}
|
20995
|
-
return
|
22275
|
+
return view4.getFloat64(0, true);
|
20996
22276
|
}
|
20997
22277
|
function parseEWKB(hex) {
|
20998
22278
|
const bytes = hexToBytes(hex);
|
20999
22279
|
let offset = 0;
|
21000
22280
|
const byteOrder = bytes[offset];
|
21001
22281
|
offset += 1;
|
21002
|
-
const
|
21003
|
-
const geomType =
|
22282
|
+
const view4 = new DataView(bytes.buffer);
|
22283
|
+
const geomType = view4.getUint32(offset, byteOrder === 1);
|
21004
22284
|
offset += 4;
|
21005
22285
|
let _srid;
|
21006
22286
|
if (geomType & 536870912) {
|
21007
|
-
_srid =
|
22287
|
+
_srid = view4.getUint32(offset, byteOrder === 1);
|
21008
22288
|
offset += 4;
|
21009
22289
|
}
|
21010
22290
|
if ((geomType & 65535) === 1) {
|
@@ -22227,7 +23507,7 @@ __export(dist_exports, {
|
|
22227
23507
|
Table: () => Table,
|
22228
23508
|
TableAliasProxyHandler: () => TableAliasProxyHandler,
|
22229
23509
|
TransactionRollbackError: () => TransactionRollbackError,
|
22230
|
-
View: () =>
|
23510
|
+
View: () => View3,
|
22231
23511
|
ViewBaseConfig: () => ViewBaseConfig,
|
22232
23512
|
WithSubquery: () => WithSubquery,
|
22233
23513
|
aliasedRelation: () => aliasedRelation,
|
@@ -22661,7 +23941,7 @@ var init_view_base = __esm({
|
|
22661
23941
|
"use strict";
|
22662
23942
|
init_entity();
|
22663
23943
|
init_sql();
|
22664
|
-
PgViewBase = class extends (_b99 =
|
23944
|
+
PgViewBase = class extends (_b99 = View3, _a128 = entityKind, _b99) {
|
22665
23945
|
};
|
22666
23946
|
__publicField(PgViewBase, _a128, "PgViewBase");
|
22667
23947
|
}
|
@@ -22884,7 +24164,7 @@ var init_dialect = __esm({
|
|
22884
24164
|
joinsArray.push(
|
22885
24165
|
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
22886
24166
|
);
|
22887
|
-
} else if (is(table22,
|
24167
|
+
} else if (is(table22, View3)) {
|
22888
24168
|
const viewName = table22[ViewBaseConfig].name;
|
22889
24169
|
const viewSchema = table22[ViewBaseConfig].schema;
|
22890
24170
|
const origViewName = table22[ViewBaseConfig].originalName;
|
@@ -23021,10 +24301,10 @@ var init_dialect = __esm({
|
|
23021
24301
|
const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
|
23022
24302
|
return sql`${withSql}insert into ${table4} ${insertOrder} values ${valuesSql}${onConflictSql}${returningSql}`;
|
23023
24303
|
}
|
23024
|
-
buildRefreshMaterializedViewQuery({ view, concurrently, withNoData }) {
|
24304
|
+
buildRefreshMaterializedViewQuery({ view: view4, concurrently, withNoData }) {
|
23025
24305
|
const concurrentlySql = concurrently ? sql` concurrently` : void 0;
|
23026
24306
|
const withNoDataSql = withNoData ? sql` with no data` : void 0;
|
23027
|
-
return sql`refresh materialized view${concurrentlySql} ${
|
24307
|
+
return sql`refresh materialized view${concurrentlySql} ${view4}${withNoDataSql}`;
|
23028
24308
|
}
|
23029
24309
|
prepareTyping(encoder) {
|
23030
24310
|
if (is(encoder, PgJsonb) || is(encoder, PgJson)) {
|
@@ -23798,7 +25078,7 @@ var init_selection_proxy = __esm({
|
|
23798
25078
|
if (typeof prop === "symbol") {
|
23799
25079
|
return subquery[prop];
|
23800
25080
|
}
|
23801
|
-
const columns = is(subquery, Subquery) ? subquery._.selectedFields : is(subquery,
|
25081
|
+
const columns = is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View3) ? subquery[ViewBaseConfig].selectedFields : subquery;
|
23802
25082
|
const value = columns[prop];
|
23803
25083
|
if (is(value, SQL.Aliased)) {
|
23804
25084
|
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) {
|
@@ -24280,7 +25560,7 @@ var init_select2 = __esm({
|
|
24280
25560
|
};
|
24281
25561
|
}
|
24282
25562
|
if (typeof tableName === "string" && !is(table4, SQL)) {
|
24283
|
-
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4,
|
25563
|
+
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4, View3) ? table4[ViewBaseConfig].selectedFields : table4[Table.Symbol.Columns];
|
24284
25564
|
this.config.fields[tableName] = selection;
|
24285
25565
|
}
|
24286
25566
|
}
|
@@ -24699,7 +25979,7 @@ var init_refresh_materialized_view = __esm({
|
|
24699
25979
|
init_query_promise();
|
24700
25980
|
init_tracing();
|
24701
25981
|
PgRefreshMaterializedView = class extends (_b102 = QueryPromise, _a136 = entityKind, _b102) {
|
24702
|
-
constructor(
|
25982
|
+
constructor(view4, session, dialect4) {
|
24703
25983
|
super();
|
24704
25984
|
__publicField(this, "config");
|
24705
25985
|
__publicField(this, "execute", (placeholderValues) => {
|
@@ -24709,7 +25989,7 @@ var init_refresh_materialized_view = __esm({
|
|
24709
25989
|
});
|
24710
25990
|
this.session = session;
|
24711
25991
|
this.dialect = dialect4;
|
24712
|
-
this.config = { view };
|
25992
|
+
this.config = { view: view4 };
|
24713
25993
|
}
|
24714
25994
|
concurrently() {
|
24715
25995
|
if (this.config.withNoData !== void 0) {
|
@@ -25340,8 +26620,8 @@ var init_db = __esm({
|
|
25340
26620
|
delete(table4) {
|
25341
26621
|
return new PgDeleteBase(table4, this.session, this.dialect);
|
25342
26622
|
}
|
25343
|
-
refreshMaterializedView(
|
25344
|
-
return new PgRefreshMaterializedView(
|
26623
|
+
refreshMaterializedView(view4) {
|
26624
|
+
return new PgRefreshMaterializedView(view4, this.session, this.dialect);
|
25345
26625
|
}
|
25346
26626
|
execute(query) {
|
25347
26627
|
const sequel = typeof query === "string" ? sql.raw(query) : query.getSQL();
|
@@ -25531,7 +26811,13 @@ function pgMaterializedViewWithSchema(name2, selection, schema4) {
|
|
25531
26811
|
}
|
25532
26812
|
return new MaterializedViewBuilder(name2, schema4);
|
25533
26813
|
}
|
25534
|
-
|
26814
|
+
function isPgView(obj) {
|
26815
|
+
return is(obj, PgView2);
|
26816
|
+
}
|
26817
|
+
function isPgMaterializedView(obj) {
|
26818
|
+
return is(obj, PgMaterializedView);
|
26819
|
+
}
|
26820
|
+
var _a148, DefaultViewBuilderCore, _a149, _b107, ViewBuilder, _a150, _b108, ManualViewBuilder, _a151, MaterializedViewBuilderCore, _a152, _b109, MaterializedViewBuilder, _a153, _b110, ManualMaterializedViewBuilder, _a154, _b111, _c4, PgView2, PgMaterializedViewConfig, _a155, _b112, _c5, PgMaterializedView;
|
25535
26821
|
var init_view = __esm({
|
25536
26822
|
"../drizzle-orm/dist/pg-core/view.js"() {
|
25537
26823
|
"use strict";
|
@@ -25568,7 +26854,7 @@ var init_view = __esm({
|
|
25568
26854
|
});
|
25569
26855
|
const aliasedSelection = new Proxy(qb.getSelectedFields(), selectionProxy);
|
25570
26856
|
return new Proxy(
|
25571
|
-
new
|
26857
|
+
new PgView2({
|
25572
26858
|
pgConfig: this.config,
|
25573
26859
|
config: {
|
25574
26860
|
name: this.name,
|
@@ -25590,7 +26876,7 @@ var init_view = __esm({
|
|
25590
26876
|
}
|
25591
26877
|
existing() {
|
25592
26878
|
return new Proxy(
|
25593
|
-
new
|
26879
|
+
new PgView2({
|
25594
26880
|
pgConfig: void 0,
|
25595
26881
|
config: {
|
25596
26882
|
name: this.name,
|
@@ -25609,7 +26895,7 @@ var init_view = __esm({
|
|
25609
26895
|
}
|
25610
26896
|
as(query) {
|
25611
26897
|
return new Proxy(
|
25612
|
-
new
|
26898
|
+
new PgView2({
|
25613
26899
|
pgConfig: this.config,
|
25614
26900
|
config: {
|
25615
26901
|
name: this.name,
|
@@ -25694,7 +26980,12 @@ var init_view = __esm({
|
|
25694
26980
|
existing() {
|
25695
26981
|
return new Proxy(
|
25696
26982
|
new PgMaterializedView({
|
25697
|
-
pgConfig:
|
26983
|
+
pgConfig: {
|
26984
|
+
tablespace: this.config.tablespace,
|
26985
|
+
using: this.config.using,
|
26986
|
+
with: this.config.with,
|
26987
|
+
withNoData: this.config.withNoData
|
26988
|
+
},
|
25698
26989
|
config: {
|
25699
26990
|
name: this.name,
|
25700
26991
|
schema: this.schema,
|
@@ -25713,7 +27004,12 @@ var init_view = __esm({
|
|
25713
27004
|
as(query) {
|
25714
27005
|
return new Proxy(
|
25715
27006
|
new PgMaterializedView({
|
25716
|
-
pgConfig:
|
27007
|
+
pgConfig: {
|
27008
|
+
tablespace: this.config.tablespace,
|
27009
|
+
using: this.config.using,
|
27010
|
+
with: this.config.with,
|
27011
|
+
withNoData: this.config.withNoData
|
27012
|
+
},
|
25717
27013
|
config: {
|
25718
27014
|
name: this.name,
|
25719
27015
|
schema: this.schema,
|
@@ -25731,7 +27027,7 @@ var init_view = __esm({
|
|
25731
27027
|
}
|
25732
27028
|
};
|
25733
27029
|
__publicField(ManualMaterializedViewBuilder, _a153, "PgManualMaterializedViewBuilder");
|
25734
|
-
|
27030
|
+
PgView2 = class extends (_c4 = PgViewBase, _b111 = entityKind, _a154 = PgViewConfig, _c4) {
|
25735
27031
|
constructor({ pgConfig, config }) {
|
25736
27032
|
super(config);
|
25737
27033
|
__publicField(this, _a154);
|
@@ -25742,7 +27038,7 @@ var init_view = __esm({
|
|
25742
27038
|
}
|
25743
27039
|
}
|
25744
27040
|
};
|
25745
|
-
__publicField(
|
27041
|
+
__publicField(PgView2, _b111, "PgView");
|
25746
27042
|
PgMaterializedViewConfig = Symbol.for("drizzle:PgMaterializedViewConfig");
|
25747
27043
|
PgMaterializedView = class extends (_c5 = PgViewBase, _b112 = entityKind, _a155 = PgMaterializedViewConfig, _c5) {
|
25748
27044
|
constructor({ pgConfig, config }) {
|
@@ -25937,17 +27233,32 @@ function getTableConfig(table4) {
|
|
25937
27233
|
schema: schema4
|
25938
27234
|
};
|
25939
27235
|
}
|
27236
|
+
function getViewConfig(view4) {
|
27237
|
+
return {
|
27238
|
+
...view4[ViewBaseConfig],
|
27239
|
+
...view4[PgViewConfig]
|
27240
|
+
};
|
27241
|
+
}
|
27242
|
+
function getMaterializedViewConfig(view4) {
|
27243
|
+
return {
|
27244
|
+
...view4[ViewBaseConfig],
|
27245
|
+
...view4[PgMaterializedViewConfig]
|
27246
|
+
};
|
27247
|
+
}
|
25940
27248
|
var init_utils4 = __esm({
|
25941
27249
|
"../drizzle-orm/dist/pg-core/utils.js"() {
|
25942
27250
|
"use strict";
|
25943
27251
|
init_entity();
|
25944
27252
|
init_table2();
|
25945
27253
|
init_table();
|
27254
|
+
init_view_common();
|
25946
27255
|
init_checks();
|
25947
27256
|
init_foreign_keys();
|
25948
27257
|
init_indexes();
|
25949
27258
|
init_primary_keys();
|
25950
27259
|
init_unique_constraint();
|
27260
|
+
init_view_common2();
|
27261
|
+
init_view();
|
25951
27262
|
}
|
25952
27263
|
});
|
25953
27264
|
|
@@ -26022,7 +27333,7 @@ function buildArrayString(array, sqlType) {
|
|
26022
27333
|
}).join(",");
|
26023
27334
|
return `{${values}}`;
|
26024
27335
|
}
|
26025
|
-
var indexName, generatePgSnapshot, trimChar, fromDatabase, defaultForColumn;
|
27336
|
+
var indexName, generatePgSnapshot, trimChar, fromDatabase, defaultForColumn, getColumnsInfoQuery;
|
26026
27337
|
var init_pgSerializer = __esm({
|
26027
27338
|
"src/serializer/pgSerializer.ts"() {
|
26028
27339
|
"use strict";
|
@@ -26037,27 +27348,21 @@ var init_pgSerializer = __esm({
|
|
26037
27348
|
indexName = (tableName, columns) => {
|
26038
27349
|
return `${tableName}_${columns.join("_")}_index`;
|
26039
27350
|
};
|
26040
|
-
generatePgSnapshot = (tables, enums, schemas, sequences, casing2, schemaFilter) => {
|
27351
|
+
generatePgSnapshot = (tables, enums, schemas, sequences, views, matViews, casing2, schemaFilter) => {
|
26041
27352
|
const dialect4 = new PgDialect({ casing: casing2 });
|
26042
27353
|
const result = {};
|
27354
|
+
const resultViews = {};
|
26043
27355
|
const sequencesToReturn = {};
|
26044
27356
|
const indexesInSchema = {};
|
26045
27357
|
for (const table4 of tables) {
|
26046
|
-
const {
|
26047
|
-
|
26048
|
-
columns,
|
26049
|
-
indexes,
|
26050
|
-
foreignKeys,
|
26051
|
-
checks,
|
26052
|
-
schema: schema4,
|
26053
|
-
primaryKeys,
|
26054
|
-
uniqueConstraints
|
26055
|
-
} = getTableConfig(table4);
|
27358
|
+
const checksInTable = {};
|
27359
|
+
const { name: tableName, columns, indexes, foreignKeys, checks, schema: schema4, primaryKeys, uniqueConstraints } = getTableConfig(table4);
|
26056
27360
|
if (schemaFilter && !schemaFilter.includes(schema4 ?? "public")) {
|
26057
27361
|
continue;
|
26058
27362
|
}
|
26059
27363
|
const columnsObject = {};
|
26060
27364
|
const indexesObject = {};
|
27365
|
+
const checksObject = {};
|
26061
27366
|
const foreignKeysObject = {};
|
26062
27367
|
const primaryKeysObject = {};
|
26063
27368
|
const uniqueConstraintObject = {};
|
@@ -26108,7 +27413,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
26108
27413
|
column4.uniqueName
|
26109
27414
|
)} on the ${source_default.underline.blue(
|
26110
27415
|
name2
|
26111
|
-
)} column is
|
27416
|
+
)} column is conflicting with a unique constraint name already defined for ${source_default.underline.blue(
|
26112
27417
|
existingUnique.columns.join(",")
|
26113
27418
|
)} columns
|
26114
27419
|
`)}`
|
@@ -26129,9 +27434,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
26129
27434
|
columnToSet.default = `'${column4.default}'`;
|
26130
27435
|
} else {
|
26131
27436
|
if (sqlTypeLowered === "jsonb" || sqlTypeLowered === "json") {
|
26132
|
-
columnToSet.default = `'${JSON.stringify(
|
26133
|
-
column4.default
|
26134
|
-
)}'::${sqlTypeLowered}`;
|
27437
|
+
columnToSet.default = `'${JSON.stringify(column4.default)}'::${sqlTypeLowered}`;
|
26135
27438
|
} else if (column4.default instanceof Date) {
|
26136
27439
|
if (sqlTypeLowered === "date") {
|
26137
27440
|
columnToSet.default = `'${column4.default.toISOString().split("T")[0]}'`;
|
@@ -26141,10 +27444,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
26141
27444
|
columnToSet.default = `'${column4.default.toISOString()}'`;
|
26142
27445
|
}
|
26143
27446
|
} else if (isPgArrayType(sqlTypeLowered) && Array.isArray(column4.default)) {
|
26144
|
-
columnToSet.default = `'${buildArrayString(
|
26145
|
-
column4.default,
|
26146
|
-
sqlTypeLowered
|
26147
|
-
)}'`;
|
27447
|
+
columnToSet.default = `'${buildArrayString(column4.default, sqlTypeLowered)}'`;
|
26148
27448
|
} else {
|
26149
27449
|
columnToSet.default = column4.default;
|
26150
27450
|
}
|
@@ -26174,17 +27474,13 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
26174
27474
|
if (typeof existingUnique !== "undefined") {
|
26175
27475
|
console.log(
|
26176
27476
|
`
|
26177
|
-
${withStyle.errorWarning(
|
26178
|
-
tableName
|
26179
|
-
|
26180
|
-
|
26181
|
-
|
26182
|
-
|
26183
|
-
|
26184
|
-
)} columns is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
26185
|
-
existingUnique.columns.join(",")
|
26186
|
-
)} columns
|
26187
|
-
`)}`
|
27477
|
+
${withStyle.errorWarning(
|
27478
|
+
`We've found duplicated unique constraint names in ${source_default.underline.blue(tableName)} table.
|
27479
|
+
The unique constraint ${source_default.underline.blue(name2)} on the ${source_default.underline.blue(
|
27480
|
+
columnNames.join(",")
|
27481
|
+
)} columns is confilcting with a unique constraint name already defined for ${source_default.underline.blue(existingUnique.columns.join(","))} columns
|
27482
|
+
`
|
27483
|
+
)}`
|
26188
27484
|
);
|
26189
27485
|
process.exit(1);
|
26190
27486
|
}
|
@@ -26237,9 +27533,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
26237
27533
|
console.log(
|
26238
27534
|
`
|
26239
27535
|
${withStyle.errorWarning(
|
26240
|
-
`Please specify an index name in ${getTableName(
|
26241
|
-
value.config.table
|
26242
|
-
)} table that has "${dialect4.sqlToQuery(it).sql}" expression. We can generate index names for indexes on columns only; for expressions in indexes, you need to specify the name yourself.`
|
27536
|
+
`Please specify an index name in ${getTableName(value.config.table)} table that has "${dialect4.sqlToQuery(it).sql}" expression. We can generate index names for indexes on columns only; for expressions in indexes, you need to specify the name yourself.`
|
26243
27537
|
)}`
|
26244
27538
|
);
|
26245
27539
|
process.exit(1);
|
@@ -26257,9 +27551,7 @@ ${withStyle.errorWarning(
|
|
26257
27551
|
tableName
|
26258
27552
|
)} table with the ${source_default.blueBright(
|
26259
27553
|
"vector"
|
26260
|
-
)} type without specifying an operator class. Vector extension doesn't have a default operator class, so you need to specify one of the available options. Here is a list of available op classes for the vector extension: [${vectorOps.map((it2) => `${source_default.underline(`${it2}`)}`).join(
|
26261
|
-
", "
|
26262
|
-
)}].
|
27554
|
+
)} type without specifying an operator class. Vector extension doesn't have a default operator class, so you need to specify one of the available options. Here is a list of available op classes for the vector extension: [${vectorOps.map((it2) => `${source_default.underline(`${it2}`)}`).join(", ")}].
|
26263
27555
|
|
26264
27556
|
You can specify it using current syntax: ${source_default.underline(
|
26265
27557
|
`index("${value.config.name}").using("${value.config.method}", table.${name3}.op("${vectorOps[0]}"))`
|
@@ -26300,9 +27592,7 @@ You can check the "pg_vector" docs for more info: https://github.com/pgvector/pg
|
|
26300
27592
|
console.log(
|
26301
27593
|
`
|
26302
27594
|
${withStyle.errorWarning(
|
26303
|
-
`We've found duplicated index name across ${source_default.underline.blue(
|
26304
|
-
schema4 ?? "public"
|
26305
|
-
)} schema. Please rename your index in either the ${source_default.underline.blue(
|
27595
|
+
`We've found duplicated index name across ${source_default.underline.blue(schema4 ?? "public")} schema. Please rename your index in either the ${source_default.underline.blue(
|
26306
27596
|
tableName
|
26307
27597
|
)} table or the table with the duplicated index name`
|
26308
27598
|
)}`
|
@@ -26323,6 +27613,33 @@ ${withStyle.errorWarning(
|
|
26323
27613
|
with: value.config.with ?? {}
|
26324
27614
|
};
|
26325
27615
|
});
|
27616
|
+
checks.forEach((check) => {
|
27617
|
+
const checkName = check.name;
|
27618
|
+
if (typeof checksInTable[`"${schema4 ?? "public"}"."${tableName}"`] !== "undefined") {
|
27619
|
+
if (checksInTable[`"${schema4 ?? "public"}"."${tableName}"`].includes(check.name)) {
|
27620
|
+
console.log(
|
27621
|
+
`
|
27622
|
+
${withStyle.errorWarning(
|
27623
|
+
`We've found duplicated check constraint name across ${source_default.underline.blue(
|
27624
|
+
schema4 ?? "public"
|
27625
|
+
)} schema in ${source_default.underline.blue(
|
27626
|
+
tableName
|
27627
|
+
)}. Please rename your check constraint in either the ${source_default.underline.blue(
|
27628
|
+
tableName
|
27629
|
+
)} table or the table with the duplicated check contraint name`
|
27630
|
+
)}`
|
27631
|
+
);
|
27632
|
+
process.exit(1);
|
27633
|
+
}
|
27634
|
+
checksInTable[`"${schema4 ?? "public"}"."${tableName}"`].push(checkName);
|
27635
|
+
} else {
|
27636
|
+
checksInTable[`"${schema4 ?? "public"}"."${tableName}"`] = [check.name];
|
27637
|
+
}
|
27638
|
+
checksObject[checkName] = {
|
27639
|
+
name: checkName,
|
27640
|
+
value: dialect4.sqlToQuery(check.value).sql
|
27641
|
+
};
|
27642
|
+
});
|
26326
27643
|
const tableKey2 = `${schema4 ?? "public"}.${tableName}`;
|
26327
27644
|
result[tableKey2] = {
|
26328
27645
|
name: tableName,
|
@@ -26331,7 +27648,8 @@ ${withStyle.errorWarning(
|
|
26331
27648
|
indexes: indexesObject,
|
26332
27649
|
foreignKeys: foreignKeysObject,
|
26333
27650
|
compositePrimaryKeys: primaryKeysObject,
|
26334
|
-
uniqueConstraints: uniqueConstraintObject
|
27651
|
+
uniqueConstraints: uniqueConstraintObject,
|
27652
|
+
checkConstraints: checksObject
|
26335
27653
|
};
|
26336
27654
|
}
|
26337
27655
|
for (const sequence of sequences) {
|
@@ -26355,6 +27673,136 @@ ${withStyle.errorWarning(
|
|
26355
27673
|
} else {
|
26356
27674
|
}
|
26357
27675
|
}
|
27676
|
+
const combinedViews = [...views, ...matViews];
|
27677
|
+
for (const view4 of combinedViews) {
|
27678
|
+
let viewName;
|
27679
|
+
let schema4;
|
27680
|
+
let query;
|
27681
|
+
let selectedFields;
|
27682
|
+
let isExisting;
|
27683
|
+
let withOption;
|
27684
|
+
let tablespace;
|
27685
|
+
let using;
|
27686
|
+
let withNoData;
|
27687
|
+
let materialized = false;
|
27688
|
+
if (is(view4, PgView2)) {
|
27689
|
+
({ name: viewName, schema: schema4, query, selectedFields, isExisting, with: withOption } = getViewConfig(view4));
|
27690
|
+
} else {
|
27691
|
+
({ name: viewName, schema: schema4, query, selectedFields, isExisting, with: withOption, tablespace, using, withNoData } = getMaterializedViewConfig(view4));
|
27692
|
+
materialized = true;
|
27693
|
+
}
|
27694
|
+
const viewSchema = schema4 ?? "public";
|
27695
|
+
const viewKey = `${viewSchema}.${viewName}`;
|
27696
|
+
const columnsObject = {};
|
27697
|
+
const uniqueConstraintObject = {};
|
27698
|
+
const existingView = resultViews[viewKey];
|
27699
|
+
if (typeof existingView !== "undefined") {
|
27700
|
+
console.log(
|
27701
|
+
`
|
27702
|
+
${withStyle.errorWarning(
|
27703
|
+
`We've found duplicated view name across ${source_default.underline.blue(schema4 ?? "public")} schema. Please rename your view`
|
27704
|
+
)}`
|
27705
|
+
);
|
27706
|
+
process.exit(1);
|
27707
|
+
}
|
27708
|
+
for (const key in selectedFields) {
|
27709
|
+
if (is(selectedFields[key], PgColumn)) {
|
27710
|
+
const column4 = selectedFields[key];
|
27711
|
+
const notNull = column4.notNull;
|
27712
|
+
const primaryKey = column4.primary;
|
27713
|
+
const sqlTypeLowered = column4.getSQLType().toLowerCase();
|
27714
|
+
const typeSchema = is(column4, PgEnumColumn) ? column4.enum.schema || "public" : void 0;
|
27715
|
+
const generated = column4.generated;
|
27716
|
+
const identity = column4.generatedIdentity;
|
27717
|
+
const increment = stringFromIdentityProperty(identity?.sequenceOptions?.increment) ?? "1";
|
27718
|
+
const minValue = stringFromIdentityProperty(identity?.sequenceOptions?.minValue) ?? (parseFloat(increment) < 0 ? minRangeForIdentityBasedOn(column4.columnType) : "1");
|
27719
|
+
const maxValue = stringFromIdentityProperty(identity?.sequenceOptions?.maxValue) ?? (parseFloat(increment) < 0 ? "-1" : maxRangeForIdentityBasedOn(column4.getSQLType()));
|
27720
|
+
const startWith = stringFromIdentityProperty(identity?.sequenceOptions?.startWith) ?? (parseFloat(increment) < 0 ? maxValue : minValue);
|
27721
|
+
const cache = stringFromIdentityProperty(identity?.sequenceOptions?.cache) ?? "1";
|
27722
|
+
const columnToSet = {
|
27723
|
+
name: column4.name,
|
27724
|
+
type: column4.getSQLType(),
|
27725
|
+
typeSchema,
|
27726
|
+
primaryKey,
|
27727
|
+
notNull,
|
27728
|
+
generated: generated ? {
|
27729
|
+
as: is(generated.as, SQL) ? dialect4.sqlToQuery(generated.as).sql : typeof generated.as === "function" ? dialect4.sqlToQuery(generated.as()).sql : generated.as,
|
27730
|
+
type: "stored"
|
27731
|
+
} : void 0,
|
27732
|
+
identity: identity ? {
|
27733
|
+
type: identity.type,
|
27734
|
+
name: identity.sequenceName ?? `${viewName}_${column4.name}_seq`,
|
27735
|
+
schema: schema4 ?? "public",
|
27736
|
+
increment,
|
27737
|
+
startWith,
|
27738
|
+
minValue,
|
27739
|
+
maxValue,
|
27740
|
+
cache,
|
27741
|
+
cycle: identity?.sequenceOptions?.cycle ?? false
|
27742
|
+
} : void 0
|
27743
|
+
};
|
27744
|
+
if (column4.isUnique) {
|
27745
|
+
const existingUnique = uniqueConstraintObject[column4.uniqueName];
|
27746
|
+
if (typeof existingUnique !== "undefined") {
|
27747
|
+
console.log(
|
27748
|
+
`
|
27749
|
+
${withStyle.errorWarning(
|
27750
|
+
`We've found duplicated unique constraint names in ${source_default.underline.blue(viewName)} table.
|
27751
|
+
The unique constraint ${source_default.underline.blue(column4.uniqueName)} on the ${source_default.underline.blue(
|
27752
|
+
column4.name
|
27753
|
+
)} column is confilcting with a unique constraint name already defined for ${source_default.underline.blue(existingUnique.columns.join(","))} columns
|
27754
|
+
`
|
27755
|
+
)}`
|
27756
|
+
);
|
27757
|
+
process.exit(1);
|
27758
|
+
}
|
27759
|
+
uniqueConstraintObject[column4.uniqueName] = {
|
27760
|
+
name: column4.uniqueName,
|
27761
|
+
nullsNotDistinct: column4.uniqueType === "not distinct",
|
27762
|
+
columns: [columnToSet.name]
|
27763
|
+
};
|
27764
|
+
}
|
27765
|
+
if (column4.default !== void 0) {
|
27766
|
+
if (is(column4.default, SQL)) {
|
27767
|
+
columnToSet.default = sqlToStr(column4.default, casing2);
|
27768
|
+
} else {
|
27769
|
+
if (typeof column4.default === "string") {
|
27770
|
+
columnToSet.default = `'${column4.default}'`;
|
27771
|
+
} else {
|
27772
|
+
if (sqlTypeLowered === "jsonb" || sqlTypeLowered === "json") {
|
27773
|
+
columnToSet.default = `'${JSON.stringify(column4.default)}'::${sqlTypeLowered}`;
|
27774
|
+
} else if (column4.default instanceof Date) {
|
27775
|
+
if (sqlTypeLowered === "date") {
|
27776
|
+
columnToSet.default = `'${column4.default.toISOString().split("T")[0]}'`;
|
27777
|
+
} else if (sqlTypeLowered === "timestamp") {
|
27778
|
+
columnToSet.default = `'${column4.default.toISOString().replace("T", " ").slice(0, 23)}'`;
|
27779
|
+
} else {
|
27780
|
+
columnToSet.default = `'${column4.default.toISOString()}'`;
|
27781
|
+
}
|
27782
|
+
} else if (isPgArrayType(sqlTypeLowered) && Array.isArray(column4.default)) {
|
27783
|
+
columnToSet.default = `'${buildArrayString(column4.default, sqlTypeLowered)}'`;
|
27784
|
+
} else {
|
27785
|
+
columnToSet.default = column4.default;
|
27786
|
+
}
|
27787
|
+
}
|
27788
|
+
}
|
27789
|
+
}
|
27790
|
+
columnsObject[column4.name] = columnToSet;
|
27791
|
+
}
|
27792
|
+
}
|
27793
|
+
resultViews[viewKey] = {
|
27794
|
+
columns: columnsObject,
|
27795
|
+
definition: isExisting ? void 0 : dialect4.sqlToQuery(query).sql,
|
27796
|
+
name: viewName,
|
27797
|
+
schema: viewSchema,
|
27798
|
+
isExisting,
|
27799
|
+
with: withOption,
|
27800
|
+
withNoData,
|
27801
|
+
materialized,
|
27802
|
+
tablespace,
|
27803
|
+
using
|
27804
|
+
};
|
27805
|
+
}
|
26358
27806
|
const enumsToReturn = enums.reduce((map, obj) => {
|
26359
27807
|
const enumSchema3 = obj.schema || "public";
|
26360
27808
|
const key = `${enumSchema3}.${obj.enumName}`;
|
@@ -26381,6 +27829,7 @@ ${withStyle.errorWarning(
|
|
26381
27829
|
enums: enumsToReturn,
|
26382
27830
|
schemas: schemasObject,
|
26383
27831
|
sequences: sequencesToReturn,
|
27832
|
+
views: resultViews,
|
26384
27833
|
_meta: {
|
26385
27834
|
schemas: {},
|
26386
27835
|
tables: {},
|
@@ -26397,10 +27846,25 @@ ${withStyle.errorWarning(
|
|
26397
27846
|
};
|
26398
27847
|
fromDatabase = async (db, tablesFilter = () => true, schemaFilters, progressCallback) => {
|
26399
27848
|
const result = {};
|
27849
|
+
const views = {};
|
26400
27850
|
const internals = { tables: {} };
|
26401
|
-
const where = schemaFilters.map((t) => `
|
27851
|
+
const where = schemaFilters.map((t) => `n.nspname = '${t}'`).join(" or ");
|
26402
27852
|
const allTables = await db.query(
|
26403
|
-
`SELECT
|
27853
|
+
`SELECT
|
27854
|
+
n.nspname AS table_schema,
|
27855
|
+
c.relname AS table_name,
|
27856
|
+
CASE
|
27857
|
+
WHEN c.relkind = 'r' THEN 'table'
|
27858
|
+
WHEN c.relkind = 'v' THEN 'view'
|
27859
|
+
WHEN c.relkind = 'm' THEN 'materialized_view'
|
27860
|
+
END AS type
|
27861
|
+
FROM
|
27862
|
+
pg_catalog.pg_class c
|
27863
|
+
JOIN
|
27864
|
+
pg_catalog.pg_namespace n ON n.oid = c.relnamespace
|
27865
|
+
WHERE
|
27866
|
+
c.relkind IN ('r', 'v', 'm')
|
27867
|
+
${where === "" ? "" : ` AND ${where}`};`
|
26404
27868
|
);
|
26405
27869
|
const schemas = new Set(allTables.map((it) => it.table_schema));
|
26406
27870
|
schemas.delete("public");
|
@@ -26420,6 +27884,8 @@ ${withStyle.errorWarning(
|
|
26420
27884
|
let indexesCount = 0;
|
26421
27885
|
let foreignKeysCount = 0;
|
26422
27886
|
let tableCount = 0;
|
27887
|
+
let checksCount = 0;
|
27888
|
+
let viewsCount = 0;
|
26423
27889
|
const sequencesToReturn = {};
|
26424
27890
|
const seqWhere = schemaFilters.map((t) => `schemaname = '${t}'`).join(" or ");
|
26425
27891
|
const allSequences = await db.query(
|
@@ -26478,7 +27944,7 @@ ${withStyle.errorWarning(
|
|
26478
27944
|
progressCallback("enums", Object.keys(enumsToReturn).length, "done");
|
26479
27945
|
}
|
26480
27946
|
const sequencesInColumns = [];
|
26481
|
-
const all = allTables.map((row) => {
|
27947
|
+
const all = allTables.filter((it) => it.type === "table").map((row) => {
|
26482
27948
|
return new Promise(async (res, rej) => {
|
26483
27949
|
const tableName = row.table_name;
|
26484
27950
|
if (!tablesFilter(tableName)) return res("");
|
@@ -26490,42 +27956,8 @@ ${withStyle.errorWarning(
|
|
26490
27956
|
const foreignKeysToReturn = {};
|
26491
27957
|
const primaryKeys = {};
|
26492
27958
|
const uniqueConstrains = {};
|
26493
|
-
const
|
26494
|
-
|
26495
|
-
, CASE WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[])
|
26496
|
-
AND EXISTS (
|
26497
|
-
SELECT FROM pg_attrdef ad
|
26498
|
-
WHERE ad.adrelid = a.attrelid
|
26499
|
-
AND ad.adnum = a.attnum
|
26500
|
-
AND pg_get_expr(ad.adbin, ad.adrelid)
|
26501
|
-
= 'nextval('''
|
26502
|
-
|| (pg_get_serial_sequence (a.attrelid::regclass::text
|
26503
|
-
, a.attname))::regclass
|
26504
|
-
|| '''::regclass)'
|
26505
|
-
)
|
26506
|
-
THEN CASE a.atttypid
|
26507
|
-
WHEN 'int'::regtype THEN 'serial'
|
26508
|
-
WHEN 'int8'::regtype THEN 'bigserial'
|
26509
|
-
WHEN 'int2'::regtype THEN 'smallserial'
|
26510
|
-
END
|
26511
|
-
ELSE format_type(a.atttypid, a.atttypmod)
|
26512
|
-
END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, ns.nspname as type_schema,
|
26513
|
-
pg_get_serial_sequence('"${tableSchema}"."${tableName}"', a.attname)::regclass as seq_name, INFORMATION_SCHEMA.COLUMNS.column_name,
|
26514
|
-
INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt,
|
26515
|
-
INFORMATION_SCHEMA.COLUMNS.udt_name as enum_name,
|
26516
|
-
INFORMATION_SCHEMA.COLUMNS.is_generated, generation_expression,
|
26517
|
-
INFORMATION_SCHEMA.COLUMNS.is_identity,INFORMATION_SCHEMA.COLUMNS.identity_generation,
|
26518
|
-
INFORMATION_SCHEMA.COLUMNS.identity_start, INFORMATION_SCHEMA.COLUMNS.identity_increment,
|
26519
|
-
INFORMATION_SCHEMA.COLUMNS.identity_maximum, INFORMATION_SCHEMA.COLUMNS.identity_minimum,
|
26520
|
-
INFORMATION_SCHEMA.COLUMNS.identity_cycle
|
26521
|
-
FROM pg_attribute a
|
26522
|
-
JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
|
26523
|
-
JOIN pg_type t ON t.oid = a.atttypid LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
|
26524
|
-
WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}' and INFORMATION_SCHEMA.COLUMNS.table_schema = '${tableSchema}'
|
26525
|
-
AND a.attnum > 0
|
26526
|
-
AND NOT a.attisdropped
|
26527
|
-
ORDER BY a.attnum;`
|
26528
|
-
);
|
27959
|
+
const checkConstraints = {};
|
27960
|
+
const tableResponse = await getColumnsInfoQuery({ schema: tableSchema, table: tableName, db });
|
26529
27961
|
const tableConstraints = await db.query(
|
26530
27962
|
`SELECT c.column_name, c.data_type, constraint_type, constraint_name, constraint_schema
|
26531
27963
|
FROM information_schema.table_constraints tc
|
@@ -26534,6 +27966,28 @@ ${withStyle.errorWarning(
|
|
26534
27966
|
AND tc.table_name = c.table_name AND ccu.column_name = c.column_name
|
26535
27967
|
WHERE tc.table_name = '${tableName}' and constraint_schema = '${tableSchema}';`
|
26536
27968
|
);
|
27969
|
+
const tableChecks = await db.query(`SELECT
|
27970
|
+
tc.constraint_name,
|
27971
|
+
tc.constraint_type,
|
27972
|
+
pg_get_constraintdef(con.oid) AS constraint_definition
|
27973
|
+
FROM
|
27974
|
+
information_schema.table_constraints AS tc
|
27975
|
+
JOIN pg_constraint AS con
|
27976
|
+
ON tc.constraint_name = con.conname
|
27977
|
+
AND con.conrelid = (
|
27978
|
+
SELECT oid
|
27979
|
+
FROM pg_class
|
27980
|
+
WHERE relname = tc.table_name
|
27981
|
+
AND relnamespace = (
|
27982
|
+
SELECT oid
|
27983
|
+
FROM pg_namespace
|
27984
|
+
WHERE nspname = tc.constraint_schema
|
27985
|
+
)
|
27986
|
+
)
|
27987
|
+
WHERE
|
27988
|
+
tc.table_name = '${tableName}'
|
27989
|
+
AND tc.constraint_schema = '${tableSchema}'
|
27990
|
+
AND tc.constraint_type = 'CHECK';`);
|
26537
27991
|
columnsCount += tableResponse.length;
|
26538
27992
|
if (progressCallback) {
|
26539
27993
|
progressCallback("columns", columnsCount, "fetching");
|
@@ -26607,13 +28061,9 @@ ${withStyle.errorWarning(
|
|
26607
28061
|
foreignKeysToReturn[foreignKeyName].columnsFrom = [
|
26608
28062
|
...new Set(foreignKeysToReturn[foreignKeyName].columnsFrom)
|
26609
28063
|
];
|
26610
|
-
foreignKeysToReturn[foreignKeyName].columnsTo = [
|
26611
|
-
...new Set(foreignKeysToReturn[foreignKeyName].columnsTo)
|
26612
|
-
];
|
28064
|
+
foreignKeysToReturn[foreignKeyName].columnsTo = [...new Set(foreignKeysToReturn[foreignKeyName].columnsTo)];
|
26613
28065
|
}
|
26614
|
-
const uniqueConstrainsRows = tableConstraints.filter(
|
26615
|
-
(mapRow) => mapRow.constraint_type === "UNIQUE"
|
26616
|
-
);
|
28066
|
+
const uniqueConstrainsRows = tableConstraints.filter((mapRow) => mapRow.constraint_type === "UNIQUE");
|
26617
28067
|
for (const unqs of uniqueConstrainsRows) {
|
26618
28068
|
const columnName = unqs.column_name;
|
26619
28069
|
const constraintName = unqs.constraint_name;
|
@@ -26627,8 +28077,21 @@ ${withStyle.errorWarning(
|
|
26627
28077
|
};
|
26628
28078
|
}
|
26629
28079
|
}
|
28080
|
+
checksCount += tableChecks.length;
|
28081
|
+
if (progressCallback) {
|
28082
|
+
progressCallback("checks", checksCount, "fetching");
|
28083
|
+
}
|
28084
|
+
for (const checks of tableChecks) {
|
28085
|
+
let checkValue = checks.constraint_definition;
|
28086
|
+
const constraintName = checks.constraint_name;
|
28087
|
+
checkValue = checkValue.replace(/^CHECK\s*\(\(/, "").replace(/\)\)\s*$/, "");
|
28088
|
+
checkConstraints[constraintName] = {
|
28089
|
+
name: constraintName,
|
28090
|
+
value: checkValue
|
28091
|
+
};
|
28092
|
+
}
|
26630
28093
|
for (const columnResponse of tableResponse) {
|
26631
|
-
const columnName = columnResponse.
|
28094
|
+
const columnName = columnResponse.column_name;
|
26632
28095
|
const columnAdditionalDT = columnResponse.additional_dt;
|
26633
28096
|
const columnDimensions = columnResponse.array_dimensions;
|
26634
28097
|
const enumType2 = columnResponse.enum_name;
|
@@ -26648,9 +28111,7 @@ ${withStyle.errorWarning(
|
|
26648
28111
|
const primaryKey = tableConstraints.filter(
|
26649
28112
|
(mapRow) => columnName === mapRow.column_name && mapRow.constraint_type === "PRIMARY KEY"
|
26650
28113
|
);
|
26651
|
-
const cprimaryKey = tableConstraints.filter(
|
26652
|
-
(mapRow) => mapRow.constraint_type === "PRIMARY KEY"
|
26653
|
-
);
|
28114
|
+
const cprimaryKey = tableConstraints.filter((mapRow) => mapRow.constraint_type === "PRIMARY KEY");
|
26654
28115
|
if (cprimaryKey.length > 1) {
|
26655
28116
|
const tableCompositePkName = await db.query(
|
26656
28117
|
`SELECT conname AS primary_key
|
@@ -26673,10 +28134,7 @@ ${withStyle.errorWarning(
|
|
26673
28134
|
[columnName]: {
|
26674
28135
|
isArray: true,
|
26675
28136
|
dimensions: columnDimensions,
|
26676
|
-
rawType: columnTypeMapped.substring(
|
26677
|
-
0,
|
26678
|
-
columnTypeMapped.length - 2
|
26679
|
-
)
|
28137
|
+
rawType: columnTypeMapped.substring(0, columnTypeMapped.length - 2)
|
26680
28138
|
}
|
26681
28139
|
}
|
26682
28140
|
};
|
@@ -26685,19 +28143,12 @@ ${withStyle.errorWarning(
|
|
26685
28143
|
internals.tables[tableName].columns[columnName] = {
|
26686
28144
|
isArray: true,
|
26687
28145
|
dimensions: columnDimensions,
|
26688
|
-
rawType: columnTypeMapped.substring(
|
26689
|
-
0,
|
26690
|
-
columnTypeMapped.length - 2
|
26691
|
-
)
|
28146
|
+
rawType: columnTypeMapped.substring(0, columnTypeMapped.length - 2)
|
26692
28147
|
};
|
26693
28148
|
}
|
26694
28149
|
}
|
26695
28150
|
}
|
26696
|
-
const defaultValue = defaultForColumn(
|
26697
|
-
columnResponse,
|
26698
|
-
internals,
|
26699
|
-
tableName
|
26700
|
-
);
|
28151
|
+
const defaultValue = defaultForColumn(columnResponse, internals, tableName);
|
26701
28152
|
if (defaultValue === "NULL" || defaultValueRes && defaultValueRes.startsWith("(") && defaultValueRes.endsWith(")")) {
|
26702
28153
|
if (typeof internals.tables[tableName] === "undefined") {
|
26703
28154
|
internals.tables[tableName] = {
|
@@ -26810,7 +28261,9 @@ ${withStyle.errorWarning(
|
|
26810
28261
|
WHERE idx.relname = '${tableName}' and schemaname = '${tableSchema}'
|
26811
28262
|
group by index_name, table_name,schemaname, generated_by_constraint;`
|
26812
28263
|
);
|
26813
|
-
const idxsInConsteraint = dbIndexFromConstraint.filter((it) => it.generated_by_constraint === 1).map(
|
28264
|
+
const idxsInConsteraint = dbIndexFromConstraint.filter((it) => it.generated_by_constraint === 1).map(
|
28265
|
+
(it) => it.index_name
|
28266
|
+
);
|
26814
28267
|
for (const dbIndex of dbIndexes) {
|
26815
28268
|
const indexName2 = dbIndex.indexname;
|
26816
28269
|
const indexColumnName = dbIndex.column_name;
|
@@ -26870,7 +28323,8 @@ ${withStyle.errorWarning(
|
|
26870
28323
|
indexes: indexToReturn,
|
26871
28324
|
foreignKeys: foreignKeysToReturn,
|
26872
28325
|
compositePrimaryKeys: primaryKeys,
|
26873
|
-
uniqueConstraints: uniqueConstrains
|
28326
|
+
uniqueConstraints: uniqueConstrains,
|
28327
|
+
checkConstraints
|
26874
28328
|
};
|
26875
28329
|
} catch (e) {
|
26876
28330
|
rej(e);
|
@@ -26884,10 +28338,181 @@ ${withStyle.errorWarning(
|
|
26884
28338
|
}
|
26885
28339
|
for await (const _2 of all) {
|
26886
28340
|
}
|
28341
|
+
const allViews = allTables.filter((it) => it.type === "view" || it.type === "materialized_view").map((row) => {
|
28342
|
+
return new Promise(async (res, rej) => {
|
28343
|
+
const viewName = row.table_name;
|
28344
|
+
if (!tablesFilter(viewName)) return res("");
|
28345
|
+
tableCount += 1;
|
28346
|
+
const viewSchema = row.table_schema;
|
28347
|
+
try {
|
28348
|
+
const columnToReturn = {};
|
28349
|
+
const viewResponses = await getColumnsInfoQuery({ schema: viewSchema, table: viewName, db });
|
28350
|
+
for (const viewResponse of viewResponses) {
|
28351
|
+
const columnName = viewResponse.column_name;
|
28352
|
+
const columnAdditionalDT = viewResponse.additional_dt;
|
28353
|
+
const columnDimensions = viewResponse.array_dimensions;
|
28354
|
+
const enumType2 = viewResponse.enum_name;
|
28355
|
+
let columnType = viewResponse.data_type;
|
28356
|
+
const typeSchema = viewResponse.type_schema;
|
28357
|
+
const isGenerated = viewResponse.is_generated === "ALWAYS";
|
28358
|
+
const generationExpression = viewResponse.generation_expression;
|
28359
|
+
const isIdentity = viewResponse.is_identity === "YES";
|
28360
|
+
const identityGeneration = viewResponse.identity_generation === "ALWAYS" ? "always" : "byDefault";
|
28361
|
+
const identityStart = viewResponse.identity_start;
|
28362
|
+
const identityIncrement = viewResponse.identity_increment;
|
28363
|
+
const identityMaximum = viewResponse.identity_maximum;
|
28364
|
+
const identityMinimum = viewResponse.identity_minimum;
|
28365
|
+
const identityCycle = viewResponse.identity_cycle === "YES";
|
28366
|
+
const identityName = viewResponse.seq_name;
|
28367
|
+
const defaultValueRes = viewResponse.column_default;
|
28368
|
+
const primaryKey = viewResponse.constraint_type === "PRIMARY KEY";
|
28369
|
+
let columnTypeMapped = columnType;
|
28370
|
+
if (columnAdditionalDT === "ARRAY") {
|
28371
|
+
if (typeof internals.tables[viewName] === "undefined") {
|
28372
|
+
internals.tables[viewName] = {
|
28373
|
+
columns: {
|
28374
|
+
[columnName]: {
|
28375
|
+
isArray: true,
|
28376
|
+
dimensions: columnDimensions,
|
28377
|
+
rawType: columnTypeMapped.substring(0, columnTypeMapped.length - 2)
|
28378
|
+
}
|
28379
|
+
}
|
28380
|
+
};
|
28381
|
+
} else {
|
28382
|
+
if (typeof internals.tables[viewName].columns[columnName] === "undefined") {
|
28383
|
+
internals.tables[viewName].columns[columnName] = {
|
28384
|
+
isArray: true,
|
28385
|
+
dimensions: columnDimensions,
|
28386
|
+
rawType: columnTypeMapped.substring(0, columnTypeMapped.length - 2)
|
28387
|
+
};
|
28388
|
+
}
|
28389
|
+
}
|
28390
|
+
}
|
28391
|
+
const defaultValue = defaultForColumn(viewResponse, internals, viewName);
|
28392
|
+
if (defaultValue === "NULL" || defaultValueRes && defaultValueRes.startsWith("(") && defaultValueRes.endsWith(")")) {
|
28393
|
+
if (typeof internals.tables[viewName] === "undefined") {
|
28394
|
+
internals.tables[viewName] = {
|
28395
|
+
columns: {
|
28396
|
+
[columnName]: {
|
28397
|
+
isDefaultAnExpression: true
|
28398
|
+
}
|
28399
|
+
}
|
28400
|
+
};
|
28401
|
+
} else {
|
28402
|
+
if (typeof internals.tables[viewName].columns[columnName] === "undefined") {
|
28403
|
+
internals.tables[viewName].columns[columnName] = {
|
28404
|
+
isDefaultAnExpression: true
|
28405
|
+
};
|
28406
|
+
} else {
|
28407
|
+
internals.tables[viewName].columns[columnName].isDefaultAnExpression = true;
|
28408
|
+
}
|
28409
|
+
}
|
28410
|
+
}
|
28411
|
+
const isSerial = columnType === "serial";
|
28412
|
+
if (columnTypeMapped.startsWith("numeric(")) {
|
28413
|
+
columnTypeMapped = columnTypeMapped.replace(",", ", ");
|
28414
|
+
}
|
28415
|
+
if (columnAdditionalDT === "ARRAY") {
|
28416
|
+
for (let i = 1; i < Number(columnDimensions); i++) {
|
28417
|
+
columnTypeMapped += "[]";
|
28418
|
+
}
|
28419
|
+
}
|
28420
|
+
columnTypeMapped = columnTypeMapped.replace("character varying", "varchar").replace(" without time zone", "").replace("character", "char");
|
28421
|
+
columnTypeMapped = trimChar(columnTypeMapped, '"');
|
28422
|
+
columnToReturn[columnName] = {
|
28423
|
+
name: columnName,
|
28424
|
+
type: (
|
28425
|
+
// filter vectors, but in future we should filter any extension that was installed by user
|
28426
|
+
columnAdditionalDT === "USER-DEFINED" && !["vector", "geometry"].includes(enumType2) ? enumType2 : columnTypeMapped
|
28427
|
+
),
|
28428
|
+
typeSchema: enumsToReturn[`${typeSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${typeSchema}.${enumType2}`].schema : void 0,
|
28429
|
+
primaryKey,
|
28430
|
+
notNull: viewResponse.is_nullable === "NO",
|
28431
|
+
generated: isGenerated ? { as: generationExpression, type: "stored" } : void 0,
|
28432
|
+
identity: isIdentity ? {
|
28433
|
+
type: identityGeneration,
|
28434
|
+
name: identityName,
|
28435
|
+
increment: stringFromDatabaseIdentityProperty(identityIncrement),
|
28436
|
+
minValue: stringFromDatabaseIdentityProperty(identityMinimum),
|
28437
|
+
maxValue: stringFromDatabaseIdentityProperty(identityMaximum),
|
28438
|
+
startWith: stringFromDatabaseIdentityProperty(identityStart),
|
28439
|
+
cache: sequencesToReturn[identityName]?.cache ? sequencesToReturn[identityName]?.cache : sequencesToReturn[`${viewSchema}.${identityName}`]?.cache ? sequencesToReturn[`${viewSchema}.${identityName}`]?.cache : void 0,
|
28440
|
+
cycle: identityCycle,
|
28441
|
+
schema: viewSchema
|
28442
|
+
} : void 0
|
28443
|
+
};
|
28444
|
+
if (identityName) {
|
28445
|
+
delete sequencesToReturn[`${viewSchema}.${identityName.startsWith('"') && identityName.endsWith('"') ? identityName.slice(1, -1) : identityName}`];
|
28446
|
+
delete sequencesToReturn[identityName];
|
28447
|
+
}
|
28448
|
+
if (!isSerial && typeof defaultValue !== "undefined") {
|
28449
|
+
columnToReturn[columnName].default = defaultValue;
|
28450
|
+
}
|
28451
|
+
}
|
28452
|
+
const [viewInfo] = await db.query(`
|
28453
|
+
SELECT
|
28454
|
+
c.relname AS view_name,
|
28455
|
+
n.nspname AS schema_name,
|
28456
|
+
pg_get_viewdef(c.oid, true) AS definition,
|
28457
|
+
ts.spcname AS tablespace_name,
|
28458
|
+
c.reloptions AS options,
|
28459
|
+
pg_tablespace_location(ts.oid) AS location
|
28460
|
+
FROM
|
28461
|
+
pg_class c
|
28462
|
+
JOIN
|
28463
|
+
pg_namespace n ON c.relnamespace = n.oid
|
28464
|
+
LEFT JOIN
|
28465
|
+
pg_tablespace ts ON c.reltablespace = ts.oid
|
28466
|
+
WHERE
|
28467
|
+
(c.relkind = 'm' OR c.relkind = 'v')
|
28468
|
+
AND n.nspname = '${viewSchema}'
|
28469
|
+
AND c.relname = '${viewName}';`);
|
28470
|
+
const resultWith = {};
|
28471
|
+
if (viewInfo.options) {
|
28472
|
+
viewInfo.options.forEach((pair) => {
|
28473
|
+
const splitted = pair.split("=");
|
28474
|
+
const key = splitted[0];
|
28475
|
+
const value = splitted[1];
|
28476
|
+
if (value === "true") {
|
28477
|
+
resultWith[key] = true;
|
28478
|
+
} else if (value === "false") {
|
28479
|
+
resultWith[key] = false;
|
28480
|
+
} else if (!isNaN(Number(value))) {
|
28481
|
+
resultWith[key] = Number(value);
|
28482
|
+
} else {
|
28483
|
+
resultWith[key] = value;
|
28484
|
+
}
|
28485
|
+
});
|
28486
|
+
}
|
28487
|
+
const definition = viewInfo.definition.replace(/\s+/g, " ").replace(";", "").trim();
|
28488
|
+
const withOption = Object.values(resultWith).length ? Object.fromEntries(Object.entries(resultWith).map(([key, value]) => [key.camelCase(), value])) : void 0;
|
28489
|
+
const materialized = row.type === "materialized_view";
|
28490
|
+
views[`${viewSchema}.${viewName}`] = {
|
28491
|
+
name: viewName,
|
28492
|
+
schema: viewSchema,
|
28493
|
+
columns: columnToReturn,
|
28494
|
+
isExisting: false,
|
28495
|
+
definition,
|
28496
|
+
materialized,
|
28497
|
+
with: withOption,
|
28498
|
+
tablespace: viewInfo.tablespace_name ?? void 0
|
28499
|
+
};
|
28500
|
+
} catch (e) {
|
28501
|
+
rej(e);
|
28502
|
+
return;
|
28503
|
+
}
|
28504
|
+
res("");
|
28505
|
+
});
|
28506
|
+
});
|
28507
|
+
viewsCount = allViews.length;
|
28508
|
+
for await (const _2 of allViews) {
|
28509
|
+
}
|
26887
28510
|
if (progressCallback) {
|
26888
28511
|
progressCallback("columns", columnsCount, "done");
|
26889
28512
|
progressCallback("indexes", indexesCount, "done");
|
26890
28513
|
progressCallback("fks", foreignKeysCount, "done");
|
28514
|
+
progressCallback("checks", checksCount, "done");
|
28515
|
+
progressCallback("views", viewsCount, "done");
|
26891
28516
|
}
|
26892
28517
|
const schemasObject = Object.fromEntries([...schemas].map((it) => [it, it]));
|
26893
28518
|
return {
|
@@ -26897,6 +28522,7 @@ ${withStyle.errorWarning(
|
|
26897
28522
|
enums: enumsToReturn,
|
26898
28523
|
schemas: schemasObject,
|
26899
28524
|
sequences: sequencesToReturn,
|
28525
|
+
views,
|
26900
28526
|
_meta: {
|
26901
28527
|
schemas: {},
|
26902
28528
|
tables: {},
|
@@ -26906,7 +28532,7 @@ ${withStyle.errorWarning(
|
|
26906
28532
|
};
|
26907
28533
|
};
|
26908
28534
|
defaultForColumn = (column4, internals, tableName) => {
|
26909
|
-
const columnName = column4.
|
28535
|
+
const columnName = column4.column_name;
|
26910
28536
|
const isArray = internals?.tables[tableName]?.columns[columnName]?.isArray ?? false;
|
26911
28537
|
if (column4.column_default === null) {
|
26912
28538
|
return void 0;
|
@@ -26959,6 +28585,8 @@ ${withStyle.errorWarning(
|
|
26959
28585
|
}
|
26960
28586
|
return columnDefaultAsString;
|
26961
28587
|
}
|
28588
|
+
} else if (column4.data_type.includes("numeric")) {
|
28589
|
+
return columnDefaultAsString.includes("'") ? columnDefaultAsString : `'${columnDefaultAsString}'`;
|
26962
28590
|
} else if (column4.data_type === "json" || column4.data_type === "jsonb") {
|
26963
28591
|
const jsonWithoutSpaces = JSON.stringify(JSON.parse(columnDefaultAsString.slice(1, -1)));
|
26964
28592
|
return `'${jsonWithoutSpaces}'::${column4.data_type}`;
|
@@ -26972,6 +28600,75 @@ ${withStyle.errorWarning(
|
|
26972
28600
|
return `${columnDefaultAsString.replace(/\\/g, "`\\")}`;
|
26973
28601
|
}
|
26974
28602
|
};
|
28603
|
+
getColumnsInfoQuery = ({ schema: schema4, table: table4, db }) => {
|
28604
|
+
return db.query(
|
28605
|
+
`SELECT
|
28606
|
+
a.attrelid::regclass::text AS table_name, -- Table, view, or materialized view name
|
28607
|
+
a.attname AS column_name, -- Column name
|
28608
|
+
CASE
|
28609
|
+
WHEN NOT a.attisdropped THEN
|
28610
|
+
CASE
|
28611
|
+
WHEN a.attnotnull THEN 'NO'
|
28612
|
+
ELSE 'YES'
|
28613
|
+
END
|
28614
|
+
ELSE NULL
|
28615
|
+
END AS is_nullable, -- NULL or NOT NULL constraint
|
28616
|
+
a.attndims AS array_dimensions, -- Array dimensions
|
28617
|
+
CASE
|
28618
|
+
WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[])
|
28619
|
+
AND EXISTS (
|
28620
|
+
SELECT FROM pg_attrdef ad
|
28621
|
+
WHERE ad.adrelid = a.attrelid
|
28622
|
+
AND ad.adnum = a.attnum
|
28623
|
+
AND pg_get_expr(ad.adbin, ad.adrelid) = 'nextval('''
|
28624
|
+
|| pg_get_serial_sequence(a.attrelid::regclass::text, a.attname)::regclass || '''::regclass)'
|
28625
|
+
)
|
28626
|
+
THEN CASE a.atttypid
|
28627
|
+
WHEN 'int'::regtype THEN 'serial'
|
28628
|
+
WHEN 'int8'::regtype THEN 'bigserial'
|
28629
|
+
WHEN 'int2'::regtype THEN 'smallserial'
|
28630
|
+
END
|
28631
|
+
ELSE format_type(a.atttypid, a.atttypmod)
|
28632
|
+
END AS data_type, -- Column data type
|
28633
|
+
-- ns.nspname AS type_schema, -- Schema name
|
28634
|
+
pg_get_serial_sequence('"${schema4}"."${table4}"', a.attname)::regclass AS seq_name, -- Serial sequence (if any)
|
28635
|
+
c.column_default, -- Column default value
|
28636
|
+
c.data_type AS additional_dt, -- Data type from information_schema
|
28637
|
+
c.udt_name AS enum_name, -- Enum type (if applicable)
|
28638
|
+
c.is_generated, -- Is it a generated column?
|
28639
|
+
c.generation_expression, -- Generation expression (if generated)
|
28640
|
+
c.is_identity, -- Is it an identity column?
|
28641
|
+
c.identity_generation, -- Identity generation strategy (ALWAYS or BY DEFAULT)
|
28642
|
+
c.identity_start, -- Start value of identity column
|
28643
|
+
c.identity_increment, -- Increment for identity column
|
28644
|
+
c.identity_maximum, -- Maximum value for identity column
|
28645
|
+
c.identity_minimum, -- Minimum value for identity column
|
28646
|
+
c.identity_cycle, -- Does the identity column cycle?
|
28647
|
+
enum_ns.nspname AS type_schema -- Schema of the enum type
|
28648
|
+
FROM
|
28649
|
+
pg_attribute a
|
28650
|
+
JOIN
|
28651
|
+
pg_class cls ON cls.oid = a.attrelid -- Join pg_class to get table/view/materialized view info
|
28652
|
+
JOIN
|
28653
|
+
pg_namespace ns ON ns.oid = cls.relnamespace -- Join namespace to get schema info
|
28654
|
+
LEFT JOIN
|
28655
|
+
information_schema.columns c ON c.column_name = a.attname
|
28656
|
+
AND c.table_schema = ns.nspname
|
28657
|
+
AND c.table_name = cls.relname -- Match schema and table/view name
|
28658
|
+
LEFT JOIN
|
28659
|
+
pg_type enum_t ON enum_t.oid = a.atttypid -- Join to get the type info
|
28660
|
+
LEFT JOIN
|
28661
|
+
pg_namespace enum_ns ON enum_ns.oid = enum_t.typnamespace -- Join to get the enum schema
|
28662
|
+
WHERE
|
28663
|
+
a.attnum > 0 -- Valid column numbers only
|
28664
|
+
AND NOT a.attisdropped -- Skip dropped columns
|
28665
|
+
AND cls.relkind IN ('r', 'v', 'm') -- Include regular tables ('r'), views ('v'), and materialized views ('m')
|
28666
|
+
AND ns.nspname = '${schema4}' -- Filter by schema
|
28667
|
+
AND cls.relname = '${table4}' -- Filter by table name
|
28668
|
+
ORDER BY
|
28669
|
+
a.attnum; -- Order by column number`
|
28670
|
+
);
|
28671
|
+
};
|
26975
28672
|
}
|
26976
28673
|
});
|
26977
28674
|
|
@@ -27726,7 +29423,9 @@ var init_delete2 = __esm({
|
|
27726
29423
|
"use strict";
|
27727
29424
|
init_entity();
|
27728
29425
|
init_query_promise();
|
29426
|
+
init_selection_proxy();
|
27729
29427
|
init_table3();
|
29428
|
+
init_table();
|
27730
29429
|
init_utils2();
|
27731
29430
|
SQLiteDeleteBase = class extends (_b141 = QueryPromise, _a194 = entityKind, _b141) {
|
27732
29431
|
constructor(table4, session, dialect4, withList) {
|
@@ -27783,6 +29482,26 @@ var init_delete2 = __esm({
|
|
27783
29482
|
this.config.where = where;
|
27784
29483
|
return this;
|
27785
29484
|
}
|
29485
|
+
orderBy(...columns) {
|
29486
|
+
if (typeof columns[0] === "function") {
|
29487
|
+
const orderBy = columns[0](
|
29488
|
+
new Proxy(
|
29489
|
+
this.config.table[Table.Symbol.Columns],
|
29490
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
29491
|
+
)
|
29492
|
+
);
|
29493
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
29494
|
+
this.config.orderBy = orderByArray;
|
29495
|
+
} else {
|
29496
|
+
const orderByArray = columns;
|
29497
|
+
this.config.orderBy = orderByArray;
|
29498
|
+
}
|
29499
|
+
return this;
|
29500
|
+
}
|
29501
|
+
limit(limit) {
|
29502
|
+
this.config.limit = limit;
|
29503
|
+
return this;
|
29504
|
+
}
|
27786
29505
|
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
27787
29506
|
this.config.returning = orderSelectedFields(fields);
|
27788
29507
|
return this;
|
@@ -27993,7 +29712,7 @@ var init_view_base2 = __esm({
|
|
27993
29712
|
"use strict";
|
27994
29713
|
init_entity();
|
27995
29714
|
init_sql();
|
27996
|
-
SQLiteViewBase = class extends (_b143 =
|
29715
|
+
SQLiteViewBase = class extends (_b143 = View3, _a197 = entityKind, _b143) {
|
27997
29716
|
};
|
27998
29717
|
__publicField(SQLiteViewBase, _a197, "SQLiteViewBase");
|
27999
29718
|
}
|
@@ -28048,11 +29767,13 @@ var init_dialect2 = __esm({
|
|
28048
29767
|
withSqlChunks.push(sql` `);
|
28049
29768
|
return sql.join(withSqlChunks);
|
28050
29769
|
}
|
28051
|
-
buildDeleteQuery({ table: table4, where, returning, withList }) {
|
29770
|
+
buildDeleteQuery({ table: table4, where, returning, withList, limit, orderBy }) {
|
28052
29771
|
const withSql = this.buildWithCTE(withList);
|
28053
29772
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
28054
29773
|
const whereSql = where ? sql` where ${where}` : void 0;
|
28055
|
-
|
29774
|
+
const orderBySql = this.buildOrderBy(orderBy);
|
29775
|
+
const limitSql = this.buildLimit(limit);
|
29776
|
+
return sql`${withSql}delete from ${table4}${whereSql}${returningSql}${orderBySql}${limitSql}`;
|
28056
29777
|
}
|
28057
29778
|
buildUpdateSet(table4, set) {
|
28058
29779
|
const tableColumns = table4[Table.Symbol.Columns];
|
@@ -28070,12 +29791,14 @@ var init_dialect2 = __esm({
|
|
28070
29791
|
return [res];
|
28071
29792
|
}));
|
28072
29793
|
}
|
28073
|
-
buildUpdateQuery({ table: table4, set, where, returning, withList }) {
|
29794
|
+
buildUpdateQuery({ table: table4, set, where, returning, withList, limit, orderBy }) {
|
28074
29795
|
const withSql = this.buildWithCTE(withList);
|
28075
29796
|
const setSql = this.buildUpdateSet(table4, set);
|
28076
29797
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
28077
29798
|
const whereSql = where ? sql` where ${where}` : void 0;
|
28078
|
-
|
29799
|
+
const orderBySql = this.buildOrderBy(orderBy);
|
29800
|
+
const limitSql = this.buildLimit(limit);
|
29801
|
+
return sql`${withSql}update ${table4} set ${setSql}${whereSql}${returningSql}${orderBySql}${limitSql}`;
|
28079
29802
|
}
|
28080
29803
|
/**
|
28081
29804
|
* Builds selection SQL with provided fields/expressions
|
@@ -28128,6 +29851,21 @@ var init_dialect2 = __esm({
|
|
28128
29851
|
});
|
28129
29852
|
return sql.join(chunks);
|
28130
29853
|
}
|
29854
|
+
buildLimit(limit) {
|
29855
|
+
return typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
|
29856
|
+
}
|
29857
|
+
buildOrderBy(orderBy) {
|
29858
|
+
const orderByList = [];
|
29859
|
+
if (orderBy) {
|
29860
|
+
for (const [index4, orderByValue] of orderBy.entries()) {
|
29861
|
+
orderByList.push(orderByValue);
|
29862
|
+
if (index4 < orderBy.length - 1) {
|
29863
|
+
orderByList.push(sql`, `);
|
29864
|
+
}
|
29865
|
+
}
|
29866
|
+
}
|
29867
|
+
return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
|
29868
|
+
}
|
28131
29869
|
buildSelectQuery({
|
28132
29870
|
withList,
|
28133
29871
|
fields,
|
@@ -28192,15 +29930,6 @@ var init_dialect2 = __esm({
|
|
28192
29930
|
const joinsSql = sql.join(joinsArray);
|
28193
29931
|
const whereSql = where ? sql` where ${where}` : void 0;
|
28194
29932
|
const havingSql = having ? sql` having ${having}` : void 0;
|
28195
|
-
const orderByList = [];
|
28196
|
-
if (orderBy) {
|
28197
|
-
for (const [index4, orderByValue] of orderBy.entries()) {
|
28198
|
-
orderByList.push(orderByValue);
|
28199
|
-
if (index4 < orderBy.length - 1) {
|
28200
|
-
orderByList.push(sql`, `);
|
28201
|
-
}
|
28202
|
-
}
|
28203
|
-
}
|
28204
29933
|
const groupByList = [];
|
28205
29934
|
if (groupBy) {
|
28206
29935
|
for (const [index4, groupByValue] of groupBy.entries()) {
|
@@ -28211,8 +29940,8 @@ var init_dialect2 = __esm({
|
|
28211
29940
|
}
|
28212
29941
|
}
|
28213
29942
|
const groupBySql = groupByList.length > 0 ? sql` group by ${sql.join(groupByList)}` : void 0;
|
28214
|
-
const orderBySql =
|
28215
|
-
const limitSql =
|
29943
|
+
const orderBySql = this.buildOrderBy(orderBy);
|
29944
|
+
const limitSql = this.buildLimit(limit);
|
28216
29945
|
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
28217
29946
|
const finalQuery = sql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}`;
|
28218
29947
|
if (setOperators.length > 0) {
|
@@ -28931,7 +30660,7 @@ var init_select3 = __esm({
|
|
28931
30660
|
};
|
28932
30661
|
}
|
28933
30662
|
if (typeof tableName === "string" && !is(table4, SQL)) {
|
28934
|
-
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4,
|
30663
|
+
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4, View3) ? table4[ViewBaseConfig].selectedFields : table4[Table.Symbol.Columns];
|
28935
30664
|
this.config.fields[tableName] = selection;
|
28936
30665
|
}
|
28937
30666
|
}
|
@@ -29323,7 +31052,9 @@ var init_update2 = __esm({
|
|
29323
31052
|
"use strict";
|
29324
31053
|
init_entity();
|
29325
31054
|
init_query_promise();
|
31055
|
+
init_selection_proxy();
|
29326
31056
|
init_table3();
|
31057
|
+
init_table();
|
29327
31058
|
init_utils2();
|
29328
31059
|
_a205 = entityKind;
|
29329
31060
|
SQLiteUpdateBuilder = class {
|
@@ -29402,6 +31133,26 @@ var init_update2 = __esm({
|
|
29402
31133
|
this.config.where = where;
|
29403
31134
|
return this;
|
29404
31135
|
}
|
31136
|
+
orderBy(...columns) {
|
31137
|
+
if (typeof columns[0] === "function") {
|
31138
|
+
const orderBy = columns[0](
|
31139
|
+
new Proxy(
|
31140
|
+
this.config.table[Table.Symbol.Columns],
|
31141
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
31142
|
+
)
|
31143
|
+
);
|
31144
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
31145
|
+
this.config.orderBy = orderByArray;
|
31146
|
+
} else {
|
31147
|
+
const orderByArray = columns;
|
31148
|
+
this.config.orderBy = orderByArray;
|
31149
|
+
}
|
31150
|
+
return this;
|
31151
|
+
}
|
31152
|
+
limit(limit) {
|
31153
|
+
this.config.limit = limit;
|
31154
|
+
return this;
|
31155
|
+
}
|
29405
31156
|
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
29406
31157
|
this.config.returning = orderSelectedFields(fields);
|
29407
31158
|
return this;
|
@@ -30217,15 +31968,6 @@ var init_subquery3 = __esm({
|
|
30217
31968
|
}
|
30218
31969
|
});
|
30219
31970
|
|
30220
|
-
// ../drizzle-orm/dist/sqlite-core/view-common.js
|
30221
|
-
var SQLiteViewConfig;
|
30222
|
-
var init_view_common3 = __esm({
|
30223
|
-
"../drizzle-orm/dist/sqlite-core/view-common.js"() {
|
30224
|
-
"use strict";
|
30225
|
-
SQLiteViewConfig = Symbol.for("drizzle:SQLiteViewConfig");
|
30226
|
-
}
|
30227
|
-
});
|
30228
|
-
|
30229
31971
|
// ../drizzle-orm/dist/sqlite-core/utils.js
|
30230
31972
|
function getTableConfig2(table4) {
|
30231
31973
|
const columns = Object.values(table4[SQLiteTable.Symbol.Columns]);
|
@@ -30262,11 +32004,18 @@ function getTableConfig2(table4) {
|
|
30262
32004
|
name: name2
|
30263
32005
|
};
|
30264
32006
|
}
|
32007
|
+
function getViewConfig2(view4) {
|
32008
|
+
return {
|
32009
|
+
...view4[ViewBaseConfig]
|
32010
|
+
// ...view[SQLiteViewConfig],
|
32011
|
+
};
|
32012
|
+
}
|
30265
32013
|
var init_utils6 = __esm({
|
30266
32014
|
"../drizzle-orm/dist/sqlite-core/utils.js"() {
|
30267
32015
|
"use strict";
|
30268
32016
|
init_entity();
|
30269
32017
|
init_table();
|
32018
|
+
init_view_common();
|
30270
32019
|
init_checks2();
|
30271
32020
|
init_foreign_keys2();
|
30272
32021
|
init_indexes2();
|
@@ -30277,7 +32026,7 @@ var init_utils6 = __esm({
|
|
30277
32026
|
});
|
30278
32027
|
|
30279
32028
|
// ../drizzle-orm/dist/sqlite-core/view.js
|
30280
|
-
var _a222, ViewBuilderCore, _a223, _b155, ViewBuilder2, _a224, _b156, ManualViewBuilder2, _a225, _b157,
|
32029
|
+
var _a222, ViewBuilderCore, _a223, _b155, ViewBuilder2, _a224, _b156, ManualViewBuilder2, _a225, _b157, SQLiteView2;
|
30281
32030
|
var init_view2 = __esm({
|
30282
32031
|
"../drizzle-orm/dist/sqlite-core/view.js"() {
|
30283
32032
|
"use strict";
|
@@ -30287,7 +32036,6 @@ var init_view2 = __esm({
|
|
30287
32036
|
init_query_builder3();
|
30288
32037
|
init_table3();
|
30289
32038
|
init_view_base2();
|
30290
|
-
init_view_common3();
|
30291
32039
|
_a222 = entityKind;
|
30292
32040
|
ViewBuilderCore = class {
|
30293
32041
|
constructor(name2) {
|
@@ -30309,8 +32057,8 @@ var init_view2 = __esm({
|
|
30309
32057
|
});
|
30310
32058
|
const aliasedSelectedFields = qb.getSelectedFields();
|
30311
32059
|
return new Proxy(
|
30312
|
-
new
|
30313
|
-
sqliteConfig: this.config,
|
32060
|
+
new SQLiteView2({
|
32061
|
+
// sqliteConfig: this.config,
|
30314
32062
|
config: {
|
30315
32063
|
name: this.name,
|
30316
32064
|
schema: void 0,
|
@@ -30331,8 +32079,7 @@ var init_view2 = __esm({
|
|
30331
32079
|
}
|
30332
32080
|
existing() {
|
30333
32081
|
return new Proxy(
|
30334
|
-
new
|
30335
|
-
sqliteConfig: void 0,
|
32082
|
+
new SQLiteView2({
|
30336
32083
|
config: {
|
30337
32084
|
name: this.name,
|
30338
32085
|
schema: void 0,
|
@@ -30350,8 +32097,7 @@ var init_view2 = __esm({
|
|
30350
32097
|
}
|
30351
32098
|
as(query) {
|
30352
32099
|
return new Proxy(
|
30353
|
-
new
|
30354
|
-
sqliteConfig: this.config,
|
32100
|
+
new SQLiteView2({
|
30355
32101
|
config: {
|
30356
32102
|
name: this.name,
|
30357
32103
|
schema: void 0,
|
@@ -30369,15 +32115,12 @@ var init_view2 = __esm({
|
|
30369
32115
|
}
|
30370
32116
|
};
|
30371
32117
|
__publicField(ManualViewBuilder2, _a224, "SQLiteManualViewBuilder");
|
30372
|
-
|
30373
|
-
constructor({
|
32118
|
+
SQLiteView2 = class extends (_b157 = SQLiteViewBase, _a225 = entityKind, _b157) {
|
32119
|
+
constructor({ config }) {
|
30374
32120
|
super(config);
|
30375
|
-
/** @internal */
|
30376
|
-
__publicField(this, _a225);
|
30377
|
-
this[SQLiteViewConfig] = sqliteConfig;
|
30378
32121
|
}
|
30379
32122
|
};
|
30380
|
-
__publicField(
|
32123
|
+
__publicField(SQLiteView2, _a225, "SQLiteView");
|
30381
32124
|
}
|
30382
32125
|
});
|
30383
32126
|
|
@@ -30475,9 +32218,10 @@ var init_sqliteSerializer = __esm({
|
|
30475
32218
|
init_outputs();
|
30476
32219
|
init_utils();
|
30477
32220
|
init_serializer();
|
30478
|
-
generateSqliteSnapshot = (tables, casing2) => {
|
32221
|
+
generateSqliteSnapshot = (tables, views, casing2) => {
|
30479
32222
|
const dialect4 = new SQLiteSyncDialect({ casing: casing2 });
|
30480
32223
|
const result = {};
|
32224
|
+
const resultViews = {};
|
30481
32225
|
const internal = { indexes: {} };
|
30482
32226
|
for (const table4 of tables) {
|
30483
32227
|
const columnsObject = {};
|
@@ -30485,10 +32229,13 @@ var init_sqliteSerializer = __esm({
|
|
30485
32229
|
const foreignKeysObject = {};
|
30486
32230
|
const primaryKeysObject = {};
|
30487
32231
|
const uniqueConstraintObject = {};
|
32232
|
+
const checkConstraintObject = {};
|
32233
|
+
const checksInTable = {};
|
30488
32234
|
const {
|
30489
32235
|
name: tableName,
|
30490
32236
|
columns,
|
30491
32237
|
indexes,
|
32238
|
+
checks,
|
30492
32239
|
foreignKeys: tableForeignKeys,
|
30493
32240
|
primaryKeys,
|
30494
32241
|
uniqueConstraints
|
@@ -30664,19 +32411,95 @@ The unique constraint ${source_default.underline.blue(
|
|
30664
32411
|
columnsObject[getColumnCasing(it.columns[0], casing2)].primaryKey = true;
|
30665
32412
|
}
|
30666
32413
|
});
|
32414
|
+
checks.forEach((check) => {
|
32415
|
+
const checkName = check.name;
|
32416
|
+
if (typeof checksInTable[tableName] !== "undefined") {
|
32417
|
+
if (checksInTable[tableName].includes(check.name)) {
|
32418
|
+
console.log(
|
32419
|
+
`
|
32420
|
+
${withStyle.errorWarning(
|
32421
|
+
`We've found duplicated check constraint name in ${source_default.underline.blue(
|
32422
|
+
tableName
|
32423
|
+
)}. Please rename your check constraint in the ${source_default.underline.blue(
|
32424
|
+
tableName
|
32425
|
+
)} table`
|
32426
|
+
)}`
|
32427
|
+
);
|
32428
|
+
process.exit(1);
|
32429
|
+
}
|
32430
|
+
checksInTable[tableName].push(checkName);
|
32431
|
+
} else {
|
32432
|
+
checksInTable[tableName] = [check.name];
|
32433
|
+
}
|
32434
|
+
checkConstraintObject[checkName] = {
|
32435
|
+
name: checkName,
|
32436
|
+
value: dialect4.sqlToQuery(check.value).sql
|
32437
|
+
};
|
32438
|
+
});
|
30667
32439
|
result[tableName] = {
|
30668
32440
|
name: tableName,
|
30669
32441
|
columns: columnsObject,
|
30670
32442
|
indexes: indexesObject,
|
30671
32443
|
foreignKeys: foreignKeysObject,
|
30672
32444
|
compositePrimaryKeys: primaryKeysObject,
|
30673
|
-
uniqueConstraints: uniqueConstraintObject
|
32445
|
+
uniqueConstraints: uniqueConstraintObject,
|
32446
|
+
checkConstraints: checkConstraintObject
|
32447
|
+
};
|
32448
|
+
}
|
32449
|
+
for (const view4 of views) {
|
32450
|
+
const { name: name2, isExisting, selectedFields, query, schema: schema4 } = getViewConfig2(view4);
|
32451
|
+
const columnsObject = {};
|
32452
|
+
const existingView = resultViews[name2];
|
32453
|
+
if (typeof existingView !== "undefined") {
|
32454
|
+
console.log(
|
32455
|
+
`
|
32456
|
+
${withStyle.errorWarning(
|
32457
|
+
`We've found duplicated view name across ${source_default.underline.blue(
|
32458
|
+
schema4 ?? "public"
|
32459
|
+
)} schema. Please rename your view`
|
32460
|
+
)}`
|
32461
|
+
);
|
32462
|
+
process.exit(1);
|
32463
|
+
}
|
32464
|
+
for (const key in selectedFields) {
|
32465
|
+
if (is(selectedFields[key], SQLiteColumn)) {
|
32466
|
+
const column4 = selectedFields[key];
|
32467
|
+
const notNull = column4.notNull;
|
32468
|
+
const primaryKey = column4.primary;
|
32469
|
+
const generated = column4.generated;
|
32470
|
+
const columnToSet = {
|
32471
|
+
name: column4.name,
|
32472
|
+
type: column4.getSQLType(),
|
32473
|
+
primaryKey,
|
32474
|
+
notNull,
|
32475
|
+
autoincrement: is(column4, SQLiteBaseInteger) ? column4.autoIncrement : false,
|
32476
|
+
generated: generated ? {
|
32477
|
+
as: is(generated.as, SQL) ? `(${dialect4.sqlToQuery(generated.as, "indexes").sql})` : typeof generated.as === "function" ? `(${dialect4.sqlToQuery(generated.as(), "indexes").sql})` : `(${generated.as})`,
|
32478
|
+
type: generated.mode ?? "virtual"
|
32479
|
+
} : void 0
|
32480
|
+
};
|
32481
|
+
if (column4.default !== void 0) {
|
32482
|
+
if (is(column4.default, SQL)) {
|
32483
|
+
columnToSet.default = sqlToStr(column4.default, casing2);
|
32484
|
+
} else {
|
32485
|
+
columnToSet.default = typeof column4.default === "string" ? `'${column4.default}'` : typeof column4.default === "object" || Array.isArray(column4.default) ? `'${JSON.stringify(column4.default)}'` : column4.default;
|
32486
|
+
}
|
32487
|
+
}
|
32488
|
+
columnsObject[column4.name] = columnToSet;
|
32489
|
+
}
|
32490
|
+
}
|
32491
|
+
resultViews[name2] = {
|
32492
|
+
columns: columnsObject,
|
32493
|
+
name: name2,
|
32494
|
+
isExisting,
|
32495
|
+
definition: isExisting ? void 0 : dialect4.sqlToQuery(query).sql
|
30674
32496
|
};
|
30675
32497
|
}
|
30676
32498
|
return {
|
30677
32499
|
version: "6",
|
30678
32500
|
dialect: "sqlite",
|
30679
32501
|
tables: result,
|
32502
|
+
views: resultViews,
|
30680
32503
|
enums: {},
|
30681
32504
|
_meta: {
|
30682
32505
|
tables: {},
|
@@ -30687,11 +32510,12 @@ The unique constraint ${source_default.underline.blue(
|
|
30687
32510
|
};
|
30688
32511
|
fromDatabase2 = async (db, tablesFilter = (table4) => true, progressCallback) => {
|
30689
32512
|
const result = {};
|
32513
|
+
const resultViews = {};
|
30690
32514
|
const columns = await db.query(
|
30691
32515
|
`SELECT
|
30692
|
-
m.name as "tableName", p.name as "columnName", p.type as "columnType", p."notnull" as "notNull", p.dflt_value as "defaultValue", p.pk as pk, p.hidden as hidden, m.sql
|
32516
|
+
m.name as "tableName", p.name as "columnName", p.type as "columnType", p."notnull" as "notNull", p.dflt_value as "defaultValue", p.pk as pk, p.hidden as hidden, m.sql, m.type as type
|
30693
32517
|
FROM sqlite_master AS m JOIN pragma_table_xinfo(m.name) AS p
|
30694
|
-
WHERE m.type = 'table'
|
32518
|
+
WHERE (m.type = 'table' OR m.type = 'view')
|
30695
32519
|
and m.tbl_name != 'sqlite_sequence'
|
30696
32520
|
and m.tbl_name != 'sqlite_stat1'
|
30697
32521
|
and m.tbl_name != '_litestream_seq'
|
@@ -30717,11 +32541,15 @@ The unique constraint ${source_default.underline.blue(
|
|
30717
32541
|
let tablesCount = /* @__PURE__ */ new Set();
|
30718
32542
|
let indexesCount = 0;
|
30719
32543
|
let foreignKeysCount = 0;
|
32544
|
+
let checksCount = 0;
|
32545
|
+
let viewsCount = 0;
|
30720
32546
|
const tableToPk = {};
|
30721
32547
|
let tableToGeneratedColumnsInfo = {};
|
30722
32548
|
for (const column4 of columns) {
|
30723
32549
|
if (!tablesFilter(column4.tableName)) continue;
|
30724
|
-
|
32550
|
+
if (column4.type !== "view") {
|
32551
|
+
columnsCount += 1;
|
32552
|
+
}
|
30725
32553
|
if (progressCallback) {
|
30726
32554
|
progressCallback("columns", columnsCount, "fetching");
|
30727
32555
|
}
|
@@ -30774,7 +32602,8 @@ The unique constraint ${source_default.underline.blue(
|
|
30774
32602
|
compositePrimaryKeys: {},
|
30775
32603
|
indexes: {},
|
30776
32604
|
foreignKeys: {},
|
30777
|
-
uniqueConstraints: {}
|
32605
|
+
uniqueConstraints: {},
|
32606
|
+
checkConstraints: {}
|
30778
32607
|
};
|
30779
32608
|
} else {
|
30780
32609
|
result[tableName].columns[columnName] = newColumn;
|
@@ -30888,10 +32717,90 @@ WHERE
|
|
30888
32717
|
progressCallback("indexes", indexesCount, "done");
|
30889
32718
|
progressCallback("enums", 0, "done");
|
30890
32719
|
}
|
32720
|
+
const views = await db.query(
|
32721
|
+
`SELECT name AS view_name, sql AS sql FROM sqlite_master WHERE type = 'view';`
|
32722
|
+
);
|
32723
|
+
viewsCount = views.length;
|
32724
|
+
if (progressCallback) {
|
32725
|
+
progressCallback("views", viewsCount, "fetching");
|
32726
|
+
}
|
32727
|
+
for (const view4 of views) {
|
32728
|
+
const viewName = view4["view_name"];
|
32729
|
+
const sql2 = view4["sql"];
|
32730
|
+
const regex = new RegExp(`\\bAS\\b\\s+(SELECT.+)$`, "i");
|
32731
|
+
const match2 = sql2.match(regex);
|
32732
|
+
if (!match2) {
|
32733
|
+
console.log("Could not process view");
|
32734
|
+
process.exit(1);
|
32735
|
+
}
|
32736
|
+
const viewDefinition = match2[1];
|
32737
|
+
const columns2 = result[viewName].columns;
|
32738
|
+
delete result[viewName];
|
32739
|
+
resultViews[viewName] = {
|
32740
|
+
columns: columns2,
|
32741
|
+
isExisting: false,
|
32742
|
+
name: viewName,
|
32743
|
+
definition: viewDefinition
|
32744
|
+
};
|
32745
|
+
}
|
32746
|
+
if (progressCallback) {
|
32747
|
+
progressCallback("views", viewsCount, "done");
|
32748
|
+
}
|
32749
|
+
const namedCheckPattern = /CONSTRAINT\s*["']?(\w+)["']?\s*CHECK\s*\((.*?)\)/gi;
|
32750
|
+
const unnamedCheckPattern = /CHECK\s*\((.*?)\)/gi;
|
32751
|
+
let checkCounter = 0;
|
32752
|
+
const checkConstraints = {};
|
32753
|
+
const checks = await db.query(`SELECT name as "tableName", sql as "sql"
|
32754
|
+
FROM sqlite_master
|
32755
|
+
WHERE type = 'table' AND name != 'sqlite_sequence';`);
|
32756
|
+
for (const check of checks) {
|
32757
|
+
if (!tablesFilter(check.tableName)) continue;
|
32758
|
+
const { tableName, sql: sql2 } = check;
|
32759
|
+
let namedChecks = [...sql2.matchAll(namedCheckPattern)];
|
32760
|
+
if (namedChecks.length > 0) {
|
32761
|
+
namedChecks.forEach(([_2, checkName, checkValue]) => {
|
32762
|
+
checkConstraints[checkName] = {
|
32763
|
+
name: checkName,
|
32764
|
+
value: checkValue.trim()
|
32765
|
+
};
|
32766
|
+
});
|
32767
|
+
} else {
|
32768
|
+
let unnamedChecks = [...sql2.matchAll(unnamedCheckPattern)];
|
32769
|
+
unnamedChecks.forEach(([_2, checkValue]) => {
|
32770
|
+
let checkName = `${tableName}_check_${++checkCounter}`;
|
32771
|
+
checkConstraints[checkName] = {
|
32772
|
+
name: checkName,
|
32773
|
+
value: checkValue.trim()
|
32774
|
+
};
|
32775
|
+
});
|
32776
|
+
}
|
32777
|
+
checksCount += Object.values(checkConstraints).length;
|
32778
|
+
if (progressCallback) {
|
32779
|
+
progressCallback("checks", checksCount, "fetching");
|
32780
|
+
}
|
32781
|
+
const table4 = result[tableName];
|
32782
|
+
if (!table4) {
|
32783
|
+
result[tableName] = {
|
32784
|
+
name: tableName,
|
32785
|
+
columns: {},
|
32786
|
+
compositePrimaryKeys: {},
|
32787
|
+
indexes: {},
|
32788
|
+
foreignKeys: {},
|
32789
|
+
uniqueConstraints: {},
|
32790
|
+
checkConstraints
|
32791
|
+
};
|
32792
|
+
} else {
|
32793
|
+
result[tableName].checkConstraints = checkConstraints;
|
32794
|
+
}
|
32795
|
+
}
|
32796
|
+
if (progressCallback) {
|
32797
|
+
progressCallback("checks", checksCount, "done");
|
32798
|
+
}
|
30891
32799
|
return {
|
30892
32800
|
version: "6",
|
30893
32801
|
dialect: "sqlite",
|
30894
32802
|
tables: result,
|
32803
|
+
views: resultViews,
|
30895
32804
|
enums: {},
|
30896
32805
|
_meta: {
|
30897
32806
|
tables: {},
|
@@ -32280,13 +34189,13 @@ var init_columns3 = __esm({
|
|
32280
34189
|
});
|
32281
34190
|
|
32282
34191
|
// ../drizzle-orm/dist/mysql-core/query-builders/count.js
|
32283
|
-
var _a295, _b220,
|
34192
|
+
var _a295, _b220, _c8, _MySqlCountBuilder, MySqlCountBuilder;
|
32284
34193
|
var init_count3 = __esm({
|
32285
34194
|
"../drizzle-orm/dist/mysql-core/query-builders/count.js"() {
|
32286
34195
|
"use strict";
|
32287
34196
|
init_entity();
|
32288
34197
|
init_sql();
|
32289
|
-
_MySqlCountBuilder = class _MySqlCountBuilder extends (
|
34198
|
+
_MySqlCountBuilder = class _MySqlCountBuilder extends (_c8 = SQL, _b220 = entityKind, _a295 = Symbol.toStringTag, _c8) {
|
32290
34199
|
constructor(params) {
|
32291
34200
|
super(_MySqlCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
|
32292
34201
|
__publicField(this, "sql");
|
@@ -32340,6 +34249,8 @@ var init_delete3 = __esm({
|
|
32340
34249
|
"use strict";
|
32341
34250
|
init_entity();
|
32342
34251
|
init_query_promise();
|
34252
|
+
init_selection_proxy();
|
34253
|
+
init_table();
|
32343
34254
|
MySqlDeleteBase = class extends (_b221 = QueryPromise, _a296 = entityKind, _b221) {
|
32344
34255
|
constructor(table4, session, dialect4, withList) {
|
32345
34256
|
super();
|
@@ -32392,6 +34303,26 @@ var init_delete3 = __esm({
|
|
32392
34303
|
this.config.where = where;
|
32393
34304
|
return this;
|
32394
34305
|
}
|
34306
|
+
orderBy(...columns) {
|
34307
|
+
if (typeof columns[0] === "function") {
|
34308
|
+
const orderBy = columns[0](
|
34309
|
+
new Proxy(
|
34310
|
+
this.config.table[Table.Symbol.Columns],
|
34311
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
34312
|
+
)
|
34313
|
+
);
|
34314
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
34315
|
+
this.config.orderBy = orderByArray;
|
34316
|
+
} else {
|
34317
|
+
const orderByArray = columns;
|
34318
|
+
this.config.orderBy = orderByArray;
|
34319
|
+
}
|
34320
|
+
return this;
|
34321
|
+
}
|
34322
|
+
limit(limit) {
|
34323
|
+
this.config.limit = limit;
|
34324
|
+
return this;
|
34325
|
+
}
|
32395
34326
|
/** @internal */
|
32396
34327
|
getSQL() {
|
32397
34328
|
return this.dialect.buildDeleteQuery(this.config);
|
@@ -32619,7 +34550,7 @@ function mysqlTableWithSchema(name2, columns, extraConfig, schema4, baseName = n
|
|
32619
34550
|
}
|
32620
34551
|
return table4;
|
32621
34552
|
}
|
32622
|
-
var InlineForeignKeys3, _a299, _b223,
|
34553
|
+
var InlineForeignKeys3, _a299, _b223, _c9, _d4, _e3, MySqlTable, mysqlTable;
|
32623
34554
|
var init_table4 = __esm({
|
32624
34555
|
"../drizzle-orm/dist/mysql-core/table.js"() {
|
32625
34556
|
"use strict";
|
@@ -32627,11 +34558,11 @@ var init_table4 = __esm({
|
|
32627
34558
|
init_table();
|
32628
34559
|
init_all3();
|
32629
34560
|
InlineForeignKeys3 = Symbol.for("drizzle:MySqlInlineForeignKeys");
|
32630
|
-
MySqlTable = class extends (_e3 = Table, _d4 = entityKind,
|
34561
|
+
MySqlTable = class extends (_e3 = Table, _d4 = entityKind, _c9 = Table.Symbol.Columns, _b223 = InlineForeignKeys3, _a299 = Table.Symbol.ExtraConfigBuilder, _e3) {
|
32631
34562
|
constructor() {
|
32632
34563
|
super(...arguments);
|
32633
34564
|
/** @internal */
|
32634
|
-
__publicField(this,
|
34565
|
+
__publicField(this, _c9);
|
32635
34566
|
/** @internal */
|
32636
34567
|
__publicField(this, _b223, []);
|
32637
34568
|
/** @internal */
|
@@ -32656,7 +34587,7 @@ var init_view_base3 = __esm({
|
|
32656
34587
|
"use strict";
|
32657
34588
|
init_entity();
|
32658
34589
|
init_sql();
|
32659
|
-
MySqlViewBase = class extends (_b224 =
|
34590
|
+
MySqlViewBase = class extends (_b224 = View3, _a300 = entityKind, _b224) {
|
32660
34591
|
};
|
32661
34592
|
__publicField(MySqlViewBase, _a300, "MySqlViewBase");
|
32662
34593
|
}
|
@@ -32738,11 +34669,13 @@ var init_dialect3 = __esm({
|
|
32738
34669
|
withSqlChunks.push(sql` `);
|
32739
34670
|
return sql.join(withSqlChunks);
|
32740
34671
|
}
|
32741
|
-
buildDeleteQuery({ table: table4, where, returning, withList }) {
|
34672
|
+
buildDeleteQuery({ table: table4, where, returning, withList, limit, orderBy }) {
|
32742
34673
|
const withSql = this.buildWithCTE(withList);
|
32743
34674
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
32744
34675
|
const whereSql = where ? sql` where ${where}` : void 0;
|
32745
|
-
|
34676
|
+
const orderBySql = this.buildOrderBy(orderBy);
|
34677
|
+
const limitSql = this.buildLimit(limit);
|
34678
|
+
return sql`${withSql}delete from ${table4}${whereSql}${orderBySql}${limitSql}${returningSql}`;
|
32746
34679
|
}
|
32747
34680
|
buildUpdateSet(table4, set) {
|
32748
34681
|
const tableColumns = table4[Table.Symbol.Columns];
|
@@ -32760,12 +34693,14 @@ var init_dialect3 = __esm({
|
|
32760
34693
|
return [res];
|
32761
34694
|
}));
|
32762
34695
|
}
|
32763
|
-
buildUpdateQuery({ table: table4, set, where, returning, withList }) {
|
34696
|
+
buildUpdateQuery({ table: table4, set, where, returning, withList, limit, orderBy }) {
|
32764
34697
|
const withSql = this.buildWithCTE(withList);
|
32765
34698
|
const setSql = this.buildUpdateSet(table4, set);
|
32766
34699
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
32767
34700
|
const whereSql = where ? sql` where ${where}` : void 0;
|
32768
|
-
|
34701
|
+
const orderBySql = this.buildOrderBy(orderBy);
|
34702
|
+
const limitSql = this.buildLimit(limit);
|
34703
|
+
return sql`${withSql}update ${table4} set ${setSql}${whereSql}${orderBySql}${limitSql}${returningSql}`;
|
32769
34704
|
}
|
32770
34705
|
/**
|
32771
34706
|
* Builds selection SQL with provided fields/expressions
|
@@ -32817,6 +34752,12 @@ var init_dialect3 = __esm({
|
|
32817
34752
|
});
|
32818
34753
|
return sql.join(chunks);
|
32819
34754
|
}
|
34755
|
+
buildLimit(limit) {
|
34756
|
+
return typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
|
34757
|
+
}
|
34758
|
+
buildOrderBy(orderBy) {
|
34759
|
+
return orderBy && orderBy.length > 0 ? sql` order by ${sql.join(orderBy, sql`, `)}` : void 0;
|
34760
|
+
}
|
32820
34761
|
buildSelectQuery({
|
32821
34762
|
withList,
|
32822
34763
|
fields,
|
@@ -32870,7 +34811,7 @@ var init_dialect3 = __esm({
|
|
32870
34811
|
joinsArray.push(
|
32871
34812
|
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
32872
34813
|
);
|
32873
|
-
} else if (is(table22,
|
34814
|
+
} else if (is(table22, View3)) {
|
32874
34815
|
const viewName = table22[ViewBaseConfig].name;
|
32875
34816
|
const viewSchema = table22[ViewBaseConfig].schema;
|
32876
34817
|
const origViewName = table22[ViewBaseConfig].originalName;
|
@@ -32891,15 +34832,9 @@ var init_dialect3 = __esm({
|
|
32891
34832
|
const joinsSql = sql.join(joinsArray);
|
32892
34833
|
const whereSql = where ? sql` where ${where}` : void 0;
|
32893
34834
|
const havingSql = having ? sql` having ${having}` : void 0;
|
32894
|
-
|
32895
|
-
|
32896
|
-
|
32897
|
-
}
|
32898
|
-
let groupBySql;
|
32899
|
-
if (groupBy && groupBy.length > 0) {
|
32900
|
-
groupBySql = sql` group by ${sql.join(groupBy, sql`, `)}`;
|
32901
|
-
}
|
32902
|
-
const limitSql = typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
|
34835
|
+
const orderBySql = this.buildOrderBy(orderBy);
|
34836
|
+
const groupBySql = groupBy && groupBy.length > 0 ? sql` group by ${sql.join(groupBy, sql`, `)}` : void 0;
|
34837
|
+
const limitSql = this.buildLimit(limit);
|
32903
34838
|
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
32904
34839
|
let lockingClausesSql;
|
32905
34840
|
if (lockingClause) {
|
@@ -33886,7 +35821,7 @@ var init_select4 = __esm({
|
|
33886
35821
|
};
|
33887
35822
|
}
|
33888
35823
|
if (typeof tableName === "string" && !is(table4, SQL)) {
|
33889
|
-
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4,
|
35824
|
+
const selection = is(table4, Subquery) ? table4._.selectedFields : is(table4, View3) ? table4[ViewBaseConfig].selectedFields : table4[Table.Symbol.Columns];
|
33890
35825
|
this.config.fields[tableName] = selection;
|
33891
35826
|
}
|
33892
35827
|
}
|
@@ -34282,6 +36217,8 @@ var init_update3 = __esm({
|
|
34282
36217
|
"use strict";
|
34283
36218
|
init_entity();
|
34284
36219
|
init_query_promise();
|
36220
|
+
init_selection_proxy();
|
36221
|
+
init_table();
|
34285
36222
|
init_utils2();
|
34286
36223
|
_a306 = entityKind;
|
34287
36224
|
MySqlUpdateBuilder = class {
|
@@ -34351,6 +36288,26 @@ var init_update3 = __esm({
|
|
34351
36288
|
this.config.where = where;
|
34352
36289
|
return this;
|
34353
36290
|
}
|
36291
|
+
orderBy(...columns) {
|
36292
|
+
if (typeof columns[0] === "function") {
|
36293
|
+
const orderBy = columns[0](
|
36294
|
+
new Proxy(
|
36295
|
+
this.config.table[Table.Symbol.Columns],
|
36296
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "alias", sqlBehavior: "sql" })
|
36297
|
+
)
|
36298
|
+
);
|
36299
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
36300
|
+
this.config.orderBy = orderByArray;
|
36301
|
+
} else {
|
36302
|
+
const orderByArray = columns;
|
36303
|
+
this.config.orderBy = orderByArray;
|
36304
|
+
}
|
36305
|
+
return this;
|
36306
|
+
}
|
36307
|
+
limit(limit) {
|
36308
|
+
this.config.limit = limit;
|
36309
|
+
return this;
|
36310
|
+
}
|
34354
36311
|
/** @internal */
|
34355
36312
|
getSQL() {
|
34356
36313
|
return this.dialect.buildUpdateQuery(this.config);
|
@@ -34832,7 +36789,7 @@ var init_primary_keys3 = __esm({
|
|
34832
36789
|
|
34833
36790
|
// ../drizzle-orm/dist/mysql-core/view-common.js
|
34834
36791
|
var MySqlViewConfig;
|
34835
|
-
var
|
36792
|
+
var init_view_common3 = __esm({
|
34836
36793
|
"../drizzle-orm/dist/mysql-core/view-common.js"() {
|
34837
36794
|
"use strict";
|
34838
36795
|
MySqlViewConfig = Symbol.for("drizzle:MySqlViewConfig");
|
@@ -34846,7 +36803,7 @@ function mysqlViewWithSchema(name2, selection, schema4) {
|
|
34846
36803
|
}
|
34847
36804
|
return new ViewBuilder3(name2, schema4);
|
34848
36805
|
}
|
34849
|
-
var _a316, ViewBuilderCore2, _a317, _b229, ViewBuilder3, _a318, _b230, ManualViewBuilder3, _a319, _b231,
|
36806
|
+
var _a316, ViewBuilderCore2, _a317, _b229, ViewBuilder3, _a318, _b230, ManualViewBuilder3, _a319, _b231, _c10, MySqlView2;
|
34850
36807
|
var init_view3 = __esm({
|
34851
36808
|
"../drizzle-orm/dist/mysql-core/view.js"() {
|
34852
36809
|
"use strict";
|
@@ -34856,7 +36813,7 @@ var init_view3 = __esm({
|
|
34856
36813
|
init_query_builder4();
|
34857
36814
|
init_table4();
|
34858
36815
|
init_view_base3();
|
34859
|
-
|
36816
|
+
init_view_common3();
|
34860
36817
|
_a316 = entityKind;
|
34861
36818
|
ViewBuilderCore2 = class {
|
34862
36819
|
constructor(name2, schema4) {
|
@@ -34868,10 +36825,6 @@ var init_view3 = __esm({
|
|
34868
36825
|
this.config.algorithm = algorithm;
|
34869
36826
|
return this;
|
34870
36827
|
}
|
34871
|
-
definer(definer) {
|
34872
|
-
this.config.definer = definer;
|
34873
|
-
return this;
|
34874
|
-
}
|
34875
36828
|
sqlSecurity(sqlSecurity) {
|
34876
36829
|
this.config.sqlSecurity = sqlSecurity;
|
34877
36830
|
return this;
|
@@ -34895,7 +36848,7 @@ var init_view3 = __esm({
|
|
34895
36848
|
});
|
34896
36849
|
const aliasedSelection = new Proxy(qb.getSelectedFields(), selectionProxy);
|
34897
36850
|
return new Proxy(
|
34898
|
-
new
|
36851
|
+
new MySqlView2({
|
34899
36852
|
mysqlConfig: this.config,
|
34900
36853
|
config: {
|
34901
36854
|
name: this.name,
|
@@ -34917,7 +36870,7 @@ var init_view3 = __esm({
|
|
34917
36870
|
}
|
34918
36871
|
existing() {
|
34919
36872
|
return new Proxy(
|
34920
|
-
new
|
36873
|
+
new MySqlView2({
|
34921
36874
|
mysqlConfig: void 0,
|
34922
36875
|
config: {
|
34923
36876
|
name: this.name,
|
@@ -34936,7 +36889,7 @@ var init_view3 = __esm({
|
|
34936
36889
|
}
|
34937
36890
|
as(query) {
|
34938
36891
|
return new Proxy(
|
34939
|
-
new
|
36892
|
+
new MySqlView2({
|
34940
36893
|
mysqlConfig: this.config,
|
34941
36894
|
config: {
|
34942
36895
|
name: this.name,
|
@@ -34955,14 +36908,14 @@ var init_view3 = __esm({
|
|
34955
36908
|
}
|
34956
36909
|
};
|
34957
36910
|
__publicField(ManualViewBuilder3, _a318, "MySqlManualViewBuilder");
|
34958
|
-
|
36911
|
+
MySqlView2 = class extends (_c10 = MySqlViewBase, _b231 = entityKind, _a319 = MySqlViewConfig, _c10) {
|
34959
36912
|
constructor({ mysqlConfig, config }) {
|
34960
36913
|
super(config);
|
34961
36914
|
__publicField(this, _a319);
|
34962
36915
|
this[MySqlViewConfig] = mysqlConfig;
|
34963
36916
|
}
|
34964
36917
|
};
|
34965
|
-
__publicField(
|
36918
|
+
__publicField(MySqlView2, _b231, "MySqlView");
|
34966
36919
|
}
|
34967
36920
|
});
|
34968
36921
|
|
@@ -35104,17 +37057,25 @@ function getTableConfig3(table4) {
|
|
35104
37057
|
baseName
|
35105
37058
|
};
|
35106
37059
|
}
|
37060
|
+
function getViewConfig3(view4) {
|
37061
|
+
return {
|
37062
|
+
...view4[ViewBaseConfig],
|
37063
|
+
...view4[MySqlViewConfig]
|
37064
|
+
};
|
37065
|
+
}
|
35107
37066
|
var init_utils7 = __esm({
|
35108
37067
|
"../drizzle-orm/dist/mysql-core/utils.js"() {
|
35109
37068
|
"use strict";
|
35110
37069
|
init_entity();
|
35111
37070
|
init_table();
|
37071
|
+
init_view_common();
|
35112
37072
|
init_checks3();
|
35113
37073
|
init_foreign_keys3();
|
35114
37074
|
init_indexes3();
|
35115
37075
|
init_primary_keys3();
|
35116
37076
|
init_table4();
|
35117
37077
|
init_unique_constraint3();
|
37078
|
+
init_view_common3();
|
35118
37079
|
}
|
35119
37080
|
});
|
35120
37081
|
|
@@ -35137,7 +37098,7 @@ var init_mysql_core = __esm({
|
|
35137
37098
|
init_table4();
|
35138
37099
|
init_unique_constraint3();
|
35139
37100
|
init_utils7();
|
35140
|
-
|
37101
|
+
init_view_common3();
|
35141
37102
|
init_view3();
|
35142
37103
|
}
|
35143
37104
|
});
|
@@ -35169,12 +37130,14 @@ var init_mysqlSerializer = __esm({
|
|
35169
37130
|
init_dist();
|
35170
37131
|
init_mysql_core();
|
35171
37132
|
init_mysql_core();
|
37133
|
+
init_mysql_core();
|
35172
37134
|
init_outputs();
|
35173
37135
|
init_utils();
|
35174
37136
|
init_serializer();
|
35175
|
-
generateMySqlSnapshot = (tables, casing2) => {
|
37137
|
+
generateMySqlSnapshot = (tables, views, casing2) => {
|
35176
37138
|
const dialect4 = new MySqlDialect({ casing: casing2 });
|
35177
37139
|
const result = {};
|
37140
|
+
const resultViews = {};
|
35178
37141
|
const internal = { tables: {}, indexes: {} };
|
35179
37142
|
for (const table4 of tables) {
|
35180
37143
|
const {
|
@@ -35183,6 +37146,7 @@ var init_mysqlSerializer = __esm({
|
|
35183
37146
|
indexes,
|
35184
37147
|
foreignKeys,
|
35185
37148
|
schema: schema4,
|
37149
|
+
checks,
|
35186
37150
|
primaryKeys,
|
35187
37151
|
uniqueConstraints
|
35188
37152
|
} = getTableConfig3(table4);
|
@@ -35191,6 +37155,8 @@ var init_mysqlSerializer = __esm({
|
|
35191
37155
|
const foreignKeysObject = {};
|
35192
37156
|
const primaryKeysObject = {};
|
35193
37157
|
const uniqueConstraintObject = {};
|
37158
|
+
const checkConstraintObject = {};
|
37159
|
+
let checksInTable = {};
|
35194
37160
|
columns.forEach((column4) => {
|
35195
37161
|
const name2 = getColumnCasing(column4, casing2);
|
35196
37162
|
const notNull = column4.notNull;
|
@@ -35421,6 +37387,32 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
35421
37387
|
lock: value.config.lock
|
35422
37388
|
};
|
35423
37389
|
});
|
37390
|
+
checks.forEach((check) => {
|
37391
|
+
check;
|
37392
|
+
const checkName = check.name;
|
37393
|
+
if (typeof checksInTable[tableName] !== "undefined") {
|
37394
|
+
if (checksInTable[tableName].includes(check.name)) {
|
37395
|
+
console.log(
|
37396
|
+
`
|
37397
|
+
${withStyle.errorWarning(
|
37398
|
+
`We've found duplicated check constraint name in ${source_default.underline.blue(
|
37399
|
+
tableName
|
37400
|
+
)}. Please rename your check constraint in the ${source_default.underline.blue(
|
37401
|
+
tableName
|
37402
|
+
)} table`
|
37403
|
+
)}`
|
37404
|
+
);
|
37405
|
+
process.exit(1);
|
37406
|
+
}
|
37407
|
+
checksInTable[tableName].push(checkName);
|
37408
|
+
} else {
|
37409
|
+
checksInTable[tableName] = [check.name];
|
37410
|
+
}
|
37411
|
+
checkConstraintObject[checkName] = {
|
37412
|
+
name: checkName,
|
37413
|
+
value: dialect4.sqlToQuery(check.value).sql
|
37414
|
+
};
|
37415
|
+
});
|
35424
37416
|
if (!schema4) {
|
35425
37417
|
result[tableName] = {
|
35426
37418
|
name: tableName,
|
@@ -35428,14 +37420,100 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
35428
37420
|
indexes: indexesObject,
|
35429
37421
|
foreignKeys: foreignKeysObject,
|
35430
37422
|
compositePrimaryKeys: primaryKeysObject,
|
35431
|
-
uniqueConstraints: uniqueConstraintObject
|
37423
|
+
uniqueConstraints: uniqueConstraintObject,
|
37424
|
+
checkConstraint: checkConstraintObject
|
35432
37425
|
};
|
35433
37426
|
}
|
35434
37427
|
}
|
37428
|
+
for (const view4 of views) {
|
37429
|
+
const {
|
37430
|
+
isExisting,
|
37431
|
+
name: name2,
|
37432
|
+
query,
|
37433
|
+
schema: schema4,
|
37434
|
+
selectedFields,
|
37435
|
+
algorithm,
|
37436
|
+
sqlSecurity,
|
37437
|
+
withCheckOption
|
37438
|
+
} = getViewConfig3(view4);
|
37439
|
+
const columnsObject = {};
|
37440
|
+
const existingView = resultViews[name2];
|
37441
|
+
if (typeof existingView !== "undefined") {
|
37442
|
+
console.log(
|
37443
|
+
`
|
37444
|
+
${withStyle.errorWarning(
|
37445
|
+
`We've found duplicated view name across ${source_default.underline.blue(
|
37446
|
+
schema4 ?? "public"
|
37447
|
+
)} schema. Please rename your view`
|
37448
|
+
)}`
|
37449
|
+
);
|
37450
|
+
process.exit(1);
|
37451
|
+
}
|
37452
|
+
for (const key in selectedFields) {
|
37453
|
+
if (is(selectedFields[key], MySqlColumn)) {
|
37454
|
+
const column4 = selectedFields[key];
|
37455
|
+
const notNull = column4.notNull;
|
37456
|
+
const sqlTypeLowered = column4.getSQLType().toLowerCase();
|
37457
|
+
const autoIncrement = typeof column4.autoIncrement === "undefined" ? false : column4.autoIncrement;
|
37458
|
+
const generated = column4.generated;
|
37459
|
+
const columnToSet = {
|
37460
|
+
name: column4.name,
|
37461
|
+
type: column4.getSQLType(),
|
37462
|
+
primaryKey: false,
|
37463
|
+
// If field is autoincrement it's notNull by default
|
37464
|
+
// notNull: autoIncrement ? true : notNull,
|
37465
|
+
notNull,
|
37466
|
+
autoincrement: autoIncrement,
|
37467
|
+
onUpdate: column4.hasOnUpdateNow,
|
37468
|
+
generated: generated ? {
|
37469
|
+
as: is(generated.as, SQL) ? dialect4.sqlToQuery(generated.as).sql : typeof generated.as === "function" ? dialect4.sqlToQuery(generated.as()).sql : generated.as,
|
37470
|
+
type: generated.mode ?? "stored"
|
37471
|
+
} : void 0
|
37472
|
+
};
|
37473
|
+
if (column4.default !== void 0) {
|
37474
|
+
if (is(column4.default, SQL)) {
|
37475
|
+
columnToSet.default = sqlToStr(column4.default, casing2);
|
37476
|
+
} else {
|
37477
|
+
if (typeof column4.default === "string") {
|
37478
|
+
columnToSet.default = `'${column4.default}'`;
|
37479
|
+
} else {
|
37480
|
+
if (sqlTypeLowered === "json") {
|
37481
|
+
columnToSet.default = `'${JSON.stringify(column4.default)}'`;
|
37482
|
+
} else if (column4.default instanceof Date) {
|
37483
|
+
if (sqlTypeLowered === "date") {
|
37484
|
+
columnToSet.default = `'${column4.default.toISOString().split("T")[0]}'`;
|
37485
|
+
} else if (sqlTypeLowered.startsWith("datetime") || sqlTypeLowered.startsWith("timestamp")) {
|
37486
|
+
columnToSet.default = `'${column4.default.toISOString().replace("T", " ").slice(0, 23)}'`;
|
37487
|
+
}
|
37488
|
+
} else {
|
37489
|
+
columnToSet.default = column4.default;
|
37490
|
+
}
|
37491
|
+
}
|
37492
|
+
if (["blob", "text", "json"].includes(column4.getSQLType())) {
|
37493
|
+
columnToSet.default = `(${columnToSet.default})`;
|
37494
|
+
}
|
37495
|
+
}
|
37496
|
+
}
|
37497
|
+
columnsObject[column4.name] = columnToSet;
|
37498
|
+
}
|
37499
|
+
}
|
37500
|
+
resultViews[name2] = {
|
37501
|
+
columns: columnsObject,
|
37502
|
+
name: name2,
|
37503
|
+
isExisting,
|
37504
|
+
definition: isExisting ? void 0 : dialect4.sqlToQuery(query).sql,
|
37505
|
+
withCheckOption,
|
37506
|
+
algorithm: algorithm ?? "undefined",
|
37507
|
+
// set default values
|
37508
|
+
sqlSecurity: sqlSecurity ?? "definer"
|
37509
|
+
// set default values
|
37510
|
+
};
|
37511
|
+
}
|
35435
37512
|
return {
|
35436
37513
|
version: "5",
|
35437
37514
|
dialect: "mysql",
|
35438
37515
|
tables: result,
|
37516
|
+
views: resultViews,
|
35439
37517
|
_meta: {
|
35440
37518
|
tables: {},
|
35441
37519
|
columns: {}
|
@@ -35455,6 +37533,8 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
35455
37533
|
let tablesCount = /* @__PURE__ */ new Set();
|
35456
37534
|
let indexesCount = 0;
|
35457
37535
|
let foreignKeysCount = 0;
|
37536
|
+
let checksCount = 0;
|
37537
|
+
let viewsCount = 0;
|
35458
37538
|
const idxs = await db.query(
|
35459
37539
|
`select * from INFORMATION_SCHEMA.STATISTICS
|
35460
37540
|
WHERE INFORMATION_SCHEMA.STATISTICS.TABLE_SCHEMA = '${inputSchema}' and INFORMATION_SCHEMA.STATISTICS.INDEX_NAME != 'PRIMARY';`
|
@@ -35549,7 +37629,8 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
35549
37629
|
compositePrimaryKeys: {},
|
35550
37630
|
indexes: {},
|
35551
37631
|
foreignKeys: {},
|
35552
|
-
uniqueConstraints: {}
|
37632
|
+
uniqueConstraints: {},
|
37633
|
+
checkConstraint: {}
|
35553
37634
|
};
|
35554
37635
|
} else {
|
35555
37636
|
result[tableName].columns[columnName] = newColumn;
|
@@ -35694,14 +37775,76 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
35694
37775
|
}
|
35695
37776
|
}
|
35696
37777
|
}
|
37778
|
+
const views = await db.query(
|
37779
|
+
`select * from INFORMATION_SCHEMA.VIEWS WHERE table_schema = '${inputSchema}';`
|
37780
|
+
);
|
37781
|
+
const resultViews = {};
|
37782
|
+
viewsCount = views.length;
|
37783
|
+
if (progressCallback) {
|
37784
|
+
progressCallback("views", viewsCount, "fetching");
|
37785
|
+
}
|
37786
|
+
for await (const view4 of views) {
|
37787
|
+
const viewName = view4["TABLE_NAME"];
|
37788
|
+
const definition = view4["VIEW_DEFINITION"];
|
37789
|
+
const withCheckOption = view4["CHECK_OPTION"] === "NONE" ? void 0 : view4["CHECK_OPTION"].toLowerCase();
|
37790
|
+
const sqlSecurity = view4["SECURITY_TYPE"].toLowerCase();
|
37791
|
+
const [createSqlStatement] = await db.query(`SHOW CREATE VIEW \`${viewName}\`;`);
|
37792
|
+
const algorithmMatch = createSqlStatement["Create View"].match(/ALGORITHM=([^ ]+)/);
|
37793
|
+
const algorithm = algorithmMatch ? algorithmMatch[1].toLowerCase() : void 0;
|
37794
|
+
const columns2 = result[viewName].columns;
|
37795
|
+
delete result[viewName];
|
37796
|
+
resultViews[viewName] = {
|
37797
|
+
columns: columns2,
|
37798
|
+
isExisting: false,
|
37799
|
+
name: viewName,
|
37800
|
+
algorithm,
|
37801
|
+
definition,
|
37802
|
+
sqlSecurity,
|
37803
|
+
withCheckOption
|
37804
|
+
};
|
37805
|
+
}
|
35697
37806
|
if (progressCallback) {
|
35698
37807
|
progressCallback("indexes", indexesCount, "done");
|
35699
37808
|
progressCallback("enums", 0, "done");
|
37809
|
+
progressCallback("views", viewsCount, "done");
|
37810
|
+
}
|
37811
|
+
const checkConstraints = await db.query(
|
37812
|
+
`SELECT
|
37813
|
+
tc.table_name,
|
37814
|
+
tc.constraint_name,
|
37815
|
+
cc.check_clause
|
37816
|
+
FROM
|
37817
|
+
information_schema.table_constraints tc
|
37818
|
+
JOIN
|
37819
|
+
information_schema.check_constraints cc
|
37820
|
+
ON tc.constraint_name = cc.constraint_name
|
37821
|
+
WHERE
|
37822
|
+
tc.constraint_schema = '${inputSchema}'
|
37823
|
+
AND
|
37824
|
+
tc.constraint_type = 'CHECK';`
|
37825
|
+
);
|
37826
|
+
checksCount += checkConstraints.length;
|
37827
|
+
if (progressCallback) {
|
37828
|
+
progressCallback("checks", checksCount, "fetching");
|
37829
|
+
}
|
37830
|
+
for (const checkConstraintRow of checkConstraints) {
|
37831
|
+
const constraintName = checkConstraintRow["CONSTRAINT_NAME"];
|
37832
|
+
const constraintValue = checkConstraintRow["CHECK_CLAUSE"];
|
37833
|
+
const tableName = checkConstraintRow["TABLE_NAME"];
|
37834
|
+
const tableInResult = result[tableName];
|
37835
|
+
tableInResult.checkConstraint[constraintName] = {
|
37836
|
+
name: constraintName,
|
37837
|
+
value: constraintValue
|
37838
|
+
};
|
37839
|
+
}
|
37840
|
+
if (progressCallback) {
|
37841
|
+
progressCallback("checks", checksCount, "done");
|
35700
37842
|
}
|
35701
37843
|
return {
|
35702
37844
|
version: "5",
|
35703
37845
|
dialect: "mysql",
|
35704
37846
|
tables: result,
|
37847
|
+
views: resultViews,
|
35705
37848
|
_meta: {
|
35706
37849
|
tables: {},
|
35707
37850
|
columns: {}
|
@@ -36017,6 +38160,8 @@ var init_pgImports = __esm({
|
|
36017
38160
|
const enums = [];
|
36018
38161
|
const schemas = [];
|
36019
38162
|
const sequences = [];
|
38163
|
+
const views = [];
|
38164
|
+
const matViews = [];
|
36020
38165
|
const i0values = Object.values(exports);
|
36021
38166
|
i0values.forEach((t) => {
|
36022
38167
|
if (isPgEnum(t)) {
|
@@ -36029,11 +38174,17 @@ var init_pgImports = __esm({
|
|
36029
38174
|
if (is(t, PgSchema5)) {
|
36030
38175
|
schemas.push(t);
|
36031
38176
|
}
|
38177
|
+
if (isPgView(t)) {
|
38178
|
+
views.push(t);
|
38179
|
+
}
|
38180
|
+
if (isPgMaterializedView(t)) {
|
38181
|
+
matViews.push(t);
|
38182
|
+
}
|
36032
38183
|
if (isPgSequence(t)) {
|
36033
38184
|
sequences.push(t);
|
36034
38185
|
}
|
36035
38186
|
});
|
36036
|
-
return { tables, enums, schemas, sequences };
|
38187
|
+
return { tables, enums, schemas, sequences, views, matViews };
|
36037
38188
|
};
|
36038
38189
|
}
|
36039
38190
|
});
|
@@ -36053,25 +38204,31 @@ var init_sqliteImports = __esm({
|
|
36053
38204
|
init_utils8();
|
36054
38205
|
prepareFromExports2 = (exports) => {
|
36055
38206
|
const tables = [];
|
38207
|
+
const views = [];
|
36056
38208
|
const i0values = Object.values(exports);
|
36057
38209
|
i0values.forEach((t) => {
|
36058
38210
|
if (is(t, SQLiteTable)) {
|
36059
38211
|
tables.push(t);
|
36060
38212
|
}
|
38213
|
+
if (is(t, SQLiteView2)) {
|
38214
|
+
views.push(t);
|
38215
|
+
}
|
36061
38216
|
});
|
36062
|
-
return { tables };
|
38217
|
+
return { tables, views };
|
36063
38218
|
};
|
36064
38219
|
prepareFromSqliteImports = async (imports) => {
|
36065
38220
|
const tables = [];
|
38221
|
+
const views = [];
|
36066
38222
|
const { unregister } = await safeRegister();
|
36067
38223
|
for (let i = 0; i < imports.length; i++) {
|
36068
38224
|
const it = imports[i];
|
36069
38225
|
const i0 = __require(`${it}`);
|
36070
38226
|
const prepared = prepareFromExports2(i0);
|
36071
38227
|
tables.push(...prepared.tables);
|
38228
|
+
views.push(...prepared.views);
|
36072
38229
|
}
|
36073
38230
|
unregister();
|
36074
|
-
return { tables: Array.from(new Set(tables)) };
|
38231
|
+
return { tables: Array.from(new Set(tables)), views };
|
36075
38232
|
};
|
36076
38233
|
}
|
36077
38234
|
});
|
@@ -36091,25 +38248,31 @@ var init_mysqlImports = __esm({
|
|
36091
38248
|
init_utils8();
|
36092
38249
|
prepareFromExports3 = (exports) => {
|
36093
38250
|
const tables = [];
|
38251
|
+
const views = [];
|
36094
38252
|
const i0values = Object.values(exports);
|
36095
38253
|
i0values.forEach((t) => {
|
36096
38254
|
if (is(t, MySqlTable)) {
|
36097
38255
|
tables.push(t);
|
36098
38256
|
}
|
38257
|
+
if (is(t, MySqlView2)) {
|
38258
|
+
views.push(t);
|
38259
|
+
}
|
36099
38260
|
});
|
36100
|
-
return { tables };
|
38261
|
+
return { tables, views };
|
36101
38262
|
};
|
36102
38263
|
prepareFromMySqlImports = async (imports) => {
|
36103
38264
|
const tables = [];
|
38265
|
+
const views = [];
|
36104
38266
|
const { unregister } = await safeRegister();
|
36105
38267
|
for (let i = 0; i < imports.length; i++) {
|
36106
38268
|
const it = imports[i];
|
36107
38269
|
const i0 = __require(`${it}`);
|
36108
38270
|
const prepared = prepareFromExports3(i0);
|
36109
38271
|
tables.push(...prepared.tables);
|
38272
|
+
views.push(...prepared.views);
|
36110
38273
|
}
|
36111
38274
|
unregister();
|
36112
|
-
return { tables: Array.from(new Set(tables)) };
|
38275
|
+
return { tables: Array.from(new Set(tables)), views };
|
36113
38276
|
};
|
36114
38277
|
}
|
36115
38278
|
});
|
@@ -36484,6 +38647,7 @@ var pgSuggestions = async (db, statements) => {
|
|
36484
38647
|
const columnsToRemove = [];
|
36485
38648
|
const schemasToRemove = [];
|
36486
38649
|
const tablesToTruncate = [];
|
38650
|
+
const matViewsToRemove = [];
|
36487
38651
|
let renamedSchemas = {};
|
36488
38652
|
let renamedTables = {};
|
36489
38653
|
for (const statement of statements) {
|
@@ -36493,38 +38657,32 @@ var pgSuggestions = async (db, statements) => {
|
|
36493
38657
|
renamedTables[concatSchemaAndTableName(statement.toSchema, statement.tableNameTo)] = statement.tableNameFrom;
|
36494
38658
|
} else if (statement.type === "drop_table") {
|
36495
38659
|
const res = await db.query(
|
36496
|
-
`select count(*) as count from ${tableNameWithSchemaFrom(
|
36497
|
-
statement.schema,
|
36498
|
-
statement.tableName,
|
36499
|
-
renamedSchemas,
|
36500
|
-
renamedTables
|
36501
|
-
)}`
|
38660
|
+
`select count(*) as count from ${tableNameWithSchemaFrom(statement.schema, statement.tableName, renamedSchemas, renamedTables)}`
|
36502
38661
|
);
|
36503
38662
|
const count2 = Number(res[0].count);
|
38663
|
+
if (count2 > 0) {
|
38664
|
+
infoToPrint.push(`\xB7 You're about to delete ${source_default.underline(statement.tableName)} table with ${count2} items`);
|
38665
|
+
tablesToRemove.push(statement.tableName);
|
38666
|
+
shouldAskForApprove = true;
|
38667
|
+
}
|
38668
|
+
} else if (statement.type === "drop_view" && statement.materialized) {
|
38669
|
+
const res = await db.query(`select count(*) as count from "${statement.schema ?? "public"}"."${statement.name}"`);
|
38670
|
+
const count2 = Number(res[0].count);
|
36504
38671
|
if (count2 > 0) {
|
36505
38672
|
infoToPrint.push(
|
36506
|
-
`\xB7 You're about to delete ${source_default.underline(
|
36507
|
-
statement.tableName
|
36508
|
-
)} table with ${count2} items`
|
38673
|
+
`\xB7 You're about to delete "${source_default.underline(statement.name)}" materialized view with ${count2} items`
|
36509
38674
|
);
|
36510
|
-
|
38675
|
+
matViewsToRemove.push(statement.name);
|
36511
38676
|
shouldAskForApprove = true;
|
36512
38677
|
}
|
36513
38678
|
} else if (statement.type === "alter_table_drop_column") {
|
36514
38679
|
const res = await db.query(
|
36515
|
-
`select count(*) as count from ${tableNameWithSchemaFrom(
|
36516
|
-
statement.schema,
|
36517
|
-
statement.tableName,
|
36518
|
-
renamedSchemas,
|
36519
|
-
renamedTables
|
36520
|
-
)}`
|
38680
|
+
`select count(*) as count from ${tableNameWithSchemaFrom(statement.schema, statement.tableName, renamedSchemas, renamedTables)}`
|
36521
38681
|
);
|
36522
38682
|
const count2 = Number(res[0].count);
|
36523
38683
|
if (count2 > 0) {
|
36524
38684
|
infoToPrint.push(
|
36525
|
-
`\xB7 You're about to delete ${source_default.underline(
|
36526
|
-
statement.columnName
|
36527
|
-
)} column in ${statement.tableName} table with ${count2} items`
|
38685
|
+
`\xB7 You're about to delete ${source_default.underline(statement.columnName)} column in ${statement.tableName} table with ${count2} items`
|
36528
38686
|
);
|
36529
38687
|
columnsToRemove.push(`${statement.tableName}_${statement.columnName}`);
|
36530
38688
|
shouldAskForApprove = true;
|
@@ -36535,58 +38693,35 @@ var pgSuggestions = async (db, statements) => {
|
|
36535
38693
|
);
|
36536
38694
|
const count2 = Number(res[0].count);
|
36537
38695
|
if (count2 > 0) {
|
36538
|
-
infoToPrint.push(
|
36539
|
-
`\xB7 You're about to delete ${source_default.underline(
|
36540
|
-
statement.name
|
36541
|
-
)} schema with ${count2} tables`
|
36542
|
-
);
|
38696
|
+
infoToPrint.push(`\xB7 You're about to delete ${source_default.underline(statement.name)} schema with ${count2} tables`);
|
36543
38697
|
schemasToRemove.push(statement.name);
|
36544
38698
|
shouldAskForApprove = true;
|
36545
38699
|
}
|
36546
38700
|
} else if (statement.type === "alter_table_alter_column_set_type") {
|
36547
38701
|
const res = await db.query(
|
36548
|
-
`select count(*) as count from ${tableNameWithSchemaFrom(
|
36549
|
-
statement.schema,
|
36550
|
-
statement.tableName,
|
36551
|
-
renamedSchemas,
|
36552
|
-
renamedTables
|
36553
|
-
)}`
|
38702
|
+
`select count(*) as count from ${tableNameWithSchemaFrom(statement.schema, statement.tableName, renamedSchemas, renamedTables)}`
|
36554
38703
|
);
|
36555
38704
|
const count2 = Number(res[0].count);
|
36556
38705
|
if (count2 > 0) {
|
36557
38706
|
infoToPrint.push(
|
36558
|
-
`\xB7 You're about to change ${source_default.underline(
|
36559
|
-
statement.
|
36560
|
-
)}
|
36561
|
-
statement.oldDataType
|
36562
|
-
)} to ${source_default.underline(statement.newDataType)} with ${count2} items`
|
38707
|
+
`\xB7 You're about to change ${source_default.underline(statement.columnName)} column type from ${source_default.underline(statement.oldDataType)} to ${source_default.underline(
|
38708
|
+
statement.newDataType
|
38709
|
+
)} with ${count2} items`
|
36563
38710
|
);
|
36564
38711
|
statementsToExecute.push(
|
36565
|
-
`truncate table ${tableNameWithSchemaFrom(
|
36566
|
-
statement.schema,
|
36567
|
-
statement.tableName,
|
36568
|
-
renamedSchemas,
|
36569
|
-
renamedTables
|
36570
|
-
)} cascade;`
|
38712
|
+
`truncate table ${tableNameWithSchemaFrom(statement.schema, statement.tableName, renamedSchemas, renamedTables)} cascade;`
|
36571
38713
|
);
|
36572
38714
|
tablesToTruncate.push(statement.tableName);
|
36573
38715
|
shouldAskForApprove = true;
|
36574
38716
|
}
|
36575
38717
|
} else if (statement.type === "alter_table_alter_column_drop_pk") {
|
36576
38718
|
const res = await db.query(
|
36577
|
-
`select count(*) as count from ${tableNameWithSchemaFrom(
|
36578
|
-
statement.schema,
|
36579
|
-
statement.tableName,
|
36580
|
-
renamedSchemas,
|
36581
|
-
renamedTables
|
36582
|
-
)}`
|
38719
|
+
`select count(*) as count from ${tableNameWithSchemaFrom(statement.schema, statement.tableName, renamedSchemas, renamedTables)}`
|
36583
38720
|
);
|
36584
38721
|
const count2 = Number(res[0].count);
|
36585
38722
|
if (count2 > 0) {
|
36586
38723
|
infoToPrint.push(
|
36587
|
-
`\xB7 You're about to change ${source_default.underline(
|
36588
|
-
statement.tableName
|
36589
|
-
)} primary key. This statements may fail and you table may left without primary key`
|
38724
|
+
`\xB7 You're about to change ${source_default.underline(statement.tableName)} primary key. This statements may fail and you table may left without primary key`
|
36590
38725
|
);
|
36591
38726
|
tablesToTruncate.push(statement.tableName);
|
36592
38727
|
shouldAskForApprove = true;
|
@@ -36610,40 +38745,23 @@ var pgSuggestions = async (db, statements) => {
|
|
36610
38745
|
} else if (statement.type === "alter_table_add_column") {
|
36611
38746
|
if (statement.column.notNull && typeof statement.column.default === "undefined") {
|
36612
38747
|
const res = await db.query(
|
36613
|
-
`select count(*) as count from ${tableNameWithSchemaFrom(
|
36614
|
-
statement.schema,
|
36615
|
-
statement.tableName,
|
36616
|
-
renamedSchemas,
|
36617
|
-
renamedTables
|
36618
|
-
)}`
|
38748
|
+
`select count(*) as count from ${tableNameWithSchemaFrom(statement.schema, statement.tableName, renamedSchemas, renamedTables)}`
|
36619
38749
|
);
|
36620
38750
|
const count2 = Number(res[0].count);
|
36621
38751
|
if (count2 > 0) {
|
36622
38752
|
infoToPrint.push(
|
36623
|
-
`\xB7 You're about to add not-null ${source_default.underline(
|
36624
|
-
statement.column.name
|
36625
|
-
)} column without default value, which contains ${count2} items`
|
38753
|
+
`\xB7 You're about to add not-null ${source_default.underline(statement.column.name)} column without default value, which contains ${count2} items`
|
36626
38754
|
);
|
36627
38755
|
tablesToTruncate.push(statement.tableName);
|
36628
38756
|
statementsToExecute.push(
|
36629
|
-
`truncate table ${tableNameWithSchemaFrom(
|
36630
|
-
statement.schema,
|
36631
|
-
statement.tableName,
|
36632
|
-
renamedSchemas,
|
36633
|
-
renamedTables
|
36634
|
-
)} cascade;`
|
38757
|
+
`truncate table ${tableNameWithSchemaFrom(statement.schema, statement.tableName, renamedSchemas, renamedTables)} cascade;`
|
36635
38758
|
);
|
36636
38759
|
shouldAskForApprove = true;
|
36637
38760
|
}
|
36638
38761
|
}
|
36639
38762
|
} else if (statement.type === "create_unique_constraint") {
|
36640
38763
|
const res = await db.query(
|
36641
|
-
`select count(*) as count from ${tableNameWithSchemaFrom(
|
36642
|
-
statement.schema,
|
36643
|
-
statement.tableName,
|
36644
|
-
renamedSchemas,
|
36645
|
-
renamedTables
|
36646
|
-
)}`
|
38764
|
+
`select count(*) as count from ${tableNameWithSchemaFrom(statement.schema, statement.tableName, renamedSchemas, renamedTables)}`
|
36647
38765
|
);
|
36648
38766
|
const count2 = Number(res[0].count);
|
36649
38767
|
if (count2 > 0) {
|
@@ -36657,20 +38775,12 @@ var pgSuggestions = async (db, statements) => {
|
|
36657
38775
|
`
|
36658
38776
|
);
|
36659
38777
|
const { status, data } = await (0, import_hanji5.render)(
|
36660
|
-
new Select([
|
36661
|
-
"No, add the constraint without truncating the table",
|
36662
|
-
`Yes, truncate the table`
|
36663
|
-
])
|
38778
|
+
new Select(["No, add the constraint without truncating the table", `Yes, truncate the table`])
|
36664
38779
|
);
|
36665
38780
|
if (data?.index === 1) {
|
36666
38781
|
tablesToTruncate.push(statement.tableName);
|
36667
38782
|
statementsToExecute.push(
|
36668
|
-
`truncate table ${tableNameWithSchemaFrom(
|
36669
|
-
statement.schema,
|
36670
|
-
statement.tableName,
|
36671
|
-
renamedSchemas,
|
36672
|
-
renamedTables
|
36673
|
-
)} cascade;`
|
38783
|
+
`truncate table ${tableNameWithSchemaFrom(statement.schema, statement.tableName, renamedSchemas, renamedTables)} cascade;`
|
36674
38784
|
);
|
36675
38785
|
shouldAskForApprove = true;
|
36676
38786
|
}
|
@@ -36680,10 +38790,7 @@ var pgSuggestions = async (db, statements) => {
|
|
36680
38790
|
if (typeof stmnt !== "undefined") {
|
36681
38791
|
if (statement.type === "drop_table") {
|
36682
38792
|
statementsToExecute.push(
|
36683
|
-
`DROP TABLE ${concatSchemaAndTableName(
|
36684
|
-
statement.schema,
|
36685
|
-
statement.tableName
|
36686
|
-
)} CASCADE;`
|
38793
|
+
`DROP TABLE ${concatSchemaAndTableName(statement.schema, statement.tableName)} CASCADE;`
|
36687
38794
|
);
|
36688
38795
|
} else {
|
36689
38796
|
statementsToExecute.push(...stmnt);
|
@@ -36694,6 +38801,7 @@ var pgSuggestions = async (db, statements) => {
|
|
36694
38801
|
statementsToExecute,
|
36695
38802
|
shouldAskForApprove,
|
36696
38803
|
infoToPrint,
|
38804
|
+
matViewsToRemove: [...new Set(matViewsToRemove)],
|
36697
38805
|
columnsToRemove: [...new Set(columnsToRemove)],
|
36698
38806
|
schemasToRemove: [...new Set(schemasToRemove)],
|
36699
38807
|
tablesToTruncate: [...new Set(tablesToTruncate)],
|
@@ -36873,6 +38981,9 @@ String.prototype.capitalise = function() {
|
|
36873
38981
|
String.prototype.concatIf = function(it, condition) {
|
36874
38982
|
return condition ? `${this}${it}` : String(this);
|
36875
38983
|
};
|
38984
|
+
String.prototype.snake_case = function() {
|
38985
|
+
return this && this.length > 0 ? `${this.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`)}` : String(this);
|
38986
|
+
};
|
36876
38987
|
Array.prototype.random = function() {
|
36877
38988
|
return this[~~(Math.random() * this.length)];
|
36878
38989
|
};
|
@@ -36933,6 +39044,8 @@ var generateDrizzleJson = (imports, prevId, schemaFilters, casing2) => {
|
|
36933
39044
|
prepared.enums,
|
36934
39045
|
prepared.schemas,
|
36935
39046
|
prepared.sequences,
|
39047
|
+
prepared.views,
|
39048
|
+
prepared.matViews,
|
36936
39049
|
casing2,
|
36937
39050
|
schemaFilters
|
36938
39051
|
);
|
@@ -36956,6 +39069,7 @@ var generateMigration = async (prev, cur) => {
|
|
36956
39069
|
sequencesResolver,
|
36957
39070
|
tablesResolver,
|
36958
39071
|
columnsResolver,
|
39072
|
+
viewsResolver,
|
36959
39073
|
validatedPrev,
|
36960
39074
|
validatedCur
|
36961
39075
|
);
|
@@ -36988,6 +39102,7 @@ var pushSchema = async (imports, drizzleInstance, schemaFilters) => {
|
|
36988
39102
|
sequencesResolver,
|
36989
39103
|
tablesResolver,
|
36990
39104
|
columnsResolver,
|
39105
|
+
viewsResolver,
|
36991
39106
|
validatedPrev,
|
36992
39107
|
validatedCur,
|
36993
39108
|
"push"
|
@@ -37008,7 +39123,7 @@ var generateSQLiteDrizzleJson = async (imports, prevId, casing2) => {
|
|
37008
39123
|
const { prepareFromExports: prepareFromExports4 } = await Promise.resolve().then(() => (init_sqliteImports(), sqliteImports_exports));
|
37009
39124
|
const prepared = prepareFromExports4(imports);
|
37010
39125
|
const id = randomUUID();
|
37011
|
-
const snapshot = generateSqliteSnapshot(prepared.tables, casing2);
|
39126
|
+
const snapshot = generateSqliteSnapshot(prepared.tables, prepared.views, casing2);
|
37012
39127
|
return {
|
37013
39128
|
...snapshot,
|
37014
39129
|
id,
|
@@ -37026,6 +39141,7 @@ var generateSQLiteMigration = async (prev, cur) => {
|
|
37026
39141
|
squashedCur,
|
37027
39142
|
tablesResolver,
|
37028
39143
|
columnsResolver,
|
39144
|
+
sqliteViewsResolver,
|
37029
39145
|
validatedPrev,
|
37030
39146
|
validatedCur
|
37031
39147
|
);
|
@@ -37057,6 +39173,7 @@ var pushSQLiteSchema = async (imports, drizzleInstance) => {
|
|
37057
39173
|
squashedCur,
|
37058
39174
|
tablesResolver,
|
37059
39175
|
columnsResolver,
|
39176
|
+
sqliteViewsResolver,
|
37060
39177
|
validatedPrev,
|
37061
39178
|
validatedCur,
|
37062
39179
|
"push"
|
@@ -37083,7 +39200,7 @@ var generateMySQLDrizzleJson = async (imports, prevId, casing2) => {
|
|
37083
39200
|
const { prepareFromExports: prepareFromExports4 } = await Promise.resolve().then(() => (init_mysqlImports(), mysqlImports_exports));
|
37084
39201
|
const prepared = prepareFromExports4(imports);
|
37085
39202
|
const id = randomUUID();
|
37086
|
-
const snapshot = generateMySqlSnapshot(prepared.tables, casing2);
|
39203
|
+
const snapshot = generateMySqlSnapshot(prepared.tables, prepared.views, casing2);
|
37087
39204
|
return {
|
37088
39205
|
...snapshot,
|
37089
39206
|
id,
|
@@ -37101,6 +39218,7 @@ var generateMySQLMigration = async (prev, cur) => {
|
|
37101
39218
|
squashedCur,
|
37102
39219
|
tablesResolver,
|
37103
39220
|
columnsResolver,
|
39221
|
+
mySqlViewsResolver,
|
37104
39222
|
validatedPrev,
|
37105
39223
|
validatedCur
|
37106
39224
|
);
|
@@ -37128,6 +39246,7 @@ var pushMySQLSchema = async (imports, drizzleInstance, databaseName) => {
|
|
37128
39246
|
squashedCur,
|
37129
39247
|
tablesResolver,
|
37130
39248
|
columnsResolver,
|
39249
|
+
mySqlViewsResolver,
|
37131
39250
|
validatedPrev,
|
37132
39251
|
validatedCur,
|
37133
39252
|
"push"
|