@sqlanvil/cli 1.17.1 → 1.19.0
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/bundle.js +648 -391
- package/package.json +1 -1
- package/worker_bundle.js +120 -0
package/bundle.js
CHANGED
|
@@ -5888,6 +5888,7 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
5888
5888
|
* @property {sqlanvil.ActionConfig.IMetadata|null} [metadata] ViewConfig metadata
|
|
5889
5889
|
* @property {string|null} [reservation] ViewConfig reservation
|
|
5890
5890
|
* @property {sqlanvil.IPostgresOptions|null} [postgres] ViewConfig postgres
|
|
5891
|
+
* @property {sqlanvil.IMysqlOptions|null} [mysql] ViewConfig mysql
|
|
5891
5892
|
*/
|
|
5892
5893
|
|
|
5893
5894
|
/**
|
|
@@ -6089,6 +6090,14 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
6089
6090
|
*/
|
|
6090
6091
|
ViewConfig.prototype.postgres = null;
|
|
6091
6092
|
|
|
6093
|
+
/**
|
|
6094
|
+
* ViewConfig mysql.
|
|
6095
|
+
* @member {sqlanvil.IMysqlOptions|null|undefined} mysql
|
|
6096
|
+
* @memberof sqlanvil.ActionConfig.ViewConfig
|
|
6097
|
+
* @instance
|
|
6098
|
+
*/
|
|
6099
|
+
ViewConfig.prototype.mysql = null;
|
|
6100
|
+
|
|
6092
6101
|
/**
|
|
6093
6102
|
* Creates a new ViewConfig instance using the specified properties.
|
|
6094
6103
|
* @function create
|
|
@@ -6169,6 +6178,8 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
6169
6178
|
writer.uint32(/* id 21, wireType 2 =*/170).string(message.reservation);
|
|
6170
6179
|
if (message.postgres != null && Object.hasOwnProperty.call(message, "postgres"))
|
|
6171
6180
|
$root.sqlanvil.PostgresOptions.encode(message.postgres, writer.uint32(/* id 22, wireType 2 =*/178).fork(), q + 1).ldelim();
|
|
6181
|
+
if (message.mysql != null && Object.hasOwnProperty.call(message, "mysql"))
|
|
6182
|
+
$root.sqlanvil.MysqlOptions.encode(message.mysql, writer.uint32(/* id 23, wireType 2 =*/186).fork(), q + 1).ldelim();
|
|
6172
6183
|
return writer;
|
|
6173
6184
|
};
|
|
6174
6185
|
|
|
@@ -6351,6 +6362,10 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
6351
6362
|
message.postgres = $root.sqlanvil.PostgresOptions.decode(reader, reader.uint32(), undefined, long + 1);
|
|
6352
6363
|
break;
|
|
6353
6364
|
}
|
|
6365
|
+
case 23: {
|
|
6366
|
+
message.mysql = $root.sqlanvil.MysqlOptions.decode(reader, reader.uint32(), undefined, long + 1);
|
|
6367
|
+
break;
|
|
6368
|
+
}
|
|
6354
6369
|
default:
|
|
6355
6370
|
reader.skipType(tag & 7, long);
|
|
6356
6371
|
break;
|
|
@@ -6500,6 +6515,11 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
6500
6515
|
if (error)
|
|
6501
6516
|
return "postgres." + error;
|
|
6502
6517
|
}
|
|
6518
|
+
if (message.mysql != null && Object.hasOwnProperty.call(message, "mysql")) {
|
|
6519
|
+
let error = $root.sqlanvil.MysqlOptions.verify(message.mysql, long + 1);
|
|
6520
|
+
if (error)
|
|
6521
|
+
return "mysql." + error;
|
|
6522
|
+
}
|
|
6503
6523
|
return null;
|
|
6504
6524
|
};
|
|
6505
6525
|
|
|
@@ -6626,6 +6646,11 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
6626
6646
|
throw TypeError(".sqlanvil.ActionConfig.ViewConfig.postgres: object expected");
|
|
6627
6647
|
message.postgres = $root.sqlanvil.PostgresOptions.fromObject(object.postgres, long + 1);
|
|
6628
6648
|
}
|
|
6649
|
+
if (object.mysql != null) {
|
|
6650
|
+
if (!$util.isObject(object.mysql))
|
|
6651
|
+
throw TypeError(".sqlanvil.ActionConfig.ViewConfig.mysql: object expected");
|
|
6652
|
+
message.mysql = $root.sqlanvil.MysqlOptions.fromObject(object.mysql, long + 1);
|
|
6653
|
+
}
|
|
6629
6654
|
return message;
|
|
6630
6655
|
};
|
|
6631
6656
|
|
|
@@ -6673,6 +6698,7 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
6673
6698
|
object.metadata = null;
|
|
6674
6699
|
object.reservation = "";
|
|
6675
6700
|
object.postgres = null;
|
|
6701
|
+
object.mysql = null;
|
|
6676
6702
|
}
|
|
6677
6703
|
if (message.name != null && Object.hasOwnProperty.call(message, "name"))
|
|
6678
6704
|
object.name = message.name;
|
|
@@ -6749,6 +6775,8 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
6749
6775
|
object.reservation = message.reservation;
|
|
6750
6776
|
if (message.postgres != null && Object.hasOwnProperty.call(message, "postgres"))
|
|
6751
6777
|
object.postgres = $root.sqlanvil.PostgresOptions.toObject(message.postgres, options, q + 1);
|
|
6778
|
+
if (message.mysql != null && Object.hasOwnProperty.call(message, "mysql"))
|
|
6779
|
+
object.mysql = $root.sqlanvil.MysqlOptions.toObject(message.mysql, options, q + 1);
|
|
6752
6780
|
return object;
|
|
6753
6781
|
};
|
|
6754
6782
|
|
|
@@ -16490,6 +16518,7 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
16490
16518
|
* @property {string|null} [engine] MysqlOptions engine
|
|
16491
16519
|
* @property {string|null} [charset] MysqlOptions charset
|
|
16492
16520
|
* @property {string|null} [collation] MysqlOptions collation
|
|
16521
|
+
* @property {string|null} [rowFormat] MysqlOptions rowFormat
|
|
16493
16522
|
* @property {Array.<sqlanvil.MysqlOptions.IIndex>|null} [indexes] MysqlOptions indexes
|
|
16494
16523
|
* @property {sqlanvil.MysqlOptions.IPartition|null} [partition] MysqlOptions partition
|
|
16495
16524
|
*/
|
|
@@ -16534,6 +16563,14 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
16534
16563
|
*/
|
|
16535
16564
|
MysqlOptions.prototype.collation = "";
|
|
16536
16565
|
|
|
16566
|
+
/**
|
|
16567
|
+
* MysqlOptions rowFormat.
|
|
16568
|
+
* @member {string} rowFormat
|
|
16569
|
+
* @memberof sqlanvil.MysqlOptions
|
|
16570
|
+
* @instance
|
|
16571
|
+
*/
|
|
16572
|
+
MysqlOptions.prototype.rowFormat = "";
|
|
16573
|
+
|
|
16537
16574
|
/**
|
|
16538
16575
|
* MysqlOptions indexes.
|
|
16539
16576
|
* @member {Array.<sqlanvil.MysqlOptions.IIndex>} indexes
|
|
@@ -16589,6 +16626,8 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
16589
16626
|
$root.sqlanvil.MysqlOptions.Index.encode(message.indexes[i], writer.uint32(/* id 4, wireType 2 =*/34).fork(), q + 1).ldelim();
|
|
16590
16627
|
if (message.partition != null && Object.hasOwnProperty.call(message, "partition"))
|
|
16591
16628
|
$root.sqlanvil.MysqlOptions.Partition.encode(message.partition, writer.uint32(/* id 5, wireType 2 =*/42).fork(), q + 1).ldelim();
|
|
16629
|
+
if (message.rowFormat != null && Object.hasOwnProperty.call(message, "rowFormat"))
|
|
16630
|
+
writer.uint32(/* id 6, wireType 2 =*/50).string(message.rowFormat);
|
|
16592
16631
|
return writer;
|
|
16593
16632
|
};
|
|
16594
16633
|
|
|
@@ -16641,6 +16680,10 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
16641
16680
|
message.collation = reader.string();
|
|
16642
16681
|
break;
|
|
16643
16682
|
}
|
|
16683
|
+
case 6: {
|
|
16684
|
+
message.rowFormat = reader.string();
|
|
16685
|
+
break;
|
|
16686
|
+
}
|
|
16644
16687
|
case 4: {
|
|
16645
16688
|
if (!(message.indexes && message.indexes.length))
|
|
16646
16689
|
message.indexes = [];
|
|
@@ -16699,6 +16742,9 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
16699
16742
|
if (message.collation != null && Object.hasOwnProperty.call(message, "collation"))
|
|
16700
16743
|
if (!$util.isString(message.collation))
|
|
16701
16744
|
return "collation: string expected";
|
|
16745
|
+
if (message.rowFormat != null && Object.hasOwnProperty.call(message, "rowFormat"))
|
|
16746
|
+
if (!$util.isString(message.rowFormat))
|
|
16747
|
+
return "rowFormat: string expected";
|
|
16702
16748
|
if (message.indexes != null && Object.hasOwnProperty.call(message, "indexes")) {
|
|
16703
16749
|
if (!Array.isArray(message.indexes))
|
|
16704
16750
|
return "indexes: array expected";
|
|
@@ -16740,6 +16786,8 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
16740
16786
|
message.charset = String(object.charset);
|
|
16741
16787
|
if (object.collation != null)
|
|
16742
16788
|
message.collation = String(object.collation);
|
|
16789
|
+
if (object.rowFormat != null)
|
|
16790
|
+
message.rowFormat = String(object.rowFormat);
|
|
16743
16791
|
if (object.indexes) {
|
|
16744
16792
|
if (!Array.isArray(object.indexes))
|
|
16745
16793
|
throw TypeError(".sqlanvil.MysqlOptions.indexes: array expected");
|
|
@@ -16782,6 +16830,7 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
16782
16830
|
object.charset = "";
|
|
16783
16831
|
object.collation = "";
|
|
16784
16832
|
object.partition = null;
|
|
16833
|
+
object.rowFormat = "";
|
|
16785
16834
|
}
|
|
16786
16835
|
if (message.engine != null && Object.hasOwnProperty.call(message, "engine"))
|
|
16787
16836
|
object.engine = message.engine;
|
|
@@ -16796,6 +16845,8 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
16796
16845
|
}
|
|
16797
16846
|
if (message.partition != null && Object.hasOwnProperty.call(message, "partition"))
|
|
16798
16847
|
object.partition = $root.sqlanvil.MysqlOptions.Partition.toObject(message.partition, options, q + 1);
|
|
16848
|
+
if (message.rowFormat != null && Object.hasOwnProperty.call(message, "rowFormat"))
|
|
16849
|
+
object.rowFormat = message.rowFormat;
|
|
16799
16850
|
return object;
|
|
16800
16851
|
};
|
|
16801
16852
|
|
|
@@ -16834,6 +16885,7 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
16834
16885
|
* @property {string|null} [name] Index name
|
|
16835
16886
|
* @property {Array.<string>|null} [columns] Index columns
|
|
16836
16887
|
* @property {boolean|null} [unique] Index unique
|
|
16888
|
+
* @property {string|null} [type] Index type
|
|
16837
16889
|
*/
|
|
16838
16890
|
|
|
16839
16891
|
/**
|
|
@@ -16876,6 +16928,14 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
16876
16928
|
*/
|
|
16877
16929
|
Index.prototype.unique = false;
|
|
16878
16930
|
|
|
16931
|
+
/**
|
|
16932
|
+
* Index type.
|
|
16933
|
+
* @member {string} type
|
|
16934
|
+
* @memberof sqlanvil.MysqlOptions.Index
|
|
16935
|
+
* @instance
|
|
16936
|
+
*/
|
|
16937
|
+
Index.prototype.type = "";
|
|
16938
|
+
|
|
16879
16939
|
/**
|
|
16880
16940
|
* Creates a new Index instance using the specified properties.
|
|
16881
16941
|
* @function create
|
|
@@ -16911,6 +16971,8 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
16911
16971
|
writer.uint32(/* id 2, wireType 2 =*/18).string(message.columns[i]);
|
|
16912
16972
|
if (message.unique != null && Object.hasOwnProperty.call(message, "unique"))
|
|
16913
16973
|
writer.uint32(/* id 3, wireType 0 =*/24).bool(message.unique);
|
|
16974
|
+
if (message.type != null && Object.hasOwnProperty.call(message, "type"))
|
|
16975
|
+
writer.uint32(/* id 4, wireType 2 =*/34).string(message.type);
|
|
16914
16976
|
return writer;
|
|
16915
16977
|
};
|
|
16916
16978
|
|
|
@@ -16965,6 +17027,10 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
16965
17027
|
message.unique = reader.bool();
|
|
16966
17028
|
break;
|
|
16967
17029
|
}
|
|
17030
|
+
case 4: {
|
|
17031
|
+
message.type = reader.string();
|
|
17032
|
+
break;
|
|
17033
|
+
}
|
|
16968
17034
|
default:
|
|
16969
17035
|
reader.skipType(tag & 7, long);
|
|
16970
17036
|
break;
|
|
@@ -17017,6 +17083,9 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
17017
17083
|
if (message.unique != null && Object.hasOwnProperty.call(message, "unique"))
|
|
17018
17084
|
if (typeof message.unique !== "boolean")
|
|
17019
17085
|
return "unique: boolean expected";
|
|
17086
|
+
if (message.type != null && Object.hasOwnProperty.call(message, "type"))
|
|
17087
|
+
if (!$util.isString(message.type))
|
|
17088
|
+
return "type: string expected";
|
|
17020
17089
|
return null;
|
|
17021
17090
|
};
|
|
17022
17091
|
|
|
@@ -17049,6 +17118,8 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
17049
17118
|
}
|
|
17050
17119
|
if (object.unique != null)
|
|
17051
17120
|
message.unique = Boolean(object.unique);
|
|
17121
|
+
if (object.type != null)
|
|
17122
|
+
message.type = String(object.type);
|
|
17052
17123
|
return message;
|
|
17053
17124
|
};
|
|
17054
17125
|
|
|
@@ -17074,6 +17145,7 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
17074
17145
|
if (options.defaults) {
|
|
17075
17146
|
object.name = "";
|
|
17076
17147
|
object.unique = false;
|
|
17148
|
+
object.type = "";
|
|
17077
17149
|
}
|
|
17078
17150
|
if (message.name != null && Object.hasOwnProperty.call(message, "name"))
|
|
17079
17151
|
object.name = message.name;
|
|
@@ -17084,6 +17156,8 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
17084
17156
|
}
|
|
17085
17157
|
if (message.unique != null && Object.hasOwnProperty.call(message, "unique"))
|
|
17086
17158
|
object.unique = message.unique;
|
|
17159
|
+
if (message.type != null && Object.hasOwnProperty.call(message, "type"))
|
|
17160
|
+
object.type = message.type;
|
|
17087
17161
|
return object;
|
|
17088
17162
|
};
|
|
17089
17163
|
|
|
@@ -27044,6 +27118,7 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
27044
27118
|
* @property {string|null} [billingProject] Extract billingProject
|
|
27045
27119
|
* @property {Object.<string,string>|null} [columnTypes] Extract columnTypes
|
|
27046
27120
|
* @property {string|null} [fileName] Extract fileName
|
|
27121
|
+
* @property {string|null} [database] Extract database
|
|
27047
27122
|
*/
|
|
27048
27123
|
|
|
27049
27124
|
/**
|
|
@@ -27184,6 +27259,14 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
27184
27259
|
*/
|
|
27185
27260
|
Extract.prototype.fileName = "";
|
|
27186
27261
|
|
|
27262
|
+
/**
|
|
27263
|
+
* Extract database.
|
|
27264
|
+
* @member {string} database
|
|
27265
|
+
* @memberof sqlanvil.Extract
|
|
27266
|
+
* @instance
|
|
27267
|
+
*/
|
|
27268
|
+
Extract.prototype.database = "";
|
|
27269
|
+
|
|
27187
27270
|
/**
|
|
27188
27271
|
* Creates a new Extract instance using the specified properties.
|
|
27189
27272
|
* @function create
|
|
@@ -27245,6 +27328,8 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
27245
27328
|
writer.uint32(/* id 14, wireType 2 =*/114).fork().uint32(/* id 1, wireType 2 =*/10).string(keys[i]).uint32(/* id 2, wireType 2 =*/18).string(message.columnTypes[keys[i]]).ldelim();
|
|
27246
27329
|
if (message.fileName != null && Object.hasOwnProperty.call(message, "fileName"))
|
|
27247
27330
|
writer.uint32(/* id 15, wireType 2 =*/122).string(message.fileName);
|
|
27331
|
+
if (message.database != null && Object.hasOwnProperty.call(message, "database"))
|
|
27332
|
+
writer.uint32(/* id 16, wireType 2 =*/130).string(message.database);
|
|
27248
27333
|
return writer;
|
|
27249
27334
|
};
|
|
27250
27335
|
|
|
@@ -27370,6 +27455,10 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
27370
27455
|
message.fileName = reader.string();
|
|
27371
27456
|
break;
|
|
27372
27457
|
}
|
|
27458
|
+
case 16: {
|
|
27459
|
+
message.database = reader.string();
|
|
27460
|
+
break;
|
|
27461
|
+
}
|
|
27373
27462
|
default:
|
|
27374
27463
|
reader.skipType(tag & 7, long);
|
|
27375
27464
|
break;
|
|
@@ -27481,6 +27570,9 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
27481
27570
|
if (message.fileName != null && Object.hasOwnProperty.call(message, "fileName"))
|
|
27482
27571
|
if (!$util.isString(message.fileName))
|
|
27483
27572
|
return "fileName: string expected";
|
|
27573
|
+
if (message.database != null && Object.hasOwnProperty.call(message, "database"))
|
|
27574
|
+
if (!$util.isString(message.database))
|
|
27575
|
+
return "database: string expected";
|
|
27484
27576
|
return null;
|
|
27485
27577
|
};
|
|
27486
27578
|
|
|
@@ -27580,6 +27672,8 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
27580
27672
|
}
|
|
27581
27673
|
if (object.fileName != null)
|
|
27582
27674
|
message.fileName = String(object.fileName);
|
|
27675
|
+
if (object.database != null)
|
|
27676
|
+
message.database = String(object.database);
|
|
27583
27677
|
return message;
|
|
27584
27678
|
};
|
|
27585
27679
|
|
|
@@ -27619,6 +27713,7 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
27619
27713
|
object.sourceName = "";
|
|
27620
27714
|
object.billingProject = "";
|
|
27621
27715
|
object.fileName = "";
|
|
27716
|
+
object.database = "";
|
|
27622
27717
|
}
|
|
27623
27718
|
if (message.target != null && Object.hasOwnProperty.call(message, "target"))
|
|
27624
27719
|
object.target = $root.sqlanvil.Target.toObject(message.target, options, q + 1);
|
|
@@ -27663,6 +27758,8 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
27663
27758
|
}
|
|
27664
27759
|
if (message.fileName != null && Object.hasOwnProperty.call(message, "fileName"))
|
|
27665
27760
|
object.fileName = message.fileName;
|
|
27761
|
+
if (message.database != null && Object.hasOwnProperty.call(message, "database"))
|
|
27762
|
+
object.database = message.database;
|
|
27666
27763
|
return object;
|
|
27667
27764
|
};
|
|
27668
27765
|
|
|
@@ -37844,6 +37941,7 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
37844
37941
|
* @property {string|null} [sourceName] ExtractSpec sourceName
|
|
37845
37942
|
* @property {string|null} [billingProject] ExtractSpec billingProject
|
|
37846
37943
|
* @property {Object.<string,string>|null} [columnTypes] ExtractSpec columnTypes
|
|
37944
|
+
* @property {string|null} [database] ExtractSpec database
|
|
37847
37945
|
*/
|
|
37848
37946
|
|
|
37849
37947
|
/**
|
|
@@ -37918,6 +38016,14 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
37918
38016
|
*/
|
|
37919
38017
|
ExtractSpec.prototype.columnTypes = $util.emptyObject;
|
|
37920
38018
|
|
|
38019
|
+
/**
|
|
38020
|
+
* ExtractSpec database.
|
|
38021
|
+
* @member {string} database
|
|
38022
|
+
* @memberof sqlanvil.ExtractSpec
|
|
38023
|
+
* @instance
|
|
38024
|
+
*/
|
|
38025
|
+
ExtractSpec.prototype.database = "";
|
|
38026
|
+
|
|
37921
38027
|
/**
|
|
37922
38028
|
* Creates a new ExtractSpec instance using the specified properties.
|
|
37923
38029
|
* @function create
|
|
@@ -37961,6 +38067,8 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
37961
38067
|
if (message.columnTypes != null && Object.hasOwnProperty.call(message, "columnTypes"))
|
|
37962
38068
|
for (let keys = Object.keys(message.columnTypes), i = 0; i < keys.length; ++i)
|
|
37963
38069
|
writer.uint32(/* id 7, wireType 2 =*/58).fork().uint32(/* id 1, wireType 2 =*/10).string(keys[i]).uint32(/* id 2, wireType 2 =*/18).string(message.columnTypes[keys[i]]).ldelim();
|
|
38070
|
+
if (message.database != null && Object.hasOwnProperty.call(message, "database"))
|
|
38071
|
+
writer.uint32(/* id 8, wireType 2 =*/66).string(message.database);
|
|
37964
38072
|
return writer;
|
|
37965
38073
|
};
|
|
37966
38074
|
|
|
@@ -38050,6 +38158,10 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
38050
38158
|
message.columnTypes[key] = value;
|
|
38051
38159
|
break;
|
|
38052
38160
|
}
|
|
38161
|
+
case 8: {
|
|
38162
|
+
message.database = reader.string();
|
|
38163
|
+
break;
|
|
38164
|
+
}
|
|
38053
38165
|
default:
|
|
38054
38166
|
reader.skipType(tag & 7, long);
|
|
38055
38167
|
break;
|
|
@@ -38115,6 +38227,9 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
38115
38227
|
if (!$util.isString(message.columnTypes[key[i]]))
|
|
38116
38228
|
return "columnTypes: string{k:string} expected";
|
|
38117
38229
|
}
|
|
38230
|
+
if (message.database != null && Object.hasOwnProperty.call(message, "database"))
|
|
38231
|
+
if (!$util.isString(message.database))
|
|
38232
|
+
return "database: string expected";
|
|
38118
38233
|
return null;
|
|
38119
38234
|
};
|
|
38120
38235
|
|
|
@@ -38158,6 +38273,8 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
38158
38273
|
message.columnTypes[keys[i]] = String(object.columnTypes[keys[i]]);
|
|
38159
38274
|
}
|
|
38160
38275
|
}
|
|
38276
|
+
if (object.database != null)
|
|
38277
|
+
message.database = String(object.database);
|
|
38161
38278
|
return message;
|
|
38162
38279
|
};
|
|
38163
38280
|
|
|
@@ -38187,6 +38304,7 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
38187
38304
|
object.dataset = "";
|
|
38188
38305
|
object.sourceName = "";
|
|
38189
38306
|
object.billingProject = "";
|
|
38307
|
+
object.database = "";
|
|
38190
38308
|
}
|
|
38191
38309
|
if (message.connectionName != null && Object.hasOwnProperty.call(message, "connectionName"))
|
|
38192
38310
|
object.connectionName = message.connectionName;
|
|
@@ -38209,6 +38327,8 @@ const sqlanvil = $root.sqlanvil = (() => {
|
|
|
38209
38327
|
object.columnTypes[keys2[j]] = message.columnTypes[keys2[j]];
|
|
38210
38328
|
}
|
|
38211
38329
|
}
|
|
38330
|
+
if (message.database != null && Object.hasOwnProperty.call(message, "database"))
|
|
38331
|
+
object.database = message.database;
|
|
38212
38332
|
return object;
|
|
38213
38333
|
};
|
|
38214
38334
|
|
|
@@ -48296,6 +48416,9 @@ class MysqlExecutionSql {
|
|
|
48296
48416
|
if (opts.collation) {
|
|
48297
48417
|
suffix += ` collate=${opts.collation}`;
|
|
48298
48418
|
}
|
|
48419
|
+
if (opts.rowFormat) {
|
|
48420
|
+
suffix += ` row_format=${opts.rowFormat}`;
|
|
48421
|
+
}
|
|
48299
48422
|
return suffix;
|
|
48300
48423
|
}
|
|
48301
48424
|
createIndexes(table) {
|
|
@@ -48306,12 +48429,28 @@ class MysqlExecutionSql {
|
|
|
48306
48429
|
}
|
|
48307
48430
|
const target = this.resolveTarget(table.target);
|
|
48308
48431
|
return indexes.map(index => {
|
|
48309
|
-
const
|
|
48310
|
-
|
|
48311
|
-
|
|
48312
|
-
|
|
48432
|
+
const kind = (index.type || "").toLowerCase();
|
|
48433
|
+
if (kind && kind !== "fulltext" && kind !== "spatial") {
|
|
48434
|
+
throw new Error(`mysql index type must be "fulltext" or "spatial" (or omitted); got "${index.type}".`);
|
|
48435
|
+
}
|
|
48436
|
+
if (kind && index.unique) {
|
|
48437
|
+
throw new Error(`a mysql ${kind} index cannot also be unique.`);
|
|
48438
|
+
}
|
|
48439
|
+
const prefix = index.unique ? "unique " : kind ? `${kind} ` : "";
|
|
48440
|
+
const cols = (index.columns || []).map(c => this.indexColumnSql(c)).join(", ");
|
|
48441
|
+
const bareColumns = (index.columns || []).map(c => this.indexColumnName(c));
|
|
48442
|
+
const name = index.name || this.defaultIndexName(table.target.name, bareColumns, !!index.unique);
|
|
48443
|
+
return `alter table ${target} add ${prefix}index \`${name}\` (${cols})`;
|
|
48313
48444
|
});
|
|
48314
48445
|
}
|
|
48446
|
+
indexColumnSql(column) {
|
|
48447
|
+
const m = /^(.*?)\((\d+)\)$/.exec(column.trim());
|
|
48448
|
+
return m ? `\`${m[1].trim()}\`(${m[2]})` : `\`${column}\``;
|
|
48449
|
+
}
|
|
48450
|
+
indexColumnName(column) {
|
|
48451
|
+
const m = /^(.*?)\((\d+)\)$/.exec(column.trim());
|
|
48452
|
+
return m ? m[1].trim() : column;
|
|
48453
|
+
}
|
|
48315
48454
|
defaultIndexName(tableName, columns, unique) {
|
|
48316
48455
|
const parts = [tableName, ...(columns || [])].filter(Boolean);
|
|
48317
48456
|
const suffix = unique ? "_key" : "_idx";
|
|
@@ -48751,7 +48890,7 @@ function collectEvaluationQueries(queryOrAction, concatenate, queryModifier = (q
|
|
|
48751
48890
|
.filter(validationQuery => !!validationQuery.query);
|
|
48752
48891
|
}
|
|
48753
48892
|
|
|
48754
|
-
const version = "1.
|
|
48893
|
+
const version = "1.19.0";
|
|
48755
48894
|
const dataformVersion = "3.0.61";
|
|
48756
48895
|
|
|
48757
48896
|
async function build(compiledGraph, runConfig, dbadapter) {
|
|
@@ -48817,6 +48956,7 @@ class Builder {
|
|
|
48817
48956
|
platform: ext.platform,
|
|
48818
48957
|
project: ext.project,
|
|
48819
48958
|
dataset: ext.dataset,
|
|
48959
|
+
database: ext.database,
|
|
48820
48960
|
sourceName: ext.sourceName,
|
|
48821
48961
|
billingProject: ext.billingProject,
|
|
48822
48962
|
columnTypes: ext.columnTypes
|
|
@@ -49269,8 +49409,36 @@ function mapBigQueryType(bqType) {
|
|
|
49269
49409
|
function mapPostgresType(pgType) {
|
|
49270
49410
|
return pgType.trim().toLowerCase();
|
|
49271
49411
|
}
|
|
49412
|
+
const MYSQL_TYPE_MAP = {
|
|
49413
|
+
tinyint: "smallint",
|
|
49414
|
+
mediumint: "integer",
|
|
49415
|
+
int: "integer",
|
|
49416
|
+
double: "double precision",
|
|
49417
|
+
float: "real",
|
|
49418
|
+
decimal: "numeric",
|
|
49419
|
+
bit: "smallint",
|
|
49420
|
+
year: "smallint",
|
|
49421
|
+
datetime: "timestamp",
|
|
49422
|
+
timestamp: "timestamptz",
|
|
49423
|
+
char: "text",
|
|
49424
|
+
varchar: "text",
|
|
49425
|
+
tinytext: "text",
|
|
49426
|
+
mediumtext: "text",
|
|
49427
|
+
longtext: "text",
|
|
49428
|
+
enum: "text",
|
|
49429
|
+
set: "text",
|
|
49430
|
+
binary: "bytea",
|
|
49431
|
+
varbinary: "bytea",
|
|
49432
|
+
tinyblob: "bytea",
|
|
49433
|
+
blob: "bytea",
|
|
49434
|
+
mediumblob: "bytea",
|
|
49435
|
+
longblob: "bytea",
|
|
49436
|
+
json: "jsonb",
|
|
49437
|
+
geometry: "text"
|
|
49438
|
+
};
|
|
49272
49439
|
function mapMysqlType(mysqlType) {
|
|
49273
|
-
|
|
49440
|
+
const key = mysqlType.trim().toLowerCase();
|
|
49441
|
+
return MYSQL_TYPE_MAP[key] || key;
|
|
49274
49442
|
}
|
|
49275
49443
|
function keyToken(name) {
|
|
49276
49444
|
return /^[A-Za-z_][A-Za-z0-9_]*$/.test(name) ? name : `"${name}"`;
|
|
@@ -50358,10 +50526,55 @@ class PostgresDbAdapter {
|
|
|
50358
50526
|
}
|
|
50359
50527
|
}
|
|
50360
50528
|
|
|
50361
|
-
const DEFAULT_ROW_CAP = 1000000;
|
|
50362
|
-
const DEFAULT_BYTE_CAP = 512 * 1024 * 1024;
|
|
50363
50529
|
const MAX_PARAMS_PER_INSERT = 60000;
|
|
50364
50530
|
const quoteIdent = (id) => `"${String(id).replace(/"/g, '""')}"`;
|
|
50531
|
+
async function loadRowsIntoPostgres(args) {
|
|
50532
|
+
var _a;
|
|
50533
|
+
const { target, columnTypes, rows } = args;
|
|
50534
|
+
const cols = Object.keys(columnTypes);
|
|
50535
|
+
const coerce = args.coerce || ((v) => (v === undefined ? null : v));
|
|
50536
|
+
const pg = await PostgresDbAdapter.create(args.pg, {
|
|
50537
|
+
disableSslForTestsOnly: args.disableSslForTestsOnly
|
|
50538
|
+
});
|
|
50539
|
+
try {
|
|
50540
|
+
const qualified = `${quoteIdent(target.schema)}.${quoteIdent(target.name)}`;
|
|
50541
|
+
const colDefs = cols.map(c => `${quoteIdent(c)} ${columnTypes[c]}`).join(", ");
|
|
50542
|
+
await pg.execute(`create schema if not exists ${quoteIdent(target.schema)}`);
|
|
50543
|
+
const { rows: existing } = await pg.execute(`select c.relkind from pg_class c join pg_namespace n on n.oid = c.relnamespace ` +
|
|
50544
|
+
`where n.nspname = $1 and c.relname = $2`, { params: [target.schema, target.name] });
|
|
50545
|
+
const relkind = (_a = existing[0]) === null || _a === void 0 ? void 0 : _a.relkind;
|
|
50546
|
+
if (relkind === "f") {
|
|
50547
|
+
await pg.execute(`drop foreign table ${qualified} cascade`);
|
|
50548
|
+
}
|
|
50549
|
+
else if (relkind === "v") {
|
|
50550
|
+
await pg.execute(`drop view ${qualified} cascade`);
|
|
50551
|
+
}
|
|
50552
|
+
else if (relkind) {
|
|
50553
|
+
await pg.execute(`drop table ${qualified} cascade`);
|
|
50554
|
+
}
|
|
50555
|
+
await pg.execute(`create table ${qualified} (${colDefs})`);
|
|
50556
|
+
const colIdents = cols.map(quoteIdent).join(", ");
|
|
50557
|
+
const batchRows = Math.max(1, Math.min(1000, Math.floor(MAX_PARAMS_PER_INSERT / cols.length)));
|
|
50558
|
+
for (let i = 0; i < rows.length; i += batchRows) {
|
|
50559
|
+
const batch = rows.slice(i, i + batchRows);
|
|
50560
|
+
const params = [];
|
|
50561
|
+
const tuples = batch.map((row, r) => {
|
|
50562
|
+
const placeholders = cols.map((c, ci) => `$${r * cols.length + ci + 1}`);
|
|
50563
|
+
cols.forEach(c => params.push(coerce(row[c])));
|
|
50564
|
+
return `(${placeholders.join(", ")})`;
|
|
50565
|
+
});
|
|
50566
|
+
await pg.execute(`insert into ${qualified} (${colIdents}) values ${tuples.join(", ")}`, {
|
|
50567
|
+
params
|
|
50568
|
+
});
|
|
50569
|
+
}
|
|
50570
|
+
}
|
|
50571
|
+
finally {
|
|
50572
|
+
await pg.close();
|
|
50573
|
+
}
|
|
50574
|
+
}
|
|
50575
|
+
|
|
50576
|
+
const DEFAULT_ROW_CAP$1 = 1000000;
|
|
50577
|
+
const DEFAULT_BYTE_CAP$1 = 512 * 1024 * 1024;
|
|
50365
50578
|
function coerce(v) {
|
|
50366
50579
|
if (v === null || v === undefined) {
|
|
50367
50580
|
return null;
|
|
@@ -50375,7 +50588,7 @@ async function runBigQueryExtract(args) {
|
|
|
50375
50588
|
var _a, _b;
|
|
50376
50589
|
const { spec, target, connectionCredentials } = args;
|
|
50377
50590
|
if ((spec.platform || "bigquery") !== "bigquery") {
|
|
50378
|
-
throw new Error(`runner-extract
|
|
50591
|
+
throw new Error(`bigquery runner-extract got a "${spec.platform}" source.`);
|
|
50379
50592
|
}
|
|
50380
50593
|
const cols = Object.keys(spec.columnTypes || {});
|
|
50381
50594
|
if (cols.length === 0) {
|
|
@@ -50391,8 +50604,8 @@ async function runBigQueryExtract(args) {
|
|
|
50391
50604
|
accessToken: conn.accessToken,
|
|
50392
50605
|
credentials: conn.credentials
|
|
50393
50606
|
}));
|
|
50394
|
-
const rowCap = (_a = args.rowCap) !== null && _a !== void 0 ? _a : DEFAULT_ROW_CAP;
|
|
50395
|
-
const byteCap = (_b = args.byteCap) !== null && _b !== void 0 ? _b : DEFAULT_BYTE_CAP;
|
|
50607
|
+
const rowCap = (_a = args.rowCap) !== null && _a !== void 0 ? _a : DEFAULT_ROW_CAP$1;
|
|
50608
|
+
const byteCap = (_b = args.byteCap) !== null && _b !== void 0 ? _b : DEFAULT_BYTE_CAP$1;
|
|
50396
50609
|
const colList = cols.map(c => "`" + c + "`").join(", ");
|
|
50397
50610
|
const fqn = "`" + `${spec.project}.${spec.dataset}.${spec.sourceName}` + "`";
|
|
50398
50611
|
const { rows } = await bq.execute(`select ${colList} from ${fqn}`, {
|
|
@@ -50402,35 +50615,432 @@ async function runBigQueryExtract(args) {
|
|
|
50402
50615
|
if (rows.length >= rowCap) {
|
|
50403
50616
|
console.warn(`runner-extract: ${target.schema}.${target.name} truncated at ${rowCap} rows (source is larger).`);
|
|
50404
50617
|
}
|
|
50405
|
-
|
|
50618
|
+
await loadRowsIntoPostgres({
|
|
50619
|
+
pg: args.pg,
|
|
50620
|
+
target,
|
|
50621
|
+
columnTypes: spec.columnTypes,
|
|
50622
|
+
rows,
|
|
50623
|
+
coerce,
|
|
50406
50624
|
disableSslForTestsOnly: args.disableSslForTestsOnly
|
|
50407
50625
|
});
|
|
50408
|
-
|
|
50409
|
-
|
|
50410
|
-
|
|
50411
|
-
|
|
50412
|
-
|
|
50413
|
-
|
|
50414
|
-
|
|
50415
|
-
|
|
50416
|
-
const
|
|
50417
|
-
|
|
50418
|
-
|
|
50419
|
-
|
|
50420
|
-
|
|
50421
|
-
|
|
50422
|
-
|
|
50423
|
-
|
|
50626
|
+
return { rowCount: rows.length };
|
|
50627
|
+
}
|
|
50628
|
+
|
|
50629
|
+
class MySqlPoolExecutor {
|
|
50630
|
+
constructor(config, options) {
|
|
50631
|
+
this.pool = mysql__namespace.createPool(Object.assign(Object.assign({}, config), { connectionLimit: (options === null || options === void 0 ? void 0 : options.concurrencyLimit) || 10, waitForConnections: true, multipleStatements: false }));
|
|
50632
|
+
}
|
|
50633
|
+
async verifyConnection() {
|
|
50634
|
+
const conn = await this.pool.getConnection();
|
|
50635
|
+
try {
|
|
50636
|
+
await conn.query("select 1");
|
|
50637
|
+
}
|
|
50638
|
+
finally {
|
|
50639
|
+
conn.release();
|
|
50640
|
+
}
|
|
50641
|
+
}
|
|
50642
|
+
async withClientLock(callback) {
|
|
50643
|
+
const conn = await this.pool.getConnection();
|
|
50644
|
+
let released = false;
|
|
50645
|
+
const releaseOnce = () => {
|
|
50646
|
+
if (released) {
|
|
50647
|
+
return;
|
|
50648
|
+
}
|
|
50649
|
+
released = true;
|
|
50650
|
+
conn.release();
|
|
50651
|
+
};
|
|
50652
|
+
try {
|
|
50653
|
+
return await callback({
|
|
50654
|
+
execute: async (statement, options = { rowLimit: 1000 }) => {
|
|
50655
|
+
const [rows] = await conn.query(statement, options.params || []);
|
|
50656
|
+
const arr = Array.isArray(rows) ? rows : [];
|
|
50657
|
+
return options.rowLimit && arr.length > options.rowLimit
|
|
50658
|
+
? arr.slice(0, options.rowLimit)
|
|
50659
|
+
: arr;
|
|
50660
|
+
}
|
|
50424
50661
|
});
|
|
50425
|
-
|
|
50426
|
-
|
|
50662
|
+
}
|
|
50663
|
+
finally {
|
|
50664
|
+
releaseOnce();
|
|
50665
|
+
}
|
|
50666
|
+
}
|
|
50667
|
+
async close() {
|
|
50668
|
+
await this.pool.end();
|
|
50669
|
+
}
|
|
50670
|
+
}
|
|
50671
|
+
function convertFieldType(type) {
|
|
50672
|
+
switch (String(type).toUpperCase()) {
|
|
50673
|
+
case "FLOAT":
|
|
50674
|
+
case "DOUBLE":
|
|
50675
|
+
case "REAL":
|
|
50676
|
+
return sqlanvil.Field.Primitive.FLOAT;
|
|
50677
|
+
case "TINYINT":
|
|
50678
|
+
case "SMALLINT":
|
|
50679
|
+
case "MEDIUMINT":
|
|
50680
|
+
case "INT":
|
|
50681
|
+
case "INTEGER":
|
|
50682
|
+
case "BIGINT":
|
|
50683
|
+
case "YEAR":
|
|
50684
|
+
case "BIT":
|
|
50685
|
+
return sqlanvil.Field.Primitive.INTEGER;
|
|
50686
|
+
case "DECIMAL":
|
|
50687
|
+
case "DEC":
|
|
50688
|
+
case "NUMERIC":
|
|
50689
|
+
case "FIXED":
|
|
50690
|
+
return sqlanvil.Field.Primitive.NUMERIC;
|
|
50691
|
+
case "BOOL":
|
|
50692
|
+
case "BOOLEAN":
|
|
50693
|
+
return sqlanvil.Field.Primitive.BOOLEAN;
|
|
50694
|
+
case "CHAR":
|
|
50695
|
+
case "VARCHAR":
|
|
50696
|
+
case "TINYTEXT":
|
|
50697
|
+
case "TEXT":
|
|
50698
|
+
case "MEDIUMTEXT":
|
|
50699
|
+
case "LONGTEXT":
|
|
50700
|
+
case "ENUM":
|
|
50701
|
+
case "SET":
|
|
50702
|
+
case "JSON":
|
|
50703
|
+
case "TIME":
|
|
50704
|
+
return sqlanvil.Field.Primitive.STRING;
|
|
50705
|
+
case "DATE":
|
|
50706
|
+
return sqlanvil.Field.Primitive.DATE;
|
|
50707
|
+
case "DATETIME":
|
|
50708
|
+
case "TIMESTAMP":
|
|
50709
|
+
return sqlanvil.Field.Primitive.TIMESTAMP;
|
|
50710
|
+
default:
|
|
50711
|
+
return sqlanvil.Field.Primitive.UNKNOWN;
|
|
50712
|
+
}
|
|
50713
|
+
}
|
|
50714
|
+
function escapeMysqlString(s) {
|
|
50715
|
+
return s.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
50716
|
+
}
|
|
50717
|
+
function reconstructColumnDef(col) {
|
|
50718
|
+
const extra = (col.extra || "").toLowerCase();
|
|
50719
|
+
const notNull = col.isNullable === "NO";
|
|
50720
|
+
if (extra.includes("generated") && col.generationExpression) {
|
|
50721
|
+
const storage = extra.includes("stored") ? "STORED" : "VIRTUAL";
|
|
50722
|
+
return `${col.columnType} GENERATED ALWAYS AS (${col.generationExpression}) ${storage}${notNull ? " NOT NULL" : ""}`;
|
|
50723
|
+
}
|
|
50724
|
+
let def = col.columnType;
|
|
50725
|
+
if (col.collationName) {
|
|
50726
|
+
def += ` COLLATE ${col.collationName}`;
|
|
50727
|
+
}
|
|
50728
|
+
def += notNull ? " NOT NULL" : " NULL";
|
|
50729
|
+
def += defaultClause(col, extra);
|
|
50730
|
+
if (extra.includes("on update current_timestamp")) {
|
|
50731
|
+
def += " ON UPDATE CURRENT_TIMESTAMP";
|
|
50732
|
+
}
|
|
50733
|
+
if (extra.includes("auto_increment")) {
|
|
50734
|
+
def += " AUTO_INCREMENT";
|
|
50735
|
+
}
|
|
50736
|
+
return def;
|
|
50737
|
+
}
|
|
50738
|
+
function defaultClause(col, extra) {
|
|
50739
|
+
if (extra.includes("default_generated")) {
|
|
50740
|
+
const d = col.columnDefault || "";
|
|
50741
|
+
return /^current_timestamp/i.test(d) ? ` DEFAULT ${d}` : ` DEFAULT (${d})`;
|
|
50742
|
+
}
|
|
50743
|
+
if (col.columnDefault === null || col.columnDefault === undefined) {
|
|
50744
|
+
return "";
|
|
50745
|
+
}
|
|
50746
|
+
const d = col.columnDefault;
|
|
50747
|
+
if (d.toUpperCase() === "NULL" || /^-?\d+(\.\d+)?$/.test(d)) {
|
|
50748
|
+
return ` DEFAULT ${d}`;
|
|
50749
|
+
}
|
|
50750
|
+
return ` DEFAULT '${escapeMysqlString(d)}'`;
|
|
50751
|
+
}
|
|
50752
|
+
|
|
50753
|
+
const INTERNAL_SCHEMAS = new Set([
|
|
50754
|
+
"information_schema",
|
|
50755
|
+
"mysql",
|
|
50756
|
+
"performance_schema",
|
|
50757
|
+
"sys"
|
|
50758
|
+
]);
|
|
50759
|
+
class MySqlDbAdapter {
|
|
50760
|
+
constructor(queryExecutor) {
|
|
50761
|
+
this.queryExecutor = queryExecutor;
|
|
50762
|
+
}
|
|
50763
|
+
static async create(credentials, options) {
|
|
50764
|
+
const sslMode = (credentials.sslMode || "").toLowerCase();
|
|
50765
|
+
const ssl = !(options === null || options === void 0 ? void 0 : options.disableSslForTestsOnly) && sslMode && sslMode !== "disable"
|
|
50766
|
+
?
|
|
50767
|
+
{ rejectUnauthorized: false }
|
|
50768
|
+
: undefined;
|
|
50769
|
+
const queryExecutor = new MySqlPoolExecutor({
|
|
50770
|
+
host: credentials.host,
|
|
50771
|
+
port: credentials.port || 3306,
|
|
50772
|
+
user: credentials.user,
|
|
50773
|
+
password: credentials.password,
|
|
50774
|
+
database: credentials.database || undefined,
|
|
50775
|
+
ssl
|
|
50776
|
+
}, options);
|
|
50777
|
+
try {
|
|
50778
|
+
await queryExecutor.verifyConnection();
|
|
50779
|
+
}
|
|
50780
|
+
catch (e) {
|
|
50781
|
+
await queryExecutor.close().catch(() => undefined);
|
|
50782
|
+
throw new ErrorWithCause(`Could not connect to MySQL at ${credentials.host}:${credentials.port || 3306} ` +
|
|
50783
|
+
`as "${credentials.user}": ${e.message}`, e);
|
|
50784
|
+
}
|
|
50785
|
+
return new MySqlDbAdapter(queryExecutor);
|
|
50786
|
+
}
|
|
50787
|
+
async execute(statement, options = { rowLimit: 1000, byteLimit: 1024 * 1024 }) {
|
|
50788
|
+
return await this.withClientLock(client => client.execute(statement, options));
|
|
50789
|
+
}
|
|
50790
|
+
async executeRaw(statement, options = { rowLimit: 1000 }) {
|
|
50791
|
+
const result = await this.execute(statement, options);
|
|
50792
|
+
return Object.assign(Object.assign({}, result), { schema: [] });
|
|
50793
|
+
}
|
|
50794
|
+
async withClientLock(callback) {
|
|
50795
|
+
return await this.queryExecutor.withClientLock(client => callback({
|
|
50796
|
+
execute: async (stmt, opts = { rowLimit: 1000, byteLimit: 1024 * 1024 }) => {
|
|
50797
|
+
try {
|
|
50798
|
+
const rows = await client.execute(stmt, { params: opts.params, rowLimit: opts.rowLimit });
|
|
50799
|
+
return { rows, metadata: {} };
|
|
50800
|
+
}
|
|
50801
|
+
catch (e) {
|
|
50802
|
+
if (opts.includeQueryInError) {
|
|
50803
|
+
throw new Error(`Error encountered while running "${stmt}": ${e.message}`);
|
|
50804
|
+
}
|
|
50805
|
+
throw new ErrorWithCause(`Error executing mysql query: ${e.message}`, e);
|
|
50806
|
+
}
|
|
50807
|
+
},
|
|
50808
|
+
executeRaw: async (stmt, opts = { rowLimit: 1000 }) => {
|
|
50809
|
+
const positional = opts.params ? Object.values(opts.params) : undefined;
|
|
50810
|
+
const rows = await client.execute(stmt, { params: positional, rowLimit: opts.rowLimit });
|
|
50811
|
+
return { rows, schema: [], metadata: {} };
|
|
50812
|
+
}
|
|
50813
|
+
}));
|
|
50814
|
+
}
|
|
50815
|
+
async evaluate(queryOrAction) {
|
|
50816
|
+
const validationQueries = collectEvaluationQueries(queryOrAction, false, (query) => !!query ? `explain ${query}` : "").map((validationQuery, index) => ({ index, validationQuery }));
|
|
50817
|
+
const validationQueriesWithoutWrappers = collectEvaluationQueries(queryOrAction, false);
|
|
50818
|
+
const queryEvaluations = new Array();
|
|
50819
|
+
for (const { index, validationQuery } of validationQueries) {
|
|
50820
|
+
let evaluationResponse = {
|
|
50821
|
+
status: sqlanvil.QueryEvaluation.QueryEvaluationStatus.SUCCESS
|
|
50822
|
+
};
|
|
50823
|
+
try {
|
|
50824
|
+
await this.execute(validationQuery.query);
|
|
50825
|
+
}
|
|
50826
|
+
catch (e) {
|
|
50827
|
+
evaluationResponse = {
|
|
50828
|
+
status: sqlanvil.QueryEvaluation.QueryEvaluationStatus.FAILURE,
|
|
50829
|
+
error: sqlanvil.QueryEvaluationError.create({
|
|
50830
|
+
message: (e === null || e === void 0 ? void 0 : e.message) ? String(e.message) : String(e)
|
|
50831
|
+
})
|
|
50832
|
+
};
|
|
50833
|
+
}
|
|
50834
|
+
queryEvaluations.push(sqlanvil.QueryEvaluation.create(Object.assign(Object.assign({}, evaluationResponse), { incremental: validationQuery.incremental, query: validationQueriesWithoutWrappers[index].query })));
|
|
50835
|
+
}
|
|
50836
|
+
return queryEvaluations;
|
|
50837
|
+
}
|
|
50838
|
+
async tables(_database, schema) {
|
|
50839
|
+
const params = [];
|
|
50840
|
+
let schemaClause = "";
|
|
50841
|
+
if (schema) {
|
|
50842
|
+
schemaClause = "and table_schema = ?";
|
|
50843
|
+
params.push(schema);
|
|
50844
|
+
}
|
|
50845
|
+
const queryResult = await this.execute(`select table_name, table_schema
|
|
50846
|
+
from information_schema.tables
|
|
50847
|
+
where table_schema not in ('information_schema', 'mysql', 'performance_schema', 'sys')
|
|
50848
|
+
${schemaClause}`, { params, rowLimit: 10000, includeQueryInError: true });
|
|
50849
|
+
const targets = queryResult.rows.map(row => ({
|
|
50850
|
+
schema: row.table_schema,
|
|
50851
|
+
name: row.table_name
|
|
50852
|
+
}));
|
|
50853
|
+
return await Promise.all(targets.map(target => this.table(target)));
|
|
50854
|
+
}
|
|
50855
|
+
async search(searchText, options = { limit: 1000 }) {
|
|
50856
|
+
const results = await this.execute(`select tables.table_schema as table_schema, tables.table_name as table_name
|
|
50857
|
+
from information_schema.tables as tables
|
|
50858
|
+
left join information_schema.columns columns
|
|
50859
|
+
on tables.table_schema = columns.table_schema
|
|
50860
|
+
and tables.table_name = columns.table_name
|
|
50861
|
+
where tables.table_schema like ?
|
|
50862
|
+
or tables.table_name like ?
|
|
50863
|
+
or columns.column_name like ?
|
|
50864
|
+
group by 1, 2`, {
|
|
50865
|
+
params: [`%${searchText}%`, `%${searchText}%`, `%${searchText}%`],
|
|
50866
|
+
rowLimit: options.limit
|
|
50867
|
+
});
|
|
50868
|
+
return await Promise.all(results.rows.map(row => this.table({
|
|
50869
|
+
schema: row.table_schema,
|
|
50870
|
+
name: row.table_name
|
|
50871
|
+
})));
|
|
50872
|
+
}
|
|
50873
|
+
async table(target) {
|
|
50874
|
+
var _a, _b, _c;
|
|
50875
|
+
const params = [target.schema, target.name];
|
|
50876
|
+
const [tableResults, columnResults] = await Promise.all([
|
|
50877
|
+
this.execute(`select table_type, table_comment from information_schema.tables
|
|
50878
|
+
where table_schema = ? and table_name = ?`, { params, includeQueryInError: true }),
|
|
50879
|
+
this.execute(`select column_name, data_type, ordinal_position, column_comment
|
|
50880
|
+
from information_schema.columns
|
|
50881
|
+
where table_schema = ? and table_name = ?
|
|
50882
|
+
order by ordinal_position`, { params, includeQueryInError: true })
|
|
50883
|
+
]);
|
|
50884
|
+
if (tableResults.rows.length === 0) {
|
|
50885
|
+
return null;
|
|
50886
|
+
}
|
|
50887
|
+
const tableType = String((_a = tableResults.rows[0].table_type) !== null && _a !== void 0 ? _a : tableResults.rows[0].TABLE_TYPE).toUpperCase();
|
|
50888
|
+
const tableComment = String((_c = (_b = tableResults.rows[0].table_comment) !== null && _b !== void 0 ? _b : tableResults.rows[0].TABLE_COMMENT) !== null && _c !== void 0 ? _c : "");
|
|
50889
|
+
return sqlanvil.TableMetadata.create({
|
|
50890
|
+
target,
|
|
50891
|
+
type: tableType === "VIEW" ? sqlanvil.TableMetadata.Type.VIEW : sqlanvil.TableMetadata.Type.TABLE,
|
|
50892
|
+
description: tableComment || undefined,
|
|
50893
|
+
fields: columnResults.rows.map(row => {
|
|
50894
|
+
var _a, _b, _c, _d;
|
|
50895
|
+
const comment = String((_b = (_a = row.column_comment) !== null && _a !== void 0 ? _a : row.COLUMN_COMMENT) !== null && _b !== void 0 ? _b : "");
|
|
50896
|
+
return sqlanvil.Field.create({
|
|
50897
|
+
name: ((_c = row.column_name) !== null && _c !== void 0 ? _c : row.COLUMN_NAME),
|
|
50898
|
+
primitive: convertFieldType(((_d = row.data_type) !== null && _d !== void 0 ? _d : row.DATA_TYPE)),
|
|
50899
|
+
description: comment || undefined
|
|
50900
|
+
});
|
|
50901
|
+
})
|
|
50902
|
+
});
|
|
50903
|
+
}
|
|
50904
|
+
async deleteTable(target) {
|
|
50905
|
+
const metadata = await this.table(target);
|
|
50906
|
+
if (!metadata) {
|
|
50907
|
+
return;
|
|
50908
|
+
}
|
|
50909
|
+
const kind = metadata.type === sqlanvil.TableMetadata.Type.VIEW ? "view" : "table";
|
|
50910
|
+
await this.execute(`drop ${kind} if exists \`${target.schema}\`.\`${target.name}\``, {
|
|
50911
|
+
includeQueryInError: true
|
|
50912
|
+
});
|
|
50913
|
+
}
|
|
50914
|
+
async schemas(_database) {
|
|
50915
|
+
const result = await this.execute(`select schema_name from information_schema.schemata`, {
|
|
50916
|
+
includeQueryInError: true
|
|
50917
|
+
});
|
|
50918
|
+
return result.rows
|
|
50919
|
+
.map(row => { var _a; return ((_a = row.schema_name) !== null && _a !== void 0 ? _a : row.SCHEMA_NAME); })
|
|
50920
|
+
.filter(name => !INTERNAL_SCHEMAS.has(name));
|
|
50921
|
+
}
|
|
50922
|
+
async createSchema(_database, schema) {
|
|
50923
|
+
await this.execute(`create database if not exists \`${schema}\``, {
|
|
50924
|
+
includeQueryInError: true
|
|
50925
|
+
});
|
|
50926
|
+
}
|
|
50927
|
+
async setMetadata(action) {
|
|
50928
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
50929
|
+
const { target, actionDescriptor } = action;
|
|
50930
|
+
const actualMetadata = await this.table(target);
|
|
50931
|
+
if (!actualMetadata) {
|
|
50932
|
+
return;
|
|
50933
|
+
}
|
|
50934
|
+
if (actualMetadata.type === sqlanvil.TableMetadata.Type.VIEW) {
|
|
50935
|
+
return;
|
|
50936
|
+
}
|
|
50937
|
+
const resolved = `\`${target.schema}\`.\`${target.name}\``;
|
|
50938
|
+
if (actionDescriptor === null || actionDescriptor === void 0 ? void 0 : actionDescriptor.description) {
|
|
50939
|
+
await this.execute(`alter table ${resolved} comment = '${escapeMysqlString(actionDescriptor.description)}'`, { includeQueryInError: true });
|
|
50940
|
+
}
|
|
50941
|
+
const columnComments = ((actionDescriptor === null || actionDescriptor === void 0 ? void 0 : actionDescriptor.columns) || []).filter(column => {
|
|
50942
|
+
var _a;
|
|
50943
|
+
return ((_a = column.path) === null || _a === void 0 ? void 0 : _a.length) === 1 &&
|
|
50944
|
+
column.description != null &&
|
|
50945
|
+
actualMetadata.fields.some(f => f.name === column.path[0]);
|
|
50946
|
+
});
|
|
50947
|
+
if (columnComments.length === 0) {
|
|
50948
|
+
return;
|
|
50949
|
+
}
|
|
50950
|
+
const defResult = await this.execute(`select column_name, column_type, is_nullable, column_default, extra,
|
|
50951
|
+
collation_name, generation_expression
|
|
50952
|
+
from information_schema.columns
|
|
50953
|
+
where table_schema = ? and table_name = ?`, { params: [target.schema, target.name], includeQueryInError: true });
|
|
50954
|
+
const defByName = new Map();
|
|
50955
|
+
defResult.rows.forEach(row => { var _a; return defByName.set(String((_a = row.column_name) !== null && _a !== void 0 ? _a : row.COLUMN_NAME), row); });
|
|
50956
|
+
for (const column of columnComments) {
|
|
50957
|
+
const name = column.path[0];
|
|
50958
|
+
const row = defByName.get(name);
|
|
50959
|
+
if (!row) {
|
|
50960
|
+
continue;
|
|
50961
|
+
}
|
|
50962
|
+
const def = reconstructColumnDef({
|
|
50963
|
+
columnType: String((_a = row.column_type) !== null && _a !== void 0 ? _a : row.COLUMN_TYPE),
|
|
50964
|
+
isNullable: String((_b = row.is_nullable) !== null && _b !== void 0 ? _b : row.IS_NULLABLE),
|
|
50965
|
+
columnDefault: ((_d = (_c = row.column_default) !== null && _c !== void 0 ? _c : row.COLUMN_DEFAULT) !== null && _d !== void 0 ? _d : null) === null
|
|
50966
|
+
? null
|
|
50967
|
+
: String((_e = row.column_default) !== null && _e !== void 0 ? _e : row.COLUMN_DEFAULT),
|
|
50968
|
+
extra: String((_g = (_f = row.extra) !== null && _f !== void 0 ? _f : row.EXTRA) !== null && _g !== void 0 ? _g : ""),
|
|
50969
|
+
collationName: ((_j = (_h = row.collation_name) !== null && _h !== void 0 ? _h : row.COLLATION_NAME) !== null && _j !== void 0 ? _j : null) === null
|
|
50970
|
+
? null
|
|
50971
|
+
: String((_k = row.collation_name) !== null && _k !== void 0 ? _k : row.COLLATION_NAME),
|
|
50972
|
+
generationExpression: ((_m = (_l = row.generation_expression) !== null && _l !== void 0 ? _l : row.GENERATION_EXPRESSION) !== null && _m !== void 0 ? _m : null) === null
|
|
50973
|
+
? null
|
|
50974
|
+
: String((_o = row.generation_expression) !== null && _o !== void 0 ? _o : row.GENERATION_EXPRESSION)
|
|
50427
50975
|
});
|
|
50976
|
+
await this.execute(`alter table ${resolved} modify column \`${name}\` ${def} comment '${escapeMysqlString(column.description)}'`, { includeQueryInError: true });
|
|
50428
50977
|
}
|
|
50429
|
-
|
|
50978
|
+
}
|
|
50979
|
+
async close() {
|
|
50980
|
+
await this.queryExecutor.close();
|
|
50981
|
+
}
|
|
50982
|
+
}
|
|
50983
|
+
|
|
50984
|
+
const DEFAULT_ROW_CAP = 1000000;
|
|
50985
|
+
const DEFAULT_BYTE_CAP = 512 * 1024 * 1024;
|
|
50986
|
+
const backquote = (id) => "`" + String(id).replace(/`/g, "``") + "`";
|
|
50987
|
+
async function runMysqlExtract(args) {
|
|
50988
|
+
var _a, _b;
|
|
50989
|
+
const { spec, target, connectionCredentials } = args;
|
|
50990
|
+
if (spec.platform !== "mysql") {
|
|
50991
|
+
throw new Error(`mysql runner-extract got a "${spec.platform}" source.`);
|
|
50992
|
+
}
|
|
50993
|
+
const cols = Object.keys(spec.columnTypes || {});
|
|
50994
|
+
if (cols.length === 0) {
|
|
50995
|
+
throw new Error(`Extract "${target.schema}.${target.name}" has no columnTypes; run \`sqlanvil introspect\`.`);
|
|
50996
|
+
}
|
|
50997
|
+
if (!args.pg) {
|
|
50998
|
+
throw new Error("runner-extract needs the write-warehouse connection (warehouseConnection).");
|
|
50999
|
+
}
|
|
51000
|
+
const conn = (connectionCredentials === null || connectionCredentials === void 0 ? void 0 : connectionCredentials[spec.connectionName]) || {};
|
|
51001
|
+
const database = spec.database || conn.database;
|
|
51002
|
+
if (!database) {
|
|
51003
|
+
throw new Error(`Extract "${target.schema}.${target.name}": no source database — set \`database:\` on ` +
|
|
51004
|
+
`connection "${spec.connectionName}" (workflow_settings.yaml) or \`schema:\` on the declaration.`);
|
|
51005
|
+
}
|
|
51006
|
+
if (!conn.host && !conn.user) {
|
|
51007
|
+
throw new Error(`No credentials for connection "${spec.connectionName}" — add it to .df-credentials.json's ` +
|
|
51008
|
+
`"connections" map ({ host, port, user, password }).`);
|
|
51009
|
+
}
|
|
51010
|
+
const rowCap = (_a = args.rowCap) !== null && _a !== void 0 ? _a : DEFAULT_ROW_CAP;
|
|
51011
|
+
const byteCap = (_b = args.byteCap) !== null && _b !== void 0 ? _b : DEFAULT_BYTE_CAP;
|
|
51012
|
+
const my = await MySqlDbAdapter.create(sqlanvil.MysqlConnection.create({
|
|
51013
|
+
host: conn.host,
|
|
51014
|
+
port: conn.port || 3306,
|
|
51015
|
+
user: conn.user,
|
|
51016
|
+
password: conn.password,
|
|
51017
|
+
database,
|
|
51018
|
+
sslMode: conn.sslMode
|
|
51019
|
+
}), { disableSslForTestsOnly: args.disableSslForTestsOnly });
|
|
51020
|
+
let rows;
|
|
51021
|
+
try {
|
|
51022
|
+
const colList = cols.map(backquote).join(", ");
|
|
51023
|
+
const source = `${backquote(database)}.${backquote(spec.sourceName)}`;
|
|
51024
|
+
({ rows } = await my.execute(`select ${colList} from ${source} limit ${rowCap + 1}`, {
|
|
51025
|
+
rowLimit: rowCap + 1,
|
|
51026
|
+
byteLimit: byteCap
|
|
51027
|
+
}));
|
|
50430
51028
|
}
|
|
50431
51029
|
finally {
|
|
50432
|
-
await
|
|
51030
|
+
await my.close().catch(() => undefined);
|
|
50433
51031
|
}
|
|
51032
|
+
if (rows.length > rowCap) {
|
|
51033
|
+
rows = rows.slice(0, rowCap);
|
|
51034
|
+
console.warn(`runner-extract: ${target.schema}.${target.name} truncated at ${rowCap} rows (source is larger).`);
|
|
51035
|
+
}
|
|
51036
|
+
await loadRowsIntoPostgres({
|
|
51037
|
+
pg: args.pg,
|
|
51038
|
+
target,
|
|
51039
|
+
columnTypes: spec.columnTypes,
|
|
51040
|
+
rows,
|
|
51041
|
+
disableSslForTestsOnly: args.disableSslForTestsOnly
|
|
51042
|
+
});
|
|
51043
|
+
return { rowCount: rows.length };
|
|
50434
51044
|
}
|
|
50435
51045
|
|
|
50436
51046
|
function loadDuckdb() {
|
|
@@ -50987,7 +51597,7 @@ class Runner {
|
|
|
50987
51597
|
return actionResult;
|
|
50988
51598
|
}
|
|
50989
51599
|
async executeTask(client, task, parentAction, options, action) {
|
|
50990
|
-
var _a, _b, _c, _d, _e;
|
|
51600
|
+
var _a, _b, _c, _d, _e, _f;
|
|
50991
51601
|
const timer = Timer.start();
|
|
50992
51602
|
const taskResult = {
|
|
50993
51603
|
status: sqlanvil.TaskResult.ExecutionStatus.RUNNING,
|
|
@@ -51038,7 +51648,9 @@ class Runner {
|
|
|
51038
51648
|
}
|
|
51039
51649
|
else if (task.type === "extract") {
|
|
51040
51650
|
try {
|
|
51041
|
-
const extractor =
|
|
51651
|
+
const extractor = ((_c = action === null || action === void 0 ? void 0 : action.extract) === null || _c === void 0 ? void 0 : _c.platform) === "mysql"
|
|
51652
|
+
? this.executionOptions.mysqlExtract || runMysqlExtract
|
|
51653
|
+
: this.executionOptions.bigQueryExtract || runBigQueryExtract;
|
|
51042
51654
|
await extractor({
|
|
51043
51655
|
spec: action === null || action === void 0 ? void 0 : action.extract,
|
|
51044
51656
|
target: action === null || action === void 0 ? void 0 : action.target,
|
|
@@ -51066,7 +51678,7 @@ class Runner {
|
|
|
51066
51678
|
}), task.type === "operation" ? 1 : options.bigquery.actionRetryLimit + 1 || 1);
|
|
51067
51679
|
taskResult.metadata = metadata;
|
|
51068
51680
|
if (task.type === "assertion") {
|
|
51069
|
-
const rowCount = (
|
|
51681
|
+
const rowCount = (_d = rows[0]) === null || _d === void 0 ? void 0 : _d[Object.keys(rows[0])[0]];
|
|
51070
51682
|
if (rowCount > 0) {
|
|
51071
51683
|
throw new Error(`Assertion failed: query returned ${rowCount} row(s).`);
|
|
51072
51684
|
}
|
|
@@ -51078,7 +51690,7 @@ class Runner {
|
|
|
51078
51690
|
? sqlanvil.TaskResult.ExecutionStatus.CANCELLED
|
|
51079
51691
|
: sqlanvil.TaskResult.ExecutionStatus.FAILED;
|
|
51080
51692
|
taskResult.errorMessage = `${this.graph.projectConfig.warehouse} error: ${e.message}`;
|
|
51081
|
-
if ((
|
|
51693
|
+
if ((_f = (_e = e.metadata) === null || _e === void 0 ? void 0 : _e.bigquery) === null || _f === void 0 ? void 0 : _f.jobId) {
|
|
51082
51694
|
taskResult.metadata = {
|
|
51083
51695
|
bigquery: {
|
|
51084
51696
|
jobId: e.metadata.bigquery.jobId
|
|
@@ -51785,361 +52397,6 @@ async function validate(compiledGraph, deps, options = {}) {
|
|
|
51785
52397
|
return results;
|
|
51786
52398
|
}
|
|
51787
52399
|
|
|
51788
|
-
class MySqlPoolExecutor {
|
|
51789
|
-
constructor(config, options) {
|
|
51790
|
-
this.pool = mysql__namespace.createPool(Object.assign(Object.assign({}, config), { connectionLimit: (options === null || options === void 0 ? void 0 : options.concurrencyLimit) || 10, waitForConnections: true, multipleStatements: false }));
|
|
51791
|
-
}
|
|
51792
|
-
async verifyConnection() {
|
|
51793
|
-
const conn = await this.pool.getConnection();
|
|
51794
|
-
try {
|
|
51795
|
-
await conn.query("select 1");
|
|
51796
|
-
}
|
|
51797
|
-
finally {
|
|
51798
|
-
conn.release();
|
|
51799
|
-
}
|
|
51800
|
-
}
|
|
51801
|
-
async withClientLock(callback) {
|
|
51802
|
-
const conn = await this.pool.getConnection();
|
|
51803
|
-
let released = false;
|
|
51804
|
-
const releaseOnce = () => {
|
|
51805
|
-
if (released) {
|
|
51806
|
-
return;
|
|
51807
|
-
}
|
|
51808
|
-
released = true;
|
|
51809
|
-
conn.release();
|
|
51810
|
-
};
|
|
51811
|
-
try {
|
|
51812
|
-
return await callback({
|
|
51813
|
-
execute: async (statement, options = { rowLimit: 1000 }) => {
|
|
51814
|
-
const [rows] = await conn.query(statement, options.params || []);
|
|
51815
|
-
const arr = Array.isArray(rows) ? rows : [];
|
|
51816
|
-
return options.rowLimit && arr.length > options.rowLimit
|
|
51817
|
-
? arr.slice(0, options.rowLimit)
|
|
51818
|
-
: arr;
|
|
51819
|
-
}
|
|
51820
|
-
});
|
|
51821
|
-
}
|
|
51822
|
-
finally {
|
|
51823
|
-
releaseOnce();
|
|
51824
|
-
}
|
|
51825
|
-
}
|
|
51826
|
-
async close() {
|
|
51827
|
-
await this.pool.end();
|
|
51828
|
-
}
|
|
51829
|
-
}
|
|
51830
|
-
function convertFieldType(type) {
|
|
51831
|
-
switch (String(type).toUpperCase()) {
|
|
51832
|
-
case "FLOAT":
|
|
51833
|
-
case "DOUBLE":
|
|
51834
|
-
case "REAL":
|
|
51835
|
-
return sqlanvil.Field.Primitive.FLOAT;
|
|
51836
|
-
case "TINYINT":
|
|
51837
|
-
case "SMALLINT":
|
|
51838
|
-
case "MEDIUMINT":
|
|
51839
|
-
case "INT":
|
|
51840
|
-
case "INTEGER":
|
|
51841
|
-
case "BIGINT":
|
|
51842
|
-
case "YEAR":
|
|
51843
|
-
case "BIT":
|
|
51844
|
-
return sqlanvil.Field.Primitive.INTEGER;
|
|
51845
|
-
case "DECIMAL":
|
|
51846
|
-
case "DEC":
|
|
51847
|
-
case "NUMERIC":
|
|
51848
|
-
case "FIXED":
|
|
51849
|
-
return sqlanvil.Field.Primitive.NUMERIC;
|
|
51850
|
-
case "BOOL":
|
|
51851
|
-
case "BOOLEAN":
|
|
51852
|
-
return sqlanvil.Field.Primitive.BOOLEAN;
|
|
51853
|
-
case "CHAR":
|
|
51854
|
-
case "VARCHAR":
|
|
51855
|
-
case "TINYTEXT":
|
|
51856
|
-
case "TEXT":
|
|
51857
|
-
case "MEDIUMTEXT":
|
|
51858
|
-
case "LONGTEXT":
|
|
51859
|
-
case "ENUM":
|
|
51860
|
-
case "SET":
|
|
51861
|
-
case "JSON":
|
|
51862
|
-
case "TIME":
|
|
51863
|
-
return sqlanvil.Field.Primitive.STRING;
|
|
51864
|
-
case "DATE":
|
|
51865
|
-
return sqlanvil.Field.Primitive.DATE;
|
|
51866
|
-
case "DATETIME":
|
|
51867
|
-
case "TIMESTAMP":
|
|
51868
|
-
return sqlanvil.Field.Primitive.TIMESTAMP;
|
|
51869
|
-
default:
|
|
51870
|
-
return sqlanvil.Field.Primitive.UNKNOWN;
|
|
51871
|
-
}
|
|
51872
|
-
}
|
|
51873
|
-
function escapeMysqlString(s) {
|
|
51874
|
-
return s.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
51875
|
-
}
|
|
51876
|
-
function reconstructColumnDef(col) {
|
|
51877
|
-
const extra = (col.extra || "").toLowerCase();
|
|
51878
|
-
const notNull = col.isNullable === "NO";
|
|
51879
|
-
if (extra.includes("generated") && col.generationExpression) {
|
|
51880
|
-
const storage = extra.includes("stored") ? "STORED" : "VIRTUAL";
|
|
51881
|
-
return `${col.columnType} GENERATED ALWAYS AS (${col.generationExpression}) ${storage}${notNull ? " NOT NULL" : ""}`;
|
|
51882
|
-
}
|
|
51883
|
-
let def = col.columnType;
|
|
51884
|
-
if (col.collationName) {
|
|
51885
|
-
def += ` COLLATE ${col.collationName}`;
|
|
51886
|
-
}
|
|
51887
|
-
def += notNull ? " NOT NULL" : " NULL";
|
|
51888
|
-
def += defaultClause(col, extra);
|
|
51889
|
-
if (extra.includes("on update current_timestamp")) {
|
|
51890
|
-
def += " ON UPDATE CURRENT_TIMESTAMP";
|
|
51891
|
-
}
|
|
51892
|
-
if (extra.includes("auto_increment")) {
|
|
51893
|
-
def += " AUTO_INCREMENT";
|
|
51894
|
-
}
|
|
51895
|
-
return def;
|
|
51896
|
-
}
|
|
51897
|
-
function defaultClause(col, extra) {
|
|
51898
|
-
if (extra.includes("default_generated")) {
|
|
51899
|
-
const d = col.columnDefault || "";
|
|
51900
|
-
return /^current_timestamp/i.test(d) ? ` DEFAULT ${d}` : ` DEFAULT (${d})`;
|
|
51901
|
-
}
|
|
51902
|
-
if (col.columnDefault === null || col.columnDefault === undefined) {
|
|
51903
|
-
return "";
|
|
51904
|
-
}
|
|
51905
|
-
const d = col.columnDefault;
|
|
51906
|
-
if (d.toUpperCase() === "NULL" || /^-?\d+(\.\d+)?$/.test(d)) {
|
|
51907
|
-
return ` DEFAULT ${d}`;
|
|
51908
|
-
}
|
|
51909
|
-
return ` DEFAULT '${escapeMysqlString(d)}'`;
|
|
51910
|
-
}
|
|
51911
|
-
|
|
51912
|
-
const INTERNAL_SCHEMAS = new Set([
|
|
51913
|
-
"information_schema",
|
|
51914
|
-
"mysql",
|
|
51915
|
-
"performance_schema",
|
|
51916
|
-
"sys"
|
|
51917
|
-
]);
|
|
51918
|
-
class MySqlDbAdapter {
|
|
51919
|
-
constructor(queryExecutor) {
|
|
51920
|
-
this.queryExecutor = queryExecutor;
|
|
51921
|
-
}
|
|
51922
|
-
static async create(credentials, options) {
|
|
51923
|
-
const sslMode = (credentials.sslMode || "").toLowerCase();
|
|
51924
|
-
const ssl = !(options === null || options === void 0 ? void 0 : options.disableSslForTestsOnly) && sslMode && sslMode !== "disable"
|
|
51925
|
-
?
|
|
51926
|
-
{ rejectUnauthorized: false }
|
|
51927
|
-
: undefined;
|
|
51928
|
-
const queryExecutor = new MySqlPoolExecutor({
|
|
51929
|
-
host: credentials.host,
|
|
51930
|
-
port: credentials.port || 3306,
|
|
51931
|
-
user: credentials.user,
|
|
51932
|
-
password: credentials.password,
|
|
51933
|
-
database: credentials.database || undefined,
|
|
51934
|
-
ssl
|
|
51935
|
-
}, options);
|
|
51936
|
-
try {
|
|
51937
|
-
await queryExecutor.verifyConnection();
|
|
51938
|
-
}
|
|
51939
|
-
catch (e) {
|
|
51940
|
-
await queryExecutor.close().catch(() => undefined);
|
|
51941
|
-
throw new ErrorWithCause(`Could not connect to MySQL at ${credentials.host}:${credentials.port || 3306} ` +
|
|
51942
|
-
`as "${credentials.user}": ${e.message}`, e);
|
|
51943
|
-
}
|
|
51944
|
-
return new MySqlDbAdapter(queryExecutor);
|
|
51945
|
-
}
|
|
51946
|
-
async execute(statement, options = { rowLimit: 1000, byteLimit: 1024 * 1024 }) {
|
|
51947
|
-
return await this.withClientLock(client => client.execute(statement, options));
|
|
51948
|
-
}
|
|
51949
|
-
async executeRaw(statement, options = { rowLimit: 1000 }) {
|
|
51950
|
-
const result = await this.execute(statement, options);
|
|
51951
|
-
return Object.assign(Object.assign({}, result), { schema: [] });
|
|
51952
|
-
}
|
|
51953
|
-
async withClientLock(callback) {
|
|
51954
|
-
return await this.queryExecutor.withClientLock(client => callback({
|
|
51955
|
-
execute: async (stmt, opts = { rowLimit: 1000, byteLimit: 1024 * 1024 }) => {
|
|
51956
|
-
try {
|
|
51957
|
-
const rows = await client.execute(stmt, { params: opts.params, rowLimit: opts.rowLimit });
|
|
51958
|
-
return { rows, metadata: {} };
|
|
51959
|
-
}
|
|
51960
|
-
catch (e) {
|
|
51961
|
-
if (opts.includeQueryInError) {
|
|
51962
|
-
throw new Error(`Error encountered while running "${stmt}": ${e.message}`);
|
|
51963
|
-
}
|
|
51964
|
-
throw new ErrorWithCause(`Error executing mysql query: ${e.message}`, e);
|
|
51965
|
-
}
|
|
51966
|
-
},
|
|
51967
|
-
executeRaw: async (stmt, opts = { rowLimit: 1000 }) => {
|
|
51968
|
-
const positional = opts.params ? Object.values(opts.params) : undefined;
|
|
51969
|
-
const rows = await client.execute(stmt, { params: positional, rowLimit: opts.rowLimit });
|
|
51970
|
-
return { rows, schema: [], metadata: {} };
|
|
51971
|
-
}
|
|
51972
|
-
}));
|
|
51973
|
-
}
|
|
51974
|
-
async evaluate(queryOrAction) {
|
|
51975
|
-
const validationQueries = collectEvaluationQueries(queryOrAction, false, (query) => !!query ? `explain ${query}` : "").map((validationQuery, index) => ({ index, validationQuery }));
|
|
51976
|
-
const validationQueriesWithoutWrappers = collectEvaluationQueries(queryOrAction, false);
|
|
51977
|
-
const queryEvaluations = new Array();
|
|
51978
|
-
for (const { index, validationQuery } of validationQueries) {
|
|
51979
|
-
let evaluationResponse = {
|
|
51980
|
-
status: sqlanvil.QueryEvaluation.QueryEvaluationStatus.SUCCESS
|
|
51981
|
-
};
|
|
51982
|
-
try {
|
|
51983
|
-
await this.execute(validationQuery.query);
|
|
51984
|
-
}
|
|
51985
|
-
catch (e) {
|
|
51986
|
-
evaluationResponse = {
|
|
51987
|
-
status: sqlanvil.QueryEvaluation.QueryEvaluationStatus.FAILURE,
|
|
51988
|
-
error: sqlanvil.QueryEvaluationError.create({
|
|
51989
|
-
message: (e === null || e === void 0 ? void 0 : e.message) ? String(e.message) : String(e)
|
|
51990
|
-
})
|
|
51991
|
-
};
|
|
51992
|
-
}
|
|
51993
|
-
queryEvaluations.push(sqlanvil.QueryEvaluation.create(Object.assign(Object.assign({}, evaluationResponse), { incremental: validationQuery.incremental, query: validationQueriesWithoutWrappers[index].query })));
|
|
51994
|
-
}
|
|
51995
|
-
return queryEvaluations;
|
|
51996
|
-
}
|
|
51997
|
-
async tables(_database, schema) {
|
|
51998
|
-
const params = [];
|
|
51999
|
-
let schemaClause = "";
|
|
52000
|
-
if (schema) {
|
|
52001
|
-
schemaClause = "and table_schema = ?";
|
|
52002
|
-
params.push(schema);
|
|
52003
|
-
}
|
|
52004
|
-
const queryResult = await this.execute(`select table_name, table_schema
|
|
52005
|
-
from information_schema.tables
|
|
52006
|
-
where table_schema not in ('information_schema', 'mysql', 'performance_schema', 'sys')
|
|
52007
|
-
${schemaClause}`, { params, rowLimit: 10000, includeQueryInError: true });
|
|
52008
|
-
const targets = queryResult.rows.map(row => ({
|
|
52009
|
-
schema: row.table_schema,
|
|
52010
|
-
name: row.table_name
|
|
52011
|
-
}));
|
|
52012
|
-
return await Promise.all(targets.map(target => this.table(target)));
|
|
52013
|
-
}
|
|
52014
|
-
async search(searchText, options = { limit: 1000 }) {
|
|
52015
|
-
const results = await this.execute(`select tables.table_schema as table_schema, tables.table_name as table_name
|
|
52016
|
-
from information_schema.tables as tables
|
|
52017
|
-
left join information_schema.columns columns
|
|
52018
|
-
on tables.table_schema = columns.table_schema
|
|
52019
|
-
and tables.table_name = columns.table_name
|
|
52020
|
-
where tables.table_schema like ?
|
|
52021
|
-
or tables.table_name like ?
|
|
52022
|
-
or columns.column_name like ?
|
|
52023
|
-
group by 1, 2`, {
|
|
52024
|
-
params: [`%${searchText}%`, `%${searchText}%`, `%${searchText}%`],
|
|
52025
|
-
rowLimit: options.limit
|
|
52026
|
-
});
|
|
52027
|
-
return await Promise.all(results.rows.map(row => this.table({
|
|
52028
|
-
schema: row.table_schema,
|
|
52029
|
-
name: row.table_name
|
|
52030
|
-
})));
|
|
52031
|
-
}
|
|
52032
|
-
async table(target) {
|
|
52033
|
-
var _a, _b, _c;
|
|
52034
|
-
const params = [target.schema, target.name];
|
|
52035
|
-
const [tableResults, columnResults] = await Promise.all([
|
|
52036
|
-
this.execute(`select table_type, table_comment from information_schema.tables
|
|
52037
|
-
where table_schema = ? and table_name = ?`, { params, includeQueryInError: true }),
|
|
52038
|
-
this.execute(`select column_name, data_type, ordinal_position, column_comment
|
|
52039
|
-
from information_schema.columns
|
|
52040
|
-
where table_schema = ? and table_name = ?
|
|
52041
|
-
order by ordinal_position`, { params, includeQueryInError: true })
|
|
52042
|
-
]);
|
|
52043
|
-
if (tableResults.rows.length === 0) {
|
|
52044
|
-
return null;
|
|
52045
|
-
}
|
|
52046
|
-
const tableType = String((_a = tableResults.rows[0].table_type) !== null && _a !== void 0 ? _a : tableResults.rows[0].TABLE_TYPE).toUpperCase();
|
|
52047
|
-
const tableComment = String((_c = (_b = tableResults.rows[0].table_comment) !== null && _b !== void 0 ? _b : tableResults.rows[0].TABLE_COMMENT) !== null && _c !== void 0 ? _c : "");
|
|
52048
|
-
return sqlanvil.TableMetadata.create({
|
|
52049
|
-
target,
|
|
52050
|
-
type: tableType === "VIEW" ? sqlanvil.TableMetadata.Type.VIEW : sqlanvil.TableMetadata.Type.TABLE,
|
|
52051
|
-
description: tableComment || undefined,
|
|
52052
|
-
fields: columnResults.rows.map(row => {
|
|
52053
|
-
var _a, _b, _c, _d;
|
|
52054
|
-
const comment = String((_b = (_a = row.column_comment) !== null && _a !== void 0 ? _a : row.COLUMN_COMMENT) !== null && _b !== void 0 ? _b : "");
|
|
52055
|
-
return sqlanvil.Field.create({
|
|
52056
|
-
name: ((_c = row.column_name) !== null && _c !== void 0 ? _c : row.COLUMN_NAME),
|
|
52057
|
-
primitive: convertFieldType(((_d = row.data_type) !== null && _d !== void 0 ? _d : row.DATA_TYPE)),
|
|
52058
|
-
description: comment || undefined
|
|
52059
|
-
});
|
|
52060
|
-
})
|
|
52061
|
-
});
|
|
52062
|
-
}
|
|
52063
|
-
async deleteTable(target) {
|
|
52064
|
-
const metadata = await this.table(target);
|
|
52065
|
-
if (!metadata) {
|
|
52066
|
-
return;
|
|
52067
|
-
}
|
|
52068
|
-
const kind = metadata.type === sqlanvil.TableMetadata.Type.VIEW ? "view" : "table";
|
|
52069
|
-
await this.execute(`drop ${kind} if exists \`${target.schema}\`.\`${target.name}\``, {
|
|
52070
|
-
includeQueryInError: true
|
|
52071
|
-
});
|
|
52072
|
-
}
|
|
52073
|
-
async schemas(_database) {
|
|
52074
|
-
const result = await this.execute(`select schema_name from information_schema.schemata`, {
|
|
52075
|
-
includeQueryInError: true
|
|
52076
|
-
});
|
|
52077
|
-
return result.rows
|
|
52078
|
-
.map(row => { var _a; return ((_a = row.schema_name) !== null && _a !== void 0 ? _a : row.SCHEMA_NAME); })
|
|
52079
|
-
.filter(name => !INTERNAL_SCHEMAS.has(name));
|
|
52080
|
-
}
|
|
52081
|
-
async createSchema(_database, schema) {
|
|
52082
|
-
await this.execute(`create database if not exists \`${schema}\``, {
|
|
52083
|
-
includeQueryInError: true
|
|
52084
|
-
});
|
|
52085
|
-
}
|
|
52086
|
-
async setMetadata(action) {
|
|
52087
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
52088
|
-
const { target, actionDescriptor } = action;
|
|
52089
|
-
const actualMetadata = await this.table(target);
|
|
52090
|
-
if (!actualMetadata) {
|
|
52091
|
-
return;
|
|
52092
|
-
}
|
|
52093
|
-
if (actualMetadata.type === sqlanvil.TableMetadata.Type.VIEW) {
|
|
52094
|
-
return;
|
|
52095
|
-
}
|
|
52096
|
-
const resolved = `\`${target.schema}\`.\`${target.name}\``;
|
|
52097
|
-
if (actionDescriptor === null || actionDescriptor === void 0 ? void 0 : actionDescriptor.description) {
|
|
52098
|
-
await this.execute(`alter table ${resolved} comment = '${escapeMysqlString(actionDescriptor.description)}'`, { includeQueryInError: true });
|
|
52099
|
-
}
|
|
52100
|
-
const columnComments = ((actionDescriptor === null || actionDescriptor === void 0 ? void 0 : actionDescriptor.columns) || []).filter(column => {
|
|
52101
|
-
var _a;
|
|
52102
|
-
return ((_a = column.path) === null || _a === void 0 ? void 0 : _a.length) === 1 &&
|
|
52103
|
-
column.description != null &&
|
|
52104
|
-
actualMetadata.fields.some(f => f.name === column.path[0]);
|
|
52105
|
-
});
|
|
52106
|
-
if (columnComments.length === 0) {
|
|
52107
|
-
return;
|
|
52108
|
-
}
|
|
52109
|
-
const defResult = await this.execute(`select column_name, column_type, is_nullable, column_default, extra,
|
|
52110
|
-
collation_name, generation_expression
|
|
52111
|
-
from information_schema.columns
|
|
52112
|
-
where table_schema = ? and table_name = ?`, { params: [target.schema, target.name], includeQueryInError: true });
|
|
52113
|
-
const defByName = new Map();
|
|
52114
|
-
defResult.rows.forEach(row => { var _a; return defByName.set(String((_a = row.column_name) !== null && _a !== void 0 ? _a : row.COLUMN_NAME), row); });
|
|
52115
|
-
for (const column of columnComments) {
|
|
52116
|
-
const name = column.path[0];
|
|
52117
|
-
const row = defByName.get(name);
|
|
52118
|
-
if (!row) {
|
|
52119
|
-
continue;
|
|
52120
|
-
}
|
|
52121
|
-
const def = reconstructColumnDef({
|
|
52122
|
-
columnType: String((_a = row.column_type) !== null && _a !== void 0 ? _a : row.COLUMN_TYPE),
|
|
52123
|
-
isNullable: String((_b = row.is_nullable) !== null && _b !== void 0 ? _b : row.IS_NULLABLE),
|
|
52124
|
-
columnDefault: ((_d = (_c = row.column_default) !== null && _c !== void 0 ? _c : row.COLUMN_DEFAULT) !== null && _d !== void 0 ? _d : null) === null
|
|
52125
|
-
? null
|
|
52126
|
-
: String((_e = row.column_default) !== null && _e !== void 0 ? _e : row.COLUMN_DEFAULT),
|
|
52127
|
-
extra: String((_g = (_f = row.extra) !== null && _f !== void 0 ? _f : row.EXTRA) !== null && _g !== void 0 ? _g : ""),
|
|
52128
|
-
collationName: ((_j = (_h = row.collation_name) !== null && _h !== void 0 ? _h : row.COLLATION_NAME) !== null && _j !== void 0 ? _j : null) === null
|
|
52129
|
-
? null
|
|
52130
|
-
: String((_k = row.collation_name) !== null && _k !== void 0 ? _k : row.COLLATION_NAME),
|
|
52131
|
-
generationExpression: ((_m = (_l = row.generation_expression) !== null && _l !== void 0 ? _l : row.GENERATION_EXPRESSION) !== null && _m !== void 0 ? _m : null) === null
|
|
52132
|
-
? null
|
|
52133
|
-
: String((_o = row.generation_expression) !== null && _o !== void 0 ? _o : row.GENERATION_EXPRESSION)
|
|
52134
|
-
});
|
|
52135
|
-
await this.execute(`alter table ${resolved} modify column \`${name}\` ${def} comment '${escapeMysqlString(column.description)}'`, { includeQueryInError: true });
|
|
52136
|
-
}
|
|
52137
|
-
}
|
|
52138
|
-
async close() {
|
|
52139
|
-
await this.queryExecutor.close();
|
|
52140
|
-
}
|
|
52141
|
-
}
|
|
52142
|
-
|
|
52143
52400
|
class SupabaseDbAdapter extends PostgresDbAdapter {
|
|
52144
52401
|
static async create(credentials, options) {
|
|
52145
52402
|
const sslMode = (credentials.sslMode || "").toLowerCase();
|