drizzle-seed 1.0.0-beta.2-278d7e6 → 1.0.0-beta.2-31baa2b
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/SeedService.d.cts +3 -12
- package/SeedService.d.mts +3 -12
- package/SeedService.d.ts +3 -12
- package/cockroach-core/index.d.cts +2 -2
- package/cockroach-core/index.d.mts +2 -2
- package/cockroach-core/index.d.ts +2 -2
- package/cockroach-core/selectGensForColumn.d.cts +3 -3
- package/cockroach-core/selectGensForColumn.d.mts +3 -3
- package/cockroach-core/selectGensForColumn.d.ts +3 -3
- package/common.d.cts +1 -1
- package/common.d.mts +1 -1
- package/common.d.ts +1 -1
- package/generators/GeneratorFuncs.d.cts +20 -950
- package/generators/GeneratorFuncs.d.mts +20 -950
- package/generators/GeneratorFuncs.d.ts +20 -950
- package/generators/Generators.d.cts +2 -29
- package/generators/Generators.d.mts +2 -29
- package/generators/Generators.d.ts +2 -29
- package/generators/apiVersion.d.cts +1 -1
- package/generators/apiVersion.d.mts +1 -1
- package/generators/apiVersion.d.ts +1 -1
- package/generators/utils.d.cts +0 -1
- package/generators/utils.d.mts +0 -1
- package/generators/utils.d.ts +0 -1
- package/generators/versioning/v2.d.cts +1 -1
- package/generators/versioning/v2.d.mts +1 -1
- package/generators/versioning/v2.d.ts +1 -1
- package/generators/versioning/v3.d.cts +1 -1
- package/generators/versioning/v3.d.mts +1 -1
- package/generators/versioning/v3.d.ts +1 -1
- package/index.cjs +26 -286
- package/index.cjs.map +1 -1
- package/index.d.cts +47 -68
- package/index.d.mts +47 -68
- package/index.d.ts +47 -68
- package/index.mjs +28 -288
- package/index.mjs.map +1 -1
- package/mssql-core/index.d.cts +1 -1
- package/mssql-core/index.d.mts +1 -1
- package/mssql-core/index.d.ts +1 -1
- package/mssql-core/selectGensForColumn.d.cts +2 -2
- package/mssql-core/selectGensForColumn.d.mts +2 -2
- package/mssql-core/selectGensForColumn.d.ts +2 -2
- package/mysql-core/index.d.cts +2 -2
- package/mysql-core/index.d.mts +2 -2
- package/mysql-core/index.d.ts +2 -2
- package/mysql-core/selectGensForColumn.d.cts +2 -2
- package/mysql-core/selectGensForColumn.d.mts +2 -2
- package/mysql-core/selectGensForColumn.d.ts +2 -2
- package/package.json +3 -5
- package/pg-core/index.d.cts +2 -2
- package/pg-core/index.d.mts +2 -2
- package/pg-core/index.d.ts +2 -2
- package/pg-core/selectGensForColumn.d.cts +3 -3
- package/pg-core/selectGensForColumn.d.mts +3 -3
- package/pg-core/selectGensForColumn.d.ts +3 -3
- package/singlestore-core/index.d.cts +2 -2
- package/singlestore-core/index.d.mts +2 -2
- package/singlestore-core/index.d.ts +2 -2
- package/singlestore-core/selectGensForColumn.d.cts +2 -2
- package/singlestore-core/selectGensForColumn.d.mts +2 -2
- package/singlestore-core/selectGensForColumn.d.ts +2 -2
- package/sqlite-core/index.d.cts +2 -2
- package/sqlite-core/index.d.mts +2 -2
- package/sqlite-core/index.d.ts +2 -2
- package/sqlite-core/selectGensForColumn.d.cts +2 -2
- package/sqlite-core/selectGensForColumn.d.mts +2 -2
- package/sqlite-core/selectGensForColumn.d.ts +2 -2
- package/types/seedService.d.cts +2 -2
- package/types/seedService.d.mts +2 -2
- package/types/seedService.d.ts +2 -2
- package/utils.d.cts +0 -4
- package/utils.d.mts +0 -4
- package/utils.d.ts +0 -4
- package/generators/versioning/v4.d.cts +0 -16
- package/generators/versioning/v4.d.mts +0 -16
- package/generators/versioning/v4.d.ts +0 -16
package/index.cjs
CHANGED
|
@@ -42,17 +42,6 @@ const isRelationCyclic = (startRel) => {
|
|
|
42
42
|
const equalSets = (set1, set2) => {
|
|
43
43
|
return set1.size === set2.size && [...set1].every((si) => set2.has(si));
|
|
44
44
|
};
|
|
45
|
-
const intMax = (args) => args.reduce((m, e) => e > m ? e : m);
|
|
46
|
-
const isPostgresColumnIntLike = (column) => {
|
|
47
|
-
return drizzleOrm.is(column, pgCore.PgSmallInt)
|
|
48
|
-
|| drizzleOrm.is(column, pgCore.PgInteger)
|
|
49
|
-
|| drizzleOrm.is(column, pgCore.PgBigInt53)
|
|
50
|
-
|| drizzleOrm.is(column, pgCore.PgBigInt64)
|
|
51
|
-
|| drizzleOrm.is(column, pgCore.PgSmallSerial)
|
|
52
|
-
|| drizzleOrm.is(column, pgCore.PgSerial)
|
|
53
|
-
|| drizzleOrm.is(column, pgCore.PgBigSerial53)
|
|
54
|
-
|| drizzleOrm.is(column, pgCore.PgBigSerial64);
|
|
55
|
-
};
|
|
56
45
|
|
|
57
46
|
const getTableConfig = (table) => {
|
|
58
47
|
if (drizzleOrm.is(table, pgCore.PgTable))
|
|
@@ -131442,9 +131431,6 @@ const isObject = (value) => {
|
|
|
131442
131431
|
return true;
|
|
131443
131432
|
return false;
|
|
131444
131433
|
};
|
|
131445
|
-
const isValidDate = (date) => {
|
|
131446
|
-
return !Number.isNaN(date.getTime());
|
|
131447
|
-
};
|
|
131448
131434
|
// const main = () => {
|
|
131449
131435
|
// console.time('range');
|
|
131450
131436
|
// const range = new OrderedBigintRange(BigInt(-10), BigInt(10), BigInt(1));
|
|
@@ -132163,20 +132149,13 @@ class GenerateDate extends AbstractGenerator {
|
|
|
132163
132149
|
const rng = prand.xoroshiro128plus(seed);
|
|
132164
132150
|
let { minDate, maxDate } = this.params;
|
|
132165
132151
|
const anchorDate = new Date('2024-05-08');
|
|
132166
|
-
// 4 years in milliseconds
|
|
132167
132152
|
const deltaMilliseconds = 4 * 31536000000;
|
|
132168
132153
|
if (typeof minDate === 'string') {
|
|
132169
132154
|
minDate = new Date(minDate);
|
|
132170
132155
|
}
|
|
132171
|
-
if (typeof minDate === 'object' && !isValidDate(minDate)) {
|
|
132172
|
-
throw new Error('Invalid Date was provided for the minDate parameter.');
|
|
132173
|
-
}
|
|
132174
132156
|
if (typeof maxDate === 'string') {
|
|
132175
132157
|
maxDate = new Date(maxDate);
|
|
132176
132158
|
}
|
|
132177
|
-
if (typeof maxDate === 'object' && !isValidDate(maxDate)) {
|
|
132178
|
-
throw new Error('Invalid Date was provided for the maxDate parameter.');
|
|
132179
|
-
}
|
|
132180
132159
|
if (minDate === undefined) {
|
|
132181
132160
|
if (maxDate === undefined) {
|
|
132182
132161
|
minDate = new Date(anchorDate.getTime() - deltaMilliseconds);
|
|
@@ -132189,9 +132168,6 @@ class GenerateDate extends AbstractGenerator {
|
|
|
132189
132168
|
if (maxDate === undefined) {
|
|
132190
132169
|
maxDate = new Date(minDate.getTime() + (2 * deltaMilliseconds));
|
|
132191
132170
|
}
|
|
132192
|
-
if (minDate > maxDate) {
|
|
132193
|
-
throw new Error(`The minDate parameter must be less than or equal to the maxDate parameter.`);
|
|
132194
|
-
}
|
|
132195
132171
|
this.state = { rng, minDate, maxDate };
|
|
132196
132172
|
}
|
|
132197
132173
|
generate() {
|
|
@@ -132213,83 +132189,18 @@ class GenerateTime extends AbstractGenerator {
|
|
|
132213
132189
|
init({ count, seed }) {
|
|
132214
132190
|
super.init({ count, seed });
|
|
132215
132191
|
const rng = prand.xoroshiro128plus(seed);
|
|
132216
|
-
|
|
132217
|
-
if (minTime === undefined && maxTime === undefined) {
|
|
132218
|
-
// TODO: maybe need to change in major version release
|
|
132219
|
-
// This is required to ensure that this generator remains deterministic when used without minTime, maxTime parameters.
|
|
132220
|
-
const oneDayInMilliseconds = 86400000;
|
|
132221
|
-
minTime = new Date(new Date('2024-05-08T12:00:00.000Z').getTime() - oneDayInMilliseconds);
|
|
132222
|
-
maxTime = new Date(new Date('2024-05-08T12:00:00.000Z').getTime() + oneDayInMilliseconds);
|
|
132223
|
-
this.state = { rng, minTime, maxTime };
|
|
132224
|
-
return;
|
|
132225
|
-
}
|
|
132226
|
-
if (minTime === undefined) {
|
|
132227
|
-
if (maxTime === undefined) {
|
|
132228
|
-
minTime = '00:00:00.000Z';
|
|
132229
|
-
maxTime = '23:59:59.999Z';
|
|
132230
|
-
}
|
|
132231
|
-
else {
|
|
132232
|
-
minTime = '00:00:00.000Z';
|
|
132233
|
-
}
|
|
132234
|
-
}
|
|
132235
|
-
if (maxTime === undefined) {
|
|
132236
|
-
maxTime = '23:59:59.999Z';
|
|
132237
|
-
new Date().toISOString();
|
|
132238
|
-
}
|
|
132239
|
-
const anchorDate = new Date('2024-05-08');
|
|
132240
|
-
const anchorDateString0 = anchorDate.toISOString().replace(/T\d{2}:\d{2}:\d{2}.\d{3}Z/, '');
|
|
132241
|
-
if (typeof minTime === 'string') {
|
|
132242
|
-
// const timeMatch0 = minTime.match(/^\d{2}:\d{2}:\d{2}.\d{1,3}Z?$/);
|
|
132243
|
-
const timeMatch1 = minTime.match(/^\d{2}:\d{2}:\d{2}Z?$/);
|
|
132244
|
-
const timeMatch2 = minTime.match(/^\d{2}:\d{2}Z?$/);
|
|
132245
|
-
if (
|
|
132246
|
-
// timeMatch0 === null
|
|
132247
|
-
timeMatch1 === null
|
|
132248
|
-
&& timeMatch2 === null) {
|
|
132249
|
-
throw new Error(`You're using the wrong format for the minTime parameter.`
|
|
132250
|
-
+ `\nPlease use one of these formats: 'HH:mm:ss', 'HH:mm' (with or without a trailing 'Z')`);
|
|
132251
|
-
}
|
|
132252
|
-
minTime = minTime.at(-1) === 'Z' ? minTime : minTime + 'Z';
|
|
132253
|
-
minTime = new Date(anchorDate.toISOString().replace(/\d{2}:\d{2}:\d{2}.\d{3}Z/, minTime));
|
|
132254
|
-
}
|
|
132255
|
-
if (typeof minTime === 'object') {
|
|
132256
|
-
if (!isValidDate(minTime)) {
|
|
132257
|
-
throw new Error('Invalid Date was provided for the minTime parameter.');
|
|
132258
|
-
}
|
|
132259
|
-
minTime = new Date(minTime.toISOString().replace(/\d{4}-\d{2}-\d{2}/, anchorDateString0));
|
|
132260
|
-
}
|
|
132261
|
-
if (typeof maxTime === 'string') {
|
|
132262
|
-
// const timeMatch0 = maxTime.match(/^\d{2}:\d{2}:\d{2}.\d{1,3}Z?$/);
|
|
132263
|
-
const timeMatch1 = maxTime.match(/^\d{2}:\d{2}:\d{2}Z?$/);
|
|
132264
|
-
const timeMatch2 = maxTime.match(/^\d{2}:\d{2}Z?$/);
|
|
132265
|
-
if (
|
|
132266
|
-
// timeMatch0 === null
|
|
132267
|
-
timeMatch1 === null
|
|
132268
|
-
&& timeMatch2 === null) {
|
|
132269
|
-
throw new Error(`You're using the wrong format for the maxTime parameter.`
|
|
132270
|
-
+ `\nPlease use one of these formats: 'HH:mm:ss', 'HH:mm' (with or without a trailing 'Z').`);
|
|
132271
|
-
}
|
|
132272
|
-
maxTime = maxTime.at(-1) === 'Z' ? maxTime : maxTime + 'Z';
|
|
132273
|
-
maxTime = new Date(anchorDate.toISOString().replace(/\d{2}:\d{2}:\d{2}.\d{3}Z/, maxTime));
|
|
132274
|
-
}
|
|
132275
|
-
if (typeof maxTime === 'object') {
|
|
132276
|
-
if (!isValidDate(maxTime)) {
|
|
132277
|
-
throw new Error('Invalid Date was provided for the maxTime parameter.');
|
|
132278
|
-
}
|
|
132279
|
-
maxTime = new Date(maxTime.toISOString().replace(/\d{4}-\d{2}-\d{2}/, anchorDateString0));
|
|
132280
|
-
}
|
|
132281
|
-
if (minTime > maxTime) {
|
|
132282
|
-
throw new Error(`The minTime parameter must be less than or equal to the maxTime parameter.`);
|
|
132283
|
-
}
|
|
132284
|
-
this.state = { rng, minTime, maxTime };
|
|
132192
|
+
this.state = { rng };
|
|
132285
132193
|
}
|
|
132286
132194
|
generate() {
|
|
132287
132195
|
if (this.state === undefined) {
|
|
132288
132196
|
throw new Error('state is not defined.');
|
|
132289
132197
|
}
|
|
132198
|
+
const anchorDateTime = new Date('2024-05-08T12:00:00.000Z');
|
|
132199
|
+
const oneDayInMilliseconds = 86400000;
|
|
132200
|
+
let date = new Date();
|
|
132290
132201
|
let milliseconds;
|
|
132291
|
-
[milliseconds, this.state.rng] = prand.uniformIntDistribution(
|
|
132292
|
-
|
|
132202
|
+
[milliseconds, this.state.rng] = prand.uniformIntDistribution(-oneDayInMilliseconds, oneDayInMilliseconds, this.state.rng);
|
|
132203
|
+
date = new Date(date.setTime(anchorDateTime.getTime() + milliseconds));
|
|
132293
132204
|
return date.toISOString().replace(/(\d{4}-\d{2}-\d{2}T)|(\.\d{3}Z)/g, '');
|
|
132294
132205
|
}
|
|
132295
132206
|
}
|
|
@@ -132299,46 +132210,18 @@ class GenerateTimestamp extends AbstractGenerator {
|
|
|
132299
132210
|
init({ count, seed }) {
|
|
132300
132211
|
super.init({ count, seed });
|
|
132301
132212
|
const rng = prand.xoroshiro128plus(seed);
|
|
132302
|
-
|
|
132303
|
-
const anchorDate = new Date('2024-05-08');
|
|
132304
|
-
// 2 years in milliseconds
|
|
132305
|
-
const deltaMilliseconds = 2 * 31536000000;
|
|
132306
|
-
if (typeof minTimestamp === 'string') {
|
|
132307
|
-
minTimestamp = new Date(minTimestamp);
|
|
132308
|
-
}
|
|
132309
|
-
if (typeof minTimestamp === 'object' && !isValidDate(minTimestamp)) {
|
|
132310
|
-
throw new Error('Invalid Date was provided for the minTimestamp parameter.');
|
|
132311
|
-
}
|
|
132312
|
-
if (typeof maxTimestamp === 'string') {
|
|
132313
|
-
maxTimestamp = new Date(maxTimestamp);
|
|
132314
|
-
}
|
|
132315
|
-
if (typeof maxTimestamp === 'object' && !isValidDate(maxTimestamp)) {
|
|
132316
|
-
throw new Error('Invalid Date was provided for the maxTimestamp parameter.');
|
|
132317
|
-
}
|
|
132318
|
-
if (minTimestamp === undefined) {
|
|
132319
|
-
if (maxTimestamp === undefined) {
|
|
132320
|
-
minTimestamp = new Date(anchorDate.getTime() - deltaMilliseconds);
|
|
132321
|
-
maxTimestamp = new Date(anchorDate.getTime() + deltaMilliseconds);
|
|
132322
|
-
}
|
|
132323
|
-
else {
|
|
132324
|
-
minTimestamp = new Date(maxTimestamp.getTime() - (2 * deltaMilliseconds));
|
|
132325
|
-
}
|
|
132326
|
-
}
|
|
132327
|
-
if (maxTimestamp === undefined) {
|
|
132328
|
-
maxTimestamp = new Date(minTimestamp.getTime() + (2 * deltaMilliseconds));
|
|
132329
|
-
}
|
|
132330
|
-
if (minTimestamp > maxTimestamp) {
|
|
132331
|
-
throw new Error(`The minTimestamp parameter must be less than or equal to the maxTimestamp parameter.`);
|
|
132332
|
-
}
|
|
132333
|
-
this.state = { rng, minTimestamp, maxTimestamp };
|
|
132213
|
+
this.state = { rng };
|
|
132334
132214
|
}
|
|
132335
132215
|
generate() {
|
|
132336
132216
|
if (this.state === undefined) {
|
|
132337
132217
|
throw new Error('state is not defined.');
|
|
132338
132218
|
}
|
|
132219
|
+
const anchorTimestamp = new Date('2024-05-08');
|
|
132220
|
+
const twoYearsInMilliseconds = 2 * 31536000000;
|
|
132221
|
+
let date = new Date();
|
|
132339
132222
|
let milliseconds;
|
|
132340
|
-
[milliseconds, this.state.rng] = prand.uniformIntDistribution(
|
|
132341
|
-
|
|
132223
|
+
[milliseconds, this.state.rng] = prand.uniformIntDistribution(-twoYearsInMilliseconds, twoYearsInMilliseconds, this.state.rng);
|
|
132224
|
+
date = new Date(date.setTime(anchorTimestamp.getTime() + milliseconds));
|
|
132342
132225
|
if (this.dataType === 'string') {
|
|
132343
132226
|
return date
|
|
132344
132227
|
.toISOString()
|
|
@@ -132354,46 +132237,18 @@ class GenerateDatetime extends AbstractGenerator {
|
|
|
132354
132237
|
init({ count, seed }) {
|
|
132355
132238
|
super.init({ count, seed });
|
|
132356
132239
|
const rng = prand.xoroshiro128plus(seed);
|
|
132357
|
-
|
|
132358
|
-
const anchorDate = new Date('2024-05-08');
|
|
132359
|
-
// 2 years in milliseconds
|
|
132360
|
-
const deltaMilliseconds = 2 * 31536000000;
|
|
132361
|
-
if (typeof minDatetime === 'string') {
|
|
132362
|
-
minDatetime = new Date(minDatetime);
|
|
132363
|
-
}
|
|
132364
|
-
if (typeof minDatetime === 'object' && !isValidDate(minDatetime)) {
|
|
132365
|
-
throw new Error('Invalid Date was provided for the minDatetime parameter.');
|
|
132366
|
-
}
|
|
132367
|
-
if (typeof maxDatetime === 'string') {
|
|
132368
|
-
maxDatetime = new Date(maxDatetime);
|
|
132369
|
-
}
|
|
132370
|
-
if (typeof maxDatetime === 'object' && !isValidDate(maxDatetime)) {
|
|
132371
|
-
throw new Error('Invalid Date was provided for the maxDatetime parameter.');
|
|
132372
|
-
}
|
|
132373
|
-
if (minDatetime === undefined) {
|
|
132374
|
-
if (maxDatetime === undefined) {
|
|
132375
|
-
minDatetime = new Date(anchorDate.getTime() - deltaMilliseconds);
|
|
132376
|
-
maxDatetime = new Date(anchorDate.getTime() + deltaMilliseconds);
|
|
132377
|
-
}
|
|
132378
|
-
else {
|
|
132379
|
-
minDatetime = new Date(maxDatetime.getTime() - (2 * deltaMilliseconds));
|
|
132380
|
-
}
|
|
132381
|
-
}
|
|
132382
|
-
if (maxDatetime === undefined) {
|
|
132383
|
-
maxDatetime = new Date(minDatetime.getTime() + (2 * deltaMilliseconds));
|
|
132384
|
-
}
|
|
132385
|
-
if (minDatetime > maxDatetime) {
|
|
132386
|
-
throw new Error(`The minDatetime parameter must be less than or equal to the maxDatetime parameter.`);
|
|
132387
|
-
}
|
|
132388
|
-
this.state = { rng, minDatetime, maxDatetime };
|
|
132240
|
+
this.state = { rng };
|
|
132389
132241
|
}
|
|
132390
132242
|
generate() {
|
|
132391
132243
|
if (this.state === undefined) {
|
|
132392
132244
|
throw new Error('state is not defined.');
|
|
132393
132245
|
}
|
|
132246
|
+
const anchorDate = new Date('2024-05-08');
|
|
132247
|
+
const twoYearsInMilliseconds = 2 * 31536000000;
|
|
132248
|
+
let date = new Date();
|
|
132394
132249
|
let milliseconds;
|
|
132395
|
-
[milliseconds, this.state.rng] = prand.uniformIntDistribution(
|
|
132396
|
-
|
|
132250
|
+
[milliseconds, this.state.rng] = prand.uniformIntDistribution(-twoYearsInMilliseconds, twoYearsInMilliseconds, this.state.rng);
|
|
132251
|
+
date = new Date(date.setTime(anchorDate.getTime() + milliseconds));
|
|
132397
132252
|
if (this.dataType === 'string') {
|
|
132398
132253
|
return date
|
|
132399
132254
|
.toISOString()
|
|
@@ -134608,49 +134463,6 @@ class GenerateHashFromStringV3 extends AbstractGenerator {
|
|
|
134608
134463
|
}
|
|
134609
134464
|
}
|
|
134610
134465
|
|
|
134611
|
-
/* eslint-disable drizzle-internal/require-entity-kind */
|
|
134612
|
-
class GenerateUUIDV4 extends AbstractGenerator {
|
|
134613
|
-
static entityKind = 'GenerateUUID';
|
|
134614
|
-
static version = 4;
|
|
134615
|
-
isGeneratorUnique = true;
|
|
134616
|
-
maxUniqueCount = Number.POSITIVE_INFINITY;
|
|
134617
|
-
state;
|
|
134618
|
-
getMaxUniqueCount() {
|
|
134619
|
-
return Number.POSITIVE_INFINITY;
|
|
134620
|
-
}
|
|
134621
|
-
init({ count, seed }) {
|
|
134622
|
-
super.init({ count, seed });
|
|
134623
|
-
const rng = prand.xoroshiro128plus(seed);
|
|
134624
|
-
this.state = { rng };
|
|
134625
|
-
}
|
|
134626
|
-
generate() {
|
|
134627
|
-
if (this.state === undefined) {
|
|
134628
|
-
throw new Error('state is not defined.');
|
|
134629
|
-
}
|
|
134630
|
-
// TODO generate uuid using string generator
|
|
134631
|
-
const stringChars = '1234567890abcdef';
|
|
134632
|
-
let idx, currStr;
|
|
134633
|
-
const strLength = 36;
|
|
134634
|
-
// uuid v4
|
|
134635
|
-
const uuidTemplate = '########-####-4###-N###-############';
|
|
134636
|
-
currStr = '';
|
|
134637
|
-
for (let i = 0; i < strLength; i++) {
|
|
134638
|
-
[idx, this.state.rng] = prand.uniformIntDistribution(0, stringChars.length - 1, this.state.rng);
|
|
134639
|
-
if (uuidTemplate[i] === '#') {
|
|
134640
|
-
currStr += stringChars[idx];
|
|
134641
|
-
continue;
|
|
134642
|
-
}
|
|
134643
|
-
// used this pr -> https://github.com/drizzle-team/drizzle-orm/pull/4503
|
|
134644
|
-
if (uuidTemplate[i] === 'N') {
|
|
134645
|
-
currStr += '89ab'[idx % 4];
|
|
134646
|
-
continue;
|
|
134647
|
-
}
|
|
134648
|
-
currStr += uuidTemplate[i];
|
|
134649
|
-
}
|
|
134650
|
-
return currStr;
|
|
134651
|
-
}
|
|
134652
|
-
}
|
|
134653
|
-
|
|
134654
134466
|
function createGenerator(generatorConstructor) {
|
|
134655
134467
|
return (...args) => {
|
|
134656
134468
|
let params = args[0];
|
|
@@ -134816,8 +134628,6 @@ const generatorsFuncs = {
|
|
|
134816
134628
|
date: createGenerator(GenerateDate),
|
|
134817
134629
|
/**
|
|
134818
134630
|
* generates time in 24 hours style.
|
|
134819
|
-
* @param minTime - lower border of range.
|
|
134820
|
-
* @param maxTime - upper border of range.
|
|
134821
134631
|
* @param arraySize - number of elements in each one-dimensional array. (If specified, arrays will be generated.)
|
|
134822
134632
|
*
|
|
134823
134633
|
* @example
|
|
@@ -134825,7 +134635,7 @@ const generatorsFuncs = {
|
|
|
134825
134635
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
134826
134636
|
* users: {
|
|
134827
134637
|
* columns: {
|
|
134828
|
-
* birthTime: funcs.time(
|
|
134638
|
+
* birthTime: funcs.time()
|
|
134829
134639
|
* },
|
|
134830
134640
|
* },
|
|
134831
134641
|
* }));
|
|
@@ -134835,8 +134645,6 @@ const generatorsFuncs = {
|
|
|
134835
134645
|
time: createGenerator(GenerateTime),
|
|
134836
134646
|
/**
|
|
134837
134647
|
* generates timestamps.
|
|
134838
|
-
* @param minTimestamp - lower border of range.
|
|
134839
|
-
* @param maxTimestamp - upper border of range.
|
|
134840
134648
|
* @param arraySize - number of elements in each one-dimensional array. (If specified, arrays will be generated.)
|
|
134841
134649
|
*
|
|
134842
134650
|
* @example
|
|
@@ -134844,7 +134652,7 @@ const generatorsFuncs = {
|
|
|
134844
134652
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
134845
134653
|
* orders: {
|
|
134846
134654
|
* columns: {
|
|
134847
|
-
* shippedDate: funcs.timestamp(
|
|
134655
|
+
* shippedDate: funcs.timestamp()
|
|
134848
134656
|
* },
|
|
134849
134657
|
* },
|
|
134850
134658
|
* }));
|
|
@@ -134854,8 +134662,6 @@ const generatorsFuncs = {
|
|
|
134854
134662
|
timestamp: createGenerator(GenerateTimestamp),
|
|
134855
134663
|
/**
|
|
134856
134664
|
* generates datetime objects.
|
|
134857
|
-
* @param minDatetime - lower border of range.
|
|
134858
|
-
* @param maxDatetime - upper border of range.
|
|
134859
134665
|
* @param arraySize - number of elements in each one-dimensional array. (If specified, arrays will be generated.)
|
|
134860
134666
|
*
|
|
134861
134667
|
* @example
|
|
@@ -134863,7 +134669,7 @@ const generatorsFuncs = {
|
|
|
134863
134669
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
134864
134670
|
* orders: {
|
|
134865
134671
|
* columns: {
|
|
134866
|
-
* shippedDate: funcs.datetime(
|
|
134672
|
+
* shippedDate: funcs.datetime()
|
|
134867
134673
|
* },
|
|
134868
134674
|
* },
|
|
134869
134675
|
* }));
|
|
@@ -135448,16 +135254,13 @@ const generatorsFuncs = {
|
|
|
135448
135254
|
*/
|
|
135449
135255
|
vector: createGenerator(GenerateVector),
|
|
135450
135256
|
};
|
|
135451
|
-
// so far, version changes don’t
|
|
135257
|
+
// so far, version changes don’t affect generator parameters.
|
|
135452
135258
|
const generatorsFuncsV2 = {
|
|
135453
135259
|
...generatorsFuncs,
|
|
135454
135260
|
};
|
|
135455
135261
|
({
|
|
135456
135262
|
...generatorsFuncs,
|
|
135457
135263
|
});
|
|
135458
|
-
({
|
|
135459
|
-
...generatorsFuncs,
|
|
135460
|
-
});
|
|
135461
135264
|
const generatorsMap = {
|
|
135462
135265
|
GenerateHashFromString: [
|
|
135463
135266
|
GenerateHashFromString,
|
|
@@ -135531,7 +135334,6 @@ const generatorsMap = {
|
|
|
135531
135334
|
],
|
|
135532
135335
|
GenerateUUID: [
|
|
135533
135336
|
GenerateUUID,
|
|
135534
|
-
GenerateUUIDV4,
|
|
135535
135337
|
],
|
|
135536
135338
|
GenerateFirstName: [
|
|
135537
135339
|
GenerateFirstName,
|
|
@@ -135862,7 +135664,7 @@ const selectGeneratorForCockroachColumn = (table, col) => {
|
|
|
135862
135664
|
return generator;
|
|
135863
135665
|
};
|
|
135864
135666
|
|
|
135865
|
-
const latestVersion =
|
|
135667
|
+
const latestVersion = 3;
|
|
135866
135668
|
|
|
135867
135669
|
const selectGeneratorForMssqlColumn = (table, col) => {
|
|
135868
135670
|
const pickGenerator = (table, col) => {
|
|
@@ -136752,7 +136554,6 @@ class SeedService {
|
|
|
136752
136554
|
};
|
|
136753
136555
|
}
|
|
136754
136556
|
}
|
|
136755
|
-
// handling refinements (count, with)
|
|
136756
136557
|
if (refinements !== undefined && refinements[table.name] !== undefined) {
|
|
136757
136558
|
if (refinements[table.name].count !== undefined) {
|
|
136758
136559
|
tablesPossibleGenerators[i].count = refinements[table.name].count;
|
|
@@ -136814,7 +136615,6 @@ class SeedService {
|
|
|
136814
136615
|
wasDefinedBefore: false,
|
|
136815
136616
|
wasRefined: false,
|
|
136816
136617
|
};
|
|
136817
|
-
// handling refinements (columnGenerator)
|
|
136818
136618
|
if (refinements !== undefined
|
|
136819
136619
|
&& refinements[table.name] !== undefined
|
|
136820
136620
|
&& refinements[table.name].columns !== undefined
|
|
@@ -136827,7 +136627,7 @@ class SeedService {
|
|
|
136827
136627
|
+ `\nwhich will cause an error because the column has a not null constraint and no default value.`);
|
|
136828
136628
|
}
|
|
136829
136629
|
// Generating undefined as a value for a column and then inserting it via drizzle-orm
|
|
136830
|
-
// will result in
|
|
136630
|
+
// will result in the value not being inserted into that column.
|
|
136831
136631
|
columnPossibleGenerator.generator = new generatorsMap.GenerateDefault[0]({ defaultValue: undefined });
|
|
136832
136632
|
columnPossibleGenerator.wasRefined = true;
|
|
136833
136633
|
continue;
|
|
@@ -137165,8 +136965,7 @@ class SeedService {
|
|
|
137165
136965
|
};
|
|
137166
136966
|
}
|
|
137167
136967
|
// get values to generate columns with foreign key
|
|
137168
|
-
// if table posts contains foreign key to table users, then rel.table === 'posts' and rel.refTable === 'users',
|
|
137169
|
-
// because table posts has reference to table users.
|
|
136968
|
+
// if table posts contains foreign key to table users, then rel.table === 'posts' and rel.refTable === 'users', because table posts has reference to table users.
|
|
137170
136969
|
if (filteredRelations.length !== 0) {
|
|
137171
136970
|
for (const rel of filteredRelations) {
|
|
137172
136971
|
if (table.withFromTable[rel.refTable] !== undefined
|
|
@@ -137304,25 +137103,6 @@ class SeedService {
|
|
|
137304
137103
|
// columnsGenerators[columnName] = uniqueGen;
|
|
137305
137104
|
// }
|
|
137306
137105
|
}
|
|
137307
|
-
// sequence updates will only be performed for PostgreSQL, since MySQL and SQLite already update their sequences correctly on their own.
|
|
137308
|
-
const columnsToUpdateSeq = new Map();
|
|
137309
|
-
if (count > 0 && drizzleOrm.is(db, pgCore.PgDatabase) && schema !== undefined && tableName !== undefined
|
|
137310
|
-
&& schema[tableName] !== undefined) {
|
|
137311
|
-
const tableConfig = pgCore.getTableConfig(schema[tableName]);
|
|
137312
|
-
for (const column of tableConfig.columns) {
|
|
137313
|
-
// TODO should I filter only primary key columns?
|
|
137314
|
-
// should I filter column by dataType or by column drizzle type?
|
|
137315
|
-
// column.dataType === 'number' || column.dataType === 'bigint'
|
|
137316
|
-
if (isPostgresColumnIntLike(column)) {
|
|
137317
|
-
columnsToUpdateSeq.set(column.name, {
|
|
137318
|
-
schemaName: tableConfig.schema,
|
|
137319
|
-
tableName: tableConfig.name,
|
|
137320
|
-
columnName: column.name,
|
|
137321
|
-
valueToUpdate: undefined,
|
|
137322
|
-
});
|
|
137323
|
-
}
|
|
137324
|
-
}
|
|
137325
|
-
}
|
|
137326
137106
|
let maxParametersNumber;
|
|
137327
137107
|
if (drizzleOrm.is(db, (pgCore.PgDatabase))) {
|
|
137328
137108
|
// @ts-ignore
|
|
@@ -137353,12 +137133,6 @@ class SeedService {
|
|
|
137353
137133
|
for (const columnName of Object.keys(columnsGenerators)) {
|
|
137354
137134
|
generatedValue = columnsGenerators[columnName].generate({ i, columnName });
|
|
137355
137135
|
row[columnName] = generatedValue;
|
|
137356
|
-
const colToUpdateSeq = columnsToUpdateSeq.get(columnName);
|
|
137357
|
-
if (columnsToUpdateSeq.size !== 0 && colToUpdateSeq !== undefined) {
|
|
137358
|
-
colToUpdateSeq.valueToUpdate = colToUpdateSeq?.valueToUpdate === undefined
|
|
137359
|
-
? generatedValue
|
|
137360
|
-
: intMax([colToUpdateSeq.valueToUpdate, generatedValue]);
|
|
137361
|
-
}
|
|
137362
137136
|
}
|
|
137363
137137
|
if ((insertDataInDb === true || updateDataInDb === true)
|
|
137364
137138
|
&& ((i + 1) % batchSize === 0 || i === count - 1)) {
|
|
@@ -137405,28 +137179,9 @@ class SeedService {
|
|
|
137405
137179
|
}
|
|
137406
137180
|
}
|
|
137407
137181
|
}
|
|
137408
|
-
const columnsToUpdateSeqFiltered = [...columnsToUpdateSeq.values()].filter((col) => col.valueToUpdate !== undefined);
|
|
137409
|
-
if (i === count - 1
|
|
137410
|
-
&& columnsToUpdateSeqFiltered.length !== 0 && db !== undefined) {
|
|
137411
|
-
for (const columnConfig of columnsToUpdateSeq.values()) {
|
|
137412
|
-
if (columnConfig) {
|
|
137413
|
-
await this.updateColumnSequence({ db, columnConfig });
|
|
137414
|
-
}
|
|
137415
|
-
}
|
|
137416
|
-
}
|
|
137417
137182
|
}
|
|
137418
137183
|
return preserveData === true ? generatedValues : [];
|
|
137419
137184
|
};
|
|
137420
|
-
updateColumnSequence = async ({ db, columnConfig: { schemaName, tableName, columnName, valueToUpdate } }) => {
|
|
137421
|
-
if (drizzleOrm.is(db, pgCore.PgDatabase)) {
|
|
137422
|
-
const fullTableName = schemaName ? `"${schemaName}"."${tableName}"` : `"${tableName}"`;
|
|
137423
|
-
const rawQuery = `SELECT setval(pg_get_serial_sequence('${fullTableName}', '${columnName}'), ${(valueToUpdate ?? 'null').toString()}, true);`;
|
|
137424
|
-
await db.execute(drizzleOrm.sql.raw(rawQuery));
|
|
137425
|
-
}
|
|
137426
|
-
// mysql updates auto_increment or serial column by itself
|
|
137427
|
-
// sqlite updates autoincrement column by itself
|
|
137428
|
-
return;
|
|
137429
|
-
};
|
|
137430
137185
|
insertInDb = async ({ generatedValues, db, schema, tableName, override, }) => {
|
|
137431
137186
|
if (drizzleOrm.is(db, (pgCore.PgDatabase))) {
|
|
137432
137187
|
const query = db.insert(schema[tableName]);
|
|
@@ -138152,7 +137907,7 @@ async function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject, drizzleSt
|
|
|
138152
137907
|
* // seeding with count and seed specified
|
|
138153
137908
|
* await seed(db, schema, { count: 100000, seed: 1 });
|
|
138154
137909
|
*
|
|
138155
|
-
* //
|
|
137910
|
+
* //seeding using refine
|
|
138156
137911
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
138157
137912
|
* users: {
|
|
138158
137913
|
* columns: {
|
|
@@ -138173,17 +137928,6 @@ async function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject, drizzleSt
|
|
|
138173
137928
|
* },
|
|
138174
137929
|
* }));
|
|
138175
137930
|
*
|
|
138176
|
-
* // seeding while ignoring column
|
|
138177
|
-
* await seed(db, schema).refine((funcs) => ({
|
|
138178
|
-
* users: {
|
|
138179
|
-
* count: 5,
|
|
138180
|
-
* columns: {
|
|
138181
|
-
* name: funcs.fullName(),
|
|
138182
|
-
* photo: false, // the photo column will not be seeded, allowing the database to use its default value.
|
|
138183
|
-
* },
|
|
138184
|
-
* },
|
|
138185
|
-
* }));
|
|
138186
|
-
*
|
|
138187
137931
|
* ```
|
|
138188
137932
|
*/
|
|
138189
137933
|
function seed(db, schema, options) {
|
|
@@ -138255,10 +137999,6 @@ const seedFunc = async (db, schema, options = {}, refinements) => {
|
|
|
138255
137999
|
* @example
|
|
138256
138000
|
* ```ts
|
|
138257
138001
|
* await reset(db, schema);
|
|
138258
|
-
*
|
|
138259
|
-
* // Alternatively, you can provide an object containing your tables
|
|
138260
|
-
* // as the `schema` parameter when calling `reset`.
|
|
138261
|
-
* await reset(db, { users });
|
|
138262
138002
|
* ```
|
|
138263
138003
|
*/
|
|
138264
138004
|
async function reset(db, schema) {
|