drizzle-seed 1.0.0-beta.2-0f52822 → 1.0.0-beta.2-278d7e6
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 +12 -3
- package/SeedService.d.mts +12 -3
- package/SeedService.d.ts +12 -3
- 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 +950 -20
- package/generators/GeneratorFuncs.d.mts +950 -20
- package/generators/GeneratorFuncs.d.ts +950 -20
- package/generators/Generators.d.cts +29 -2
- package/generators/Generators.d.mts +29 -2
- package/generators/Generators.d.ts +29 -2
- 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 +1 -0
- package/generators/utils.d.mts +1 -0
- package/generators/utils.d.ts +1 -0
- 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/generators/versioning/v4.d.cts +16 -0
- package/generators/versioning/v4.d.mts +16 -0
- package/generators/versioning/v4.d.ts +16 -0
- package/index.cjs +286 -26
- package/index.cjs.map +1 -1
- package/index.d.cts +68 -47
- package/index.d.mts +68 -47
- package/index.d.ts +68 -47
- package/index.mjs +288 -28
- 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 +5 -3
- 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 +4 -0
- package/utils.d.mts +4 -0
- package/utils.d.ts +4 -0
package/index.cjs
CHANGED
|
@@ -42,6 +42,17 @@ 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
|
+
};
|
|
45
56
|
|
|
46
57
|
const getTableConfig = (table) => {
|
|
47
58
|
if (drizzleOrm.is(table, pgCore.PgTable))
|
|
@@ -131431,6 +131442,9 @@ const isObject = (value) => {
|
|
|
131431
131442
|
return true;
|
|
131432
131443
|
return false;
|
|
131433
131444
|
};
|
|
131445
|
+
const isValidDate = (date) => {
|
|
131446
|
+
return !Number.isNaN(date.getTime());
|
|
131447
|
+
};
|
|
131434
131448
|
// const main = () => {
|
|
131435
131449
|
// console.time('range');
|
|
131436
131450
|
// const range = new OrderedBigintRange(BigInt(-10), BigInt(10), BigInt(1));
|
|
@@ -132149,13 +132163,20 @@ class GenerateDate extends AbstractGenerator {
|
|
|
132149
132163
|
const rng = prand.xoroshiro128plus(seed);
|
|
132150
132164
|
let { minDate, maxDate } = this.params;
|
|
132151
132165
|
const anchorDate = new Date('2024-05-08');
|
|
132166
|
+
// 4 years in milliseconds
|
|
132152
132167
|
const deltaMilliseconds = 4 * 31536000000;
|
|
132153
132168
|
if (typeof minDate === 'string') {
|
|
132154
132169
|
minDate = new Date(minDate);
|
|
132155
132170
|
}
|
|
132171
|
+
if (typeof minDate === 'object' && !isValidDate(minDate)) {
|
|
132172
|
+
throw new Error('Invalid Date was provided for the minDate parameter.');
|
|
132173
|
+
}
|
|
132156
132174
|
if (typeof maxDate === 'string') {
|
|
132157
132175
|
maxDate = new Date(maxDate);
|
|
132158
132176
|
}
|
|
132177
|
+
if (typeof maxDate === 'object' && !isValidDate(maxDate)) {
|
|
132178
|
+
throw new Error('Invalid Date was provided for the maxDate parameter.');
|
|
132179
|
+
}
|
|
132159
132180
|
if (minDate === undefined) {
|
|
132160
132181
|
if (maxDate === undefined) {
|
|
132161
132182
|
minDate = new Date(anchorDate.getTime() - deltaMilliseconds);
|
|
@@ -132168,6 +132189,9 @@ class GenerateDate extends AbstractGenerator {
|
|
|
132168
132189
|
if (maxDate === undefined) {
|
|
132169
132190
|
maxDate = new Date(minDate.getTime() + (2 * deltaMilliseconds));
|
|
132170
132191
|
}
|
|
132192
|
+
if (minDate > maxDate) {
|
|
132193
|
+
throw new Error(`The minDate parameter must be less than or equal to the maxDate parameter.`);
|
|
132194
|
+
}
|
|
132171
132195
|
this.state = { rng, minDate, maxDate };
|
|
132172
132196
|
}
|
|
132173
132197
|
generate() {
|
|
@@ -132189,18 +132213,83 @@ class GenerateTime extends AbstractGenerator {
|
|
|
132189
132213
|
init({ count, seed }) {
|
|
132190
132214
|
super.init({ count, seed });
|
|
132191
132215
|
const rng = prand.xoroshiro128plus(seed);
|
|
132192
|
-
|
|
132216
|
+
let { minTime, maxTime } = this.params;
|
|
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 };
|
|
132193
132285
|
}
|
|
132194
132286
|
generate() {
|
|
132195
132287
|
if (this.state === undefined) {
|
|
132196
132288
|
throw new Error('state is not defined.');
|
|
132197
132289
|
}
|
|
132198
|
-
const anchorDateTime = new Date('2024-05-08T12:00:00.000Z');
|
|
132199
|
-
const oneDayInMilliseconds = 86400000;
|
|
132200
|
-
let date = new Date();
|
|
132201
132290
|
let milliseconds;
|
|
132202
|
-
[milliseconds, this.state.rng] = prand.uniformIntDistribution(
|
|
132203
|
-
date = new Date(
|
|
132291
|
+
[milliseconds, this.state.rng] = prand.uniformIntDistribution(this.state.minTime.getTime(), this.state.maxTime.getTime(), this.state.rng);
|
|
132292
|
+
const date = new Date(milliseconds);
|
|
132204
132293
|
return date.toISOString().replace(/(\d{4}-\d{2}-\d{2}T)|(\.\d{3}Z)/g, '');
|
|
132205
132294
|
}
|
|
132206
132295
|
}
|
|
@@ -132210,18 +132299,46 @@ class GenerateTimestamp extends AbstractGenerator {
|
|
|
132210
132299
|
init({ count, seed }) {
|
|
132211
132300
|
super.init({ count, seed });
|
|
132212
132301
|
const rng = prand.xoroshiro128plus(seed);
|
|
132213
|
-
|
|
132302
|
+
let { minTimestamp, maxTimestamp } = this.params;
|
|
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 };
|
|
132214
132334
|
}
|
|
132215
132335
|
generate() {
|
|
132216
132336
|
if (this.state === undefined) {
|
|
132217
132337
|
throw new Error('state is not defined.');
|
|
132218
132338
|
}
|
|
132219
|
-
const anchorTimestamp = new Date('2024-05-08');
|
|
132220
|
-
const twoYearsInMilliseconds = 2 * 31536000000;
|
|
132221
|
-
let date = new Date();
|
|
132222
132339
|
let milliseconds;
|
|
132223
|
-
[milliseconds, this.state.rng] = prand.uniformIntDistribution(
|
|
132224
|
-
date = new Date(
|
|
132340
|
+
[milliseconds, this.state.rng] = prand.uniformIntDistribution(this.state.minTimestamp.getTime(), this.state.maxTimestamp.getTime(), this.state.rng);
|
|
132341
|
+
const date = new Date(milliseconds);
|
|
132225
132342
|
if (this.dataType === 'string') {
|
|
132226
132343
|
return date
|
|
132227
132344
|
.toISOString()
|
|
@@ -132237,18 +132354,46 @@ class GenerateDatetime extends AbstractGenerator {
|
|
|
132237
132354
|
init({ count, seed }) {
|
|
132238
132355
|
super.init({ count, seed });
|
|
132239
132356
|
const rng = prand.xoroshiro128plus(seed);
|
|
132240
|
-
|
|
132357
|
+
let { minDatetime, maxDatetime } = this.params;
|
|
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 };
|
|
132241
132389
|
}
|
|
132242
132390
|
generate() {
|
|
132243
132391
|
if (this.state === undefined) {
|
|
132244
132392
|
throw new Error('state is not defined.');
|
|
132245
132393
|
}
|
|
132246
|
-
const anchorDate = new Date('2024-05-08');
|
|
132247
|
-
const twoYearsInMilliseconds = 2 * 31536000000;
|
|
132248
|
-
let date = new Date();
|
|
132249
132394
|
let milliseconds;
|
|
132250
|
-
[milliseconds, this.state.rng] = prand.uniformIntDistribution(
|
|
132251
|
-
date = new Date(
|
|
132395
|
+
[milliseconds, this.state.rng] = prand.uniformIntDistribution(this.state.minDatetime.getTime(), this.state.maxDatetime.getTime(), this.state.rng);
|
|
132396
|
+
const date = new Date(milliseconds);
|
|
132252
132397
|
if (this.dataType === 'string') {
|
|
132253
132398
|
return date
|
|
132254
132399
|
.toISOString()
|
|
@@ -134463,6 +134608,49 @@ class GenerateHashFromStringV3 extends AbstractGenerator {
|
|
|
134463
134608
|
}
|
|
134464
134609
|
}
|
|
134465
134610
|
|
|
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
|
+
|
|
134466
134654
|
function createGenerator(generatorConstructor) {
|
|
134467
134655
|
return (...args) => {
|
|
134468
134656
|
let params = args[0];
|
|
@@ -134628,6 +134816,8 @@ const generatorsFuncs = {
|
|
|
134628
134816
|
date: createGenerator(GenerateDate),
|
|
134629
134817
|
/**
|
|
134630
134818
|
* generates time in 24 hours style.
|
|
134819
|
+
* @param minTime - lower border of range.
|
|
134820
|
+
* @param maxTime - upper border of range.
|
|
134631
134821
|
* @param arraySize - number of elements in each one-dimensional array. (If specified, arrays will be generated.)
|
|
134632
134822
|
*
|
|
134633
134823
|
* @example
|
|
@@ -134635,7 +134825,7 @@ const generatorsFuncs = {
|
|
|
134635
134825
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
134636
134826
|
* users: {
|
|
134637
134827
|
* columns: {
|
|
134638
|
-
* birthTime: funcs.time()
|
|
134828
|
+
* birthTime: funcs.time({ minTime: "11:12:13.141", maxTime: "15:16:17.181" })
|
|
134639
134829
|
* },
|
|
134640
134830
|
* },
|
|
134641
134831
|
* }));
|
|
@@ -134645,6 +134835,8 @@ const generatorsFuncs = {
|
|
|
134645
134835
|
time: createGenerator(GenerateTime),
|
|
134646
134836
|
/**
|
|
134647
134837
|
* generates timestamps.
|
|
134838
|
+
* @param minTimestamp - lower border of range.
|
|
134839
|
+
* @param maxTimestamp - upper border of range.
|
|
134648
134840
|
* @param arraySize - number of elements in each one-dimensional array. (If specified, arrays will be generated.)
|
|
134649
134841
|
*
|
|
134650
134842
|
* @example
|
|
@@ -134652,7 +134844,7 @@ const generatorsFuncs = {
|
|
|
134652
134844
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
134653
134845
|
* orders: {
|
|
134654
134846
|
* columns: {
|
|
134655
|
-
* shippedDate: funcs.timestamp()
|
|
134847
|
+
* shippedDate: funcs.timestamp({ minTimestamp: "2025-03-07T11:12:13.141", maxTimestamp: "2025-03-08T15:16:17.181" })
|
|
134656
134848
|
* },
|
|
134657
134849
|
* },
|
|
134658
134850
|
* }));
|
|
@@ -134662,6 +134854,8 @@ const generatorsFuncs = {
|
|
|
134662
134854
|
timestamp: createGenerator(GenerateTimestamp),
|
|
134663
134855
|
/**
|
|
134664
134856
|
* generates datetime objects.
|
|
134857
|
+
* @param minDatetime - lower border of range.
|
|
134858
|
+
* @param maxDatetime - upper border of range.
|
|
134665
134859
|
* @param arraySize - number of elements in each one-dimensional array. (If specified, arrays will be generated.)
|
|
134666
134860
|
*
|
|
134667
134861
|
* @example
|
|
@@ -134669,7 +134863,7 @@ const generatorsFuncs = {
|
|
|
134669
134863
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
134670
134864
|
* orders: {
|
|
134671
134865
|
* columns: {
|
|
134672
|
-
* shippedDate: funcs.datetime()
|
|
134866
|
+
* shippedDate: funcs.datetime({ minDatetime: "2025-03-07T11:12:13.141", maxDatetime: "2025-03-08T15:16:17.181" })
|
|
134673
134867
|
* },
|
|
134674
134868
|
* },
|
|
134675
134869
|
* }));
|
|
@@ -135254,13 +135448,16 @@ const generatorsFuncs = {
|
|
|
135254
135448
|
*/
|
|
135255
135449
|
vector: createGenerator(GenerateVector),
|
|
135256
135450
|
};
|
|
135257
|
-
// so far, version changes don’t
|
|
135451
|
+
// so far, version changes don’t change generator parameters.
|
|
135258
135452
|
const generatorsFuncsV2 = {
|
|
135259
135453
|
...generatorsFuncs,
|
|
135260
135454
|
};
|
|
135261
135455
|
({
|
|
135262
135456
|
...generatorsFuncs,
|
|
135263
135457
|
});
|
|
135458
|
+
({
|
|
135459
|
+
...generatorsFuncs,
|
|
135460
|
+
});
|
|
135264
135461
|
const generatorsMap = {
|
|
135265
135462
|
GenerateHashFromString: [
|
|
135266
135463
|
GenerateHashFromString,
|
|
@@ -135334,6 +135531,7 @@ const generatorsMap = {
|
|
|
135334
135531
|
],
|
|
135335
135532
|
GenerateUUID: [
|
|
135336
135533
|
GenerateUUID,
|
|
135534
|
+
GenerateUUIDV4,
|
|
135337
135535
|
],
|
|
135338
135536
|
GenerateFirstName: [
|
|
135339
135537
|
GenerateFirstName,
|
|
@@ -135664,7 +135862,7 @@ const selectGeneratorForCockroachColumn = (table, col) => {
|
|
|
135664
135862
|
return generator;
|
|
135665
135863
|
};
|
|
135666
135864
|
|
|
135667
|
-
const latestVersion =
|
|
135865
|
+
const latestVersion = 4;
|
|
135668
135866
|
|
|
135669
135867
|
const selectGeneratorForMssqlColumn = (table, col) => {
|
|
135670
135868
|
const pickGenerator = (table, col) => {
|
|
@@ -136554,6 +136752,7 @@ class SeedService {
|
|
|
136554
136752
|
};
|
|
136555
136753
|
}
|
|
136556
136754
|
}
|
|
136755
|
+
// handling refinements (count, with)
|
|
136557
136756
|
if (refinements !== undefined && refinements[table.name] !== undefined) {
|
|
136558
136757
|
if (refinements[table.name].count !== undefined) {
|
|
136559
136758
|
tablesPossibleGenerators[i].count = refinements[table.name].count;
|
|
@@ -136615,6 +136814,7 @@ class SeedService {
|
|
|
136615
136814
|
wasDefinedBefore: false,
|
|
136616
136815
|
wasRefined: false,
|
|
136617
136816
|
};
|
|
136817
|
+
// handling refinements (columnGenerator)
|
|
136618
136818
|
if (refinements !== undefined
|
|
136619
136819
|
&& refinements[table.name] !== undefined
|
|
136620
136820
|
&& refinements[table.name].columns !== undefined
|
|
@@ -136627,7 +136827,7 @@ class SeedService {
|
|
|
136627
136827
|
+ `\nwhich will cause an error because the column has a not null constraint and no default value.`);
|
|
136628
136828
|
}
|
|
136629
136829
|
// Generating undefined as a value for a column and then inserting it via drizzle-orm
|
|
136630
|
-
// will result in
|
|
136830
|
+
// will result in null of default value being inserted into that column.
|
|
136631
136831
|
columnPossibleGenerator.generator = new generatorsMap.GenerateDefault[0]({ defaultValue: undefined });
|
|
136632
136832
|
columnPossibleGenerator.wasRefined = true;
|
|
136633
136833
|
continue;
|
|
@@ -136965,7 +137165,8 @@ class SeedService {
|
|
|
136965
137165
|
};
|
|
136966
137166
|
}
|
|
136967
137167
|
// get values to generate columns with foreign key
|
|
136968
|
-
// if table posts contains foreign key to table users, then rel.table === 'posts' and rel.refTable === 'users',
|
|
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.
|
|
136969
137170
|
if (filteredRelations.length !== 0) {
|
|
136970
137171
|
for (const rel of filteredRelations) {
|
|
136971
137172
|
if (table.withFromTable[rel.refTable] !== undefined
|
|
@@ -137103,6 +137304,25 @@ class SeedService {
|
|
|
137103
137304
|
// columnsGenerators[columnName] = uniqueGen;
|
|
137104
137305
|
// }
|
|
137105
137306
|
}
|
|
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
|
+
}
|
|
137106
137326
|
let maxParametersNumber;
|
|
137107
137327
|
if (drizzleOrm.is(db, (pgCore.PgDatabase))) {
|
|
137108
137328
|
// @ts-ignore
|
|
@@ -137133,6 +137353,12 @@ class SeedService {
|
|
|
137133
137353
|
for (const columnName of Object.keys(columnsGenerators)) {
|
|
137134
137354
|
generatedValue = columnsGenerators[columnName].generate({ i, columnName });
|
|
137135
137355
|
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
|
+
}
|
|
137136
137362
|
}
|
|
137137
137363
|
if ((insertDataInDb === true || updateDataInDb === true)
|
|
137138
137364
|
&& ((i + 1) % batchSize === 0 || i === count - 1)) {
|
|
@@ -137179,9 +137405,28 @@ class SeedService {
|
|
|
137179
137405
|
}
|
|
137180
137406
|
}
|
|
137181
137407
|
}
|
|
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
|
+
}
|
|
137182
137417
|
}
|
|
137183
137418
|
return preserveData === true ? generatedValues : [];
|
|
137184
137419
|
};
|
|
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
|
+
};
|
|
137185
137430
|
insertInDb = async ({ generatedValues, db, schema, tableName, override, }) => {
|
|
137186
137431
|
if (drizzleOrm.is(db, (pgCore.PgDatabase))) {
|
|
137187
137432
|
const query = db.insert(schema[tableName]);
|
|
@@ -137907,7 +138152,7 @@ async function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject, drizzleSt
|
|
|
137907
138152
|
* // seeding with count and seed specified
|
|
137908
138153
|
* await seed(db, schema, { count: 100000, seed: 1 });
|
|
137909
138154
|
*
|
|
137910
|
-
* //seeding using refine
|
|
138155
|
+
* // seeding using refine
|
|
137911
138156
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
137912
138157
|
* users: {
|
|
137913
138158
|
* columns: {
|
|
@@ -137928,6 +138173,17 @@ async function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject, drizzleSt
|
|
|
137928
138173
|
* },
|
|
137929
138174
|
* }));
|
|
137930
138175
|
*
|
|
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
|
+
*
|
|
137931
138187
|
* ```
|
|
137932
138188
|
*/
|
|
137933
138189
|
function seed(db, schema, options) {
|
|
@@ -137999,6 +138255,10 @@ const seedFunc = async (db, schema, options = {}, refinements) => {
|
|
|
137999
138255
|
* @example
|
|
138000
138256
|
* ```ts
|
|
138001
138257
|
* 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 });
|
|
138002
138262
|
* ```
|
|
138003
138263
|
*/
|
|
138004
138264
|
async function reset(db, schema) {
|