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