drizzle-kit 0.16.9-fcedf83 → 0.17.0-0cf3fe9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +19975 -18647
- package/package.json +13 -7
- package/readme.md +89 -15
- package/utils.js +593 -191
package/utils.js
CHANGED
|
@@ -6669,7 +6669,7 @@ __export(utils_exports, {
|
|
|
6669
6669
|
mapValues: () => mapValues,
|
|
6670
6670
|
prepareMigrationFolder: () => prepareMigrationFolder,
|
|
6671
6671
|
prepareMigrationMeta: () => prepareMigrationMeta,
|
|
6672
|
-
prepareOutFolder: () =>
|
|
6672
|
+
prepareOutFolder: () => prepareOutFolder2,
|
|
6673
6673
|
schemaRenameKey: () => schemaRenameKey,
|
|
6674
6674
|
snapshotsPriorV4: () => snapshotsPriorV4,
|
|
6675
6675
|
statementsForDiffs: () => statementsForDiffs,
|
|
@@ -7169,7 +7169,7 @@ var info = (msg, greyMsg = "") => {
|
|
|
7169
7169
|
var originUUID = "00000000-0000-0000-0000-000000000000";
|
|
7170
7170
|
var snapshotVersion = "5";
|
|
7171
7171
|
|
|
7172
|
-
// node_modules/.pnpm/zod@3.20.
|
|
7172
|
+
// node_modules/.pnpm/zod@3.20.6/node_modules/zod/lib/index.mjs
|
|
7173
7173
|
var util;
|
|
7174
7174
|
(function(util2) {
|
|
7175
7175
|
util2.assertEqual = (val) => val;
|
|
@@ -7584,7 +7584,7 @@ var OK = (value) => ({ status: "valid", value });
|
|
|
7584
7584
|
var isAborted = (x) => x.status === "aborted";
|
|
7585
7585
|
var isDirty = (x) => x.status === "dirty";
|
|
7586
7586
|
var isValid = (x) => x.status === "valid";
|
|
7587
|
-
var isAsync = (x) => typeof Promise !==
|
|
7587
|
+
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
7588
7588
|
var errorUtil;
|
|
7589
7589
|
(function(errorUtil2) {
|
|
7590
7590
|
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
@@ -7800,28 +7800,29 @@ var ZodType = class {
|
|
|
7800
7800
|
return this._refinement(refinement);
|
|
7801
7801
|
}
|
|
7802
7802
|
optional() {
|
|
7803
|
-
return ZodOptional.create(this);
|
|
7803
|
+
return ZodOptional.create(this, this._def);
|
|
7804
7804
|
}
|
|
7805
7805
|
nullable() {
|
|
7806
|
-
return ZodNullable.create(this);
|
|
7806
|
+
return ZodNullable.create(this, this._def);
|
|
7807
7807
|
}
|
|
7808
7808
|
nullish() {
|
|
7809
|
-
return this.
|
|
7809
|
+
return this.nullable().optional();
|
|
7810
7810
|
}
|
|
7811
7811
|
array() {
|
|
7812
|
-
return ZodArray.create(this);
|
|
7812
|
+
return ZodArray.create(this, this._def);
|
|
7813
7813
|
}
|
|
7814
7814
|
promise() {
|
|
7815
|
-
return ZodPromise.create(this);
|
|
7815
|
+
return ZodPromise.create(this, this._def);
|
|
7816
7816
|
}
|
|
7817
7817
|
or(option) {
|
|
7818
|
-
return ZodUnion.create([this, option]);
|
|
7818
|
+
return ZodUnion.create([this, option], this._def);
|
|
7819
7819
|
}
|
|
7820
7820
|
and(incoming) {
|
|
7821
|
-
return ZodIntersection.create(this, incoming);
|
|
7821
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
7822
7822
|
}
|
|
7823
7823
|
transform(transform) {
|
|
7824
7824
|
return new ZodEffects({
|
|
7825
|
+
...processCreateParams(this._def),
|
|
7825
7826
|
schema: this,
|
|
7826
7827
|
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
7827
7828
|
effect: { type: "transform", transform }
|
|
@@ -7830,6 +7831,7 @@ var ZodType = class {
|
|
|
7830
7831
|
default(def) {
|
|
7831
7832
|
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
7832
7833
|
return new ZodDefault({
|
|
7834
|
+
...processCreateParams(this._def),
|
|
7833
7835
|
innerType: this,
|
|
7834
7836
|
defaultValue: defaultValueFunc,
|
|
7835
7837
|
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
@@ -7839,14 +7841,15 @@ var ZodType = class {
|
|
|
7839
7841
|
return new ZodBranded({
|
|
7840
7842
|
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
7841
7843
|
type: this,
|
|
7842
|
-
...processCreateParams(
|
|
7844
|
+
...processCreateParams(this._def)
|
|
7843
7845
|
});
|
|
7844
7846
|
}
|
|
7845
7847
|
catch(def) {
|
|
7846
|
-
const
|
|
7848
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
7847
7849
|
return new ZodCatch({
|
|
7850
|
+
...processCreateParams(this._def),
|
|
7848
7851
|
innerType: this,
|
|
7849
|
-
|
|
7852
|
+
catchValue: catchValueFunc,
|
|
7850
7853
|
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
7851
7854
|
});
|
|
7852
7855
|
}
|
|
@@ -7868,24 +7871,25 @@ var ZodType = class {
|
|
|
7868
7871
|
}
|
|
7869
7872
|
};
|
|
7870
7873
|
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
7874
|
+
var cuid2Regex = /^[a-z][a-z0-9]*$/;
|
|
7871
7875
|
var uuidRegex = /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
7872
|
-
var emailRegex = /^(([^<>()[\]
|
|
7876
|
+
var emailRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|([^-]([a-zA-Z0-9-]*\.)+[a-zA-Z]{2,}))$/;
|
|
7873
7877
|
var datetimeRegex = (args) => {
|
|
7874
7878
|
if (args.precision) {
|
|
7875
7879
|
if (args.offset) {
|
|
7876
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}
|
|
7880
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
7877
7881
|
} else {
|
|
7878
7882
|
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
|
|
7879
7883
|
}
|
|
7880
7884
|
} else if (args.precision === 0) {
|
|
7881
7885
|
if (args.offset) {
|
|
7882
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}
|
|
7886
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
7883
7887
|
} else {
|
|
7884
7888
|
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
|
|
7885
7889
|
}
|
|
7886
7890
|
} else {
|
|
7887
7891
|
if (args.offset) {
|
|
7888
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}
|
|
7892
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
7889
7893
|
} else {
|
|
7890
7894
|
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
|
|
7891
7895
|
}
|
|
@@ -8007,6 +8011,16 @@ var ZodString = class extends ZodType {
|
|
|
8007
8011
|
});
|
|
8008
8012
|
status.dirty();
|
|
8009
8013
|
}
|
|
8014
|
+
} else if (check.kind === "cuid2") {
|
|
8015
|
+
if (!cuid2Regex.test(input.data)) {
|
|
8016
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
8017
|
+
addIssueToContext(ctx, {
|
|
8018
|
+
validation: "cuid2",
|
|
8019
|
+
code: ZodIssueCode.invalid_string,
|
|
8020
|
+
message: check.message
|
|
8021
|
+
});
|
|
8022
|
+
status.dirty();
|
|
8023
|
+
}
|
|
8010
8024
|
} else if (check.kind === "url") {
|
|
8011
8025
|
try {
|
|
8012
8026
|
new URL(input.data);
|
|
@@ -8088,6 +8102,9 @@ var ZodString = class extends ZodType {
|
|
|
8088
8102
|
cuid(message) {
|
|
8089
8103
|
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
8090
8104
|
}
|
|
8105
|
+
cuid2(message) {
|
|
8106
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
8107
|
+
}
|
|
8091
8108
|
datetime(options) {
|
|
8092
8109
|
var _a;
|
|
8093
8110
|
if (typeof options === "string") {
|
|
@@ -8162,6 +8179,9 @@ var ZodString = class extends ZodType {
|
|
|
8162
8179
|
get isCUID() {
|
|
8163
8180
|
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
8164
8181
|
}
|
|
8182
|
+
get isCUID2() {
|
|
8183
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
8184
|
+
}
|
|
8165
8185
|
get minLength() {
|
|
8166
8186
|
let min = null;
|
|
8167
8187
|
for (const ch of this._def.checks) {
|
|
@@ -8392,7 +8412,22 @@ var ZodNumber = class extends ZodType {
|
|
|
8392
8412
|
return max;
|
|
8393
8413
|
}
|
|
8394
8414
|
get isInt() {
|
|
8395
|
-
return !!this._def.checks.find((ch) => ch.kind === "int");
|
|
8415
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
8416
|
+
}
|
|
8417
|
+
get isFinite() {
|
|
8418
|
+
let max = null, min = null;
|
|
8419
|
+
for (const ch of this._def.checks) {
|
|
8420
|
+
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
8421
|
+
return true;
|
|
8422
|
+
} else if (ch.kind === "min") {
|
|
8423
|
+
if (min === null || ch.value > min)
|
|
8424
|
+
min = ch.value;
|
|
8425
|
+
} else if (ch.kind === "max") {
|
|
8426
|
+
if (max === null || ch.value < max)
|
|
8427
|
+
max = ch.value;
|
|
8428
|
+
}
|
|
8429
|
+
}
|
|
8430
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
|
8396
8431
|
}
|
|
8397
8432
|
};
|
|
8398
8433
|
ZodNumber.create = (params) => {
|
|
@@ -8749,13 +8784,13 @@ var ZodArray = class extends ZodType {
|
|
|
8749
8784
|
}
|
|
8750
8785
|
}
|
|
8751
8786
|
if (ctx.common.async) {
|
|
8752
|
-
return Promise.all(ctx.data.map((item, i) => {
|
|
8787
|
+
return Promise.all([...ctx.data].map((item, i) => {
|
|
8753
8788
|
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
8754
8789
|
})).then((result2) => {
|
|
8755
8790
|
return ParseStatus.mergeArray(status, result2);
|
|
8756
8791
|
});
|
|
8757
8792
|
}
|
|
8758
|
-
const result = ctx.data.map((item, i) => {
|
|
8793
|
+
const result = [...ctx.data].map((item, i) => {
|
|
8759
8794
|
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
8760
8795
|
});
|
|
8761
8796
|
return ParseStatus.mergeArray(status, result);
|
|
@@ -8804,15 +8839,6 @@ var objectUtil;
|
|
|
8804
8839
|
};
|
|
8805
8840
|
};
|
|
8806
8841
|
})(objectUtil || (objectUtil = {}));
|
|
8807
|
-
var AugmentFactory = (def) => (augmentation) => {
|
|
8808
|
-
return new ZodObject({
|
|
8809
|
-
...def,
|
|
8810
|
-
shape: () => ({
|
|
8811
|
-
...def.shape(),
|
|
8812
|
-
...augmentation
|
|
8813
|
-
})
|
|
8814
|
-
});
|
|
8815
|
-
};
|
|
8816
8842
|
function deepPartialify(schema3) {
|
|
8817
8843
|
if (schema3 instanceof ZodObject) {
|
|
8818
8844
|
const newShape = {};
|
|
@@ -8841,8 +8867,7 @@ var ZodObject = class extends ZodType {
|
|
|
8841
8867
|
super(...arguments);
|
|
8842
8868
|
this._cached = null;
|
|
8843
8869
|
this.nonstrict = this.passthrough;
|
|
8844
|
-
this.augment =
|
|
8845
|
-
this.extend = AugmentFactory(this._def);
|
|
8870
|
+
this.augment = this.extend;
|
|
8846
8871
|
}
|
|
8847
8872
|
_getCached() {
|
|
8848
8873
|
if (this._cached !== null)
|
|
@@ -8971,8 +8996,14 @@ var ZodObject = class extends ZodType {
|
|
|
8971
8996
|
unknownKeys: "passthrough"
|
|
8972
8997
|
});
|
|
8973
8998
|
}
|
|
8974
|
-
|
|
8975
|
-
return
|
|
8999
|
+
extend(augmentation) {
|
|
9000
|
+
return new ZodObject({
|
|
9001
|
+
...this._def,
|
|
9002
|
+
shape: () => ({
|
|
9003
|
+
...this._def.shape(),
|
|
9004
|
+
...augmentation
|
|
9005
|
+
})
|
|
9006
|
+
});
|
|
8976
9007
|
}
|
|
8977
9008
|
merge(merging) {
|
|
8978
9009
|
const merged = new ZodObject({
|
|
@@ -8983,6 +9014,9 @@ var ZodObject = class extends ZodType {
|
|
|
8983
9014
|
});
|
|
8984
9015
|
return merged;
|
|
8985
9016
|
}
|
|
9017
|
+
setKey(key, schema3) {
|
|
9018
|
+
return this.augment({ [key]: schema3 });
|
|
9019
|
+
}
|
|
8986
9020
|
catchall(index4) {
|
|
8987
9021
|
return new ZodObject({
|
|
8988
9022
|
...this._def,
|
|
@@ -8991,9 +9025,10 @@ var ZodObject = class extends ZodType {
|
|
|
8991
9025
|
}
|
|
8992
9026
|
pick(mask) {
|
|
8993
9027
|
const shape = {};
|
|
8994
|
-
util.objectKeys(mask).
|
|
8995
|
-
if (this.shape[key])
|
|
9028
|
+
util.objectKeys(mask).forEach((key) => {
|
|
9029
|
+
if (mask[key] && this.shape[key]) {
|
|
8996
9030
|
shape[key] = this.shape[key];
|
|
9031
|
+
}
|
|
8997
9032
|
});
|
|
8998
9033
|
return new ZodObject({
|
|
8999
9034
|
...this._def,
|
|
@@ -9002,8 +9037,8 @@ var ZodObject = class extends ZodType {
|
|
|
9002
9037
|
}
|
|
9003
9038
|
omit(mask) {
|
|
9004
9039
|
const shape = {};
|
|
9005
|
-
util.objectKeys(this.shape).
|
|
9006
|
-
if (
|
|
9040
|
+
util.objectKeys(this.shape).forEach((key) => {
|
|
9041
|
+
if (!mask[key]) {
|
|
9007
9042
|
shape[key] = this.shape[key];
|
|
9008
9043
|
}
|
|
9009
9044
|
});
|
|
@@ -9017,24 +9052,14 @@ var ZodObject = class extends ZodType {
|
|
|
9017
9052
|
}
|
|
9018
9053
|
partial(mask) {
|
|
9019
9054
|
const newShape = {};
|
|
9020
|
-
|
|
9021
|
-
|
|
9022
|
-
|
|
9023
|
-
|
|
9024
|
-
|
|
9025
|
-
newShape[key] = this.shape[key].optional();
|
|
9026
|
-
}
|
|
9027
|
-
});
|
|
9028
|
-
return new ZodObject({
|
|
9029
|
-
...this._def,
|
|
9030
|
-
shape: () => newShape
|
|
9031
|
-
});
|
|
9032
|
-
} else {
|
|
9033
|
-
for (const key in this.shape) {
|
|
9034
|
-
const fieldSchema = this.shape[key];
|
|
9055
|
+
util.objectKeys(this.shape).forEach((key) => {
|
|
9056
|
+
const fieldSchema = this.shape[key];
|
|
9057
|
+
if (mask && !mask[key]) {
|
|
9058
|
+
newShape[key] = fieldSchema;
|
|
9059
|
+
} else {
|
|
9035
9060
|
newShape[key] = fieldSchema.optional();
|
|
9036
9061
|
}
|
|
9037
|
-
}
|
|
9062
|
+
});
|
|
9038
9063
|
return new ZodObject({
|
|
9039
9064
|
...this._def,
|
|
9040
9065
|
shape: () => newShape
|
|
@@ -9042,21 +9067,10 @@ var ZodObject = class extends ZodType {
|
|
|
9042
9067
|
}
|
|
9043
9068
|
required(mask) {
|
|
9044
9069
|
const newShape = {};
|
|
9045
|
-
|
|
9046
|
-
|
|
9047
|
-
|
|
9048
|
-
|
|
9049
|
-
} else {
|
|
9050
|
-
const fieldSchema = this.shape[key];
|
|
9051
|
-
let newField = fieldSchema;
|
|
9052
|
-
while (newField instanceof ZodOptional) {
|
|
9053
|
-
newField = newField._def.innerType;
|
|
9054
|
-
}
|
|
9055
|
-
newShape[key] = newField;
|
|
9056
|
-
}
|
|
9057
|
-
});
|
|
9058
|
-
} else {
|
|
9059
|
-
for (const key in this.shape) {
|
|
9070
|
+
util.objectKeys(this.shape).forEach((key) => {
|
|
9071
|
+
if (mask && !mask[key]) {
|
|
9072
|
+
newShape[key] = this.shape[key];
|
|
9073
|
+
} else {
|
|
9060
9074
|
const fieldSchema = this.shape[key];
|
|
9061
9075
|
let newField = fieldSchema;
|
|
9062
9076
|
while (newField instanceof ZodOptional) {
|
|
@@ -9064,7 +9078,7 @@ var ZodObject = class extends ZodType {
|
|
|
9064
9078
|
}
|
|
9065
9079
|
newShape[key] = newField;
|
|
9066
9080
|
}
|
|
9067
|
-
}
|
|
9081
|
+
});
|
|
9068
9082
|
return new ZodObject({
|
|
9069
9083
|
...this._def,
|
|
9070
9084
|
shape: () => newShape
|
|
@@ -9404,7 +9418,7 @@ var ZodTuple = class extends ZodType {
|
|
|
9404
9418
|
});
|
|
9405
9419
|
status.dirty();
|
|
9406
9420
|
}
|
|
9407
|
-
const items = ctx.data.map((item, itemIndex) => {
|
|
9421
|
+
const items = [...ctx.data].map((item, itemIndex) => {
|
|
9408
9422
|
const schema3 = this._def.items[itemIndex] || this._def.rest;
|
|
9409
9423
|
if (!schema3)
|
|
9410
9424
|
return null;
|
|
@@ -9771,6 +9785,7 @@ var ZodLiteral = class extends ZodType {
|
|
|
9771
9785
|
if (input.data !== this._def.value) {
|
|
9772
9786
|
const ctx = this._getOrReturnCtx(input);
|
|
9773
9787
|
addIssueToContext(ctx, {
|
|
9788
|
+
received: ctx.data,
|
|
9774
9789
|
code: ZodIssueCode.invalid_literal,
|
|
9775
9790
|
expected: this._def.value
|
|
9776
9791
|
});
|
|
@@ -9844,6 +9859,12 @@ var ZodEnum = class extends ZodType {
|
|
|
9844
9859
|
}
|
|
9845
9860
|
return enumValues;
|
|
9846
9861
|
}
|
|
9862
|
+
extract(values) {
|
|
9863
|
+
return ZodEnum.create(values);
|
|
9864
|
+
}
|
|
9865
|
+
exclude(values) {
|
|
9866
|
+
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
|
|
9867
|
+
}
|
|
9847
9868
|
};
|
|
9848
9869
|
ZodEnum.create = createZodEnum;
|
|
9849
9870
|
var ZodNativeEnum = class extends ZodType {
|
|
@@ -9882,6 +9903,9 @@ ZodNativeEnum.create = (values, params) => {
|
|
|
9882
9903
|
});
|
|
9883
9904
|
};
|
|
9884
9905
|
var ZodPromise = class extends ZodType {
|
|
9906
|
+
unwrap() {
|
|
9907
|
+
return this._def.type;
|
|
9908
|
+
}
|
|
9885
9909
|
_parse(input) {
|
|
9886
9910
|
const { ctx } = this._processInputParams(input);
|
|
9887
9911
|
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
@@ -10095,23 +10119,29 @@ var ZodCatch = class extends ZodType {
|
|
|
10095
10119
|
const result = this._def.innerType._parse({
|
|
10096
10120
|
data: ctx.data,
|
|
10097
10121
|
path: ctx.path,
|
|
10098
|
-
parent:
|
|
10122
|
+
parent: {
|
|
10123
|
+
...ctx,
|
|
10124
|
+
common: {
|
|
10125
|
+
...ctx.common,
|
|
10126
|
+
issues: []
|
|
10127
|
+
}
|
|
10128
|
+
}
|
|
10099
10129
|
});
|
|
10100
10130
|
if (isAsync(result)) {
|
|
10101
10131
|
return result.then((result2) => {
|
|
10102
10132
|
return {
|
|
10103
10133
|
status: "valid",
|
|
10104
|
-
value: result2.status === "valid" ? result2.value : this._def.
|
|
10134
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue()
|
|
10105
10135
|
};
|
|
10106
10136
|
});
|
|
10107
10137
|
} else {
|
|
10108
10138
|
return {
|
|
10109
10139
|
status: "valid",
|
|
10110
|
-
value: result.status === "valid" ? result.value : this._def.
|
|
10140
|
+
value: result.status === "valid" ? result.value : this._def.catchValue()
|
|
10111
10141
|
};
|
|
10112
10142
|
}
|
|
10113
10143
|
}
|
|
10114
|
-
|
|
10144
|
+
removeCatch() {
|
|
10115
10145
|
return this._def.innerType;
|
|
10116
10146
|
}
|
|
10117
10147
|
};
|
|
@@ -10119,7 +10149,7 @@ ZodCatch.create = (type, params) => {
|
|
|
10119
10149
|
return new ZodCatch({
|
|
10120
10150
|
innerType: type,
|
|
10121
10151
|
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
10122
|
-
|
|
10152
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
10123
10153
|
...processCreateParams(params)
|
|
10124
10154
|
});
|
|
10125
10155
|
};
|
|
@@ -10323,13 +10353,25 @@ var tableV3 = objectType({
|
|
|
10323
10353
|
indexes: recordType(stringType(), index),
|
|
10324
10354
|
foreignKeys: recordType(stringType(), fk)
|
|
10325
10355
|
}).strict();
|
|
10326
|
-
var
|
|
10356
|
+
var compositePK = objectType({
|
|
10357
|
+
name: stringType(),
|
|
10358
|
+
columns: stringType().array()
|
|
10359
|
+
}).strict();
|
|
10360
|
+
var tableV4 = objectType({
|
|
10327
10361
|
name: stringType(),
|
|
10328
10362
|
schema: stringType().optional(),
|
|
10329
10363
|
columns: recordType(stringType(), column),
|
|
10330
10364
|
indexes: recordType(stringType(), index),
|
|
10331
10365
|
foreignKeys: recordType(stringType(), fk)
|
|
10332
10366
|
}).strict();
|
|
10367
|
+
var table = objectType({
|
|
10368
|
+
name: stringType(),
|
|
10369
|
+
schema: stringType().optional(),
|
|
10370
|
+
columns: recordType(stringType(), column),
|
|
10371
|
+
indexes: recordType(stringType(), index),
|
|
10372
|
+
foreignKeys: recordType(stringType(), fk),
|
|
10373
|
+
compositePrimaryKeys: recordType(stringType(), compositePK)
|
|
10374
|
+
}).strict();
|
|
10333
10375
|
var dialect = literalType("mysql");
|
|
10334
10376
|
var schemaHash = objectType({
|
|
10335
10377
|
id: stringType(),
|
|
@@ -10343,7 +10385,7 @@ var schemaInternalV3 = objectType({
|
|
|
10343
10385
|
var schemaInternalV4 = objectType({
|
|
10344
10386
|
version: literalType("4"),
|
|
10345
10387
|
dialect,
|
|
10346
|
-
tables: recordType(stringType(),
|
|
10388
|
+
tables: recordType(stringType(), tableV4),
|
|
10347
10389
|
schemas: recordType(stringType(), stringType())
|
|
10348
10390
|
}).strict();
|
|
10349
10391
|
var schemaInternal = objectType({
|
|
@@ -10360,19 +10402,33 @@ var schemaInternal = objectType({
|
|
|
10360
10402
|
var schemaV3 = schemaInternalV3.merge(schemaHash);
|
|
10361
10403
|
var schemaV4 = schemaInternalV4.merge(schemaHash);
|
|
10362
10404
|
var schema = schemaInternal.merge(schemaHash);
|
|
10363
|
-
var
|
|
10405
|
+
var tableSquashedV4 = objectType({
|
|
10364
10406
|
name: stringType(),
|
|
10365
10407
|
schema: stringType().optional(),
|
|
10366
10408
|
columns: recordType(stringType(), column),
|
|
10367
10409
|
indexes: recordType(stringType(), stringType()),
|
|
10368
10410
|
foreignKeys: recordType(stringType(), stringType())
|
|
10369
10411
|
}).strict();
|
|
10412
|
+
var tableSquashed = objectType({
|
|
10413
|
+
name: stringType(),
|
|
10414
|
+
schema: stringType().optional(),
|
|
10415
|
+
columns: recordType(stringType(), column),
|
|
10416
|
+
indexes: recordType(stringType(), stringType()),
|
|
10417
|
+
foreignKeys: recordType(stringType(), stringType()),
|
|
10418
|
+
compositePrimaryKeys: recordType(stringType(), stringType())
|
|
10419
|
+
}).strict();
|
|
10370
10420
|
var schemaSquashed = objectType({
|
|
10371
10421
|
version: literalType("5"),
|
|
10372
10422
|
dialect,
|
|
10373
10423
|
tables: recordType(stringType(), tableSquashed),
|
|
10374
10424
|
schemas: recordType(stringType(), stringType())
|
|
10375
10425
|
}).strict();
|
|
10426
|
+
var schemaSquashedV4 = objectType({
|
|
10427
|
+
version: literalType("4"),
|
|
10428
|
+
dialect,
|
|
10429
|
+
tables: recordType(stringType(), tableSquashedV4),
|
|
10430
|
+
schemas: recordType(stringType(), stringType())
|
|
10431
|
+
}).strict();
|
|
10376
10432
|
var MySqlSquasher = {
|
|
10377
10433
|
squashIdx: (idx) => {
|
|
10378
10434
|
var _a, _b, _c;
|
|
@@ -10391,6 +10447,13 @@ var MySqlSquasher = {
|
|
|
10391
10447
|
};
|
|
10392
10448
|
return index.parse(destructed);
|
|
10393
10449
|
},
|
|
10450
|
+
squashPK: (pk) => {
|
|
10451
|
+
return `${pk.name};${pk.columns.join(",")}`;
|
|
10452
|
+
},
|
|
10453
|
+
unsquashPK: (pk) => {
|
|
10454
|
+
const splitted = pk.split(";");
|
|
10455
|
+
return { name: splitted[0], columns: splitted[1].split(",") };
|
|
10456
|
+
},
|
|
10394
10457
|
squashFK: (fk4) => {
|
|
10395
10458
|
var _a, _b;
|
|
10396
10459
|
return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${(_a = fk4.onUpdate) != null ? _a : ""};${(_b = fk4.onDelete) != null ? _b : ""}`;
|
|
@@ -10518,13 +10581,25 @@ var tableV32 = objectType({
|
|
|
10518
10581
|
indexes: recordType(stringType(), index2),
|
|
10519
10582
|
foreignKeys: recordType(stringType(), fk2)
|
|
10520
10583
|
}).strict();
|
|
10521
|
-
var
|
|
10584
|
+
var compositePK2 = objectType({
|
|
10585
|
+
name: stringType(),
|
|
10586
|
+
columns: stringType().array()
|
|
10587
|
+
}).strict();
|
|
10588
|
+
var tableV42 = objectType({
|
|
10522
10589
|
name: stringType(),
|
|
10523
10590
|
schema: stringType(),
|
|
10524
10591
|
columns: recordType(stringType(), column2),
|
|
10525
10592
|
indexes: recordType(stringType(), index2),
|
|
10526
10593
|
foreignKeys: recordType(stringType(), fk2)
|
|
10527
10594
|
}).strict();
|
|
10595
|
+
var table2 = objectType({
|
|
10596
|
+
name: stringType(),
|
|
10597
|
+
schema: stringType(),
|
|
10598
|
+
columns: recordType(stringType(), column2),
|
|
10599
|
+
indexes: recordType(stringType(), index2),
|
|
10600
|
+
foreignKeys: recordType(stringType(), fk2),
|
|
10601
|
+
compositePrimaryKeys: recordType(stringType(), compositePK2)
|
|
10602
|
+
}).strict();
|
|
10528
10603
|
var schemaHash2 = objectType({
|
|
10529
10604
|
id: stringType(),
|
|
10530
10605
|
prevId: stringType()
|
|
@@ -10538,7 +10613,7 @@ var pgSchemaInternalV3 = objectType({
|
|
|
10538
10613
|
var pgSchemaInternalV4 = objectType({
|
|
10539
10614
|
version: literalType("4"),
|
|
10540
10615
|
dialect: literalType("pg"),
|
|
10541
|
-
tables: recordType(stringType(),
|
|
10616
|
+
tables: recordType(stringType(), tableV42),
|
|
10542
10617
|
enums: recordType(stringType(), enumSchema),
|
|
10543
10618
|
schemas: recordType(stringType(), stringType())
|
|
10544
10619
|
}).strict();
|
|
@@ -10555,12 +10630,27 @@ var pgSchemaInternal = objectType({
|
|
|
10555
10630
|
})
|
|
10556
10631
|
}).strict();
|
|
10557
10632
|
var tableSquashed2 = objectType({
|
|
10633
|
+
name: stringType(),
|
|
10634
|
+
schema: stringType(),
|
|
10635
|
+
columns: recordType(stringType(), column2),
|
|
10636
|
+
indexes: recordType(stringType(), stringType()),
|
|
10637
|
+
foreignKeys: recordType(stringType(), stringType()),
|
|
10638
|
+
compositePrimaryKeys: recordType(stringType(), stringType())
|
|
10639
|
+
}).strict();
|
|
10640
|
+
var tableSquashedV42 = objectType({
|
|
10558
10641
|
name: stringType(),
|
|
10559
10642
|
schema: stringType(),
|
|
10560
10643
|
columns: recordType(stringType(), column2),
|
|
10561
10644
|
indexes: recordType(stringType(), stringType()),
|
|
10562
10645
|
foreignKeys: recordType(stringType(), stringType())
|
|
10563
10646
|
}).strict();
|
|
10647
|
+
var pgSchemaSquashedV4 = objectType({
|
|
10648
|
+
version: literalType("4"),
|
|
10649
|
+
dialect: enumType(["pg"]),
|
|
10650
|
+
tables: recordType(stringType(), tableSquashedV42),
|
|
10651
|
+
enums: recordType(stringType(), enumSchema),
|
|
10652
|
+
schemas: recordType(stringType(), stringType())
|
|
10653
|
+
}).strict();
|
|
10564
10654
|
var pgSchemaSquashed = objectType({
|
|
10565
10655
|
version: literalType("5"),
|
|
10566
10656
|
dialect: enumType(["pg"]),
|
|
@@ -10596,6 +10686,12 @@ var PgSquasher = {
|
|
|
10596
10686
|
var _a, _b;
|
|
10597
10687
|
return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${(_a = fk4.onUpdate) != null ? _a : ""};${(_b = fk4.onDelete) != null ? _b : ""}`;
|
|
10598
10688
|
},
|
|
10689
|
+
squashPK: (pk) => {
|
|
10690
|
+
return `${pk.columns.join(",")}`;
|
|
10691
|
+
},
|
|
10692
|
+
unsquashPK: (pk) => {
|
|
10693
|
+
return { name: "", columns: pk.split(",") };
|
|
10694
|
+
},
|
|
10599
10695
|
unsquashFK: (input) => {
|
|
10600
10696
|
const [
|
|
10601
10697
|
name,
|
|
@@ -10627,6 +10723,9 @@ var squashPgScheme = (json) => {
|
|
|
10627
10723
|
const squashedFKs = mapValues(it[1].foreignKeys, (fk4) => {
|
|
10628
10724
|
return PgSquasher.squashFK(fk4);
|
|
10629
10725
|
});
|
|
10726
|
+
const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
|
|
10727
|
+
return PgSquasher.squashPK(pk);
|
|
10728
|
+
});
|
|
10630
10729
|
return [
|
|
10631
10730
|
it[0],
|
|
10632
10731
|
{
|
|
@@ -10634,7 +10733,8 @@ var squashPgScheme = (json) => {
|
|
|
10634
10733
|
schema: it[1].schema,
|
|
10635
10734
|
columns: it[1].columns,
|
|
10636
10735
|
indexes: squashedIndexes,
|
|
10637
|
-
foreignKeys: squashedFKs
|
|
10736
|
+
foreignKeys: squashedFKs,
|
|
10737
|
+
compositePrimaryKeys: squashedPKs
|
|
10638
10738
|
}
|
|
10639
10739
|
];
|
|
10640
10740
|
})
|
|
@@ -10678,7 +10778,7 @@ var fk3 = objectType({
|
|
|
10678
10778
|
onUpdate: stringType().optional(),
|
|
10679
10779
|
onDelete: stringType().optional()
|
|
10680
10780
|
}).strict();
|
|
10681
|
-
var
|
|
10781
|
+
var compositePK3 = objectType({
|
|
10682
10782
|
columns: stringType().array()
|
|
10683
10783
|
}).strict();
|
|
10684
10784
|
var column3 = objectType({
|
|
@@ -10700,7 +10800,7 @@ var table3 = objectType({
|
|
|
10700
10800
|
columns: recordType(stringType(), column3),
|
|
10701
10801
|
indexes: recordType(stringType(), index3),
|
|
10702
10802
|
foreignKeys: recordType(stringType(), fk3),
|
|
10703
|
-
compositePrimaryKeys: recordType(stringType(),
|
|
10803
|
+
compositePrimaryKeys: recordType(stringType(), compositePK3)
|
|
10704
10804
|
}).strict();
|
|
10705
10805
|
var dialect2 = enumType(["sqlite"]);
|
|
10706
10806
|
var schemaHash3 = objectType({
|
|
@@ -10995,6 +11095,19 @@ var alternationsInColumn = (column4) => {
|
|
|
10995
11095
|
return { ...others, notNull: { type: "deleted", value: it.notNull__deleted } };
|
|
10996
11096
|
}
|
|
10997
11097
|
return it;
|
|
11098
|
+
}).map((it) => {
|
|
11099
|
+
if ("primaryKey" in it) {
|
|
11100
|
+
return { ...it, primaryKey: { type: "changed", old: it.primaryKey.__old, new: it.primaryKey.__new } };
|
|
11101
|
+
}
|
|
11102
|
+
if ("primaryKey__added" in it) {
|
|
11103
|
+
const { notNull__added, ...others } = it;
|
|
11104
|
+
return { ...others, primaryKey: { type: "added", value: it.primaryKey__added } };
|
|
11105
|
+
}
|
|
11106
|
+
if ("primaryKey__deleted" in it) {
|
|
11107
|
+
const { notNull__deleted, ...others } = it;
|
|
11108
|
+
return { ...others, primaryKey: { type: "deleted", value: it.primaryKey__deleted } };
|
|
11109
|
+
}
|
|
11110
|
+
return it;
|
|
10998
11111
|
}).map((it) => {
|
|
10999
11112
|
if ("onUpdate" in it) {
|
|
11000
11113
|
return { ...it, onUpdate: { type: "changed", old: it.onUpdate.__old, new: it.onUpdate.__new } };
|
|
@@ -11052,13 +11165,26 @@ var pgNativeTypes = /* @__PURE__ */ new Set([
|
|
|
11052
11165
|
"interval",
|
|
11053
11166
|
"bigint",
|
|
11054
11167
|
"bigserial",
|
|
11055
|
-
"double precision"
|
|
11168
|
+
"double precision",
|
|
11169
|
+
"interval year",
|
|
11170
|
+
"interval month",
|
|
11171
|
+
"interval day",
|
|
11172
|
+
"interval hour",
|
|
11173
|
+
"interval minute",
|
|
11174
|
+
"interval second",
|
|
11175
|
+
"interval year to month",
|
|
11176
|
+
"interval day to hour",
|
|
11177
|
+
"interval day to minute",
|
|
11178
|
+
"interval day to second",
|
|
11179
|
+
"interval hour to minute",
|
|
11180
|
+
"interval hour to second",
|
|
11181
|
+
"interval minute to second"
|
|
11056
11182
|
]);
|
|
11057
11183
|
var isPgNativeType = (it) => {
|
|
11058
11184
|
if (pgNativeTypes.has(it))
|
|
11059
11185
|
return true;
|
|
11060
11186
|
const toCheck = it.replace(/ /g, "");
|
|
11061
|
-
return toCheck.startsWith("varchar(") || toCheck.startsWith("numeric(") || toCheck.startsWith("timestamp(");
|
|
11187
|
+
return toCheck.startsWith("varchar(") || toCheck.startsWith("char(") || toCheck.startsWith("numeric(") || toCheck.startsWith("timestamp(");
|
|
11062
11188
|
};
|
|
11063
11189
|
var Convertor = class {
|
|
11064
11190
|
};
|
|
@@ -11067,7 +11193,7 @@ var PgCreateTableConvertor = class extends Convertor {
|
|
|
11067
11193
|
return statement.type === "create_table" && dialect3 === "pg";
|
|
11068
11194
|
}
|
|
11069
11195
|
convert(st) {
|
|
11070
|
-
const { tableName, schema: schema3, columns } = st;
|
|
11196
|
+
const { tableName, schema: schema3, columns, compositePKs } = st;
|
|
11071
11197
|
let statement = "";
|
|
11072
11198
|
const name = schema3 ? `"${schema3}"."${tableName}"` : `"${tableName}"`;
|
|
11073
11199
|
statement += `CREATE TABLE IF NOT EXISTS ${name} (
|
|
@@ -11077,13 +11203,19 @@ var PgCreateTableConvertor = class extends Convertor {
|
|
|
11077
11203
|
const primaryKeyStatement = column4.primaryKey ? "PRIMARY KEY" : "";
|
|
11078
11204
|
const notNullStatement = column4.notNull ? "NOT NULL" : "";
|
|
11079
11205
|
const defaultStatement = column4.default !== void 0 ? `DEFAULT ${column4.default}` : "";
|
|
11080
|
-
const type = isPgNativeType(column4.type) ? column4.type :
|
|
11206
|
+
const type = isPgNativeType(column4.type) ? column4.type : `${column4.type}`;
|
|
11081
11207
|
statement += " " + `"${column4.name}" ${type} ${primaryKeyStatement} ${defaultStatement} ${notNullStatement}`.replace(/ +/g, " ").trim();
|
|
11082
11208
|
statement += (i === columns.length - 1 ? "" : ",") + "\n";
|
|
11083
11209
|
}
|
|
11084
11210
|
statement += `);`;
|
|
11085
11211
|
statement += `
|
|
11086
11212
|
`;
|
|
11213
|
+
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
11214
|
+
const compositePK4 = PgSquasher.unsquashPK(compositePKs[0]);
|
|
11215
|
+
statement += `ALTER TABLE ${name} ADD CONSTRAINT "${st.compositePkName}" PRIMARY KEY("${compositePK4.columns.join('","')}");`;
|
|
11216
|
+
statement += `
|
|
11217
|
+
`;
|
|
11218
|
+
}
|
|
11087
11219
|
return statement;
|
|
11088
11220
|
}
|
|
11089
11221
|
};
|
|
@@ -11092,20 +11224,27 @@ var MySqlCreateTableConvertor = class extends Convertor {
|
|
|
11092
11224
|
return statement.type === "create_table" && dialect3 === "mysql";
|
|
11093
11225
|
}
|
|
11094
11226
|
convert(st) {
|
|
11095
|
-
const { tableName, columns, schema: schema3 } = st;
|
|
11227
|
+
const { tableName, columns, schema: schema3, compositePKs } = st;
|
|
11096
11228
|
let statement = "";
|
|
11097
11229
|
const tName = schema3 ? `\`${schema3}\`.\`${tableName}\`` : `\`${tableName}\``;
|
|
11098
11230
|
statement += `CREATE TABLE ${tName} (
|
|
11099
11231
|
`;
|
|
11100
11232
|
for (let i = 0; i < columns.length; i++) {
|
|
11101
11233
|
const column4 = columns[i];
|
|
11102
|
-
const primaryKeyStatement = column4.primaryKey ? "PRIMARY KEY" : "";
|
|
11103
|
-
const notNullStatement = column4.notNull ? "NOT NULL" : "";
|
|
11104
|
-
const defaultStatement = column4.default !== void 0 ? `DEFAULT ${column4.default}` : "";
|
|
11105
|
-
const onUpdateStatement = column4.onUpdate ? `ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
11106
|
-
const autoincrementStatement = column4.autoincrement ? "AUTO_INCREMENT" : "";
|
|
11107
|
-
statement += " " + `\`${column4.name}\` ${column4.type}
|
|
11108
|
-
statement +=
|
|
11234
|
+
const primaryKeyStatement = column4.primaryKey ? " PRIMARY KEY" : "";
|
|
11235
|
+
const notNullStatement = column4.notNull ? " NOT NULL" : "";
|
|
11236
|
+
const defaultStatement = column4.default !== void 0 ? ` DEFAULT ${column4.default}` : "";
|
|
11237
|
+
const onUpdateStatement = column4.onUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
11238
|
+
const autoincrementStatement = column4.autoincrement ? " AUTO_INCREMENT" : "";
|
|
11239
|
+
statement += " " + `\`${column4.name}\` ${column4.type}${autoincrementStatement}${primaryKeyStatement}${notNullStatement}${defaultStatement}${onUpdateStatement}`.trim();
|
|
11240
|
+
statement += i === columns.length - 1 ? "" : ",\n";
|
|
11241
|
+
}
|
|
11242
|
+
if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
|
|
11243
|
+
statement += ",\n";
|
|
11244
|
+
const compositePK4 = MySqlSquasher.unsquashPK(compositePKs[0]);
|
|
11245
|
+
statement += ` PRIMARY KEY(\`${compositePK4.columns.join("`,`")}\`)`;
|
|
11246
|
+
statement += `
|
|
11247
|
+
`;
|
|
11109
11248
|
}
|
|
11110
11249
|
statement += `);`;
|
|
11111
11250
|
statement += `
|
|
@@ -11200,7 +11339,7 @@ var DropTableConvertor = class extends Convertor {
|
|
|
11200
11339
|
}
|
|
11201
11340
|
convert(statement) {
|
|
11202
11341
|
const { tableName } = statement;
|
|
11203
|
-
return `DROP TABLE
|
|
11342
|
+
return `DROP TABLE \`${tableName}\`;`;
|
|
11204
11343
|
}
|
|
11205
11344
|
};
|
|
11206
11345
|
var PgRenameTableConvertor = class extends Convertor {
|
|
@@ -11308,12 +11447,13 @@ var MySqlAlterTableAddColumnConvertor = class extends Convertor {
|
|
|
11308
11447
|
}
|
|
11309
11448
|
convert(statement) {
|
|
11310
11449
|
const { tableName, column: column4 } = statement;
|
|
11311
|
-
const { name, type, notNull, primaryKey, autoincrement } = column4;
|
|
11312
|
-
const defaultStatement = `${column4.default !== void 0 ? `DEFAULT ${column4.default}` : ""}`;
|
|
11313
|
-
const notNullStatement = `${notNull ? "NOT NULL" : ""}`;
|
|
11314
|
-
const primaryKeyStatement = `${primaryKey ? "PRIMARY KEY" : ""}`;
|
|
11315
|
-
const autoincrementStatement = `${autoincrement ? "AUTO_INCREMENT" : ""}`;
|
|
11316
|
-
|
|
11450
|
+
const { name, type, notNull, primaryKey, autoincrement, onUpdate } = column4;
|
|
11451
|
+
const defaultStatement = `${column4.default !== void 0 ? ` DEFAULT ${column4.default}` : ""}`;
|
|
11452
|
+
const notNullStatement = `${notNull ? " NOT NULL" : ""}`;
|
|
11453
|
+
const primaryKeyStatement = `${primaryKey ? " PRIMARY KEY" : ""}`;
|
|
11454
|
+
const autoincrementStatement = `${autoincrement ? " AUTO_INCREMENT" : ""}`;
|
|
11455
|
+
const onUpdateStatement = `${onUpdate ? " ON UPDATE CURRENT_TIMESTAMP" : ""}`;
|
|
11456
|
+
return `ALTER TABLE ${tableName} ADD \`${name}\` ${type}${primaryKeyStatement}${autoincrementStatement}${defaultStatement}${notNullStatement}${onUpdateStatement};`;
|
|
11317
11457
|
}
|
|
11318
11458
|
};
|
|
11319
11459
|
var SQLiteAlterTableAddColumnConvertor = class extends Convertor {
|
|
@@ -11388,27 +11528,25 @@ var PgAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
|
|
|
11388
11528
|
return `ALTER TABLE ${tableName} ALTER COLUMN "${columnName}" DROP DEFAULT;`;
|
|
11389
11529
|
}
|
|
11390
11530
|
};
|
|
11391
|
-
var
|
|
11531
|
+
var MySqlAlterTableAddPk = class extends Convertor {
|
|
11392
11532
|
can(statement, dialect3) {
|
|
11393
|
-
return statement.type === "
|
|
11533
|
+
return statement.type === "alter_table_alter_column_set_pk" && dialect3 === "mysql";
|
|
11394
11534
|
}
|
|
11395
11535
|
convert(statement) {
|
|
11396
|
-
|
|
11397
|
-
return `ALTER TABLE ${tableName} ALTER COLUMN \`${columnName}\` SET DEFAULT ${statement.newDefaultValue};`;
|
|
11536
|
+
return `ALTER TABLE \`${statement.tableName}\` ADD PRIMARY KEY (\`${statement.columnName}\`);`;
|
|
11398
11537
|
}
|
|
11399
11538
|
};
|
|
11400
|
-
var
|
|
11539
|
+
var MySqlAlterTableDropPk = class extends Convertor {
|
|
11401
11540
|
can(statement, dialect3) {
|
|
11402
|
-
return statement.type === "
|
|
11541
|
+
return statement.type === "alter_table_alter_column_drop_pk" && dialect3 === "mysql";
|
|
11403
11542
|
}
|
|
11404
11543
|
convert(statement) {
|
|
11405
|
-
|
|
11406
|
-
return `ALTER TABLE ${tableName} ALTER COLUMN \`${columnName}\` DROP DEFAULT;`;
|
|
11544
|
+
return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY`;
|
|
11407
11545
|
}
|
|
11408
11546
|
};
|
|
11409
11547
|
var MySqlModifyColumn = class extends Convertor {
|
|
11410
11548
|
can(statement, dialect3) {
|
|
11411
|
-
return (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_on_update" || statement.type === "alter_table_alter_column_set_on_update" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_autoincrement") && dialect3 === "mysql";
|
|
11549
|
+
return (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_on_update" || statement.type === "alter_table_alter_column_set_on_update" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default") && dialect3 === "mysql";
|
|
11412
11550
|
}
|
|
11413
11551
|
convert(statement) {
|
|
11414
11552
|
const { tableName, columnName } = statement;
|
|
@@ -11417,6 +11555,7 @@ var MySqlModifyColumn = class extends Convertor {
|
|
|
11417
11555
|
let columnNotNull = "";
|
|
11418
11556
|
let columnOnUpdate = "";
|
|
11419
11557
|
let columnAutoincrement = "";
|
|
11558
|
+
let primaryKey = statement.columnPk ? " PRIMARY KEY" : "";
|
|
11420
11559
|
if (statement.type === "alter_table_alter_column_drop_notnull") {
|
|
11421
11560
|
columnType = ` ${statement.newDataType}`;
|
|
11422
11561
|
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
|
@@ -11446,19 +11585,31 @@ var MySqlModifyColumn = class extends Convertor {
|
|
|
11446
11585
|
columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
11447
11586
|
columnType = ` ${statement.newDataType}`;
|
|
11448
11587
|
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
|
11449
|
-
columnAutoincrement = "AUTO_INCREMENT";
|
|
11588
|
+
columnAutoincrement = " AUTO_INCREMENT";
|
|
11450
11589
|
} else if (statement.type === "alter_table_alter_column_drop_autoincrement") {
|
|
11451
11590
|
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
|
11452
11591
|
columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
11453
11592
|
columnType = ` ${statement.newDataType}`;
|
|
11454
11593
|
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
|
11455
11594
|
columnAutoincrement = "";
|
|
11595
|
+
} else if (statement.type === "alter_table_alter_column_set_default") {
|
|
11596
|
+
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
|
11597
|
+
columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
11598
|
+
columnType = ` ${statement.newDataType}`;
|
|
11599
|
+
columnDefault = ` DEFAULT ${statement.newDefaultValue}`;
|
|
11600
|
+
columnAutoincrement = statement.columnAutoIncrement ? " AUTO_INCREMENT" : "";
|
|
11601
|
+
} else if (statement.type === "alter_table_alter_column_drop_default") {
|
|
11602
|
+
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
|
11603
|
+
columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
11604
|
+
columnType = ` ${statement.newDataType}`;
|
|
11605
|
+
columnDefault = "";
|
|
11606
|
+
columnAutoincrement = statement.columnAutoIncrement ? " AUTO_INCREMENT" : "";
|
|
11456
11607
|
} else {
|
|
11457
11608
|
columnType = ` ${statement.newDataType}`;
|
|
11458
11609
|
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
|
11459
11610
|
columnOnUpdate = columnOnUpdate = statement.columnOnUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
|
|
11460
11611
|
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
|
11461
|
-
columnAutoincrement = statement.columnAutoIncrement ? "AUTO_INCREMENT" : "";
|
|
11612
|
+
columnAutoincrement = statement.columnAutoIncrement ? " AUTO_INCREMENT" : "";
|
|
11462
11613
|
}
|
|
11463
11614
|
columnDefault = columnDefault instanceof Date ? columnDefault.toISOString() : columnDefault;
|
|
11464
11615
|
return `ALTER TABLE ${tableName} MODIFY COLUMN \`${columnName}\`${columnType}${columnAutoincrement}${columnNotNull}${columnDefault}${columnOnUpdate};`;
|
|
@@ -11479,6 +11630,67 @@ var SqliteAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
|
|
|
11479
11630
|
*/`;
|
|
11480
11631
|
}
|
|
11481
11632
|
};
|
|
11633
|
+
var PgAlterTableCreateCompositePrimaryKeyConvertor = class extends Convertor {
|
|
11634
|
+
can(statement, dialect3) {
|
|
11635
|
+
return statement.type === "create_composite_pk" && dialect3 === "pg";
|
|
11636
|
+
}
|
|
11637
|
+
convert(statement) {
|
|
11638
|
+
const { name, columns } = PgSquasher.unsquashPK(statement.data);
|
|
11639
|
+
return `ALTER TABLE "${statement.tableName}" ADD CONSTRAINT "${statement.constraintName}" PRIMARY KEY("${columns.join('","')}");`;
|
|
11640
|
+
}
|
|
11641
|
+
};
|
|
11642
|
+
var PgAlterTableDeleteCompositePrimaryKeyConvertor = class extends Convertor {
|
|
11643
|
+
can(statement, dialect3) {
|
|
11644
|
+
return statement.type === "delete_composite_pk" && dialect3 === "pg";
|
|
11645
|
+
}
|
|
11646
|
+
convert(statement) {
|
|
11647
|
+
const { name, columns } = PgSquasher.unsquashPK(statement.data);
|
|
11648
|
+
return `ALTER TABLE "${statement.tableName}" DROP CONSTRAINT "${statement.constraintName}";`;
|
|
11649
|
+
}
|
|
11650
|
+
};
|
|
11651
|
+
var PgAlterTableAlterCompositePrimaryKeyConvertor = class extends Convertor {
|
|
11652
|
+
can(statement, dialect3) {
|
|
11653
|
+
return statement.type === "alter_composite_pk" && dialect3 === "pg";
|
|
11654
|
+
}
|
|
11655
|
+
convert(statement) {
|
|
11656
|
+
const { name, columns } = PgSquasher.unsquashPK(statement.old);
|
|
11657
|
+
const { name: newName, columns: newColumns } = PgSquasher.unsquashPK(
|
|
11658
|
+
statement.new
|
|
11659
|
+
);
|
|
11660
|
+
return `ALTER TABLE "${statement.tableName}" DROP CONSTRAINT ${statement.oldConstraintName};
|
|
11661
|
+
ALTER TABLE "${statement.tableName}" ADD CONSTRAINT ${statement.newConstraintName} PRIMARY KEY(${newColumns.join(",")});`;
|
|
11662
|
+
}
|
|
11663
|
+
};
|
|
11664
|
+
var MySqlAlterTableCreateCompositePrimaryKeyConvertor = class extends Convertor {
|
|
11665
|
+
can(statement, dialect3) {
|
|
11666
|
+
return statement.type === "create_composite_pk" && dialect3 === "mysql";
|
|
11667
|
+
}
|
|
11668
|
+
convert(statement) {
|
|
11669
|
+
const { name, columns } = MySqlSquasher.unsquashPK(statement.data);
|
|
11670
|
+
return `ALTER TABLE \`${statement.tableName}\` ADD PRIMARY KEY(\`${columns.join("`,`")}\`);`;
|
|
11671
|
+
}
|
|
11672
|
+
};
|
|
11673
|
+
var MySqlAlterTableDeleteCompositePrimaryKeyConvertor = class extends Convertor {
|
|
11674
|
+
can(statement, dialect3) {
|
|
11675
|
+
return statement.type === "delete_composite_pk" && dialect3 === "mysql";
|
|
11676
|
+
}
|
|
11677
|
+
convert(statement) {
|
|
11678
|
+
const { name, columns } = MySqlSquasher.unsquashPK(statement.data);
|
|
11679
|
+
return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY;`;
|
|
11680
|
+
}
|
|
11681
|
+
};
|
|
11682
|
+
var MySqlAlterTableAlterCompositePrimaryKeyConvertor = class extends Convertor {
|
|
11683
|
+
can(statement, dialect3) {
|
|
11684
|
+
return statement.type === "alter_composite_pk" && dialect3 === "mysql";
|
|
11685
|
+
}
|
|
11686
|
+
convert(statement) {
|
|
11687
|
+
const { name, columns } = MySqlSquasher.unsquashPK(statement.old);
|
|
11688
|
+
const { name: newName, columns: newColumns } = MySqlSquasher.unsquashPK(
|
|
11689
|
+
statement.new
|
|
11690
|
+
);
|
|
11691
|
+
return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY, ADD PRIMARY KEY(\`${newColumns.join("`,`")}\`);`;
|
|
11692
|
+
}
|
|
11693
|
+
};
|
|
11482
11694
|
var SqliteAlterTableCreateCompositePrimaryKeyConvertor = class extends Convertor {
|
|
11483
11695
|
can(statement, dialect3) {
|
|
11484
11696
|
return statement.type === "create_composite_pk" && dialect3 === "sqlite";
|
|
@@ -11956,8 +12168,6 @@ convertors.push(new PgAlterTableAlterColumnDropNotNullConvertor());
|
|
|
11956
12168
|
convertors.push(new PgAlterTableAlterColumnSetDefaultConvertor());
|
|
11957
12169
|
convertors.push(new PgAlterTableAlterColumnDropDefaultConvertor());
|
|
11958
12170
|
convertors.push(new MySqlModifyColumn());
|
|
11959
|
-
convertors.push(new MySqlAlterTableAlterColumnSetDefaultConvertor());
|
|
11960
|
-
convertors.push(new MySqlAlterTableAlterColumnDropDefaultConvertor());
|
|
11961
12171
|
convertors.push(new PgCreateForeignKeyConvertor());
|
|
11962
12172
|
convertors.push(new MySqlCreateForeignKeyConvertor());
|
|
11963
12173
|
convertors.push(new PgAlterForeignKeyConvertor());
|
|
@@ -11985,6 +12195,14 @@ convertors.push(new SqliteAlterTableAlterColumnDropDefaultConvertor());
|
|
|
11985
12195
|
convertors.push(new SqliteAlterTableCreateCompositePrimaryKeyConvertor());
|
|
11986
12196
|
convertors.push(new SqliteAlterTableDeleteCompositePrimaryKeyConvertor());
|
|
11987
12197
|
convertors.push(new SqliteAlterTableAlterCompositePrimaryKeyConvertor());
|
|
12198
|
+
convertors.push(new PgAlterTableCreateCompositePrimaryKeyConvertor());
|
|
12199
|
+
convertors.push(new PgAlterTableDeleteCompositePrimaryKeyConvertor());
|
|
12200
|
+
convertors.push(new PgAlterTableAlterCompositePrimaryKeyConvertor());
|
|
12201
|
+
convertors.push(new MySqlAlterTableDeleteCompositePrimaryKeyConvertor());
|
|
12202
|
+
convertors.push(new MySqlAlterTableDropPk());
|
|
12203
|
+
convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
|
|
12204
|
+
convertors.push(new MySqlAlterTableAddPk());
|
|
12205
|
+
convertors.push(new MySqlAlterTableAlterCompositePrimaryKeyConvertor());
|
|
11988
12206
|
var fromJson = (statements, dialect3) => {
|
|
11989
12207
|
const result = statements.map((statement) => {
|
|
11990
12208
|
const filtered = convertors.filter((it) => {
|
|
@@ -11993,10 +12211,10 @@ var fromJson = (statements, dialect3) => {
|
|
|
11993
12211
|
const convertor = filtered.length === 1 ? filtered[0] : void 0;
|
|
11994
12212
|
if (!convertor) {
|
|
11995
12213
|
console.log("no convertor:", statement.type, dialect3);
|
|
11996
|
-
return "
|
|
12214
|
+
return "";
|
|
11997
12215
|
}
|
|
11998
12216
|
return convertor.convert(statement);
|
|
11999
|
-
});
|
|
12217
|
+
}).filter((it) => it !== "");
|
|
12000
12218
|
return result;
|
|
12001
12219
|
};
|
|
12002
12220
|
https:
|
|
@@ -12025,13 +12243,30 @@ drop type __venum;
|
|
|
12025
12243
|
`;
|
|
12026
12244
|
|
|
12027
12245
|
// src/jsonStatements.ts
|
|
12028
|
-
var
|
|
12029
|
-
const { name, schema: schema3, columns } = table4;
|
|
12246
|
+
var preparePgCreateTableJson = (table4, json2) => {
|
|
12247
|
+
const { name, schema: schema3, columns, compositePrimaryKeys } = table4;
|
|
12248
|
+
return {
|
|
12249
|
+
type: "create_table",
|
|
12250
|
+
tableName: name,
|
|
12251
|
+
schema: schema3,
|
|
12252
|
+
columns: Object.values(columns),
|
|
12253
|
+
compositePKs: Object.values(compositePrimaryKeys),
|
|
12254
|
+
compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${name}_${PgSquasher.unsquashPK(
|
|
12255
|
+
Object.values(compositePrimaryKeys)[0]
|
|
12256
|
+
).columns.join("_")}`].name : ""
|
|
12257
|
+
};
|
|
12258
|
+
};
|
|
12259
|
+
var prepareMySqlCreateTableJson = (table4, json2) => {
|
|
12260
|
+
const { name, schema: schema3, columns, compositePrimaryKeys } = table4;
|
|
12030
12261
|
return {
|
|
12031
12262
|
type: "create_table",
|
|
12032
12263
|
tableName: name,
|
|
12033
12264
|
schema: schema3,
|
|
12034
|
-
columns: Object.values(columns)
|
|
12265
|
+
columns: Object.values(columns),
|
|
12266
|
+
compositePKs: Object.values(compositePrimaryKeys),
|
|
12267
|
+
compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${name}_${MySqlSquasher.unsquashPK(
|
|
12268
|
+
Object.values(compositePrimaryKeys)[0]
|
|
12269
|
+
).columns.join("_")}`].name : ""
|
|
12035
12270
|
};
|
|
12036
12271
|
};
|
|
12037
12272
|
var prepareSQLiteCreateTable = (table4) => {
|
|
@@ -12170,7 +12405,7 @@ var _prepareSQLiteAddColumns = (tableName, columns, referenceData) => {
|
|
|
12170
12405
|
});
|
|
12171
12406
|
};
|
|
12172
12407
|
var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
|
|
12173
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
12408
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
12174
12409
|
let statements = [];
|
|
12175
12410
|
for (const column4 of columns) {
|
|
12176
12411
|
const columnName = typeof column4.name !== "string" ? column4.name.new : column4.name;
|
|
@@ -12179,97 +12414,134 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
|
|
|
12179
12414
|
const columnOnUpdate = json2.tables[tableName].columns[columnName].onUpdate;
|
|
12180
12415
|
const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
|
|
12181
12416
|
const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
|
|
12182
|
-
|
|
12417
|
+
const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
|
|
12418
|
+
if (((_a = column4.autoincrement) == null ? void 0 : _a.type) === "added") {
|
|
12183
12419
|
statements.push({
|
|
12184
|
-
type: "
|
|
12420
|
+
type: "alter_table_alter_column_set_autoincrement",
|
|
12185
12421
|
tableName,
|
|
12186
|
-
|
|
12187
|
-
|
|
12188
|
-
|
|
12422
|
+
columnName,
|
|
12423
|
+
schema: schema3,
|
|
12424
|
+
newDataType: columnType,
|
|
12425
|
+
columnDefault,
|
|
12426
|
+
columnOnUpdate,
|
|
12427
|
+
columnNotNull,
|
|
12428
|
+
columnAutoIncrement,
|
|
12429
|
+
columnPk
|
|
12189
12430
|
});
|
|
12190
12431
|
}
|
|
12191
|
-
if (((
|
|
12432
|
+
if (((_b = column4.autoincrement) == null ? void 0 : _b.type) === "changed") {
|
|
12433
|
+
const type = column4.autoincrement.new ? "alter_table_alter_column_set_autoincrement" : "alter_table_alter_column_drop_autoincrement";
|
|
12192
12434
|
statements.push({
|
|
12193
|
-
type
|
|
12435
|
+
type,
|
|
12194
12436
|
tableName,
|
|
12195
12437
|
columnName,
|
|
12196
|
-
newDataType: column4.type.new,
|
|
12197
12438
|
schema: schema3,
|
|
12439
|
+
newDataType: columnType,
|
|
12198
12440
|
columnDefault,
|
|
12199
12441
|
columnOnUpdate,
|
|
12200
12442
|
columnNotNull,
|
|
12201
|
-
columnAutoIncrement
|
|
12443
|
+
columnAutoIncrement,
|
|
12444
|
+
columnPk
|
|
12202
12445
|
});
|
|
12203
12446
|
}
|
|
12204
|
-
if (((
|
|
12447
|
+
if (((_c = column4.autoincrement) == null ? void 0 : _c.type) === "deleted") {
|
|
12205
12448
|
statements.push({
|
|
12206
|
-
type: "
|
|
12449
|
+
type: "alter_table_alter_column_drop_autoincrement",
|
|
12207
12450
|
tableName,
|
|
12208
12451
|
columnName,
|
|
12209
|
-
|
|
12210
|
-
|
|
12452
|
+
schema: schema3,
|
|
12453
|
+
newDataType: columnType,
|
|
12454
|
+
columnDefault,
|
|
12455
|
+
columnOnUpdate,
|
|
12456
|
+
columnNotNull,
|
|
12457
|
+
columnAutoIncrement,
|
|
12458
|
+
columnPk
|
|
12211
12459
|
});
|
|
12212
12460
|
}
|
|
12213
|
-
|
|
12461
|
+
}
|
|
12462
|
+
for (const column4 of columns) {
|
|
12463
|
+
const columnName = typeof column4.name !== "string" ? column4.name.new : column4.name;
|
|
12464
|
+
const columnType = json2.tables[tableName].columns[columnName].type;
|
|
12465
|
+
const columnDefault = json2.tables[tableName].columns[columnName].default;
|
|
12466
|
+
const columnOnUpdate = json2.tables[tableName].columns[columnName].onUpdate;
|
|
12467
|
+
const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
|
|
12468
|
+
const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
|
|
12469
|
+
const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
|
|
12470
|
+
if (typeof column4.name !== "string") {
|
|
12214
12471
|
statements.push({
|
|
12215
|
-
type: "
|
|
12472
|
+
type: "alter_table_rename_column",
|
|
12216
12473
|
tableName,
|
|
12217
|
-
|
|
12218
|
-
|
|
12474
|
+
oldColumnName: column4.name.old,
|
|
12475
|
+
newColumnName: column4.name.new,
|
|
12219
12476
|
schema: schema3
|
|
12220
12477
|
});
|
|
12221
12478
|
}
|
|
12222
|
-
if (((_d = column4.
|
|
12479
|
+
if (((_d = column4.type) == null ? void 0 : _d.type) === "changed") {
|
|
12223
12480
|
statements.push({
|
|
12224
|
-
type: "
|
|
12481
|
+
type: "alter_table_alter_column_set_type",
|
|
12225
12482
|
tableName,
|
|
12226
12483
|
columnName,
|
|
12227
|
-
|
|
12484
|
+
newDataType: column4.type.new,
|
|
12485
|
+
schema: schema3,
|
|
12486
|
+
columnDefault,
|
|
12487
|
+
columnOnUpdate,
|
|
12488
|
+
columnNotNull,
|
|
12489
|
+
columnAutoIncrement,
|
|
12490
|
+
columnPk
|
|
12228
12491
|
});
|
|
12229
12492
|
}
|
|
12230
|
-
if (((_e = column4.
|
|
12493
|
+
if (((_e = column4.primaryKey) == null ? void 0 : _e.type) === "deleted" || ((_f = column4.primaryKey) == null ? void 0 : _f.type) === "changed" && !column4.primaryKey.new) {
|
|
12231
12494
|
statements.push({
|
|
12232
|
-
type: "
|
|
12495
|
+
type: "alter_table_alter_column_drop_pk",
|
|
12496
|
+
tableName,
|
|
12497
|
+
columnName
|
|
12498
|
+
});
|
|
12499
|
+
}
|
|
12500
|
+
if (((_g = column4.default) == null ? void 0 : _g.type) === "added") {
|
|
12501
|
+
statements.push({
|
|
12502
|
+
type: "alter_table_alter_column_set_default",
|
|
12233
12503
|
tableName,
|
|
12234
12504
|
columnName,
|
|
12505
|
+
newDefaultValue: column4.default.value,
|
|
12235
12506
|
schema: schema3,
|
|
12236
|
-
newDataType: columnType,
|
|
12237
|
-
columnDefault,
|
|
12238
12507
|
columnOnUpdate,
|
|
12239
12508
|
columnNotNull,
|
|
12240
|
-
columnAutoIncrement
|
|
12509
|
+
columnAutoIncrement,
|
|
12510
|
+
newDataType: columnType,
|
|
12511
|
+
columnPk
|
|
12241
12512
|
});
|
|
12242
12513
|
}
|
|
12243
|
-
if (((
|
|
12244
|
-
const type = column4.notNull.new ? "alter_table_alter_column_set_notnull" : "alter_table_alter_column_drop_notnull";
|
|
12514
|
+
if (((_h = column4.default) == null ? void 0 : _h.type) === "changed") {
|
|
12245
12515
|
statements.push({
|
|
12246
|
-
type,
|
|
12516
|
+
type: "alter_table_alter_column_set_default",
|
|
12247
12517
|
tableName,
|
|
12248
12518
|
columnName,
|
|
12519
|
+
newDefaultValue: column4.default.new,
|
|
12249
12520
|
schema: schema3,
|
|
12250
|
-
newDataType: columnType,
|
|
12251
|
-
columnDefault,
|
|
12252
12521
|
columnOnUpdate,
|
|
12253
12522
|
columnNotNull,
|
|
12254
|
-
columnAutoIncrement
|
|
12523
|
+
columnAutoIncrement,
|
|
12524
|
+
newDataType: columnType,
|
|
12525
|
+
columnPk
|
|
12255
12526
|
});
|
|
12256
12527
|
}
|
|
12257
|
-
if (((
|
|
12528
|
+
if (((_i = column4.default) == null ? void 0 : _i.type) === "deleted") {
|
|
12258
12529
|
statements.push({
|
|
12259
|
-
type: "
|
|
12530
|
+
type: "alter_table_alter_column_drop_default",
|
|
12260
12531
|
tableName,
|
|
12261
12532
|
columnName,
|
|
12262
12533
|
schema: schema3,
|
|
12263
|
-
newDataType: columnType,
|
|
12264
12534
|
columnDefault,
|
|
12265
12535
|
columnOnUpdate,
|
|
12266
12536
|
columnNotNull,
|
|
12267
|
-
columnAutoIncrement
|
|
12537
|
+
columnAutoIncrement,
|
|
12538
|
+
newDataType: columnType,
|
|
12539
|
+
columnPk
|
|
12268
12540
|
});
|
|
12269
12541
|
}
|
|
12270
|
-
if (((
|
|
12542
|
+
if (((_j = column4.notNull) == null ? void 0 : _j.type) === "added") {
|
|
12271
12543
|
statements.push({
|
|
12272
|
-
type: "
|
|
12544
|
+
type: "alter_table_alter_column_set_notnull",
|
|
12273
12545
|
tableName,
|
|
12274
12546
|
columnName,
|
|
12275
12547
|
schema: schema3,
|
|
@@ -12277,11 +12549,12 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
|
|
|
12277
12549
|
columnDefault,
|
|
12278
12550
|
columnOnUpdate,
|
|
12279
12551
|
columnNotNull,
|
|
12280
|
-
columnAutoIncrement
|
|
12552
|
+
columnAutoIncrement,
|
|
12553
|
+
columnPk
|
|
12281
12554
|
});
|
|
12282
12555
|
}
|
|
12283
|
-
if (((
|
|
12284
|
-
const type = column4.
|
|
12556
|
+
if (((_k = column4.notNull) == null ? void 0 : _k.type) === "changed") {
|
|
12557
|
+
const type = column4.notNull.new ? "alter_table_alter_column_set_notnull" : "alter_table_alter_column_drop_notnull";
|
|
12285
12558
|
statements.push({
|
|
12286
12559
|
type,
|
|
12287
12560
|
tableName,
|
|
@@ -12291,12 +12564,13 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
|
|
|
12291
12564
|
columnDefault,
|
|
12292
12565
|
columnOnUpdate,
|
|
12293
12566
|
columnNotNull,
|
|
12294
|
-
columnAutoIncrement
|
|
12567
|
+
columnAutoIncrement,
|
|
12568
|
+
columnPk
|
|
12295
12569
|
});
|
|
12296
12570
|
}
|
|
12297
|
-
if (((
|
|
12571
|
+
if (((_l = column4.notNull) == null ? void 0 : _l.type) === "deleted") {
|
|
12298
12572
|
statements.push({
|
|
12299
|
-
type: "
|
|
12573
|
+
type: "alter_table_alter_column_drop_notnull",
|
|
12300
12574
|
tableName,
|
|
12301
12575
|
columnName,
|
|
12302
12576
|
schema: schema3,
|
|
@@ -12304,10 +12578,23 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
|
|
|
12304
12578
|
columnDefault,
|
|
12305
12579
|
columnOnUpdate,
|
|
12306
12580
|
columnNotNull,
|
|
12307
|
-
columnAutoIncrement
|
|
12581
|
+
columnAutoIncrement,
|
|
12582
|
+
columnPk
|
|
12308
12583
|
});
|
|
12309
12584
|
}
|
|
12310
|
-
if (((
|
|
12585
|
+
if (((_m = column4.primaryKey) == null ? void 0 : _m.type) === "added" || ((_n = column4.primaryKey) == null ? void 0 : _n.type) === "changed" && column4.primaryKey.new) {
|
|
12586
|
+
const wasAutoincrement = statements.filter(
|
|
12587
|
+
(it) => it.type === "alter_table_alter_column_set_autoincrement"
|
|
12588
|
+
);
|
|
12589
|
+
if (wasAutoincrement.length === 0) {
|
|
12590
|
+
statements.push({
|
|
12591
|
+
type: "alter_table_alter_column_set_pk",
|
|
12592
|
+
tableName,
|
|
12593
|
+
columnName
|
|
12594
|
+
});
|
|
12595
|
+
}
|
|
12596
|
+
}
|
|
12597
|
+
if (((_o = column4.onUpdate) == null ? void 0 : _o.type) === "added") {
|
|
12311
12598
|
statements.push({
|
|
12312
12599
|
type: "alter_table_alter_column_set_on_update",
|
|
12313
12600
|
tableName,
|
|
@@ -12317,10 +12604,11 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
|
|
|
12317
12604
|
columnDefault,
|
|
12318
12605
|
columnOnUpdate,
|
|
12319
12606
|
columnNotNull,
|
|
12320
|
-
columnAutoIncrement
|
|
12607
|
+
columnAutoIncrement,
|
|
12608
|
+
columnPk
|
|
12321
12609
|
});
|
|
12322
12610
|
}
|
|
12323
|
-
if (((
|
|
12611
|
+
if (((_p = column4.onUpdate) == null ? void 0 : _p.type) === "deleted") {
|
|
12324
12612
|
statements.push({
|
|
12325
12613
|
type: "alter_table_alter_column_drop_on_update",
|
|
12326
12614
|
tableName,
|
|
@@ -12330,7 +12618,8 @@ var _prepareAlterColumns = (tableName, schema3, columns, json2) => {
|
|
|
12330
12618
|
columnDefault,
|
|
12331
12619
|
columnOnUpdate,
|
|
12332
12620
|
columnNotNull,
|
|
12333
|
-
columnAutoIncrement
|
|
12621
|
+
columnAutoIncrement,
|
|
12622
|
+
columnPk
|
|
12334
12623
|
});
|
|
12335
12624
|
}
|
|
12336
12625
|
}
|
|
@@ -12415,6 +12704,70 @@ var prepareAlterCompositePrimaryKeySqlite = (tableName, pks) => {
|
|
|
12415
12704
|
};
|
|
12416
12705
|
});
|
|
12417
12706
|
};
|
|
12707
|
+
var prepareAddCompositePrimaryKeyPg = (tableName, pks, json2) => {
|
|
12708
|
+
return Object.values(pks).map((it) => {
|
|
12709
|
+
return {
|
|
12710
|
+
type: "create_composite_pk",
|
|
12711
|
+
tableName,
|
|
12712
|
+
data: it,
|
|
12713
|
+
constraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${PgSquasher.unsquashPK(it).columns.join("_")}`].name
|
|
12714
|
+
};
|
|
12715
|
+
});
|
|
12716
|
+
};
|
|
12717
|
+
var prepareDeleteCompositePrimaryKeyPg = (tableName, pks, json1) => {
|
|
12718
|
+
return Object.values(pks).map((it) => {
|
|
12719
|
+
return {
|
|
12720
|
+
type: "delete_composite_pk",
|
|
12721
|
+
tableName,
|
|
12722
|
+
data: it,
|
|
12723
|
+
constraintName: json1.tables[tableName].compositePrimaryKeys[`${tableName}_${PgSquasher.unsquashPK(it).columns.join("_")}`].name
|
|
12724
|
+
};
|
|
12725
|
+
});
|
|
12726
|
+
};
|
|
12727
|
+
var prepareAlterCompositePrimaryKeyPg = (tableName, pks, json1, json2) => {
|
|
12728
|
+
return Object.values(pks).map((it) => {
|
|
12729
|
+
return {
|
|
12730
|
+
type: "alter_composite_pk",
|
|
12731
|
+
tableName,
|
|
12732
|
+
old: it.__old,
|
|
12733
|
+
new: it.__new,
|
|
12734
|
+
oldConstraintName: json1.tables[tableName].compositePrimaryKeys[`${tableName}_${PgSquasher.unsquashPK(it.__old).columns.join("_")}`].name,
|
|
12735
|
+
newConstraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${PgSquasher.unsquashPK(it.__new).columns.join("_")}`].name
|
|
12736
|
+
};
|
|
12737
|
+
});
|
|
12738
|
+
};
|
|
12739
|
+
var prepareAddCompositePrimaryKeyMySql = (tableName, pks, json2) => {
|
|
12740
|
+
return Object.values(pks).map((it) => {
|
|
12741
|
+
return {
|
|
12742
|
+
type: "create_composite_pk",
|
|
12743
|
+
tableName,
|
|
12744
|
+
data: it,
|
|
12745
|
+
constraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${MySqlSquasher.unsquashPK(it).columns.join("_")}`].name
|
|
12746
|
+
};
|
|
12747
|
+
});
|
|
12748
|
+
};
|
|
12749
|
+
var prepareDeleteCompositePrimaryKeyMySql = (tableName, pks, json1) => {
|
|
12750
|
+
return Object.values(pks).map((it) => {
|
|
12751
|
+
return {
|
|
12752
|
+
type: "delete_composite_pk",
|
|
12753
|
+
tableName,
|
|
12754
|
+
data: it,
|
|
12755
|
+
constraintName: json1.tables[tableName].compositePrimaryKeys[`${tableName}_${MySqlSquasher.unsquashPK(it).columns.join("_")}`].name
|
|
12756
|
+
};
|
|
12757
|
+
});
|
|
12758
|
+
};
|
|
12759
|
+
var prepareAlterCompositePrimaryKeyMySql = (tableName, pks, json1, json2) => {
|
|
12760
|
+
return Object.values(pks).map((it) => {
|
|
12761
|
+
return {
|
|
12762
|
+
type: "alter_composite_pk",
|
|
12763
|
+
tableName,
|
|
12764
|
+
old: it.__old,
|
|
12765
|
+
new: it.__new,
|
|
12766
|
+
oldConstraintName: json1.tables[tableName].compositePrimaryKeys[`${tableName}_${MySqlSquasher.unsquashPK(it.__old).columns.join("_")}`].name,
|
|
12767
|
+
newConstraintName: json2.tables[tableName].compositePrimaryKeys[`${tableName}_${MySqlSquasher.unsquashPK(it.__new).columns.join("_")}`].name
|
|
12768
|
+
};
|
|
12769
|
+
});
|
|
12770
|
+
};
|
|
12418
12771
|
|
|
12419
12772
|
// src/snapshotsDiffer.ts
|
|
12420
12773
|
var makeChanged = (schema3) => {
|
|
@@ -12498,6 +12851,7 @@ var alteredColumnSchema = objectType({
|
|
|
12498
12851
|
name: makeSelfOrChanged(stringType()),
|
|
12499
12852
|
type: makeChanged(stringType()).optional(),
|
|
12500
12853
|
default: makePatched(anyType()).optional(),
|
|
12854
|
+
primaryKey: makePatched(booleanType()).optional(),
|
|
12501
12855
|
notNull: makePatched(booleanType()).optional(),
|
|
12502
12856
|
onUpdate: makePatched(booleanType()).optional(),
|
|
12503
12857
|
autoincrement: makePatched(booleanType()).optional()
|
|
@@ -12556,7 +12910,7 @@ var diffResultScheme = objectType({
|
|
|
12556
12910
|
addedSchemas: stringType().array(),
|
|
12557
12911
|
deletedSchemas: stringType().array()
|
|
12558
12912
|
}).strict();
|
|
12559
|
-
var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesResolver, columnsResolver) => {
|
|
12913
|
+
var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesResolver, columnsResolver, prevFull, curFull) => {
|
|
12560
12914
|
var _a, _b, _c, _d;
|
|
12561
12915
|
const diffResult = applyJsonDiff(json1, json2);
|
|
12562
12916
|
if (Object.keys(diffResult).length === 0) {
|
|
@@ -12586,9 +12940,6 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
|
12586
12940
|
const jsonSQLiteCreateTables = created.map((it) => {
|
|
12587
12941
|
return prepareSQLiteCreateTable(it);
|
|
12588
12942
|
});
|
|
12589
|
-
const jsonCreateTables = created.map((it) => {
|
|
12590
|
-
return prepareCreateTableJson(it);
|
|
12591
|
-
});
|
|
12592
12943
|
const jsonCreateIndexesForCreatedTables = created.map((it) => {
|
|
12593
12944
|
return prepareCreateIndexesJson(it.name, it.schema, it.indexes);
|
|
12594
12945
|
}).flat();
|
|
@@ -12646,18 +12997,57 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
|
12646
12997
|
const jsonRemoveTableFromSchemas = [];
|
|
12647
12998
|
const jsonSetNewTableSchemas = [];
|
|
12648
12999
|
allAlteredResolved.forEach((it) => {
|
|
12649
|
-
|
|
12650
|
-
|
|
12651
|
-
|
|
12652
|
-
)
|
|
12653
|
-
|
|
12654
|
-
|
|
12655
|
-
|
|
12656
|
-
|
|
12657
|
-
|
|
12658
|
-
|
|
12659
|
-
|
|
12660
|
-
|
|
13000
|
+
let addedCompositePKs;
|
|
13001
|
+
let deletedCompositePKs;
|
|
13002
|
+
let alteredCompositePKs;
|
|
13003
|
+
if (dialect3 === "sqlite") {
|
|
13004
|
+
addedCompositePKs = prepareAddCompositePrimaryKeySqlite(
|
|
13005
|
+
it.name,
|
|
13006
|
+
it.addedCompositePKs
|
|
13007
|
+
);
|
|
13008
|
+
deletedCompositePKs = prepareDeleteCompositePrimaryKeySqlite(
|
|
13009
|
+
it.name,
|
|
13010
|
+
it.deletedCompositePKs
|
|
13011
|
+
);
|
|
13012
|
+
alteredCompositePKs = prepareAlterCompositePrimaryKeySqlite(
|
|
13013
|
+
it.name,
|
|
13014
|
+
it.alteredCompositePKs
|
|
13015
|
+
);
|
|
13016
|
+
} else if (dialect3 === "pg") {
|
|
13017
|
+
addedCompositePKs = prepareAddCompositePrimaryKeyPg(
|
|
13018
|
+
it.name,
|
|
13019
|
+
it.addedCompositePKs,
|
|
13020
|
+
curFull
|
|
13021
|
+
);
|
|
13022
|
+
deletedCompositePKs = prepareDeleteCompositePrimaryKeyPg(
|
|
13023
|
+
it.name,
|
|
13024
|
+
it.deletedCompositePKs,
|
|
13025
|
+
prevFull
|
|
13026
|
+
);
|
|
13027
|
+
alteredCompositePKs = prepareAlterCompositePrimaryKeyPg(
|
|
13028
|
+
it.name,
|
|
13029
|
+
it.alteredCompositePKs,
|
|
13030
|
+
prevFull,
|
|
13031
|
+
curFull
|
|
13032
|
+
);
|
|
13033
|
+
} else {
|
|
13034
|
+
addedCompositePKs = prepareAddCompositePrimaryKeyMySql(
|
|
13035
|
+
it.name,
|
|
13036
|
+
it.addedCompositePKs,
|
|
13037
|
+
curFull
|
|
13038
|
+
);
|
|
13039
|
+
deletedCompositePKs = prepareDeleteCompositePrimaryKeyMySql(
|
|
13040
|
+
it.name,
|
|
13041
|
+
it.deletedCompositePKs,
|
|
13042
|
+
prevFull
|
|
13043
|
+
);
|
|
13044
|
+
alteredCompositePKs = prepareAlterCompositePrimaryKeyMySql(
|
|
13045
|
+
it.name,
|
|
13046
|
+
it.alteredCompositePKs,
|
|
13047
|
+
prevFull,
|
|
13048
|
+
curFull
|
|
13049
|
+
);
|
|
13050
|
+
}
|
|
12661
13051
|
if (it.schema && typeof it.schema !== "string") {
|
|
12662
13052
|
switch (it.schema.type) {
|
|
12663
13053
|
case "added": {
|
|
@@ -12780,12 +13170,21 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
|
12780
13170
|
jsonStatements.push(...jsonAlterEnumsWithAddedValues);
|
|
12781
13171
|
if (dialect3 === "sqlite") {
|
|
12782
13172
|
jsonStatements.push(...jsonSQLiteCreateTables);
|
|
13173
|
+
} else if (dialect3 === "pg") {
|
|
13174
|
+
const jsonPgCreateTables = created.map((it) => {
|
|
13175
|
+
return preparePgCreateTableJson(it, curFull);
|
|
13176
|
+
});
|
|
13177
|
+
jsonStatements.push(...jsonPgCreateTables);
|
|
12783
13178
|
} else {
|
|
12784
|
-
|
|
13179
|
+
const jsonMySqlCreateTables = created.map((it) => {
|
|
13180
|
+
return prepareMySqlCreateTableJson(it, curFull);
|
|
13181
|
+
});
|
|
13182
|
+
jsonStatements.push(...jsonMySqlCreateTables);
|
|
12785
13183
|
}
|
|
12786
13184
|
jsonStatements.push(...jsonDropTables);
|
|
12787
13185
|
jsonStatements.push(...jsonRenameTables);
|
|
12788
13186
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
|
13187
|
+
jsonStatements.push(...jsonDeletedCompositePKs);
|
|
12789
13188
|
jsonStatements.push(...jsonTableAlternations.alterColumns);
|
|
12790
13189
|
jsonStatements.push(...jsonTableAlternations.createColumns);
|
|
12791
13190
|
jsonStatements.push(...jsonAlterReferencesForAlteredTables);
|
|
@@ -12795,7 +13194,6 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
|
12795
13194
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
|
12796
13195
|
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
|
12797
13196
|
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
|
12798
|
-
jsonStatements.push(...jsonDeletedCompositePKs);
|
|
12799
13197
|
jsonStatements.push(...jsonAddedCompositePKs);
|
|
12800
13198
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
|
12801
13199
|
jsonStatements.push(...jsonSetTableSchemas);
|
|
@@ -12810,7 +13208,11 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
|
12810
13208
|
}
|
|
12811
13209
|
});
|
|
12812
13210
|
const _meta = prepareMigrationMeta(rSchemas, rTables, rColumns);
|
|
12813
|
-
return {
|
|
13211
|
+
return {
|
|
13212
|
+
statements: jsonStatements,
|
|
13213
|
+
sqlStatements: uniqueSqlStatements,
|
|
13214
|
+
_meta
|
|
13215
|
+
};
|
|
12814
13216
|
};
|
|
12815
13217
|
|
|
12816
13218
|
// src/cli/commands/upFolders.ts
|
|
@@ -12945,7 +13347,7 @@ var snapshotsPriorV4 = (out) => {
|
|
|
12945
13347
|
return pathJson;
|
|
12946
13348
|
});
|
|
12947
13349
|
};
|
|
12948
|
-
var
|
|
13350
|
+
var prepareOutFolder2 = (out, dialect3) => {
|
|
12949
13351
|
const meta = (0, import_path.join)(out, "meta");
|
|
12950
13352
|
const journalPath = (0, import_path.join)(meta, "_journal.json");
|
|
12951
13353
|
if (!(0, import_fs.existsSync)((0, import_path.join)(out, "meta"))) {
|
|
@@ -12969,7 +13371,7 @@ var validatorForDialect = (dialect3) => {
|
|
|
12969
13371
|
case "pg":
|
|
12970
13372
|
return { validator: backwardCompatiblePgSchema, version: 5 };
|
|
12971
13373
|
case "sqlite":
|
|
12972
|
-
return { validator: backwardCompatibleSqliteSchema, version:
|
|
13374
|
+
return { validator: backwardCompatibleSqliteSchema, version: 5 };
|
|
12973
13375
|
case "mysql":
|
|
12974
13376
|
return { validator: backwardCompatibleMysqlSchema, version: 5 };
|
|
12975
13377
|
}
|
|
@@ -13018,7 +13420,7 @@ var validateWithReport = (snapshots, dialect3) => {
|
|
|
13018
13420
|
return result;
|
|
13019
13421
|
};
|
|
13020
13422
|
var prepareMigrationFolder = (outFolder = "drizzle", dialect3) => {
|
|
13021
|
-
const { snapshots, journal } =
|
|
13423
|
+
const { snapshots, journal } = prepareOutFolder2(outFolder, dialect3);
|
|
13022
13424
|
const report = validateWithReport(snapshots, dialect3);
|
|
13023
13425
|
if (report.nonLatest.length > 0) {
|
|
13024
13426
|
console.log(
|