drizzle-seed 0.1.2 → 0.1.3-e14a5a2
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.
Potentially problematic release.
This version of drizzle-seed might be problematic. Click here for more details.
- package/index.cjs +718 -307
- package/index.cjs.map +1 -1
- package/index.d.cts +52 -10
- package/index.d.mts +52 -10
- package/index.d.ts +52 -10
- package/index.mjs +718 -309
- package/index.mjs.map +1 -1
- package/package.json +3 -3
- package/services/GeneratorsWrappers.d.cts +232 -47
- package/services/GeneratorsWrappers.d.mts +232 -47
- package/services/GeneratorsWrappers.d.ts +232 -47
- package/services/SeedService.d.cts +80 -34
- package/services/SeedService.d.mts +80 -34
- package/services/SeedService.d.ts +80 -34
- package/services/utils.d.cts +2 -0
- package/services/utils.d.mts +2 -0
- package/services/utils.d.ts +2 -0
- package/types/seedService.d.cts +4 -0
- package/types/seedService.d.mts +4 -0
- package/types/seedService.d.ts +4 -0
- package/types/tables.d.cts +7 -0
- package/types/tables.d.mts +7 -0
- package/types/tables.d.ts +7 -0
- package/tests/benchmarks/generatorsBenchmark.d.cts +0 -1
- package/tests/benchmarks/generatorsBenchmark.d.mts +0 -1
- package/tests/benchmarks/generatorsBenchmark.d.ts +0 -1
- package/tests/mysql/allDataTypesTest/drizzle.config.d.cts +0 -2
- package/tests/mysql/allDataTypesTest/drizzle.config.d.mts +0 -2
- package/tests/mysql/allDataTypesTest/drizzle.config.d.ts +0 -2
- package/tests/mysql/allDataTypesTest/mysqlSchema.d.cts +0 -466
- package/tests/mysql/allDataTypesTest/mysqlSchema.d.mts +0 -466
- package/tests/mysql/allDataTypesTest/mysqlSchema.d.ts +0 -466
- package/tests/mysql/allDataTypesTest/mysql_all_data_types.test.d.cts +0 -1
- package/tests/mysql/allDataTypesTest/mysql_all_data_types.test.d.mts +0 -1
- package/tests/mysql/allDataTypesTest/mysql_all_data_types.test.d.ts +0 -1
- package/tests/mysql/drizzle.config.d.cts +0 -2
- package/tests/mysql/drizzle.config.d.mts +0 -2
- package/tests/mysql/drizzle.config.d.ts +0 -2
- package/tests/mysql/generatorsTest/drizzle.config.d.cts +0 -2
- package/tests/mysql/generatorsTest/drizzle.config.d.mts +0 -2
- package/tests/mysql/generatorsTest/drizzle.config.d.ts +0 -2
- package/tests/mysql/generatorsTest/generators.test.d.cts +0 -1
- package/tests/mysql/generatorsTest/generators.test.d.mts +0 -1
- package/tests/mysql/generatorsTest/generators.test.d.ts +0 -1
- package/tests/mysql/generatorsTest/mysqlSchema.d.cts +0 -48
- package/tests/mysql/generatorsTest/mysqlSchema.d.mts +0 -48
- package/tests/mysql/generatorsTest/mysqlSchema.d.ts +0 -48
- package/tests/mysql/mysql.test.d.cts +0 -1
- package/tests/mysql/mysql.test.d.mts +0 -1
- package/tests/mysql/mysql.test.d.ts +0 -1
- package/tests/mysql/mysqlSchema.d.cts +0 -1130
- package/tests/mysql/mysqlSchema.d.mts +0 -1130
- package/tests/mysql/mysqlSchema.d.ts +0 -1130
- package/tests/northwind/mysqlSchema.d.cts +0 -1130
- package/tests/northwind/mysqlSchema.d.mts +0 -1130
- package/tests/northwind/mysqlSchema.d.ts +0 -1130
- package/tests/northwind/mysqlTest.d.cts +0 -1
- package/tests/northwind/mysqlTest.d.mts +0 -1
- package/tests/northwind/mysqlTest.d.ts +0 -1
- package/tests/northwind/pgSchema.d.cts +0 -1131
- package/tests/northwind/pgSchema.d.mts +0 -1131
- package/tests/northwind/pgSchema.d.ts +0 -1131
- package/tests/northwind/pgTest.d.cts +0 -1
- package/tests/northwind/pgTest.d.mts +0 -1
- package/tests/northwind/pgTest.d.ts +0 -1
- package/tests/northwind/sqliteSchema.d.cts +0 -1130
- package/tests/northwind/sqliteSchema.d.mts +0 -1130
- package/tests/northwind/sqliteSchema.d.ts +0 -1130
- package/tests/northwind/sqliteTest.d.cts +0 -1
- package/tests/northwind/sqliteTest.d.mts +0 -1
- package/tests/northwind/sqliteTest.d.ts +0 -1
- package/tests/pg/allDataTypesTest/drizzle.config.d.cts +0 -2
- package/tests/pg/allDataTypesTest/drizzle.config.d.mts +0 -2
- package/tests/pg/allDataTypesTest/drizzle.config.d.ts +0 -2
- package/tests/pg/allDataTypesTest/pgSchema.d.cts +0 -509
- package/tests/pg/allDataTypesTest/pgSchema.d.mts +0 -509
- package/tests/pg/allDataTypesTest/pgSchema.d.ts +0 -509
- package/tests/pg/allDataTypesTest/pg_all_data_types.test.d.cts +0 -1
- package/tests/pg/allDataTypesTest/pg_all_data_types.test.d.mts +0 -1
- package/tests/pg/allDataTypesTest/pg_all_data_types.test.d.ts +0 -1
- package/tests/pg/drizzle.config.d.cts +0 -2
- package/tests/pg/drizzle.config.d.mts +0 -2
- package/tests/pg/drizzle.config.d.ts +0 -2
- package/tests/pg/generatorsTest/drizzle.config.d.cts +0 -2
- package/tests/pg/generatorsTest/drizzle.config.d.mts +0 -2
- package/tests/pg/generatorsTest/drizzle.config.d.ts +0 -2
- package/tests/pg/generatorsTest/generators.test.d.cts +0 -1
- package/tests/pg/generatorsTest/generators.test.d.mts +0 -1
- package/tests/pg/generatorsTest/generators.test.d.ts +0 -1
- package/tests/pg/generatorsTest/pgSchema.d.cts +0 -1136
- package/tests/pg/generatorsTest/pgSchema.d.mts +0 -1136
- package/tests/pg/generatorsTest/pgSchema.d.ts +0 -1136
- package/tests/pg/pg.test.d.cts +0 -1
- package/tests/pg/pg.test.d.mts +0 -1
- package/tests/pg/pg.test.d.ts +0 -1
- package/tests/pg/pgSchema.d.cts +0 -1189
- package/tests/pg/pgSchema.d.mts +0 -1189
- package/tests/pg/pgSchema.d.ts +0 -1189
- package/tests/sqlite/allDataTypesTest/sqliteSchema.d.cts +0 -194
- package/tests/sqlite/allDataTypesTest/sqliteSchema.d.mts +0 -194
- package/tests/sqlite/allDataTypesTest/sqliteSchema.d.ts +0 -194
- package/tests/sqlite/allDataTypesTest/sqlite_all_data_types.test.d.cts +0 -1
- package/tests/sqlite/allDataTypesTest/sqlite_all_data_types.test.d.mts +0 -1
- package/tests/sqlite/allDataTypesTest/sqlite_all_data_types.test.d.ts +0 -1
- package/tests/sqlite/sqlite.test.d.cts +0 -1
- package/tests/sqlite/sqlite.test.d.mts +0 -1
- package/tests/sqlite/sqlite.test.d.ts +0 -1
- package/tests/sqlite/sqliteSchema.d.cts +0 -1130
- package/tests/sqlite/sqliteSchema.d.mts +0 -1130
- package/tests/sqlite/sqliteSchema.d.ts +0 -1130
- package/tests/vitest.config.d.cts +0 -2
- package/tests/vitest.config.d.mts +0 -2
- package/tests/vitest.config.d.ts +0 -2
- package/type-tests/mysql.d.cts +0 -1
- package/type-tests/mysql.d.mts +0 -1
- package/type-tests/mysql.d.ts +0 -1
- package/type-tests/pg.d.cts +0 -1
- package/type-tests/pg.d.mts +0 -1
- package/type-tests/pg.d.ts +0 -1
- package/type-tests/sqlite.d.cts +0 -1
- package/type-tests/sqlite.d.mts +0 -1
- package/type-tests/sqlite.d.ts +0 -1
package/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { entityKind, is, sql, getTableName } from 'drizzle-orm';
|
|
1
|
+
import { entityKind, is, eq, sql, getTableName } from 'drizzle-orm';
|
|
2
2
|
import { MySqlDatabase, MySqlTable, getTableConfig as getTableConfig$1 } from 'drizzle-orm/mysql-core';
|
|
3
3
|
import { PgDatabase, getTableConfig, PgTable } from 'drizzle-orm/pg-core';
|
|
4
4
|
import { BaseSQLiteDatabase, SQLiteTable, getTableConfig as getTableConfig$2 } from 'drizzle-orm/sqlite-core';
|
|
@@ -131190,6 +131190,19 @@ const fillTemplate = ({ template, placeholdersCount, values, defaultValue = ' '
|
|
|
131190
131190
|
}
|
|
131191
131191
|
return resultStr;
|
|
131192
131192
|
};
|
|
131193
|
+
// is variable is object-like.
|
|
131194
|
+
// Example:
|
|
131195
|
+
// isObject({f: 4}) === true;
|
|
131196
|
+
// isObject([1,2,3]) === false;
|
|
131197
|
+
// isObject(new Set()) === false;
|
|
131198
|
+
const isObject = (value) => {
|
|
131199
|
+
if (value !== null && value !== undefined && value.constructor === Object)
|
|
131200
|
+
return true;
|
|
131201
|
+
return false;
|
|
131202
|
+
};
|
|
131203
|
+
const equalSets = (set1, set2) => {
|
|
131204
|
+
return set1.size === set2.size && [...set1].every((si) => set2.has(si));
|
|
131205
|
+
};
|
|
131193
131206
|
|
|
131194
131207
|
class AbstractGenerator {
|
|
131195
131208
|
params;
|
|
@@ -131199,9 +131212,56 @@ class AbstractGenerator {
|
|
|
131199
131212
|
uniqueVersionOfGen;
|
|
131200
131213
|
dataType;
|
|
131201
131214
|
timeSpent;
|
|
131215
|
+
arraySize;
|
|
131216
|
+
baseColumnDataType;
|
|
131202
131217
|
constructor(params) {
|
|
131203
131218
|
this.params = params;
|
|
131204
131219
|
}
|
|
131220
|
+
init() {
|
|
131221
|
+
if (this.params.arraySize !== undefined) {
|
|
131222
|
+
this.arraySize = this.params.arraySize;
|
|
131223
|
+
}
|
|
131224
|
+
if (this.params.isUnique !== undefined) {
|
|
131225
|
+
if (this.params.isUnique === false && this.isUnique === true) {
|
|
131226
|
+
throw new Error('specifying non unique generator to unique column.');
|
|
131227
|
+
}
|
|
131228
|
+
this.isUnique = this.params.isUnique;
|
|
131229
|
+
}
|
|
131230
|
+
}
|
|
131231
|
+
getEntityKind() {
|
|
131232
|
+
const constructor = this.constructor;
|
|
131233
|
+
return constructor[entityKind];
|
|
131234
|
+
}
|
|
131235
|
+
replaceIfUnique({ count, seed }) {
|
|
131236
|
+
if (this.uniqueVersionOfGen !== undefined
|
|
131237
|
+
&& this.isUnique === true) {
|
|
131238
|
+
const uniqueGen = new this.uniqueVersionOfGen({
|
|
131239
|
+
...this.params,
|
|
131240
|
+
});
|
|
131241
|
+
uniqueGen.init({
|
|
131242
|
+
count,
|
|
131243
|
+
seed,
|
|
131244
|
+
});
|
|
131245
|
+
uniqueGen.isUnique = this.isUnique;
|
|
131246
|
+
uniqueGen.dataType = this.dataType;
|
|
131247
|
+
return uniqueGen;
|
|
131248
|
+
}
|
|
131249
|
+
return;
|
|
131250
|
+
}
|
|
131251
|
+
replaceIfArray({ count, seed }) {
|
|
131252
|
+
if (!(this.getEntityKind() === 'GenerateArray') && this.arraySize !== undefined) {
|
|
131253
|
+
const uniqueGen = this.replaceIfUnique({ count, seed });
|
|
131254
|
+
const baseColumnGen = uniqueGen === undefined ? this : uniqueGen;
|
|
131255
|
+
baseColumnGen.dataType = this.baseColumnDataType;
|
|
131256
|
+
const arrayGen = new GenerateArray({
|
|
131257
|
+
baseColumnGen,
|
|
131258
|
+
size: this.arraySize,
|
|
131259
|
+
});
|
|
131260
|
+
arrayGen.init({ count, seed });
|
|
131261
|
+
return arrayGen;
|
|
131262
|
+
}
|
|
131263
|
+
return;
|
|
131264
|
+
}
|
|
131205
131265
|
}
|
|
131206
131266
|
function createGenerator(generatorConstructor) {
|
|
131207
131267
|
return (...args) => {
|
|
@@ -131212,6 +131272,22 @@ function createGenerator(generatorConstructor) {
|
|
|
131212
131272
|
};
|
|
131213
131273
|
}
|
|
131214
131274
|
// Generators Classes -----------------------------------------------------------------------------------------------------------------------
|
|
131275
|
+
class GenerateArray extends AbstractGenerator {
|
|
131276
|
+
static [entityKind] = 'GenerateArray';
|
|
131277
|
+
arraySize = 10;
|
|
131278
|
+
init({ count, seed }) {
|
|
131279
|
+
super.init({ count, seed });
|
|
131280
|
+
this.arraySize = this.params.size === undefined ? this.arraySize : this.params.size;
|
|
131281
|
+
this.params.baseColumnGen.init({ count: count * this.arraySize, seed });
|
|
131282
|
+
}
|
|
131283
|
+
generate() {
|
|
131284
|
+
const array = [];
|
|
131285
|
+
for (let i = 0; i < this.arraySize; i++) {
|
|
131286
|
+
array.push(this.params.baseColumnGen.generate({ i }));
|
|
131287
|
+
}
|
|
131288
|
+
return array;
|
|
131289
|
+
}
|
|
131290
|
+
}
|
|
131215
131291
|
class GenerateWeightedCount extends AbstractGenerator {
|
|
131216
131292
|
static [entityKind] = 'GenerateWeightedCount';
|
|
131217
131293
|
state;
|
|
@@ -131247,7 +131323,6 @@ class HollowGenerator extends AbstractGenerator {
|
|
|
131247
131323
|
}
|
|
131248
131324
|
class GenerateDefault extends AbstractGenerator {
|
|
131249
131325
|
static [entityKind] = 'GenerateDefault';
|
|
131250
|
-
init() { }
|
|
131251
131326
|
generate() {
|
|
131252
131327
|
return this.params.defaultValue;
|
|
131253
131328
|
}
|
|
@@ -131264,7 +131339,7 @@ class GenerateValuesFromArray extends AbstractGenerator {
|
|
|
131264
131339
|
if (values.length === 0) {
|
|
131265
131340
|
throw new Error('Values length equals zero.');
|
|
131266
131341
|
}
|
|
131267
|
-
if (
|
|
131342
|
+
if (isObject(values[0])
|
|
131268
131343
|
&& !values.every((val) => val.values.length !== 0)) {
|
|
131269
131344
|
throw new Error('One of weighted values length equals zero.');
|
|
131270
131345
|
}
|
|
@@ -131276,14 +131351,14 @@ class GenerateValuesFromArray extends AbstractGenerator {
|
|
|
131276
131351
|
throw new Error('maxRepeatedValuesCount should be greater than zero.');
|
|
131277
131352
|
}
|
|
131278
131353
|
let allValuesCount = values.length;
|
|
131279
|
-
if (
|
|
131354
|
+
if (isObject(values[0])) {
|
|
131280
131355
|
allValuesCount = values.reduce((acc, currVal) => acc + currVal.values.length, 0);
|
|
131281
131356
|
}
|
|
131282
131357
|
if (notNull === true
|
|
131283
131358
|
&& maxRepeatedValuesCount !== undefined
|
|
131284
|
-
&& ((
|
|
131359
|
+
&& ((!isObject(values[0]) && typeof maxRepeatedValuesCount === 'number'
|
|
131285
131360
|
&& maxRepeatedValuesCount * values.length < count)
|
|
131286
|
-
|| (
|
|
131361
|
+
|| (isObject(values[0]) && typeof maxRepeatedValuesCount === 'number'
|
|
131287
131362
|
&& maxRepeatedValuesCount * allValuesCount < count))) {
|
|
131288
131363
|
throw new Error("Can't fill notNull column with null values.");
|
|
131289
131364
|
}
|
|
@@ -131294,25 +131369,20 @@ class GenerateValuesFromArray extends AbstractGenerator {
|
|
|
131294
131369
|
: obj.count.every((count) => count === 1))))) {
|
|
131295
131370
|
throw new Error("Can't be greater than 1 if column is unique.");
|
|
131296
131371
|
}
|
|
131297
|
-
if (isUnique === true && notNull === true && ((
|
|
131298
|
-
|| (
|
|
131372
|
+
if (isUnique === true && notNull === true && ((!isObject(values[0]) && values.length < count)
|
|
131373
|
+
|| (isObject(values[0]) && allValuesCount < count))) {
|
|
131299
131374
|
// console.log(maxRepeatedValuesCount, values.length, allValuesCount, count)
|
|
131300
131375
|
throw new Error('There are no enough values to fill unique column.');
|
|
131301
131376
|
}
|
|
131302
131377
|
}
|
|
131303
131378
|
init({ count, seed }) {
|
|
131304
|
-
|
|
131305
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
131306
|
-
throw new Error('Specifying non unique generator to unique column.');
|
|
131307
|
-
}
|
|
131308
|
-
this.isUnique = this.params.isUnique;
|
|
131309
|
-
}
|
|
131379
|
+
super.init({ count, seed });
|
|
131310
131380
|
this.checks({ count });
|
|
131311
131381
|
let { maxRepeatedValuesCount } = this;
|
|
131312
131382
|
const { params, isUnique, notNull, weightedCountSeed } = this;
|
|
131313
131383
|
const values = params.values;
|
|
131314
131384
|
let valuesWeightedIndices;
|
|
131315
|
-
if (
|
|
131385
|
+
if (isObject(values[0])) {
|
|
131316
131386
|
valuesWeightedIndices = getWeightedIndices(values.map((val) => val.weight));
|
|
131317
131387
|
if (isUnique === true && notNull === true) {
|
|
131318
131388
|
let idx, valueIdx, rng = prand.xoroshiro128plus(seed);
|
|
@@ -131351,13 +131421,13 @@ class GenerateValuesFromArray extends AbstractGenerator {
|
|
|
131351
131421
|
let genIndicesObj;
|
|
131352
131422
|
let genIndicesObjList;
|
|
131353
131423
|
if (maxRepeatedValuesCount !== undefined) {
|
|
131354
|
-
if (
|
|
131424
|
+
if (!isObject(values[0])) {
|
|
131355
131425
|
genIndicesObj = new GenerateUniqueInt({ minValue: 0, maxValue: values.length - 1 });
|
|
131356
131426
|
genIndicesObj.genMaxRepeatedValuesCount = genMaxRepeatedValuesCount;
|
|
131357
131427
|
genIndicesObj.skipCheck = true;
|
|
131358
131428
|
genIndicesObj.init({ count, seed });
|
|
131359
131429
|
}
|
|
131360
|
-
else if (
|
|
131430
|
+
else if (isObject(values[0])) {
|
|
131361
131431
|
genIndicesObjList = [];
|
|
131362
131432
|
for (const obj of values) {
|
|
131363
131433
|
const genIndicesObj = new GenerateUniqueInt({ minValue: 0, maxValue: obj.values.length - 1 });
|
|
@@ -131452,15 +131522,8 @@ class GenerateNumber extends AbstractGenerator {
|
|
|
131452
131522
|
static [entityKind] = 'GenerateNumber';
|
|
131453
131523
|
state;
|
|
131454
131524
|
uniqueVersionOfGen = GenerateUniqueNumber;
|
|
131455
|
-
init({ seed }) {
|
|
131456
|
-
|
|
131457
|
-
this.params = {};
|
|
131458
|
-
if (this.params.isUnique !== undefined) {
|
|
131459
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
131460
|
-
throw new Error('specifying non unique generator to unique column.');
|
|
131461
|
-
}
|
|
131462
|
-
this.isUnique = this.params.isUnique;
|
|
131463
|
-
}
|
|
131525
|
+
init({ count, seed }) {
|
|
131526
|
+
super.init({ count, seed });
|
|
131464
131527
|
let { minValue, maxValue, precision } = this.params;
|
|
131465
131528
|
if (precision === undefined) {
|
|
131466
131529
|
precision = 100;
|
|
@@ -131494,8 +131557,6 @@ class GenerateUniqueNumber extends AbstractGenerator {
|
|
|
131494
131557
|
state;
|
|
131495
131558
|
isUnique = true;
|
|
131496
131559
|
init({ count, seed }) {
|
|
131497
|
-
if (this.params === undefined)
|
|
131498
|
-
this.params = {};
|
|
131499
131560
|
let { minValue, maxValue, precision } = this.params;
|
|
131500
131561
|
if (precision === undefined) {
|
|
131501
131562
|
precision = 100;
|
|
@@ -131528,13 +131589,8 @@ class GenerateInt extends AbstractGenerator {
|
|
|
131528
131589
|
static [entityKind] = 'GenerateInt';
|
|
131529
131590
|
state;
|
|
131530
131591
|
uniqueVersionOfGen = GenerateUniqueInt;
|
|
131531
|
-
init({ seed }) {
|
|
131532
|
-
|
|
131533
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
131534
|
-
throw new Error('specifying non unique generator to unique column.');
|
|
131535
|
-
}
|
|
131536
|
-
this.isUnique = this.params.isUnique;
|
|
131537
|
-
}
|
|
131592
|
+
init({ count, seed }) {
|
|
131593
|
+
super.init({ count, seed });
|
|
131538
131594
|
let { minValue, maxValue } = this.params;
|
|
131539
131595
|
if (maxValue === undefined) {
|
|
131540
131596
|
maxValue = 1000;
|
|
@@ -131697,7 +131753,8 @@ class GenerateUniqueInt extends AbstractGenerator {
|
|
|
131697
131753
|
class GenerateBoolean extends AbstractGenerator {
|
|
131698
131754
|
static [entityKind] = 'GenerateBoolean';
|
|
131699
131755
|
state;
|
|
131700
|
-
init({ seed }) {
|
|
131756
|
+
init({ count, seed }) {
|
|
131757
|
+
super.init({ count, seed });
|
|
131701
131758
|
const rng = prand.xoroshiro128plus(seed);
|
|
131702
131759
|
this.state = { rng };
|
|
131703
131760
|
}
|
|
@@ -131713,7 +131770,8 @@ class GenerateBoolean extends AbstractGenerator {
|
|
|
131713
131770
|
class GenerateDate extends AbstractGenerator {
|
|
131714
131771
|
static [entityKind] = 'GenerateDate';
|
|
131715
131772
|
state;
|
|
131716
|
-
init({ seed }) {
|
|
131773
|
+
init({ count, seed }) {
|
|
131774
|
+
super.init({ count, seed });
|
|
131717
131775
|
const rng = prand.xoroshiro128plus(seed);
|
|
131718
131776
|
let { minDate, maxDate } = this.params;
|
|
131719
131777
|
const anchorDate = new Date('2024-05-08');
|
|
@@ -131754,7 +131812,8 @@ class GenerateDate extends AbstractGenerator {
|
|
|
131754
131812
|
class GenerateTime extends AbstractGenerator {
|
|
131755
131813
|
static [entityKind] = 'GenerateTime';
|
|
131756
131814
|
state;
|
|
131757
|
-
init({ seed }) {
|
|
131815
|
+
init({ count, seed }) {
|
|
131816
|
+
super.init({ count, seed });
|
|
131758
131817
|
const rng = prand.xoroshiro128plus(seed);
|
|
131759
131818
|
this.state = { rng };
|
|
131760
131819
|
}
|
|
@@ -131774,7 +131833,8 @@ class GenerateTime extends AbstractGenerator {
|
|
|
131774
131833
|
class GenerateTimestamp extends AbstractGenerator {
|
|
131775
131834
|
static [entityKind] = 'GenerateTimestamp';
|
|
131776
131835
|
state;
|
|
131777
|
-
init({ seed }) {
|
|
131836
|
+
init({ count, seed }) {
|
|
131837
|
+
super.init({ count, seed });
|
|
131778
131838
|
const rng = prand.xoroshiro128plus(seed);
|
|
131779
131839
|
this.state = { rng };
|
|
131780
131840
|
}
|
|
@@ -131800,7 +131860,8 @@ class GenerateTimestamp extends AbstractGenerator {
|
|
|
131800
131860
|
class GenerateDatetime extends AbstractGenerator {
|
|
131801
131861
|
static [entityKind] = 'GenerateDatetime';
|
|
131802
131862
|
state;
|
|
131803
|
-
init({ seed }) {
|
|
131863
|
+
init({ count, seed }) {
|
|
131864
|
+
super.init({ count, seed });
|
|
131804
131865
|
const rng = prand.xoroshiro128plus(seed);
|
|
131805
131866
|
this.state = { rng };
|
|
131806
131867
|
}
|
|
@@ -131826,7 +131887,8 @@ class GenerateDatetime extends AbstractGenerator {
|
|
|
131826
131887
|
class GenerateYear extends AbstractGenerator {
|
|
131827
131888
|
static [entityKind] = 'GenerateYear';
|
|
131828
131889
|
state;
|
|
131829
|
-
init({ seed }) {
|
|
131890
|
+
init({ count, seed }) {
|
|
131891
|
+
super.init({ count, seed });
|
|
131830
131892
|
const rng = prand.xoroshiro128plus(seed);
|
|
131831
131893
|
this.state = { rng };
|
|
131832
131894
|
}
|
|
@@ -131849,12 +131911,14 @@ class GenerateJson extends AbstractGenerator {
|
|
|
131849
131911
|
static [entityKind] = 'GenerateJson';
|
|
131850
131912
|
state;
|
|
131851
131913
|
init({ count, seed }) {
|
|
131914
|
+
super.init({ count, seed });
|
|
131852
131915
|
const emailGeneratorObj = new GenerateEmail({});
|
|
131853
131916
|
emailGeneratorObj.init({ count, seed });
|
|
131854
131917
|
const nameGeneratorObj = new GenerateFirstName({});
|
|
131855
|
-
nameGeneratorObj.init({ seed });
|
|
131918
|
+
nameGeneratorObj.init({ count, seed });
|
|
131856
131919
|
const booleanGeneratorObj = new GenerateBoolean({});
|
|
131857
131920
|
booleanGeneratorObj.init({
|
|
131921
|
+
count,
|
|
131858
131922
|
seed,
|
|
131859
131923
|
});
|
|
131860
131924
|
const salaryGeneratorObj = new GenerateInt({ minValue: 200, maxValue: 4000 });
|
|
@@ -131865,7 +131929,7 @@ class GenerateJson extends AbstractGenerator {
|
|
|
131865
131929
|
});
|
|
131866
131930
|
const dateGeneratorObj = new GenerateDate({});
|
|
131867
131931
|
dateGeneratorObj.dataType = 'string';
|
|
131868
|
-
dateGeneratorObj.init({ seed });
|
|
131932
|
+
dateGeneratorObj.init({ count, seed });
|
|
131869
131933
|
const visitedCountriesNumberGeneratorObj = new GenerateInt({ minValue: 0, maxValue: 4 });
|
|
131870
131934
|
visitedCountriesNumberGeneratorObj.init({ count, seed, ...visitedCountriesNumberGeneratorObj.params });
|
|
131871
131935
|
this.state = {
|
|
@@ -131942,13 +132006,8 @@ class GenerateInterval extends AbstractGenerator {
|
|
|
131942
132006
|
static [entityKind] = 'GenerateInterval';
|
|
131943
132007
|
state;
|
|
131944
132008
|
uniqueVersionOfGen = GenerateUniqueInterval;
|
|
131945
|
-
init({ seed }) {
|
|
131946
|
-
|
|
131947
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
131948
|
-
throw new Error('specifying non unique generator to unique column.');
|
|
131949
|
-
}
|
|
131950
|
-
this.isUnique = this.params.isUnique;
|
|
131951
|
-
}
|
|
132009
|
+
init({ count, seed }) {
|
|
132010
|
+
super.init({ count, seed });
|
|
131952
132011
|
const rng = prand.xoroshiro128plus(seed);
|
|
131953
132012
|
this.state = { rng };
|
|
131954
132013
|
}
|
|
@@ -131976,6 +132035,7 @@ class GenerateInterval extends AbstractGenerator {
|
|
|
131976
132035
|
class GenerateUniqueInterval extends AbstractGenerator {
|
|
131977
132036
|
static [entityKind] = 'GenerateUniqueInterval';
|
|
131978
132037
|
state;
|
|
132038
|
+
isUnique = true;
|
|
131979
132039
|
init({ count, seed }) {
|
|
131980
132040
|
const maxUniqueIntervalsNumber = 6 * 13 * 29 * 25 * 61 * 61;
|
|
131981
132041
|
if (count > maxUniqueIntervalsNumber) {
|
|
@@ -132016,13 +132076,8 @@ class GenerateString extends AbstractGenerator {
|
|
|
132016
132076
|
static [entityKind] = 'GenerateString';
|
|
132017
132077
|
state;
|
|
132018
132078
|
uniqueVersionOfGen = GenerateUniqueString;
|
|
132019
|
-
init({ seed }) {
|
|
132020
|
-
|
|
132021
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
132022
|
-
throw new Error('specifying non unique generator to unique column.');
|
|
132023
|
-
}
|
|
132024
|
-
this.isUnique = this.params.isUnique;
|
|
132025
|
-
}
|
|
132079
|
+
init({ count, seed }) {
|
|
132080
|
+
super.init({ count, seed });
|
|
132026
132081
|
const rng = prand.xoroshiro128plus(seed);
|
|
132027
132082
|
this.state = { rng };
|
|
132028
132083
|
}
|
|
@@ -132070,18 +132125,44 @@ class GenerateUniqueString extends AbstractGenerator {
|
|
|
132070
132125
|
return currStr.slice(0, 4) + uniqueStr + currStr.slice(4);
|
|
132071
132126
|
}
|
|
132072
132127
|
}
|
|
132128
|
+
class GenerateUUID extends AbstractGenerator {
|
|
132129
|
+
static [entityKind] = 'GenerateUUID';
|
|
132130
|
+
isUnique = true;
|
|
132131
|
+
state;
|
|
132132
|
+
init({ count, seed }) {
|
|
132133
|
+
super.init({ count, seed });
|
|
132134
|
+
const rng = prand.xoroshiro128plus(seed);
|
|
132135
|
+
this.state = { rng };
|
|
132136
|
+
}
|
|
132137
|
+
generate() {
|
|
132138
|
+
if (this.state === undefined) {
|
|
132139
|
+
throw new Error('state is not defined.');
|
|
132140
|
+
}
|
|
132141
|
+
// TODO generate uuid using string generator
|
|
132142
|
+
const stringChars = '1234567890abcdef';
|
|
132143
|
+
let idx, currStr;
|
|
132144
|
+
const strLength = 36;
|
|
132145
|
+
// uuid v4
|
|
132146
|
+
const uuidTemplate = '########-####-4###-####-############';
|
|
132147
|
+
currStr = '';
|
|
132148
|
+
for (let i = 0; i < strLength; i++) {
|
|
132149
|
+
[idx, this.state.rng] = prand.uniformIntDistribution(0, stringChars.length - 1, this.state.rng);
|
|
132150
|
+
if (uuidTemplate[i] === '#') {
|
|
132151
|
+
currStr += stringChars[idx];
|
|
132152
|
+
continue;
|
|
132153
|
+
}
|
|
132154
|
+
currStr += uuidTemplate[i];
|
|
132155
|
+
}
|
|
132156
|
+
return currStr;
|
|
132157
|
+
}
|
|
132158
|
+
}
|
|
132073
132159
|
class GenerateFirstName extends AbstractGenerator {
|
|
132074
132160
|
static [entityKind] = 'GenerateFirstName';
|
|
132075
132161
|
timeSpent = 0;
|
|
132076
132162
|
state;
|
|
132077
132163
|
uniqueVersionOfGen = GenerateUniqueFirstName;
|
|
132078
|
-
init({ seed }) {
|
|
132079
|
-
|
|
132080
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
132081
|
-
throw new Error('specifying non unique generator to unique column.');
|
|
132082
|
-
}
|
|
132083
|
-
this.isUnique = this.params.isUnique;
|
|
132084
|
-
}
|
|
132164
|
+
init({ count, seed }) {
|
|
132165
|
+
super.init({ count, seed });
|
|
132085
132166
|
const rng = prand.xoroshiro128plus(seed);
|
|
132086
132167
|
this.state = { rng };
|
|
132087
132168
|
}
|
|
@@ -132123,13 +132204,8 @@ class GenerateLastName extends AbstractGenerator {
|
|
|
132123
132204
|
static [entityKind] = 'GenerateLastName';
|
|
132124
132205
|
state;
|
|
132125
132206
|
uniqueVersionOfGen = GenerateUniqueLastName;
|
|
132126
|
-
init({ seed }) {
|
|
132127
|
-
|
|
132128
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
132129
|
-
throw new Error('specifying non unique generator to unique column.');
|
|
132130
|
-
}
|
|
132131
|
-
this.isUnique = this.params.isUnique;
|
|
132132
|
-
}
|
|
132207
|
+
init({ count, seed }) {
|
|
132208
|
+
super.init({ count, seed });
|
|
132133
132209
|
const rng = prand.xoroshiro128plus(seed);
|
|
132134
132210
|
this.state = { rng };
|
|
132135
132211
|
}
|
|
@@ -132167,13 +132243,8 @@ class GenerateFullName extends AbstractGenerator {
|
|
|
132167
132243
|
static [entityKind] = 'GenerateFullName';
|
|
132168
132244
|
state;
|
|
132169
132245
|
uniqueVersionOfGen = GenerateUniqueFullName;
|
|
132170
|
-
init({ seed }) {
|
|
132171
|
-
|
|
132172
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
132173
|
-
throw new Error('specifying non unique generator to unique column.');
|
|
132174
|
-
}
|
|
132175
|
-
this.isUnique = this.params.isUnique;
|
|
132176
|
-
}
|
|
132246
|
+
init({ count, seed }) {
|
|
132247
|
+
super.init({ count, seed });
|
|
132177
132248
|
const rng = prand.xoroshiro128plus(seed);
|
|
132178
132249
|
this.state = { rng };
|
|
132179
132250
|
}
|
|
@@ -132233,6 +132304,7 @@ class GenerateEmail extends AbstractGenerator {
|
|
|
132233
132304
|
timeSpent = 0;
|
|
132234
132305
|
isUnique = true;
|
|
132235
132306
|
init({ count, seed }) {
|
|
132307
|
+
super.init({ count, seed });
|
|
132236
132308
|
const domainsArray = emailDomains;
|
|
132237
132309
|
const adjectivesArray = adjectives;
|
|
132238
132310
|
const namesArray = firstNames;
|
|
@@ -132266,6 +132338,7 @@ class GeneratePhoneNumber extends AbstractGenerator {
|
|
|
132266
132338
|
state;
|
|
132267
132339
|
isUnique = true;
|
|
132268
132340
|
init({ count, seed }) {
|
|
132341
|
+
super.init({ count, seed });
|
|
132269
132342
|
let { generatedDigitsNumbers } = this.params;
|
|
132270
132343
|
const { prefixes, template } = this.params;
|
|
132271
132344
|
const rng = prand.xoroshiro128plus(seed);
|
|
@@ -132382,13 +132455,8 @@ class GenerateCountry extends AbstractGenerator {
|
|
|
132382
132455
|
static [entityKind] = 'GenerateCountry';
|
|
132383
132456
|
state;
|
|
132384
132457
|
uniqueVersionOfGen = GenerateUniqueCountry;
|
|
132385
|
-
init({ seed }) {
|
|
132386
|
-
|
|
132387
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
132388
|
-
throw new Error('specifying non unique generator to unique column.');
|
|
132389
|
-
}
|
|
132390
|
-
this.isUnique = this.params.isUnique;
|
|
132391
|
-
}
|
|
132458
|
+
init({ count, seed }) {
|
|
132459
|
+
super.init({ count, seed });
|
|
132392
132460
|
const rng = prand.xoroshiro128plus(seed);
|
|
132393
132461
|
this.state = { rng };
|
|
132394
132462
|
}
|
|
@@ -132426,7 +132494,8 @@ class GenerateUniqueCountry extends AbstractGenerator {
|
|
|
132426
132494
|
class GenerateJobTitle extends AbstractGenerator {
|
|
132427
132495
|
static [entityKind] = 'GenerateJobTitle';
|
|
132428
132496
|
state;
|
|
132429
|
-
init({ seed }) {
|
|
132497
|
+
init({ count, seed }) {
|
|
132498
|
+
super.init({ count, seed });
|
|
132430
132499
|
const rng = prand.xoroshiro128plus(seed);
|
|
132431
132500
|
this.state = { rng };
|
|
132432
132501
|
}
|
|
@@ -132443,13 +132512,8 @@ class GenerateStreetAdddress extends AbstractGenerator {
|
|
|
132443
132512
|
static [entityKind] = 'GenerateStreetAdddress';
|
|
132444
132513
|
state;
|
|
132445
132514
|
uniqueVersionOfGen = GenerateUniqueStreetAdddress;
|
|
132446
|
-
init({ seed }) {
|
|
132447
|
-
|
|
132448
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
132449
|
-
throw new Error('specifying non unique generator to unique column.');
|
|
132450
|
-
}
|
|
132451
|
-
this.isUnique = this.params.isUnique;
|
|
132452
|
-
}
|
|
132515
|
+
init({ count, seed }) {
|
|
132516
|
+
super.init({ count, seed });
|
|
132453
132517
|
const rng = prand.xoroshiro128plus(seed);
|
|
132454
132518
|
const possStreetNames = [firstNames, lastNames];
|
|
132455
132519
|
this.state = { rng, possStreetNames };
|
|
@@ -132470,6 +132534,7 @@ class GenerateStreetAdddress extends AbstractGenerator {
|
|
|
132470
132534
|
class GenerateUniqueStreetAdddress extends AbstractGenerator {
|
|
132471
132535
|
static [entityKind] = 'GenerateUniqueStreetAdddress';
|
|
132472
132536
|
state;
|
|
132537
|
+
isUnique = true;
|
|
132473
132538
|
init({ count, seed }) {
|
|
132474
132539
|
const streetNumberStrs = Array.from({ length: 999 }, (_, i) => String(i + 1));
|
|
132475
132540
|
const maxUniqueStreetnamesNumber = streetNumberStrs.length * firstNames.length * streetSuffix.length
|
|
@@ -132528,13 +132593,8 @@ class GenerateCity extends AbstractGenerator {
|
|
|
132528
132593
|
static [entityKind] = 'GenerateCity';
|
|
132529
132594
|
state;
|
|
132530
132595
|
uniqueVersionOfGen = GenerateUniqueCity;
|
|
132531
|
-
init({ seed }) {
|
|
132532
|
-
|
|
132533
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
132534
|
-
throw new Error('specifying non unique generator to unique column.');
|
|
132535
|
-
}
|
|
132536
|
-
this.isUnique = this.params.isUnique;
|
|
132537
|
-
}
|
|
132596
|
+
init({ count, seed }) {
|
|
132597
|
+
super.init({ count, seed });
|
|
132538
132598
|
const rng = prand.xoroshiro128plus(seed);
|
|
132539
132599
|
this.state = { rng };
|
|
132540
132600
|
}
|
|
@@ -132572,13 +132632,8 @@ class GeneratePostcode extends AbstractGenerator {
|
|
|
132572
132632
|
static [entityKind] = 'GeneratePostcode';
|
|
132573
132633
|
state;
|
|
132574
132634
|
uniqueVersionOfGen = GenerateUniquePostcode;
|
|
132575
|
-
init({ seed }) {
|
|
132576
|
-
|
|
132577
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
132578
|
-
throw new Error('specifying non unique generator to unique column.');
|
|
132579
|
-
}
|
|
132580
|
-
this.isUnique = this.params.isUnique;
|
|
132581
|
-
}
|
|
132635
|
+
init({ count, seed }) {
|
|
132636
|
+
super.init({ count, seed });
|
|
132582
132637
|
const rng = prand.xoroshiro128plus(seed);
|
|
132583
132638
|
const templates = ['#####', '#####-####'];
|
|
132584
132639
|
this.state = { rng, templates };
|
|
@@ -132605,6 +132660,7 @@ class GeneratePostcode extends AbstractGenerator {
|
|
|
132605
132660
|
class GenerateUniquePostcode extends AbstractGenerator {
|
|
132606
132661
|
static [entityKind] = 'GenerateUniquePostcode';
|
|
132607
132662
|
state;
|
|
132663
|
+
isUnique = true;
|
|
132608
132664
|
init({ count, seed }) {
|
|
132609
132665
|
const maxUniquePostcodeNumber = Math.pow(10, 5) + Math.pow(10, 9);
|
|
132610
132666
|
if (count > maxUniquePostcodeNumber) {
|
|
@@ -132658,7 +132714,8 @@ class GenerateUniquePostcode extends AbstractGenerator {
|
|
|
132658
132714
|
class GenerateState extends AbstractGenerator {
|
|
132659
132715
|
static [entityKind] = 'GenerateState';
|
|
132660
132716
|
state;
|
|
132661
|
-
init({ seed }) {
|
|
132717
|
+
init({ count, seed }) {
|
|
132718
|
+
super.init({ count, seed });
|
|
132662
132719
|
const rng = prand.xoroshiro128plus(seed);
|
|
132663
132720
|
this.state = { rng };
|
|
132664
132721
|
}
|
|
@@ -132675,13 +132732,8 @@ class GenerateCompanyName extends AbstractGenerator {
|
|
|
132675
132732
|
static [entityKind] = 'GenerateCompanyName';
|
|
132676
132733
|
state;
|
|
132677
132734
|
uniqueVersionOfGen = GenerateUniqueCompanyName;
|
|
132678
|
-
init({ seed }) {
|
|
132679
|
-
|
|
132680
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
132681
|
-
throw new Error('specifying non unique generator to unique column.');
|
|
132682
|
-
}
|
|
132683
|
-
this.isUnique = this.params.isUnique;
|
|
132684
|
-
}
|
|
132735
|
+
init({ count, seed }) {
|
|
132736
|
+
super.init({ count, seed });
|
|
132685
132737
|
const rng = prand.xoroshiro128plus(seed);
|
|
132686
132738
|
const templates = [
|
|
132687
132739
|
{ template: '#', placeholdersCount: 1 },
|
|
@@ -132722,13 +132774,8 @@ class GenerateCompanyName extends AbstractGenerator {
|
|
|
132722
132774
|
class GenerateUniqueCompanyName extends AbstractGenerator {
|
|
132723
132775
|
static [entityKind] = 'GenerateUniqueCompanyName';
|
|
132724
132776
|
state;
|
|
132777
|
+
isUnique = true;
|
|
132725
132778
|
init({ count, seed }) {
|
|
132726
|
-
if (this.params.isUnique !== undefined) {
|
|
132727
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
132728
|
-
throw new Error('specifying non unique generator to unique column.');
|
|
132729
|
-
}
|
|
132730
|
-
this.isUnique = this.params.isUnique;
|
|
132731
|
-
}
|
|
132732
132779
|
const maxUniqueCompanyNameNumber = lastNames.length * companyNameSuffixes.length + Math.pow(lastNames.length, 2)
|
|
132733
132780
|
+ Math.pow(lastNames.length, 2) + Math.pow(lastNames.length, 3);
|
|
132734
132781
|
if (count > maxUniqueCompanyNameNumber) {
|
|
@@ -132801,7 +132848,8 @@ class GenerateUniqueCompanyName extends AbstractGenerator {
|
|
|
132801
132848
|
class GenerateLoremIpsum extends AbstractGenerator {
|
|
132802
132849
|
static [entityKind] = 'GenerateLoremIpsum';
|
|
132803
132850
|
state;
|
|
132804
|
-
init({ seed }) {
|
|
132851
|
+
init({ count, seed }) {
|
|
132852
|
+
super.init({ count, seed });
|
|
132805
132853
|
const rng = prand.xoroshiro128plus(seed);
|
|
132806
132854
|
if (this.params.sentencesCount === undefined)
|
|
132807
132855
|
this.params.sentencesCount = 1;
|
|
@@ -132870,25 +132918,20 @@ class GeneratePoint extends AbstractGenerator {
|
|
|
132870
132918
|
static [entityKind] = 'GeneratePoint';
|
|
132871
132919
|
state;
|
|
132872
132920
|
uniqueVersionOfGen = GenerateUniquePoint;
|
|
132873
|
-
init({ seed }) {
|
|
132874
|
-
|
|
132875
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
132876
|
-
throw new Error('specifying non unique generator to unique column.');
|
|
132877
|
-
}
|
|
132878
|
-
this.isUnique = this.params.isUnique;
|
|
132879
|
-
}
|
|
132921
|
+
init({ count, seed }) {
|
|
132922
|
+
super.init({ count, seed });
|
|
132880
132923
|
const xCoordinateGen = new GenerateNumber({
|
|
132881
132924
|
minValue: this.params.minXValue,
|
|
132882
132925
|
maxValue: this.params.maxXValue,
|
|
132883
132926
|
precision: 10,
|
|
132884
132927
|
});
|
|
132885
|
-
xCoordinateGen.init({ seed });
|
|
132928
|
+
xCoordinateGen.init({ count, seed });
|
|
132886
132929
|
const yCoordinateGen = new GenerateNumber({
|
|
132887
132930
|
minValue: this.params.minYValue,
|
|
132888
132931
|
maxValue: this.params.maxYValue,
|
|
132889
132932
|
precision: 10,
|
|
132890
132933
|
});
|
|
132891
|
-
yCoordinateGen.init({ seed });
|
|
132934
|
+
yCoordinateGen.init({ count, seed });
|
|
132892
132935
|
this.state = { xCoordinateGen, yCoordinateGen };
|
|
132893
132936
|
}
|
|
132894
132937
|
generate() {
|
|
@@ -132912,6 +132955,7 @@ class GeneratePoint extends AbstractGenerator {
|
|
|
132912
132955
|
class GenerateUniquePoint extends AbstractGenerator {
|
|
132913
132956
|
static [entityKind] = 'GenerateUniquePoint';
|
|
132914
132957
|
state;
|
|
132958
|
+
isUnique = true;
|
|
132915
132959
|
init({ count, seed }) {
|
|
132916
132960
|
const xCoordinateGen = new GenerateUniqueNumber({
|
|
132917
132961
|
minValue: this.params.minXValue,
|
|
@@ -132949,31 +132993,26 @@ class GenerateLine extends AbstractGenerator {
|
|
|
132949
132993
|
static [entityKind] = 'GenerateLine';
|
|
132950
132994
|
state;
|
|
132951
132995
|
uniqueVersionOfGen = GenerateUniqueLine;
|
|
132952
|
-
init({ seed }) {
|
|
132953
|
-
|
|
132954
|
-
if (this.params.isUnique === false && this.isUnique === true) {
|
|
132955
|
-
throw new Error('specifying non unique generator to unique column.');
|
|
132956
|
-
}
|
|
132957
|
-
this.isUnique = this.params.isUnique;
|
|
132958
|
-
}
|
|
132996
|
+
init({ count, seed }) {
|
|
132997
|
+
super.init({ count, seed });
|
|
132959
132998
|
const aCoefficientGen = new GenerateNumber({
|
|
132960
132999
|
minValue: this.params.minAValue,
|
|
132961
133000
|
maxValue: this.params.maxAValue,
|
|
132962
133001
|
precision: 10,
|
|
132963
133002
|
});
|
|
132964
|
-
aCoefficientGen.init({ seed });
|
|
133003
|
+
aCoefficientGen.init({ count, seed });
|
|
132965
133004
|
const bCoefficientGen = new GenerateNumber({
|
|
132966
133005
|
minValue: this.params.minBValue,
|
|
132967
133006
|
maxValue: this.params.maxBValue,
|
|
132968
133007
|
precision: 10,
|
|
132969
133008
|
});
|
|
132970
|
-
bCoefficientGen.init({ seed });
|
|
133009
|
+
bCoefficientGen.init({ count, seed });
|
|
132971
133010
|
const cCoefficientGen = new GenerateNumber({
|
|
132972
133011
|
minValue: this.params.minCValue,
|
|
132973
133012
|
maxValue: this.params.maxCValue,
|
|
132974
133013
|
precision: 10,
|
|
132975
133014
|
});
|
|
132976
|
-
cCoefficientGen.init({ seed });
|
|
133015
|
+
cCoefficientGen.init({ count, seed });
|
|
132977
133016
|
this.state = { aCoefficientGen, bCoefficientGen, cCoefficientGen };
|
|
132978
133017
|
}
|
|
132979
133018
|
generate() {
|
|
@@ -133002,6 +133041,7 @@ class GenerateLine extends AbstractGenerator {
|
|
|
133002
133041
|
class GenerateUniqueLine extends AbstractGenerator {
|
|
133003
133042
|
static [entityKind] = 'GenerateUniqueLine';
|
|
133004
133043
|
state;
|
|
133044
|
+
isUnique = true;
|
|
133005
133045
|
init({ count, seed }) {
|
|
133006
133046
|
const aCoefficientGen = new GenerateUniqueNumber({
|
|
133007
133047
|
minValue: this.params.minAValue,
|
|
@@ -133050,6 +133090,7 @@ const generatorsFuncs = {
|
|
|
133050
133090
|
/**
|
|
133051
133091
|
* generates same given value each time the generator is called.
|
|
133052
133092
|
* @param defaultValue - value you want to generate
|
|
133093
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133053
133094
|
*
|
|
133054
133095
|
* @example
|
|
133055
133096
|
* ```ts
|
|
@@ -133067,6 +133108,7 @@ const generatorsFuncs = {
|
|
|
133067
133108
|
* generates values from given array
|
|
133068
133109
|
* @param values - array of values you want to generate. can be array of weighted values.
|
|
133069
133110
|
* @param isUnique - property that controls if generated values gonna be unique or not.
|
|
133111
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133070
133112
|
*
|
|
133071
133113
|
* @example
|
|
133072
133114
|
* ```ts
|
|
@@ -133126,6 +133168,7 @@ const generatorsFuncs = {
|
|
|
133126
133168
|
* precision equals 10 means that values will be accurate to one tenth (1.2, 34.6);
|
|
133127
133169
|
* precision equals 100 means that values will be accurate to one hundredth (1.23, 34.67).
|
|
133128
133170
|
* @param isUnique - property that controls if generated values gonna be unique or not.
|
|
133171
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133129
133172
|
*
|
|
133130
133173
|
* @example
|
|
133131
133174
|
* ```ts
|
|
@@ -133146,6 +133189,7 @@ const generatorsFuncs = {
|
|
|
133146
133189
|
* @param minValue - lower border of range.
|
|
133147
133190
|
* @param maxValue - upper border of range.
|
|
133148
133191
|
* @param isUnique - property that controls if generated values gonna be unique or not.
|
|
133192
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133149
133193
|
*
|
|
133150
133194
|
* @example
|
|
133151
133195
|
* ```ts
|
|
@@ -133163,6 +133207,7 @@ const generatorsFuncs = {
|
|
|
133163
133207
|
// uniqueInt: createGenerator(GenerateUniqueInt),
|
|
133164
133208
|
/**
|
|
133165
133209
|
* generates boolean values(true or false)
|
|
133210
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133166
133211
|
*
|
|
133167
133212
|
* @example
|
|
133168
133213
|
* ```ts
|
|
@@ -133181,6 +133226,7 @@ const generatorsFuncs = {
|
|
|
133181
133226
|
* generates date within given range.
|
|
133182
133227
|
* @param minDate - lower border of range.
|
|
133183
133228
|
* @param maxDate - upper border of range.
|
|
133229
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133184
133230
|
*
|
|
133185
133231
|
* @example
|
|
133186
133232
|
* ```ts
|
|
@@ -133197,6 +133243,8 @@ const generatorsFuncs = {
|
|
|
133197
133243
|
date: createGenerator(GenerateDate),
|
|
133198
133244
|
/**
|
|
133199
133245
|
* generates time in 24 hours style.
|
|
133246
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133247
|
+
*
|
|
133200
133248
|
* @example
|
|
133201
133249
|
* ```ts
|
|
133202
133250
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
@@ -133212,6 +133260,8 @@ const generatorsFuncs = {
|
|
|
133212
133260
|
time: createGenerator(GenerateTime),
|
|
133213
133261
|
/**
|
|
133214
133262
|
* generates timestamps.
|
|
133263
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133264
|
+
*
|
|
133215
133265
|
* @example
|
|
133216
133266
|
* ```ts
|
|
133217
133267
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
@@ -133227,6 +133277,8 @@ const generatorsFuncs = {
|
|
|
133227
133277
|
timestamp: createGenerator(GenerateTimestamp),
|
|
133228
133278
|
/**
|
|
133229
133279
|
* generates datetime objects.
|
|
133280
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133281
|
+
*
|
|
133230
133282
|
* @example
|
|
133231
133283
|
* ```ts
|
|
133232
133284
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
@@ -133242,6 +133294,8 @@ const generatorsFuncs = {
|
|
|
133242
133294
|
datetime: createGenerator(GenerateDatetime),
|
|
133243
133295
|
/**
|
|
133244
133296
|
* generates years.
|
|
133297
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133298
|
+
*
|
|
133245
133299
|
* @example
|
|
133246
133300
|
* ```ts
|
|
133247
133301
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
@@ -133257,6 +133311,7 @@ const generatorsFuncs = {
|
|
|
133257
133311
|
year: createGenerator(GenerateYear),
|
|
133258
133312
|
/**
|
|
133259
133313
|
* generates json objects with fixed structure.
|
|
133314
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133260
133315
|
*
|
|
133261
133316
|
* json structure can equal this:
|
|
133262
133317
|
* ```
|
|
@@ -133300,6 +133355,7 @@ const generatorsFuncs = {
|
|
|
133300
133355
|
* interval example: "1 years 12 days 5 minutes"
|
|
133301
133356
|
*
|
|
133302
133357
|
* @param isUnique - property that controls if generated values gonna be unique or not.
|
|
133358
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133303
133359
|
* @example
|
|
133304
133360
|
* ```ts
|
|
133305
133361
|
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
@@ -133316,6 +133372,7 @@ const generatorsFuncs = {
|
|
|
133316
133372
|
/**
|
|
133317
133373
|
* generates random strings.
|
|
133318
133374
|
* @param isUnique - property that controls if generated values gonna be unique or not.
|
|
133375
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133319
133376
|
*
|
|
133320
133377
|
* @example
|
|
133321
133378
|
* ```ts
|
|
@@ -133330,9 +133387,29 @@ const generatorsFuncs = {
|
|
|
133330
133387
|
*/
|
|
133331
133388
|
string: createGenerator(GenerateString),
|
|
133332
133389
|
// uniqueString: createGenerator(GenerateUniqueString),
|
|
133390
|
+
/**
|
|
133391
|
+
* generates v4 UUID strings if arraySize is not specified, or v4 UUID 1D arrays if it is.
|
|
133392
|
+
*
|
|
133393
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133394
|
+
*
|
|
133395
|
+
* @example
|
|
133396
|
+
* ```ts
|
|
133397
|
+
* await seed(db, schema, { count: 1000 }).refine((funcs) => ({
|
|
133398
|
+
* users: {
|
|
133399
|
+
* columns: {
|
|
133400
|
+
* uuid: funcs.uuid({
|
|
133401
|
+
* arraySize: 4
|
|
133402
|
+
* })
|
|
133403
|
+
* },
|
|
133404
|
+
* },
|
|
133405
|
+
* }));
|
|
133406
|
+
* ```
|
|
133407
|
+
*/
|
|
133408
|
+
uuid: createGenerator(GenerateUUID),
|
|
133333
133409
|
/**
|
|
133334
133410
|
* generates person's first names.
|
|
133335
133411
|
* @param isUnique - property that controls if generated values gonna be unique or not.
|
|
133412
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133336
133413
|
*
|
|
133337
133414
|
* @example
|
|
133338
133415
|
* ```ts
|
|
@@ -133350,6 +133427,7 @@ const generatorsFuncs = {
|
|
|
133350
133427
|
/**
|
|
133351
133428
|
* generates person's last names.
|
|
133352
133429
|
* @param isUnique - property that controls if generated values gonna be unique or not.
|
|
133430
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133353
133431
|
*
|
|
133354
133432
|
* @example
|
|
133355
133433
|
* ```ts
|
|
@@ -133367,6 +133445,7 @@ const generatorsFuncs = {
|
|
|
133367
133445
|
/**
|
|
133368
133446
|
* generates person's full names.
|
|
133369
133447
|
* @param isUnique - property that controls if generated values gonna be unique or not.
|
|
133448
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133370
133449
|
*
|
|
133371
133450
|
* @example
|
|
133372
133451
|
* ```ts
|
|
@@ -133383,6 +133462,7 @@ const generatorsFuncs = {
|
|
|
133383
133462
|
// uniqueFullName: createGenerator(GenerateUniqueFullName),
|
|
133384
133463
|
/**
|
|
133385
133464
|
* generates unique emails.
|
|
133465
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133386
133466
|
*
|
|
133387
133467
|
* @example
|
|
133388
133468
|
* ```ts
|
|
@@ -133398,6 +133478,7 @@ const generatorsFuncs = {
|
|
|
133398
133478
|
email: createGenerator(GenerateEmail),
|
|
133399
133479
|
/**
|
|
133400
133480
|
* generates unique phone numbers.
|
|
133481
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133401
133482
|
*
|
|
133402
133483
|
* @param template - phone number template, where all '#' symbols will be substituted with generated digits.
|
|
133403
133484
|
* @param prefixes - array of any string you want to be your phone number prefixes.(not compatible with template property)
|
|
@@ -133437,6 +133518,7 @@ const generatorsFuncs = {
|
|
|
133437
133518
|
/**
|
|
133438
133519
|
* generates country's names.
|
|
133439
133520
|
* @param isUnique - property that controls if generated values gonna be unique or not.
|
|
133521
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133440
133522
|
*
|
|
133441
133523
|
* @example
|
|
133442
133524
|
* ```ts
|
|
@@ -133454,6 +133536,7 @@ const generatorsFuncs = {
|
|
|
133454
133536
|
/**
|
|
133455
133537
|
* generates city's names.
|
|
133456
133538
|
* @param isUnique - property that controls if generated values gonna be unique or not.
|
|
133539
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133457
133540
|
*
|
|
133458
133541
|
* @example
|
|
133459
133542
|
* ```ts
|
|
@@ -133471,6 +133554,7 @@ const generatorsFuncs = {
|
|
|
133471
133554
|
/**
|
|
133472
133555
|
* generates street address.
|
|
133473
133556
|
* @param isUnique - property that controls if generated values gonna be unique or not.
|
|
133557
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133474
133558
|
*
|
|
133475
133559
|
* @example
|
|
133476
133560
|
* ```ts
|
|
@@ -133487,6 +133571,7 @@ const generatorsFuncs = {
|
|
|
133487
133571
|
// uniqueStreetAddress: createGenerator(GenerateUniqueStreetAdddress),
|
|
133488
133572
|
/**
|
|
133489
133573
|
* generates job titles.
|
|
133574
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133490
133575
|
*
|
|
133491
133576
|
* @example
|
|
133492
133577
|
* ```ts
|
|
@@ -133504,6 +133589,7 @@ const generatorsFuncs = {
|
|
|
133504
133589
|
* generates postal codes.
|
|
133505
133590
|
*
|
|
133506
133591
|
* @param isUnique - property that controls if generated values gonna be unique or not.
|
|
133592
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133507
133593
|
*
|
|
133508
133594
|
* @example
|
|
133509
133595
|
* ```ts
|
|
@@ -133520,6 +133606,7 @@ const generatorsFuncs = {
|
|
|
133520
133606
|
// uniquePostcoe: createGenerator(GenerateUniquePostcode),
|
|
133521
133607
|
/**
|
|
133522
133608
|
* generates states of America.
|
|
133609
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133523
133610
|
*
|
|
133524
133611
|
* @example
|
|
133525
133612
|
* ```ts
|
|
@@ -133537,6 +133624,7 @@ const generatorsFuncs = {
|
|
|
133537
133624
|
* generates company's names.
|
|
133538
133625
|
*
|
|
133539
133626
|
* @param isUnique - property that controls if generated values gonna be unique or not.
|
|
133627
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133540
133628
|
*
|
|
133541
133629
|
* @example
|
|
133542
133630
|
* ```ts
|
|
@@ -133555,6 +133643,7 @@ const generatorsFuncs = {
|
|
|
133555
133643
|
* generates 'lorem ipsum' text sentences.
|
|
133556
133644
|
*
|
|
133557
133645
|
* @param sentencesCount - number of sentences you want to generate as one generated value(string).
|
|
133646
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133558
133647
|
*
|
|
133559
133648
|
* @example
|
|
133560
133649
|
* ```ts
|
|
@@ -133576,6 +133665,7 @@ const generatorsFuncs = {
|
|
|
133576
133665
|
* @param maxXValue - upper bound of range for x coordinate.
|
|
133577
133666
|
* @param minYValue - lower bound of range for y coordinate.
|
|
133578
133667
|
* @param maxYValue - upper bound of range for y coordinate.
|
|
133668
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133579
133669
|
*
|
|
133580
133670
|
* @example
|
|
133581
133671
|
* ```ts
|
|
@@ -133608,6 +133698,7 @@ const generatorsFuncs = {
|
|
|
133608
133698
|
* @param maxBValue - upper bound of range for y parameter.
|
|
133609
133699
|
* @param minCValue - lower bound of range for y parameter.
|
|
133610
133700
|
* @param maxCValue - upper bound of range for y parameter.
|
|
133701
|
+
* @param arraySize - number of elements in each one-dimensional array.
|
|
133611
133702
|
*
|
|
133612
133703
|
* @example
|
|
133613
133704
|
* ```ts
|
|
@@ -133663,15 +133754,20 @@ class SeedService {
|
|
|
133663
133754
|
mysqlMaxParametersNumber = 100000;
|
|
133664
133755
|
// SQLITE_MAX_VARIABLE_NUMBER, which by default equals to 999 for SQLite versions prior to 3.32.0 (2020-05-22) or 32766 for SQLite versions after 3.32.0.
|
|
133665
133756
|
sqliteMaxParametersNumber = 32766;
|
|
133666
|
-
generatePossibleGenerators = (connectionType, tables, relations, refinements, options) => {
|
|
133757
|
+
generatePossibleGenerators = (connectionType, tables, relations, tableRelations, refinements, options) => {
|
|
133667
133758
|
let columnPossibleGenerator;
|
|
133668
133759
|
let tablePossibleGenerators;
|
|
133669
133760
|
const customSeed = options?.seed === undefined ? 0 : options.seed;
|
|
133670
133761
|
// sorting table in order which they will be filled up (tables with foreign keys case)
|
|
133671
133762
|
// relations = relations.filter(rel => rel.type === "one");
|
|
133672
|
-
const tablesInOutRelations = this.
|
|
133763
|
+
const { tablesInOutRelations } = this.getInfoFromRelations(relations);
|
|
133673
133764
|
const orderedTablesNames = this.getOrderedTablesList(tablesInOutRelations);
|
|
133674
133765
|
tables = tables.sort((table1, table2) => {
|
|
133766
|
+
const rel = relations.find((rel) => rel.table === table1.name && rel.refTable === table2.name);
|
|
133767
|
+
if (rel?.isCyclic === true) {
|
|
133768
|
+
const reverseRel = relations.find((rel) => rel.table === table2.name && rel.refTable === table1.name);
|
|
133769
|
+
return this.cyclicTablesCompare(table1, table2, rel, reverseRel);
|
|
133770
|
+
}
|
|
133675
133771
|
const table1Order = orderedTablesNames.indexOf(table1.name), table2Order = orderedTablesNames.indexOf(table2.name);
|
|
133676
133772
|
return table1Order - table2Order;
|
|
133677
133773
|
});
|
|
@@ -133743,37 +133839,54 @@ class SeedService {
|
|
|
133743
133839
|
columnName: col.name,
|
|
133744
133840
|
isUnique: col.isUnique,
|
|
133745
133841
|
notNull: col.notNull,
|
|
133842
|
+
primary: col.primary,
|
|
133746
133843
|
generatedIdentityType: col.generatedIdentityType,
|
|
133747
133844
|
generator: undefined,
|
|
133845
|
+
isCyclic: false,
|
|
133846
|
+
wasDefinedBefore: false,
|
|
133847
|
+
wasRefined: false,
|
|
133748
133848
|
};
|
|
133749
133849
|
if (refinements !== undefined
|
|
133750
133850
|
&& refinements[table.name] !== undefined
|
|
133751
133851
|
&& refinements[table.name].columns !== undefined
|
|
133752
133852
|
&& refinements[table.name].columns[col.name] !== undefined) {
|
|
133753
133853
|
const genObj = refinements[table.name].columns[col.name];
|
|
133754
|
-
// for now only GenerateValuesFromArray support notNull property
|
|
133854
|
+
// TODO: for now only GenerateValuesFromArray support notNull property
|
|
133755
133855
|
genObj.notNull = col.notNull;
|
|
133856
|
+
if (col.dataType === 'array') {
|
|
133857
|
+
if (col.baseColumn?.dataType === 'array' && col.baseColumn?.columnType === 'array') {
|
|
133858
|
+
throw new Error("for now you can't specify generators for columns of dimensition greater than 1.");
|
|
133859
|
+
}
|
|
133860
|
+
genObj.baseColumnDataType = col.baseColumn?.dataType;
|
|
133861
|
+
}
|
|
133756
133862
|
columnPossibleGenerator.generator = genObj;
|
|
133863
|
+
columnPossibleGenerator.wasRefined = true;
|
|
133757
133864
|
}
|
|
133758
133865
|
else if (Object.hasOwn(foreignKeyColumns, col.name)) {
|
|
133759
133866
|
// TODO: I might need to assign repeatedValuesCount to column there instead of doing so in generateTablesValues
|
|
133867
|
+
const cyclicRelation = tableRelations[table.name].find((rel) => rel.isCyclic === true
|
|
133868
|
+
&& rel.columns.includes(col.name));
|
|
133869
|
+
if (cyclicRelation !== undefined) {
|
|
133870
|
+
columnPossibleGenerator.isCyclic = true;
|
|
133871
|
+
}
|
|
133872
|
+
const predicate = cyclicRelation !== undefined && col.notNull === false;
|
|
133873
|
+
if (predicate === true) {
|
|
133874
|
+
columnPossibleGenerator.generator = new GenerateDefault({ defaultValue: null });
|
|
133875
|
+
columnPossibleGenerator.wasDefinedBefore = true;
|
|
133876
|
+
}
|
|
133760
133877
|
columnPossibleGenerator.generator = new HollowGenerator({});
|
|
133761
|
-
}
|
|
133762
|
-
else if (col.hasDefault && col.default !== undefined) {
|
|
133763
|
-
columnPossibleGenerator.generator = new GenerateDefault({
|
|
133764
|
-
defaultValue: col.default,
|
|
133765
|
-
});
|
|
133766
133878
|
} // TODO: rewrite pickGeneratorFor... using new col properties: isUnique and notNull
|
|
133767
133879
|
else if (connectionType === 'postgresql') {
|
|
133768
|
-
columnPossibleGenerator = this.pickGeneratorForPostgresColumn(
|
|
133880
|
+
columnPossibleGenerator.generator = this.pickGeneratorForPostgresColumn(table, col);
|
|
133769
133881
|
}
|
|
133770
133882
|
else if (connectionType === 'mysql') {
|
|
133771
|
-
columnPossibleGenerator = this.pickGeneratorForMysqlColumn(
|
|
133883
|
+
columnPossibleGenerator.generator = this.pickGeneratorForMysqlColumn(table, col);
|
|
133772
133884
|
}
|
|
133773
133885
|
else if (connectionType === 'sqlite') {
|
|
133774
|
-
columnPossibleGenerator = this.pickGeneratorForSqlite(
|
|
133886
|
+
columnPossibleGenerator.generator = this.pickGeneratorForSqlite(table, col);
|
|
133775
133887
|
}
|
|
133776
133888
|
if (columnPossibleGenerator.generator === undefined) {
|
|
133889
|
+
console.log(col);
|
|
133777
133890
|
throw new Error(`column with type ${col.columnType} is not supported for now.`);
|
|
133778
133891
|
}
|
|
133779
133892
|
columnPossibleGenerator.generator.isUnique = col.isUnique;
|
|
@@ -133783,6 +133896,27 @@ class SeedService {
|
|
|
133783
133896
|
}
|
|
133784
133897
|
return tablesPossibleGenerators;
|
|
133785
133898
|
};
|
|
133899
|
+
cyclicTablesCompare = (table1, table2, relation, reverseRelation) => {
|
|
133900
|
+
// TODO: revise
|
|
133901
|
+
const hasTable1NotNullColumns = relation.columns.some((colIName) => table1.columns.find((colJ) => colJ.name === colIName)?.notNull === true);
|
|
133902
|
+
if (reverseRelation !== undefined) {
|
|
133903
|
+
const hasTable2NotNullColumns = reverseRelation.columns.some((colIName) => table2.columns.find((colJ) => colJ.name === colIName)?.notNull === true);
|
|
133904
|
+
if (hasTable1NotNullColumns && hasTable2NotNullColumns) {
|
|
133905
|
+
throw new Error(`The '${table1.name}' and '${table2.name}' tables have not null foreign keys. You can't seed cyclic tables with not null foreign key columns.`);
|
|
133906
|
+
}
|
|
133907
|
+
if (hasTable1NotNullColumns)
|
|
133908
|
+
return 1;
|
|
133909
|
+
else if (hasTable2NotNullColumns)
|
|
133910
|
+
return -1;
|
|
133911
|
+
return 0;
|
|
133912
|
+
}
|
|
133913
|
+
if (hasTable1NotNullColumns) {
|
|
133914
|
+
return 1;
|
|
133915
|
+
}
|
|
133916
|
+
return 0;
|
|
133917
|
+
// if (hasTable1NotNullColumns) return 1;
|
|
133918
|
+
// else if (hasTable2NotNullColumns) return -1;
|
|
133919
|
+
};
|
|
133786
133920
|
getOrderedTablesList = (tablesInOutRelations) => {
|
|
133787
133921
|
const leafTablesNames = Object.entries(tablesInOutRelations)
|
|
133788
133922
|
.filter((tableRel) => tableRel[1].out === 0
|
|
@@ -133803,7 +133937,8 @@ class SeedService {
|
|
|
133803
133937
|
for (const orderedTableName of orderedTablesNames) {
|
|
133804
133938
|
tablesInOutRelations[parent].requiredTableNames.delete(orderedTableName);
|
|
133805
133939
|
}
|
|
133806
|
-
if (tablesInOutRelations[parent].requiredTableNames.size === 0
|
|
133940
|
+
if (tablesInOutRelations[parent].requiredTableNames.size === 0
|
|
133941
|
+
|| equalSets(tablesInOutRelations[parent].requiredTableNames, tablesInOutRelations[parent].dependantTableNames)) {
|
|
133807
133942
|
orderedTablesNames.push(parent);
|
|
133808
133943
|
}
|
|
133809
133944
|
else {
|
|
@@ -133815,9 +133950,13 @@ class SeedService {
|
|
|
133815
133950
|
}
|
|
133816
133951
|
return orderedTablesNames;
|
|
133817
133952
|
};
|
|
133818
|
-
|
|
133953
|
+
getInfoFromRelations = (relations) => {
|
|
133819
133954
|
const tablesInOutRelations = {};
|
|
133955
|
+
// const cyclicRelations: { [cyclicTableName: string]: Relation & { isCyclic: boolean } } = {};
|
|
133820
133956
|
for (const rel of relations) {
|
|
133957
|
+
// if (rel.isCyclic) {
|
|
133958
|
+
// cyclicRelations[rel.table] = rel;
|
|
133959
|
+
// }
|
|
133821
133960
|
if (tablesInOutRelations[rel.table] === undefined) {
|
|
133822
133961
|
tablesInOutRelations[rel.table] = {
|
|
133823
133962
|
out: 0,
|
|
@@ -133849,7 +133988,7 @@ class SeedService {
|
|
|
133849
133988
|
tablesInOutRelations[rel.refTable].dependantTableNames.add(rel.table);
|
|
133850
133989
|
}
|
|
133851
133990
|
}
|
|
133852
|
-
return tablesInOutRelations;
|
|
133991
|
+
return { tablesInOutRelations };
|
|
133853
133992
|
};
|
|
133854
133993
|
getWeightedWithCount = (weightedCount, count, seed) => {
|
|
133855
133994
|
const gen = new GenerateWeightedCount({});
|
|
@@ -133861,15 +134000,18 @@ class SeedService {
|
|
|
133861
134000
|
return weightedWithCount;
|
|
133862
134001
|
};
|
|
133863
134002
|
// TODO: revise serial part generators
|
|
133864
|
-
pickGeneratorForPostgresColumn = (
|
|
134003
|
+
pickGeneratorForPostgresColumn = (table, col) => {
|
|
134004
|
+
let generator;
|
|
133865
134005
|
// INT ------------------------------------------------------------------------------------------------------------
|
|
133866
134006
|
if ((col.columnType.includes('serial')
|
|
133867
134007
|
|| col.columnType === 'integer'
|
|
133868
134008
|
|| col.columnType === 'smallint'
|
|
133869
134009
|
|| col.columnType.includes('bigint'))
|
|
133870
134010
|
&& table.primaryKeys.includes(col.name)) {
|
|
133871
|
-
|
|
133872
|
-
|
|
134011
|
+
generator = new GenerateIntPrimaryKey({});
|
|
134012
|
+
generator.isUnique = col.isUnique;
|
|
134013
|
+
generator.dataType = col.dataType;
|
|
134014
|
+
return generator;
|
|
133873
134015
|
}
|
|
133874
134016
|
let minValue;
|
|
133875
134017
|
let maxValue;
|
|
@@ -133916,111 +134058,167 @@ class SeedService {
|
|
|
133916
134058
|
if (col.columnType.includes('int')
|
|
133917
134059
|
&& !col.columnType.includes('interval')
|
|
133918
134060
|
&& !col.columnType.includes('point')) {
|
|
133919
|
-
|
|
134061
|
+
generator = new GenerateInt({
|
|
133920
134062
|
minValue,
|
|
133921
134063
|
maxValue,
|
|
133922
134064
|
});
|
|
133923
|
-
|
|
134065
|
+
generator.isUnique = col.isUnique;
|
|
134066
|
+
generator.dataType = col.dataType;
|
|
134067
|
+
return generator;
|
|
133924
134068
|
}
|
|
133925
134069
|
if (col.columnType.includes('serial')) {
|
|
133926
|
-
|
|
133927
|
-
|
|
133928
|
-
|
|
134070
|
+
generator = new GenerateIntPrimaryKey({});
|
|
134071
|
+
generator.maxValue = maxValue;
|
|
134072
|
+
generator.isUnique = col.isUnique;
|
|
134073
|
+
generator.dataType = col.dataType;
|
|
134074
|
+
return generator;
|
|
133929
134075
|
}
|
|
133930
134076
|
// NUMBER(real, double, decimal, numeric)
|
|
133931
134077
|
if (col.columnType === 'real'
|
|
133932
134078
|
|| col.columnType === 'doubleprecision'
|
|
133933
134079
|
|| col.columnType === 'decimal'
|
|
133934
134080
|
|| col.columnType === 'numeric') {
|
|
133935
|
-
|
|
133936
|
-
|
|
134081
|
+
generator = new GenerateNumber({});
|
|
134082
|
+
generator.isUnique = col.isUnique;
|
|
134083
|
+
generator.dataType = col.dataType;
|
|
134084
|
+
return generator;
|
|
133937
134085
|
}
|
|
133938
134086
|
// STRING
|
|
133939
134087
|
if ((col.columnType === 'text'
|
|
133940
134088
|
|| col.columnType === 'varchar'
|
|
133941
134089
|
|| col.columnType === 'char')
|
|
133942
134090
|
&& table.primaryKeys.includes(col.name)) {
|
|
133943
|
-
|
|
133944
|
-
|
|
134091
|
+
generator = new GenerateUniqueString({});
|
|
134092
|
+
generator.isUnique = col.isUnique;
|
|
134093
|
+
generator.dataType = col.dataType;
|
|
134094
|
+
return generator;
|
|
133945
134095
|
}
|
|
133946
134096
|
if ((col.columnType === 'text'
|
|
133947
134097
|
|| col.columnType === 'varchar'
|
|
133948
134098
|
|| col.columnType === 'char')
|
|
133949
134099
|
&& col.name.toLowerCase().includes('name')) {
|
|
133950
|
-
|
|
133951
|
-
|
|
134100
|
+
generator = new GenerateFirstName({});
|
|
134101
|
+
generator.isUnique = col.isUnique;
|
|
134102
|
+
generator.dataType = col.dataType;
|
|
134103
|
+
return generator;
|
|
133952
134104
|
}
|
|
133953
134105
|
if ((col.columnType === 'text'
|
|
133954
134106
|
|| col.columnType === 'varchar'
|
|
133955
134107
|
|| col.columnType === 'char')
|
|
133956
134108
|
&& col.name.toLowerCase().includes('email')) {
|
|
133957
|
-
|
|
133958
|
-
|
|
134109
|
+
generator = new GenerateEmail({});
|
|
134110
|
+
generator.isUnique = col.isUnique;
|
|
134111
|
+
generator.dataType = col.dataType;
|
|
134112
|
+
return generator;
|
|
133959
134113
|
}
|
|
133960
134114
|
if (col.columnType === 'text'
|
|
133961
134115
|
|| col.columnType === 'varchar'
|
|
133962
134116
|
|| col.columnType === 'char') {
|
|
133963
134117
|
// console.log(col, table)
|
|
133964
|
-
|
|
133965
|
-
|
|
134118
|
+
generator = new GenerateString({});
|
|
134119
|
+
generator.isUnique = col.isUnique;
|
|
134120
|
+
generator.dataType = col.dataType;
|
|
134121
|
+
return generator;
|
|
134122
|
+
}
|
|
134123
|
+
// UUID
|
|
134124
|
+
if (col.columnType === 'uuid') {
|
|
134125
|
+
generator = new GenerateUUID({});
|
|
134126
|
+
generator.isUnique = col.isUnique;
|
|
134127
|
+
generator.dataType = col.dataType;
|
|
134128
|
+
return generator;
|
|
133966
134129
|
}
|
|
133967
134130
|
// BOOLEAN
|
|
133968
134131
|
if (col.columnType === 'boolean') {
|
|
133969
|
-
|
|
133970
|
-
|
|
134132
|
+
generator = new GenerateBoolean({});
|
|
134133
|
+
generator.isUnique = col.isUnique;
|
|
134134
|
+
generator.dataType = col.dataType;
|
|
134135
|
+
return generator;
|
|
133971
134136
|
}
|
|
133972
134137
|
// DATE, TIME, TIMESTAMP
|
|
133973
134138
|
if (col.columnType.includes('date')) {
|
|
133974
|
-
|
|
133975
|
-
|
|
134139
|
+
generator = new GenerateDate({});
|
|
134140
|
+
generator.isUnique = col.isUnique;
|
|
134141
|
+
generator.dataType = col.dataType;
|
|
134142
|
+
return generator;
|
|
133976
134143
|
}
|
|
133977
134144
|
if (col.columnType === 'time') {
|
|
133978
|
-
|
|
133979
|
-
|
|
134145
|
+
generator = new GenerateTime({});
|
|
134146
|
+
generator.isUnique = col.isUnique;
|
|
134147
|
+
generator.dataType = col.dataType;
|
|
134148
|
+
return generator;
|
|
133980
134149
|
}
|
|
133981
134150
|
if (col.columnType.includes('timestamp')) {
|
|
133982
|
-
|
|
133983
|
-
|
|
134151
|
+
generator = new GenerateTimestamp({});
|
|
134152
|
+
generator.isUnique = col.isUnique;
|
|
134153
|
+
generator.dataType = col.dataType;
|
|
134154
|
+
return generator;
|
|
133984
134155
|
}
|
|
133985
134156
|
// JSON, JSONB
|
|
133986
134157
|
if (col.columnType === 'json' || col.columnType === 'jsonb') {
|
|
133987
|
-
|
|
133988
|
-
|
|
134158
|
+
generator = new GenerateJson({});
|
|
134159
|
+
generator.isUnique = col.isUnique;
|
|
134160
|
+
generator.dataType = col.dataType;
|
|
134161
|
+
return generator;
|
|
133989
134162
|
}
|
|
133990
134163
|
// if (col.columnType === "jsonb") {
|
|
133991
|
-
//
|
|
133992
|
-
// return
|
|
134164
|
+
// const generator = new GenerateJsonb({});
|
|
134165
|
+
// return generator;
|
|
133993
134166
|
// }
|
|
133994
134167
|
// ENUM
|
|
133995
134168
|
if (col.enumValues !== undefined) {
|
|
133996
|
-
|
|
134169
|
+
generator = new GenerateEnum({
|
|
133997
134170
|
enumValues: col.enumValues,
|
|
133998
134171
|
});
|
|
133999
|
-
|
|
134172
|
+
generator.isUnique = col.isUnique;
|
|
134173
|
+
generator.dataType = col.dataType;
|
|
134174
|
+
return generator;
|
|
134000
134175
|
}
|
|
134001
134176
|
// INTERVAL
|
|
134002
134177
|
if (col.columnType === 'interval') {
|
|
134003
|
-
|
|
134004
|
-
|
|
134178
|
+
generator = new GenerateInterval({});
|
|
134179
|
+
generator.isUnique = col.isUnique;
|
|
134180
|
+
generator.dataType = col.dataType;
|
|
134181
|
+
return generator;
|
|
134005
134182
|
}
|
|
134006
134183
|
// POINT, LINE
|
|
134007
134184
|
if (col.columnType.includes('point')) {
|
|
134008
|
-
|
|
134009
|
-
|
|
134185
|
+
generator = new GeneratePoint({});
|
|
134186
|
+
generator.isUnique = col.isUnique;
|
|
134187
|
+
generator.dataType = col.dataType;
|
|
134188
|
+
return generator;
|
|
134010
134189
|
}
|
|
134011
134190
|
if (col.columnType.includes('line')) {
|
|
134012
|
-
|
|
134013
|
-
|
|
134191
|
+
generator = new GenerateLine({});
|
|
134192
|
+
generator.isUnique = col.isUnique;
|
|
134193
|
+
generator.dataType = col.dataType;
|
|
134194
|
+
return generator;
|
|
134195
|
+
}
|
|
134196
|
+
// ARRAY
|
|
134197
|
+
if (col.columnType.includes('array') && col.baseColumn !== undefined) {
|
|
134198
|
+
const baseColumnGen = this.pickGeneratorForPostgresColumn(table, col.baseColumn);
|
|
134199
|
+
if (baseColumnGen === undefined) {
|
|
134200
|
+
throw new Error(`column with type ${col.baseColumn.columnType} is not supported for now.`);
|
|
134201
|
+
}
|
|
134202
|
+
generator = new GenerateArray({ baseColumnGen, size: col.size });
|
|
134203
|
+
generator.isUnique = col.isUnique;
|
|
134204
|
+
generator.dataType = col.dataType;
|
|
134205
|
+
return generator;
|
|
134206
|
+
}
|
|
134207
|
+
if (col.hasDefault && col.default !== undefined) {
|
|
134208
|
+
generator = new GenerateDefault({
|
|
134209
|
+
defaultValue: col.default,
|
|
134210
|
+
});
|
|
134211
|
+
return generator;
|
|
134014
134212
|
}
|
|
134015
|
-
return
|
|
134213
|
+
return generator;
|
|
134016
134214
|
};
|
|
134017
|
-
pickGeneratorForMysqlColumn = (
|
|
134215
|
+
pickGeneratorForMysqlColumn = (table, col) => {
|
|
134018
134216
|
// console.log(col);
|
|
134019
134217
|
// INT ------------------------------------------------------------------------------------------------------------
|
|
134020
134218
|
if ((col.columnType.includes('serial') || col.columnType.includes('int'))
|
|
134021
134219
|
&& table.primaryKeys.includes(col.name)) {
|
|
134022
|
-
|
|
134023
|
-
return
|
|
134220
|
+
const generator = new GenerateIntPrimaryKey({});
|
|
134221
|
+
return generator;
|
|
134024
134222
|
}
|
|
134025
134223
|
let minValue;
|
|
134026
134224
|
let maxValue;
|
|
@@ -134057,24 +134255,24 @@ class SeedService {
|
|
|
134057
134255
|
}
|
|
134058
134256
|
}
|
|
134059
134257
|
if (col.columnType.includes('int')) {
|
|
134060
|
-
|
|
134258
|
+
const generator = new GenerateInt({
|
|
134061
134259
|
minValue,
|
|
134062
134260
|
maxValue,
|
|
134063
134261
|
});
|
|
134064
|
-
return
|
|
134262
|
+
return generator;
|
|
134065
134263
|
}
|
|
134066
134264
|
if (col.columnType.includes('serial')) {
|
|
134067
|
-
const
|
|
134068
|
-
|
|
134069
|
-
|
|
134265
|
+
const generator = new GenerateIntPrimaryKey({});
|
|
134266
|
+
generator.maxValue = maxValue;
|
|
134267
|
+
return generator;
|
|
134070
134268
|
}
|
|
134071
134269
|
// NUMBER(real, double, decimal, float)
|
|
134072
134270
|
if (col.columnType === 'real'
|
|
134073
134271
|
|| col.columnType === 'double'
|
|
134074
134272
|
|| col.columnType === 'decimal'
|
|
134075
134273
|
|| col.columnType === 'float') {
|
|
134076
|
-
|
|
134077
|
-
return
|
|
134274
|
+
const generator = new GenerateNumber({});
|
|
134275
|
+
return generator;
|
|
134078
134276
|
}
|
|
134079
134277
|
// STRING
|
|
134080
134278
|
if ((col.columnType === 'text'
|
|
@@ -134084,8 +134282,8 @@ class SeedService {
|
|
|
134084
134282
|
|| col.columnType.includes('binary')
|
|
134085
134283
|
|| col.columnType.includes('varbinary'))
|
|
134086
134284
|
&& table.primaryKeys.includes(col.name)) {
|
|
134087
|
-
|
|
134088
|
-
return
|
|
134285
|
+
const generator = new GenerateUniqueString({});
|
|
134286
|
+
return generator;
|
|
134089
134287
|
}
|
|
134090
134288
|
if ((col.columnType === 'text'
|
|
134091
134289
|
|| col.columnType === 'blob'
|
|
@@ -134094,8 +134292,8 @@ class SeedService {
|
|
|
134094
134292
|
|| col.columnType.includes('binary')
|
|
134095
134293
|
|| col.columnType.includes('varbinary'))
|
|
134096
134294
|
&& col.name.toLowerCase().includes('name')) {
|
|
134097
|
-
|
|
134098
|
-
return
|
|
134295
|
+
const generator = new GenerateFirstName({});
|
|
134296
|
+
return generator;
|
|
134099
134297
|
}
|
|
134100
134298
|
if ((col.columnType === 'text'
|
|
134101
134299
|
|| col.columnType === 'blob'
|
|
@@ -134104,8 +134302,8 @@ class SeedService {
|
|
|
134104
134302
|
|| col.columnType.includes('binary')
|
|
134105
134303
|
|| col.columnType.includes('varbinary'))
|
|
134106
134304
|
&& col.name.toLowerCase().includes('email')) {
|
|
134107
|
-
|
|
134108
|
-
return
|
|
134305
|
+
const generator = new GenerateEmail({});
|
|
134306
|
+
return generator;
|
|
134109
134307
|
}
|
|
134110
134308
|
if (col.columnType === 'text'
|
|
134111
134309
|
|| col.columnType === 'blob'
|
|
@@ -134114,109 +134312,140 @@ class SeedService {
|
|
|
134114
134312
|
|| col.columnType.includes('binary')
|
|
134115
134313
|
|| col.columnType.includes('varbinary')) {
|
|
134116
134314
|
// console.log(col, table);
|
|
134117
|
-
|
|
134118
|
-
return
|
|
134315
|
+
const generator = new GenerateString({});
|
|
134316
|
+
return generator;
|
|
134119
134317
|
}
|
|
134120
134318
|
// BOOLEAN
|
|
134121
134319
|
if (col.columnType === 'boolean') {
|
|
134122
|
-
|
|
134123
|
-
return
|
|
134320
|
+
const generator = new GenerateBoolean({});
|
|
134321
|
+
return generator;
|
|
134124
134322
|
}
|
|
134125
134323
|
// DATE, TIME, TIMESTAMP, DATETIME, YEAR
|
|
134126
134324
|
if (col.columnType.includes('datetime')) {
|
|
134127
|
-
|
|
134128
|
-
return
|
|
134325
|
+
const generator = new GenerateDatetime({});
|
|
134326
|
+
return generator;
|
|
134129
134327
|
}
|
|
134130
134328
|
if (col.columnType.includes('date')) {
|
|
134131
|
-
|
|
134132
|
-
return
|
|
134329
|
+
const generator = new GenerateDate({});
|
|
134330
|
+
return generator;
|
|
134133
134331
|
}
|
|
134134
134332
|
if (col.columnType === 'time') {
|
|
134135
|
-
|
|
134136
|
-
return
|
|
134333
|
+
const generator = new GenerateTime({});
|
|
134334
|
+
return generator;
|
|
134137
134335
|
}
|
|
134138
134336
|
if (col.columnType.includes('timestamp')) {
|
|
134139
|
-
|
|
134140
|
-
return
|
|
134337
|
+
const generator = new GenerateTimestamp({});
|
|
134338
|
+
return generator;
|
|
134141
134339
|
}
|
|
134142
134340
|
if (col.columnType === 'year') {
|
|
134143
|
-
|
|
134144
|
-
return
|
|
134341
|
+
const generator = new GenerateYear({});
|
|
134342
|
+
return generator;
|
|
134145
134343
|
}
|
|
134146
134344
|
// JSON
|
|
134147
134345
|
if (col.columnType === 'json') {
|
|
134148
|
-
|
|
134149
|
-
return
|
|
134346
|
+
const generator = new GenerateJson({});
|
|
134347
|
+
return generator;
|
|
134150
134348
|
}
|
|
134151
134349
|
// ENUM
|
|
134152
134350
|
if (col.enumValues !== undefined) {
|
|
134153
|
-
|
|
134351
|
+
const generator = new GenerateEnum({
|
|
134154
134352
|
enumValues: col.enumValues,
|
|
134155
134353
|
});
|
|
134156
|
-
return
|
|
134354
|
+
return generator;
|
|
134157
134355
|
}
|
|
134158
|
-
|
|
134356
|
+
if (col.hasDefault && col.default !== undefined) {
|
|
134357
|
+
const generator = new GenerateDefault({
|
|
134358
|
+
defaultValue: col.default,
|
|
134359
|
+
});
|
|
134360
|
+
return generator;
|
|
134361
|
+
}
|
|
134362
|
+
return;
|
|
134159
134363
|
};
|
|
134160
|
-
pickGeneratorForSqlite = (
|
|
134364
|
+
pickGeneratorForSqlite = (table, col) => {
|
|
134161
134365
|
// int section ---------------------------------------------------------------------------------------
|
|
134162
134366
|
if ((col.columnType === 'integer' || col.columnType === 'numeric')
|
|
134163
134367
|
&& table.primaryKeys.includes(col.name)) {
|
|
134164
|
-
|
|
134165
|
-
return
|
|
134368
|
+
const generator = new GenerateIntPrimaryKey({});
|
|
134369
|
+
return generator;
|
|
134166
134370
|
}
|
|
134167
134371
|
if (col.columnType === 'integer'
|
|
134168
134372
|
|| col.columnType === 'numeric'
|
|
134169
134373
|
|| col.columnType === 'bigint') {
|
|
134170
|
-
|
|
134171
|
-
return
|
|
134374
|
+
const generator = new GenerateInt({});
|
|
134375
|
+
return generator;
|
|
134172
134376
|
}
|
|
134173
134377
|
if (col.columnType === 'boolean') {
|
|
134174
|
-
|
|
134175
|
-
return
|
|
134378
|
+
const generator = new GenerateBoolean({});
|
|
134379
|
+
return generator;
|
|
134176
134380
|
}
|
|
134177
134381
|
// number section ------------------------------------------------------------------------------------
|
|
134178
134382
|
if (col.columnType === 'real' || col.columnType === 'numeric') {
|
|
134179
|
-
|
|
134180
|
-
return
|
|
134383
|
+
const generator = new GenerateNumber({});
|
|
134384
|
+
return generator;
|
|
134181
134385
|
}
|
|
134182
134386
|
// string section ------------------------------------------------------------------------------------
|
|
134183
134387
|
if ((col.columnType === 'text'
|
|
134184
134388
|
|| col.columnType === 'numeric'
|
|
134185
134389
|
|| col.columnType === 'blob')
|
|
134186
134390
|
&& table.primaryKeys.includes(col.name)) {
|
|
134187
|
-
|
|
134188
|
-
return
|
|
134391
|
+
const generator = new GenerateUniqueString({});
|
|
134392
|
+
return generator;
|
|
134189
134393
|
}
|
|
134190
134394
|
if ((col.columnType === 'text'
|
|
134191
134395
|
|| col.columnType === 'numeric'
|
|
134192
134396
|
|| col.columnType === 'blob')
|
|
134193
134397
|
&& col.name.toLowerCase().includes('name')) {
|
|
134194
|
-
|
|
134195
|
-
return
|
|
134398
|
+
const generator = new GenerateFirstName({});
|
|
134399
|
+
return generator;
|
|
134196
134400
|
}
|
|
134197
134401
|
if ((col.columnType === 'text'
|
|
134198
134402
|
|| col.columnType === 'numeric'
|
|
134199
134403
|
|| col.columnType === 'blob')
|
|
134200
134404
|
&& col.name.toLowerCase().includes('email')) {
|
|
134201
|
-
|
|
134202
|
-
return
|
|
134405
|
+
const generator = new GenerateEmail({});
|
|
134406
|
+
return generator;
|
|
134203
134407
|
}
|
|
134204
134408
|
if (col.columnType === 'text'
|
|
134205
134409
|
|| col.columnType === 'numeric'
|
|
134206
134410
|
|| col.columnType === 'blob'
|
|
134207
134411
|
|| col.columnType === 'blobbuffer') {
|
|
134208
|
-
|
|
134209
|
-
return
|
|
134412
|
+
const generator = new GenerateString({});
|
|
134413
|
+
return generator;
|
|
134210
134414
|
}
|
|
134211
134415
|
if (col.columnType === 'textjson' || col.columnType === 'blobjson') {
|
|
134212
|
-
|
|
134213
|
-
return
|
|
134416
|
+
const generator = new GenerateJson({});
|
|
134417
|
+
return generator;
|
|
134214
134418
|
}
|
|
134215
134419
|
if (col.columnType === 'timestamp' || col.columnType === 'timestamp_ms') {
|
|
134216
|
-
|
|
134217
|
-
return
|
|
134420
|
+
const generator = new GenerateTimestamp({});
|
|
134421
|
+
return generator;
|
|
134218
134422
|
}
|
|
134219
|
-
|
|
134423
|
+
if (col.hasDefault && col.default !== undefined) {
|
|
134424
|
+
const generator = new GenerateDefault({
|
|
134425
|
+
defaultValue: col.default,
|
|
134426
|
+
});
|
|
134427
|
+
return generator;
|
|
134428
|
+
}
|
|
134429
|
+
return;
|
|
134430
|
+
};
|
|
134431
|
+
filterCyclicTables = (tablesGenerators) => {
|
|
134432
|
+
const filteredTablesGenerators = tablesGenerators.filter((tableGen) => tableGen.columnsPossibleGenerators.some((columnGen) => columnGen.isCyclic === true && columnGen.wasDefinedBefore === true));
|
|
134433
|
+
const tablesUniqueNotNullColumn = {};
|
|
134434
|
+
for (const [idx, tableGen] of filteredTablesGenerators.entries()) {
|
|
134435
|
+
const uniqueNotNullColName = filteredTablesGenerators[idx].columnsPossibleGenerators.find((colGen) => colGen.primary === true
|
|
134436
|
+
|| (colGen.isUnique === true
|
|
134437
|
+
&& colGen.notNull === true))?.columnName;
|
|
134438
|
+
if (uniqueNotNullColName === undefined) {
|
|
134439
|
+
throw new Error(`Table '${tableGen.tableName}' does not have primary or (unique and notNull) column. Can't seed table with cyclic relation.`);
|
|
134440
|
+
}
|
|
134441
|
+
tablesUniqueNotNullColumn[tableGen.tableName] = { uniqueNotNullColName };
|
|
134442
|
+
filteredTablesGenerators[idx].columnsPossibleGenerators = tableGen.columnsPossibleGenerators.filter((colGen) => (colGen.isCyclic === true && colGen.wasDefinedBefore === true) || colGen.columnName === uniqueNotNullColName).map((colGen) => {
|
|
134443
|
+
const newColGen = { ...colGen };
|
|
134444
|
+
newColGen.wasDefinedBefore = false;
|
|
134445
|
+
return newColGen;
|
|
134446
|
+
});
|
|
134447
|
+
}
|
|
134448
|
+
return { filteredTablesGenerators, tablesUniqueNotNullColumn };
|
|
134220
134449
|
};
|
|
134221
134450
|
generateTablesValues = async (relations, tablesGenerators, db, schema, options) => {
|
|
134222
134451
|
// console.time(
|
|
@@ -134227,17 +134456,21 @@ class SeedService {
|
|
|
134227
134456
|
let columnsGenerators;
|
|
134228
134457
|
let tableGenerators;
|
|
134229
134458
|
let tableValues;
|
|
134230
|
-
let tablesValues = [];
|
|
134459
|
+
let tablesValues = options?.tablesValues === undefined ? [] : options.tablesValues;
|
|
134231
134460
|
let pRNGSeed;
|
|
134232
134461
|
// relations = relations.filter(rel => rel.type === "one");
|
|
134233
134462
|
let filteredRelations;
|
|
134234
|
-
let preserveData, insertDataInDb = true;
|
|
134463
|
+
let preserveData, insertDataInDb = true, updateDataInDb = false;
|
|
134235
134464
|
if (options?.preserveData !== undefined)
|
|
134236
134465
|
preserveData = options.preserveData;
|
|
134237
134466
|
if (options?.insertDataInDb !== undefined)
|
|
134238
134467
|
insertDataInDb = options.insertDataInDb;
|
|
134468
|
+
if (options?.updateDataInDb !== undefined)
|
|
134469
|
+
updateDataInDb = options.updateDataInDb;
|
|
134470
|
+
if (updateDataInDb === true)
|
|
134471
|
+
insertDataInDb = false;
|
|
134239
134472
|
// TODO: now I'm generating tablesInOutRelations twice, first time in generatePossibleGenerators and second time here. maybe should generate it once instead.
|
|
134240
|
-
const tablesInOutRelations = this.
|
|
134473
|
+
const { tablesInOutRelations } = this.getInfoFromRelations(relations);
|
|
134241
134474
|
for (const table of tablesGenerators) {
|
|
134242
134475
|
tableCount = table.count === undefined ? options?.count || this.defaultCountForTable : table.count;
|
|
134243
134476
|
tableGenerators = {};
|
|
@@ -134265,10 +134498,11 @@ class SeedService {
|
|
|
134265
134498
|
}
|
|
134266
134499
|
for (let colIdx = 0; colIdx < rel.columns.length; colIdx++) {
|
|
134267
134500
|
let refColumnValues;
|
|
134268
|
-
let hasSelfRelation;
|
|
134501
|
+
let hasSelfRelation = false;
|
|
134269
134502
|
let repeatedValuesCount, weightedCountSeed;
|
|
134270
134503
|
let genObj;
|
|
134271
|
-
if (rel.table === rel.refTable
|
|
134504
|
+
if (rel.table === rel.refTable
|
|
134505
|
+
&& tableGenerators[rel.columns[colIdx]]?.wasRefined === false) {
|
|
134272
134506
|
const refColName = rel.refColumns[colIdx];
|
|
134273
134507
|
pRNGSeed = generateHashFromString(`${table.tableName}.${refColName}`);
|
|
134274
134508
|
const refColumnGenerator = {};
|
|
@@ -134287,11 +134521,11 @@ class SeedService {
|
|
|
134287
134521
|
values: refColumnValues,
|
|
134288
134522
|
});
|
|
134289
134523
|
}
|
|
134290
|
-
else
|
|
134524
|
+
else if (tableGenerators[rel.columns[colIdx]]?.wasDefinedBefore === false
|
|
134525
|
+
&& tableGenerators[rel.columns[colIdx]]?.wasRefined === false) {
|
|
134291
134526
|
refColumnValues = tablesValues
|
|
134292
134527
|
.find((val) => val.tableName === rel.refTable)
|
|
134293
134528
|
.rows.map((row) => row[rel.refColumns[colIdx]]);
|
|
134294
|
-
hasSelfRelation = false;
|
|
134295
134529
|
if (table.withFromTable[rel.refTable] !== undefined
|
|
134296
134530
|
&& table.withFromTable[rel.refTable].repeatedValuesCount
|
|
134297
134531
|
!== undefined) {
|
|
@@ -134304,7 +134538,9 @@ class SeedService {
|
|
|
134304
134538
|
genObj.maxRepeatedValuesCount = repeatedValuesCount;
|
|
134305
134539
|
}
|
|
134306
134540
|
// console.log(rel.columns[colIdx], tableGenerators)
|
|
134307
|
-
|
|
134541
|
+
if (genObj !== undefined) {
|
|
134542
|
+
tableGenerators[rel.columns[colIdx]].generator = genObj;
|
|
134543
|
+
}
|
|
134308
134544
|
tableGenerators[rel.columns[colIdx]] = {
|
|
134309
134545
|
...tableGenerators[rel.columns[colIdx]],
|
|
134310
134546
|
hasSelfRelation,
|
|
@@ -134317,6 +134553,8 @@ class SeedService {
|
|
|
134317
134553
|
&& tablesInOutRelations[table.tableName]?.in === 0)
|
|
134318
134554
|
? false
|
|
134319
134555
|
: true;
|
|
134556
|
+
preserveData = preserveData || (options?.preserveCyclicTablesData === true
|
|
134557
|
+
&& table.columnsPossibleGenerators.some((colGen) => colGen.isCyclic === true));
|
|
134320
134558
|
tableValues = await this.generateColumnsValuesByGenerators({
|
|
134321
134559
|
tableGenerators,
|
|
134322
134560
|
db,
|
|
@@ -134325,6 +134563,10 @@ class SeedService {
|
|
|
134325
134563
|
count: tableCount,
|
|
134326
134564
|
preserveData,
|
|
134327
134565
|
insertDataInDb,
|
|
134566
|
+
updateDataInDb,
|
|
134567
|
+
uniqueNotNullColName: options?.tablesUniqueNotNullColumn === undefined
|
|
134568
|
+
? undefined
|
|
134569
|
+
: options?.tablesUniqueNotNullColumn[table.tableName]?.uniqueNotNullColName,
|
|
134328
134570
|
});
|
|
134329
134571
|
if (preserveData === true) {
|
|
134330
134572
|
tablesValues.push({
|
|
@@ -134344,10 +134586,13 @@ class SeedService {
|
|
|
134344
134586
|
}
|
|
134345
134587
|
return tablesValues;
|
|
134346
134588
|
};
|
|
134347
|
-
generateColumnsValuesByGenerators = async ({ tableGenerators, db, schema, tableName, count, preserveData = true, insertDataInDb = true, batchSize = 10000, }) => {
|
|
134589
|
+
generateColumnsValuesByGenerators = async ({ tableGenerators, db, schema, tableName, count, preserveData = true, insertDataInDb = true, updateDataInDb = false, uniqueNotNullColName, batchSize = 10000, }) => {
|
|
134348
134590
|
if (count === undefined) {
|
|
134349
134591
|
count = this.defaultCountForTable;
|
|
134350
134592
|
}
|
|
134593
|
+
if (updateDataInDb === true) {
|
|
134594
|
+
batchSize = 1;
|
|
134595
|
+
}
|
|
134351
134596
|
let columnGenerator;
|
|
134352
134597
|
const columnsGenerators = {};
|
|
134353
134598
|
let generatedValues = [];
|
|
@@ -134362,17 +134607,12 @@ class SeedService {
|
|
|
134362
134607
|
count,
|
|
134363
134608
|
seed: columnGenerator.pRNGSeed,
|
|
134364
134609
|
});
|
|
134365
|
-
|
|
134366
|
-
|
|
134367
|
-
|
|
134368
|
-
|
|
134369
|
-
|
|
134370
|
-
|
|
134371
|
-
count,
|
|
134372
|
-
seed: columnGenerator.pRNGSeed,
|
|
134373
|
-
});
|
|
134374
|
-
uniqueGen.isUnique = columnsGenerators[columnName].isUnique;
|
|
134375
|
-
uniqueGen.dataType = columnsGenerators[columnName].dataType;
|
|
134610
|
+
const arrayGen = columnsGenerators[columnName].replaceIfArray({ count, seed: columnGenerator.pRNGSeed });
|
|
134611
|
+
if (arrayGen !== undefined) {
|
|
134612
|
+
columnsGenerators[columnName] = arrayGen;
|
|
134613
|
+
}
|
|
134614
|
+
const uniqueGen = columnsGenerators[columnName].replaceIfUnique({ count, seed: columnGenerator.pRNGSeed });
|
|
134615
|
+
if (uniqueGen !== undefined) {
|
|
134376
134616
|
columnsGenerators[columnName] = uniqueGen;
|
|
134377
134617
|
}
|
|
134378
134618
|
}
|
|
@@ -134392,7 +134632,7 @@ class SeedService {
|
|
|
134392
134632
|
}
|
|
134393
134633
|
const maxBatchSize = Math.floor(maxParametersNumber / columnsNumber);
|
|
134394
134634
|
batchSize = batchSize > maxBatchSize ? maxBatchSize : batchSize;
|
|
134395
|
-
if (insertDataInDb === true
|
|
134635
|
+
if ((insertDataInDb === true || updateDataInDb === true)
|
|
134396
134636
|
&& (db === undefined || schema === undefined || tableName === undefined)) {
|
|
134397
134637
|
throw new Error('db or schema or tableName is undefined.');
|
|
134398
134638
|
}
|
|
@@ -134408,27 +134648,49 @@ class SeedService {
|
|
|
134408
134648
|
generatedValue = columnsGenerators[columnName].generate({ i });
|
|
134409
134649
|
row[columnName] = generatedValue;
|
|
134410
134650
|
}
|
|
134411
|
-
if (insertDataInDb === true
|
|
134651
|
+
if ((insertDataInDb === true || updateDataInDb === true)
|
|
134412
134652
|
&& ((i + 1) % batchSize === 0 || i === count - 1)) {
|
|
134413
134653
|
if (preserveData === false) {
|
|
134414
|
-
|
|
134415
|
-
|
|
134416
|
-
|
|
134417
|
-
|
|
134418
|
-
|
|
134419
|
-
|
|
134420
|
-
|
|
134654
|
+
if (insertDataInDb === true) {
|
|
134655
|
+
await this.insertInDb({
|
|
134656
|
+
generatedValues,
|
|
134657
|
+
db: db,
|
|
134658
|
+
schema: schema,
|
|
134659
|
+
tableName: tableName,
|
|
134660
|
+
override,
|
|
134661
|
+
});
|
|
134662
|
+
}
|
|
134663
|
+
else if (updateDataInDb === true) {
|
|
134664
|
+
await this.updateDb({
|
|
134665
|
+
generatedValues,
|
|
134666
|
+
db: db,
|
|
134667
|
+
schema: schema,
|
|
134668
|
+
tableName: tableName,
|
|
134669
|
+
uniqueNotNullColName: uniqueNotNullColName,
|
|
134670
|
+
});
|
|
134671
|
+
}
|
|
134421
134672
|
generatedValues = [];
|
|
134422
134673
|
}
|
|
134423
134674
|
else {
|
|
134424
134675
|
const batchCount = Math.floor(i / batchSize);
|
|
134425
|
-
|
|
134426
|
-
|
|
134427
|
-
|
|
134428
|
-
|
|
134429
|
-
|
|
134430
|
-
|
|
134431
|
-
|
|
134676
|
+
if (insertDataInDb === true) {
|
|
134677
|
+
await this.insertInDb({
|
|
134678
|
+
generatedValues: generatedValues.slice(batchSize * batchCount, batchSize * (batchCount + 1)),
|
|
134679
|
+
db: db,
|
|
134680
|
+
schema: schema,
|
|
134681
|
+
tableName: tableName,
|
|
134682
|
+
override,
|
|
134683
|
+
});
|
|
134684
|
+
}
|
|
134685
|
+
else if (updateDataInDb === true) {
|
|
134686
|
+
await this.updateDb({
|
|
134687
|
+
generatedValues: generatedValues.slice(batchSize * batchCount, batchSize * (batchCount + 1)),
|
|
134688
|
+
db: db,
|
|
134689
|
+
schema: schema,
|
|
134690
|
+
tableName: tableName,
|
|
134691
|
+
uniqueNotNullColName: uniqueNotNullColName,
|
|
134692
|
+
});
|
|
134693
|
+
}
|
|
134432
134694
|
}
|
|
134433
134695
|
}
|
|
134434
134696
|
}
|
|
@@ -134453,6 +134715,21 @@ class SeedService {
|
|
|
134453
134715
|
.values(generatedValues);
|
|
134454
134716
|
}
|
|
134455
134717
|
};
|
|
134718
|
+
updateDb = async ({ generatedValues, db, schema, tableName, uniqueNotNullColName, }) => {
|
|
134719
|
+
if (is(db, (PgDatabase))) {
|
|
134720
|
+
const table = schema[tableName];
|
|
134721
|
+
const uniqueNotNullCol = table[uniqueNotNullColName];
|
|
134722
|
+
await db.update(table).set(generatedValues[0]).where(eq(uniqueNotNullCol, generatedValues[0][uniqueNotNullColName]));
|
|
134723
|
+
}
|
|
134724
|
+
else if (is(db, (MySqlDatabase))) {
|
|
134725
|
+
const table = schema[tableName];
|
|
134726
|
+
await db.update(table).set(generatedValues[0]).where(eq(table[uniqueNotNullColName], generatedValues[0][uniqueNotNullColName]));
|
|
134727
|
+
}
|
|
134728
|
+
else if (is(db, (BaseSQLiteDatabase))) {
|
|
134729
|
+
const table = schema[tableName];
|
|
134730
|
+
await db.update(table).set(generatedValues[0]).where(eq(table[uniqueNotNullColName], generatedValues[0][uniqueNotNullColName]));
|
|
134731
|
+
}
|
|
134732
|
+
};
|
|
134456
134733
|
}
|
|
134457
134734
|
var seedService = new SeedService();
|
|
134458
134735
|
|
|
@@ -134506,6 +134783,7 @@ async function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject, drizzleSt
|
|
|
134506
134783
|
hasDefault: col.default === undefined ? false : true,
|
|
134507
134784
|
isUnique: col.isUnique === undefined ? false : col.isUnique,
|
|
134508
134785
|
notNull: col.notNull,
|
|
134786
|
+
primary: col.primaryKey,
|
|
134509
134787
|
}));
|
|
134510
134788
|
tables.push({
|
|
134511
134789
|
name: tableName,
|
|
@@ -134514,11 +134792,18 @@ async function seedForDrizzleStudio({ sqlDialect, drizzleStudioObject, drizzleSt
|
|
|
134514
134792
|
});
|
|
134515
134793
|
}
|
|
134516
134794
|
relations = drizzleStudioRelations.filter((rel) => rel.schema === schemaName && rel.refSchema === schemaName);
|
|
134795
|
+
const isCyclicRelations = relations.map((reli) => {
|
|
134796
|
+
if (relations.some((relj) => reli.table === relj.refTable && reli.refTable === relj.table)) {
|
|
134797
|
+
return { ...reli, isCyclic: true };
|
|
134798
|
+
}
|
|
134799
|
+
return { ...reli, isCyclic: false };
|
|
134800
|
+
});
|
|
134517
134801
|
refinements = schemasRefinements !== undefined && schemasRefinements[schemaName] !== undefined
|
|
134518
134802
|
? schemasRefinements[schemaName]
|
|
134519
134803
|
: undefined;
|
|
134520
|
-
const generatedTablesGenerators = seedService.generatePossibleGenerators(sqlDialect, tables,
|
|
134521
|
-
|
|
134804
|
+
const generatedTablesGenerators = seedService.generatePossibleGenerators(sqlDialect, tables, isCyclicRelations, {}, // TODO: fix later
|
|
134805
|
+
refinements, options);
|
|
134806
|
+
const generatedTables = await seedService.generateTablesValues(isCyclicRelations, generatedTablesGenerators, undefined, undefined, { ...options, preserveData: true, insertDataInDb: false });
|
|
134522
134807
|
generatedSchemas[schemaName] = { tables: generatedTables };
|
|
134523
134808
|
}
|
|
134524
134809
|
return generatedSchemas;
|
|
@@ -134657,7 +134942,7 @@ const resetPostgres = async (db, schema) => {
|
|
|
134657
134942
|
const tablesToTruncate = Object.entries(schema).map(([_, table]) => {
|
|
134658
134943
|
const config = getTableConfig(table);
|
|
134659
134944
|
config.schema = config.schema === undefined ? 'public' : config.schema;
|
|
134660
|
-
return
|
|
134945
|
+
return `"${config.schema}"."${config.name}"`;
|
|
134661
134946
|
});
|
|
134662
134947
|
await db.execute(sql.raw(`truncate ${tablesToTruncate.join(',')} cascade;`));
|
|
134663
134948
|
};
|
|
@@ -134666,9 +134951,13 @@ const filterPgTables = (schema) => {
|
|
|
134666
134951
|
return { pgSchema };
|
|
134667
134952
|
};
|
|
134668
134953
|
const seedPostgres = async (db, schema, options = {}, refinements) => {
|
|
134669
|
-
const { tables, relations } = getPostgresInfo(schema);
|
|
134670
|
-
const generatedTablesGenerators = seedService.generatePossibleGenerators('postgresql', tables, relations, refinements, options);
|
|
134671
|
-
|
|
134954
|
+
const { tables, relations, tableRelations } = getPostgresInfo(schema);
|
|
134955
|
+
const generatedTablesGenerators = seedService.generatePossibleGenerators('postgresql', tables, relations, tableRelations, refinements, options);
|
|
134956
|
+
const preserveCyclicTablesData = relations.some((rel) => rel.isCyclic === true);
|
|
134957
|
+
const tablesValues = await seedService.generateTablesValues(relations, generatedTablesGenerators, db, schema, { ...options, preserveCyclicTablesData });
|
|
134958
|
+
const { filteredTablesGenerators, tablesUniqueNotNullColumn } = seedService.filterCyclicTables(generatedTablesGenerators);
|
|
134959
|
+
const updateDataInDb = filteredTablesGenerators.length === 0 ? false : true;
|
|
134960
|
+
await seedService.generateTablesValues(relations, filteredTablesGenerators, db, schema, { ...options, tablesValues, updateDataInDb, tablesUniqueNotNullColumn });
|
|
134672
134961
|
};
|
|
134673
134962
|
const getPostgresInfo = (schema) => {
|
|
134674
134963
|
let tableConfig;
|
|
@@ -134677,6 +134966,7 @@ const getPostgresInfo = (schema) => {
|
|
|
134677
134966
|
const tables = [];
|
|
134678
134967
|
const relations = [];
|
|
134679
134968
|
const dbToTsColumnNamesMapGlobal = {};
|
|
134969
|
+
const tableRelations = {};
|
|
134680
134970
|
const getDbToTsColumnNamesMap = (table) => {
|
|
134681
134971
|
let dbToTsColumnNamesMap = {};
|
|
134682
134972
|
const tableName = getTableName(table);
|
|
@@ -134697,10 +134987,14 @@ const getPostgresInfo = (schema) => {
|
|
|
134697
134987
|
for (const [tsCol, col] of Object.entries(tableConfig.columns[0].table)) {
|
|
134698
134988
|
dbToTsColumnNamesMap[col.name] = tsCol;
|
|
134699
134989
|
}
|
|
134700
|
-
|
|
134990
|
+
// might be empty list
|
|
134991
|
+
const newRelations = tableConfig.foreignKeys.map((fk) => {
|
|
134701
134992
|
const table = dbToTsTableNamesMap[tableConfig.name];
|
|
134702
134993
|
const refTable = dbToTsTableNamesMap[getTableName(fk.reference().foreignTable)];
|
|
134703
134994
|
const dbToTsColumnNamesMapForRefTable = getDbToTsColumnNamesMap(fk.reference().foreignTable);
|
|
134995
|
+
if (tableRelations[refTable] === undefined) {
|
|
134996
|
+
tableRelations[refTable] = [];
|
|
134997
|
+
}
|
|
134704
134998
|
return {
|
|
134705
134999
|
table,
|
|
134706
135000
|
columns: fk
|
|
@@ -134710,27 +135004,94 @@ const getPostgresInfo = (schema) => {
|
|
|
134710
135004
|
refColumns: fk
|
|
134711
135005
|
.reference()
|
|
134712
135006
|
.foreignColumns.map((fCol) => dbToTsColumnNamesMapForRefTable[fCol.name]),
|
|
135007
|
+
refTableRels: tableRelations[refTable],
|
|
134713
135008
|
};
|
|
134714
|
-
})
|
|
135009
|
+
});
|
|
135010
|
+
relations.push(...newRelations);
|
|
135011
|
+
if (tableRelations[dbToTsTableNamesMap[tableConfig.name]] === undefined) {
|
|
135012
|
+
tableRelations[dbToTsTableNamesMap[tableConfig.name]] = [];
|
|
135013
|
+
}
|
|
135014
|
+
tableRelations[dbToTsTableNamesMap[tableConfig.name]].push(...newRelations);
|
|
135015
|
+
const getAllBaseColumns = (baseColumn) => {
|
|
135016
|
+
const baseColumnResult = {
|
|
135017
|
+
name: baseColumn.name,
|
|
135018
|
+
columnType: baseColumn.columnType.replace('Pg', '').toLowerCase(),
|
|
135019
|
+
dataType: baseColumn.dataType,
|
|
135020
|
+
size: baseColumn.size,
|
|
135021
|
+
hasDefault: baseColumn.hasDefault,
|
|
135022
|
+
enumValues: baseColumn.enumValues,
|
|
135023
|
+
default: baseColumn.default,
|
|
135024
|
+
isUnique: baseColumn.isUnique,
|
|
135025
|
+
notNull: baseColumn.notNull,
|
|
135026
|
+
primary: baseColumn.primary,
|
|
135027
|
+
baseColumn: baseColumn.baseColumn === undefined ? undefined : getAllBaseColumns(baseColumn.baseColumn),
|
|
135028
|
+
};
|
|
135029
|
+
return baseColumnResult;
|
|
135030
|
+
};
|
|
135031
|
+
// console.log(tableConfig.columns);
|
|
134715
135032
|
tables.push({
|
|
134716
135033
|
name: dbToTsTableNamesMap[tableConfig.name],
|
|
134717
135034
|
columns: tableConfig.columns.map((column) => ({
|
|
134718
135035
|
name: dbToTsColumnNamesMap[column.name],
|
|
134719
135036
|
columnType: column.columnType.replace('Pg', '').toLowerCase(),
|
|
134720
135037
|
dataType: column.dataType,
|
|
135038
|
+
size: column.size,
|
|
134721
135039
|
hasDefault: column.hasDefault,
|
|
134722
135040
|
default: column.default,
|
|
134723
135041
|
enumValues: column.enumValues,
|
|
134724
135042
|
isUnique: column.isUnique,
|
|
134725
135043
|
notNull: column.notNull,
|
|
135044
|
+
primary: column.primary,
|
|
134726
135045
|
generatedIdentityType: column.generatedIdentity?.type,
|
|
135046
|
+
baseColumn: (column.baseColumn === undefined)
|
|
135047
|
+
? undefined
|
|
135048
|
+
: getAllBaseColumns(column.baseColumn),
|
|
134727
135049
|
})),
|
|
134728
135050
|
primaryKeys: tableConfig.columns
|
|
134729
135051
|
.filter((column) => column.primary)
|
|
134730
135052
|
.map((column) => dbToTsColumnNamesMap[column.name]),
|
|
134731
135053
|
});
|
|
134732
135054
|
}
|
|
134733
|
-
|
|
135055
|
+
const isCyclicRelations = relations.map((relI) => {
|
|
135056
|
+
// if (relations.some((relj) => relI.table === relj.refTable && relI.refTable === relj.table)) {
|
|
135057
|
+
const tableRel = tableRelations[relI.table].find((relJ) => relJ.refTable === relI.refTable);
|
|
135058
|
+
if (isRelationCyclic(relI)) {
|
|
135059
|
+
tableRel['isCyclic'] = true;
|
|
135060
|
+
return { ...relI, isCyclic: true };
|
|
135061
|
+
}
|
|
135062
|
+
tableRel['isCyclic'] = false;
|
|
135063
|
+
return { ...relI, isCyclic: false };
|
|
135064
|
+
});
|
|
135065
|
+
return { tables, relations: isCyclicRelations, tableRelations };
|
|
135066
|
+
};
|
|
135067
|
+
const isRelationCyclic = (startRel) => {
|
|
135068
|
+
// self relation
|
|
135069
|
+
if (startRel.table === startRel.refTable)
|
|
135070
|
+
return false;
|
|
135071
|
+
// DFS
|
|
135072
|
+
const targetTable = startRel.table;
|
|
135073
|
+
const queue = [startRel];
|
|
135074
|
+
let path = [];
|
|
135075
|
+
while (queue.length !== 0) {
|
|
135076
|
+
const currRel = queue.shift();
|
|
135077
|
+
if (path.includes(currRel.table)) {
|
|
135078
|
+
const idx = path.indexOf(currRel.table);
|
|
135079
|
+
path = path.slice(0, idx);
|
|
135080
|
+
}
|
|
135081
|
+
path.push(currRel.table);
|
|
135082
|
+
for (const rel of currRel.refTableRels) {
|
|
135083
|
+
// self relation
|
|
135084
|
+
if (rel.table === rel.refTable)
|
|
135085
|
+
continue;
|
|
135086
|
+
if (rel.refTable === targetTable)
|
|
135087
|
+
return true;
|
|
135088
|
+
// found cycle, but not the one we are looking for
|
|
135089
|
+
if (path.includes(rel.refTable))
|
|
135090
|
+
continue;
|
|
135091
|
+
queue.unshift(rel);
|
|
135092
|
+
}
|
|
135093
|
+
}
|
|
135094
|
+
return false;
|
|
134734
135095
|
};
|
|
134735
135096
|
// MySql-----------------------------------------------------------------------------------------------------
|
|
134736
135097
|
const resetMySql = async (db, schema) => {
|
|
@@ -134750,9 +135111,13 @@ const filterMySqlTables = (schema) => {
|
|
|
134750
135111
|
return { mySqlSchema };
|
|
134751
135112
|
};
|
|
134752
135113
|
const seedMySql = async (db, schema, options = {}, refinements) => {
|
|
134753
|
-
const { tables, relations } = getMySqlInfo(schema);
|
|
134754
|
-
const generatedTablesGenerators = seedService.generatePossibleGenerators('mysql', tables, relations, refinements, options);
|
|
134755
|
-
|
|
135114
|
+
const { tables, relations, tableRelations } = getMySqlInfo(schema);
|
|
135115
|
+
const generatedTablesGenerators = seedService.generatePossibleGenerators('mysql', tables, relations, tableRelations, refinements, options);
|
|
135116
|
+
const preserveCyclicTablesData = relations.some((rel) => rel.isCyclic === true);
|
|
135117
|
+
const tablesValues = await seedService.generateTablesValues(relations, generatedTablesGenerators, db, schema, { ...options, preserveCyclicTablesData });
|
|
135118
|
+
const { filteredTablesGenerators, tablesUniqueNotNullColumn } = seedService.filterCyclicTables(generatedTablesGenerators);
|
|
135119
|
+
const updateDataInDb = filteredTablesGenerators.length === 0 ? false : true;
|
|
135120
|
+
await seedService.generateTablesValues(relations, filteredTablesGenerators, db, schema, { ...options, tablesValues, updateDataInDb, tablesUniqueNotNullColumn });
|
|
134756
135121
|
};
|
|
134757
135122
|
const getMySqlInfo = (schema) => {
|
|
134758
135123
|
let tableConfig;
|
|
@@ -134761,6 +135126,7 @@ const getMySqlInfo = (schema) => {
|
|
|
134761
135126
|
const tables = [];
|
|
134762
135127
|
const relations = [];
|
|
134763
135128
|
const dbToTsColumnNamesMapGlobal = {};
|
|
135129
|
+
const tableRelations = {};
|
|
134764
135130
|
const getDbToTsColumnNamesMap = (table) => {
|
|
134765
135131
|
let dbToTsColumnNamesMap = {};
|
|
134766
135132
|
const tableName = getTableName(table);
|
|
@@ -134781,10 +135147,13 @@ const getMySqlInfo = (schema) => {
|
|
|
134781
135147
|
for (const [tsCol, col] of Object.entries(tableConfig.columns[0].table)) {
|
|
134782
135148
|
dbToTsColumnNamesMap[col.name] = tsCol;
|
|
134783
135149
|
}
|
|
134784
|
-
|
|
135150
|
+
const newRelations = tableConfig.foreignKeys.map((fk) => {
|
|
134785
135151
|
const table = dbToTsTableNamesMap[tableConfig.name];
|
|
134786
135152
|
const refTable = dbToTsTableNamesMap[getTableName(fk.reference().foreignTable)];
|
|
134787
135153
|
const dbToTsColumnNamesMapForRefTable = getDbToTsColumnNamesMap(fk.reference().foreignTable);
|
|
135154
|
+
if (tableRelations[refTable] === undefined) {
|
|
135155
|
+
tableRelations[refTable] = [];
|
|
135156
|
+
}
|
|
134788
135157
|
return {
|
|
134789
135158
|
table,
|
|
134790
135159
|
columns: fk
|
|
@@ -134794,8 +135163,14 @@ const getMySqlInfo = (schema) => {
|
|
|
134794
135163
|
refColumns: fk
|
|
134795
135164
|
.reference()
|
|
134796
135165
|
.foreignColumns.map((fCol) => dbToTsColumnNamesMapForRefTable[fCol.name]),
|
|
135166
|
+
refTableRels: tableRelations[refTable],
|
|
134797
135167
|
};
|
|
134798
|
-
})
|
|
135168
|
+
});
|
|
135169
|
+
relations.push(...newRelations);
|
|
135170
|
+
if (tableRelations[dbToTsTableNamesMap[tableConfig.name]] === undefined) {
|
|
135171
|
+
tableRelations[dbToTsTableNamesMap[tableConfig.name]] = [];
|
|
135172
|
+
}
|
|
135173
|
+
tableRelations[dbToTsTableNamesMap[tableConfig.name]].push(...newRelations);
|
|
134799
135174
|
tables.push({
|
|
134800
135175
|
name: dbToTsTableNamesMap[tableConfig.name],
|
|
134801
135176
|
columns: tableConfig.columns.map((column) => ({
|
|
@@ -134807,13 +135182,23 @@ const getMySqlInfo = (schema) => {
|
|
|
134807
135182
|
enumValues: column.enumValues,
|
|
134808
135183
|
isUnique: column.isUnique,
|
|
134809
135184
|
notNull: column.notNull,
|
|
135185
|
+
primary: column.primary,
|
|
134810
135186
|
})),
|
|
134811
135187
|
primaryKeys: tableConfig.columns
|
|
134812
135188
|
.filter((column) => column.primary)
|
|
134813
135189
|
.map((column) => dbToTsColumnNamesMap[column.name]),
|
|
134814
135190
|
});
|
|
134815
135191
|
}
|
|
134816
|
-
|
|
135192
|
+
const isCyclicRelations = relations.map((relI) => {
|
|
135193
|
+
const tableRel = tableRelations[relI.table].find((relJ) => relJ.refTable === relI.refTable);
|
|
135194
|
+
if (isRelationCyclic(relI)) {
|
|
135195
|
+
tableRel['isCyclic'] = true;
|
|
135196
|
+
return { ...relI, isCyclic: true };
|
|
135197
|
+
}
|
|
135198
|
+
tableRel['isCyclic'] = false;
|
|
135199
|
+
return { ...relI, isCyclic: false };
|
|
135200
|
+
});
|
|
135201
|
+
return { tables, relations: isCyclicRelations, tableRelations };
|
|
134817
135202
|
};
|
|
134818
135203
|
// Sqlite------------------------------------------------------------------------------------------------------------------------
|
|
134819
135204
|
const resetSqlite = async (db, schema) => {
|
|
@@ -134833,9 +135218,13 @@ const filterSqliteTables = (schema) => {
|
|
|
134833
135218
|
return { sqliteSchema };
|
|
134834
135219
|
};
|
|
134835
135220
|
const seedSqlite = async (db, schema, options = {}, refinements) => {
|
|
134836
|
-
const { tables, relations } = getSqliteInfo(schema);
|
|
134837
|
-
const generatedTablesGenerators = seedService.generatePossibleGenerators('sqlite', tables, relations, refinements, options);
|
|
134838
|
-
|
|
135221
|
+
const { tables, relations, tableRelations } = getSqliteInfo(schema);
|
|
135222
|
+
const generatedTablesGenerators = seedService.generatePossibleGenerators('sqlite', tables, relations, tableRelations, refinements, options);
|
|
135223
|
+
const preserveCyclicTablesData = relations.some((rel) => rel.isCyclic === true);
|
|
135224
|
+
const tablesValues = await seedService.generateTablesValues(relations, generatedTablesGenerators, db, schema, { ...options, preserveCyclicTablesData });
|
|
135225
|
+
const { filteredTablesGenerators, tablesUniqueNotNullColumn } = seedService.filterCyclicTables(generatedTablesGenerators);
|
|
135226
|
+
const updateDataInDb = filteredTablesGenerators.length === 0 ? false : true;
|
|
135227
|
+
await seedService.generateTablesValues(relations, filteredTablesGenerators, db, schema, { ...options, tablesValues, updateDataInDb, tablesUniqueNotNullColumn });
|
|
134839
135228
|
};
|
|
134840
135229
|
const getSqliteInfo = (schema) => {
|
|
134841
135230
|
let tableConfig;
|
|
@@ -134844,6 +135233,7 @@ const getSqliteInfo = (schema) => {
|
|
|
134844
135233
|
const tables = [];
|
|
134845
135234
|
const relations = [];
|
|
134846
135235
|
const dbToTsColumnNamesMapGlobal = {};
|
|
135236
|
+
const tableRelations = {};
|
|
134847
135237
|
const getDbToTsColumnNamesMap = (table) => {
|
|
134848
135238
|
let dbToTsColumnNamesMap = {};
|
|
134849
135239
|
const tableName = getTableName(table);
|
|
@@ -134864,10 +135254,13 @@ const getSqliteInfo = (schema) => {
|
|
|
134864
135254
|
for (const [tsCol, col] of Object.entries(tableConfig.columns[0].table)) {
|
|
134865
135255
|
dbToTsColumnNamesMap[col.name] = tsCol;
|
|
134866
135256
|
}
|
|
134867
|
-
|
|
135257
|
+
const newRelations = tableConfig.foreignKeys.map((fk) => {
|
|
134868
135258
|
const table = dbToTsTableNamesMap[tableConfig.name];
|
|
134869
135259
|
const refTable = dbToTsTableNamesMap[getTableName(fk.reference().foreignTable)];
|
|
134870
135260
|
const dbToTsColumnNamesMapForRefTable = getDbToTsColumnNamesMap(fk.reference().foreignTable);
|
|
135261
|
+
if (tableRelations[refTable] === undefined) {
|
|
135262
|
+
tableRelations[refTable] = [];
|
|
135263
|
+
}
|
|
134871
135264
|
return {
|
|
134872
135265
|
table,
|
|
134873
135266
|
columns: fk
|
|
@@ -134877,8 +135270,14 @@ const getSqliteInfo = (schema) => {
|
|
|
134877
135270
|
refColumns: fk
|
|
134878
135271
|
.reference()
|
|
134879
135272
|
.foreignColumns.map((fCol) => dbToTsColumnNamesMapForRefTable[fCol.name]),
|
|
135273
|
+
refTableRels: tableRelations[refTable],
|
|
134880
135274
|
};
|
|
134881
|
-
})
|
|
135275
|
+
});
|
|
135276
|
+
relations.push(...newRelations);
|
|
135277
|
+
if (tableRelations[dbToTsTableNamesMap[tableConfig.name]] === undefined) {
|
|
135278
|
+
tableRelations[dbToTsTableNamesMap[tableConfig.name]] = [];
|
|
135279
|
+
}
|
|
135280
|
+
tableRelations[dbToTsTableNamesMap[tableConfig.name]].push(...newRelations);
|
|
134882
135281
|
tables.push({
|
|
134883
135282
|
name: dbToTsTableNamesMap[tableConfig.name],
|
|
134884
135283
|
columns: tableConfig.columns.map((column) => ({
|
|
@@ -134890,14 +135289,24 @@ const getSqliteInfo = (schema) => {
|
|
|
134890
135289
|
enumValues: column.enumValues,
|
|
134891
135290
|
isUnique: column.isUnique,
|
|
134892
135291
|
notNull: column.notNull,
|
|
135292
|
+
primary: column.primary,
|
|
134893
135293
|
})),
|
|
134894
135294
|
primaryKeys: tableConfig.columns
|
|
134895
135295
|
.filter((column) => column.primary)
|
|
134896
135296
|
.map((column) => dbToTsColumnNamesMap[column.name]),
|
|
134897
135297
|
});
|
|
134898
135298
|
}
|
|
134899
|
-
|
|
135299
|
+
const isCyclicRelations = relations.map((relI) => {
|
|
135300
|
+
const tableRel = tableRelations[relI.table].find((relJ) => relJ.refTable === relI.refTable);
|
|
135301
|
+
if (isRelationCyclic(relI)) {
|
|
135302
|
+
tableRel['isCyclic'] = true;
|
|
135303
|
+
return { ...relI, isCyclic: true };
|
|
135304
|
+
}
|
|
135305
|
+
tableRel['isCyclic'] = false;
|
|
135306
|
+
return { ...relI, isCyclic: false };
|
|
135307
|
+
});
|
|
135308
|
+
return { tables, relations: isCyclicRelations, tableRelations };
|
|
134900
135309
|
};
|
|
134901
135310
|
|
|
134902
|
-
export { firstNames, getGeneratorsFunctions, lastNames, reset, seed, seedForDrizzleStudio };
|
|
135311
|
+
export { cityNames as cities, countries, firstNames, getGeneratorsFunctions, lastNames, reset, seed, seedForDrizzleStudio };
|
|
134903
135312
|
//# sourceMappingURL=index.mjs.map
|