Skip to content

Commit

Permalink
updated generator versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksiiKH0240 committed Dec 20, 2024
1 parent 34bb829 commit ec5d35e
Show file tree
Hide file tree
Showing 7 changed files with 514 additions and 327 deletions.
5 changes: 3 additions & 2 deletions drizzle-seed/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { entityKind, getTableName, is, sql } from 'drizzle-orm';
/* eslint-disable drizzle-internal/require-entity-kind */
import { getTableName, is, sql } from 'drizzle-orm';

import type { MySqlColumn, MySqlSchema } from 'drizzle-orm/mysql-core';
import { getTableConfig as getMysqlTableConfig, MySqlDatabase, MySqlTable } from 'drizzle-orm/mysql-core';
Expand Down Expand Up @@ -131,7 +132,7 @@ class SeedPromise<
[key: string]: PgTable | PgSchema | MySqlTable | MySqlSchema | SQLiteTable;
},
> implements Promise<void> {
static readonly [entityKind]: string = 'SeedPromise';
static readonly entityKind: string = 'SeedPromise';

[Symbol.toStringTag] = 'SeedPromise';

Expand Down
227 changes: 178 additions & 49 deletions drizzle-seed/src/services/GeneratorFuncs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { AbstractGenerator } from './Generators.ts';
import {
GenerateArray,
GenerateBoolean,
GenerateCity,
GenerateCompanyName,
Expand All @@ -8,6 +9,7 @@ import {
GenerateDatetime,
GenerateDefault,
GenerateEmail,
GenerateEnum,
GenerateFirstName,
GenerateFullName,
GenerateInt,
Expand All @@ -22,16 +24,34 @@ import {
GeneratePhoneNumber,
GeneratePoint,
GeneratePostcode,
GenerateSelfRelationsValuesFromArray,
GenerateState,
GenerateStreetAdddress,
GenerateStreetAddress,
GenerateString,
GenerateTime,
GenerateTimestamp,
GenerateUniqueCity,
GenerateUniqueCompanyName,
GenerateUniqueCountry,
GenerateUniqueFirstName,
GenerateUniqueFullName,
GenerateUniqueInt,
GenerateUniqueInterval,
GenerateUniqueLastName,
GenerateUniqueLine,
GenerateUniqueNumber,
GenerateUniquePoint,
GenerateUniquePostcode,
GenerateUniqueStreetAddress,
GenerateUniqueString,
GenerateUUID,
GenerateValuesFromArray,
GenerateWeightedCount,
GenerateYear,
HollowGenerator,
WeightedRandomGenerator,
} from './Generators.ts';
import { GenerateStringV2 } from './versioning/v2.ts';
import { GenerateStringV2, GenerateUniqueIntervalV2, GenerateUniqueStringV2 } from './versioning/v2.ts';

function createGenerator<GeneratorType extends AbstractGenerator<T>, T>(
generatorConstructor: new(params: T) => GeneratorType,
Expand Down Expand Up @@ -359,7 +379,7 @@ export const generatorsFuncs = {
* }));
* ```
*/
string: createGenerator(GenerateStringV2),
string: createGenerator(GenerateString),
// uniqueString: createGenerator(GenerateUniqueString),

/**
Expand Down Expand Up @@ -550,8 +570,8 @@ export const generatorsFuncs = {
* }));
* ```
*/
streetAddress: createGenerator(GenerateStreetAdddress),
// uniqueStreetAddress: createGenerator(GenerateUniqueStreetAdddress),
streetAddress: createGenerator(GenerateStreetAddress),
// uniqueStreetAddress: createGenerator(GenerateUniqueStreetAddress),

/**
* generates job titles.
Expand Down Expand Up @@ -736,53 +756,162 @@ export const generatorsFuncs = {
weightedRandom: createGenerator(WeightedRandomGenerator),
};

export const generatorsList: (new(params: any) => AbstractGenerator<any>)[] = [
GenerateBoolean,
GenerateCity,
GenerateCompanyName,
GenerateCountry,
GenerateDate,
GenerateDatetime,
GenerateDefault,
GenerateEmail,
GenerateFirstName,
GenerateFullName,
GenerateInt,
GenerateInterval,
GenerateIntPrimaryKey,
GenerateJobTitle,
GenerateJson,
GenerateLastName,
GenerateLine,
GenerateLoremIpsum,
GenerateNumber,
GeneratePhoneNumber,
GeneratePoint,
GeneratePostcode,
GenerateState,
GenerateStreetAdddress,
GenerateTime,
GenerateTimestamp,
GenerateUUID,
GenerateValuesFromArray,
GenerateYear,
WeightedRandomGenerator,
];
// TODO: revise
// so far, version changes don’t affect generator parameters.
export const generatorsFuncsV2 = { ...generatorsFuncs };

//
const generatorsObj = {
[entityKind]: [
GenerateStreetAdddress,
export const generatorsMap = {
HollowGenerator: [
HollowGenerator,
],
GenerateDefault: [
GenerateDefault,
],
GenerateValuesFromArray: [
GenerateValuesFromArray,
],
GenerateSelfRelationsValuesFromArray: [
GenerateSelfRelationsValuesFromArray,
],
GenerateIntPrimaryKey: [
GenerateIntPrimaryKey,
],
GenerateNumber: [
GenerateNumber,
],
GenerateUniqueNumber: [
GenerateUniqueNumber,
],
GenerateInt: [
GenerateInt,
],
GenerateUniqueInt: [
GenerateUniqueInt,
],
GenerateBoolean: [
GenerateBoolean,
],
GenerateDate: [
GenerateDate,
],
GenerateTime: [
GenerateTime,
],
GenerateTimestamp: [
GenerateTimestamp,
],
GenerateDatetime: [
GenerateDatetime,
],
GenerateYear: [
GenerateYear,
],
GenerateJson: [
GenerateJson,
],
GenerateEnum: [
GenerateEnum,
],
GenerateInterval: [
GenerateInterval,
],
GenerateUniqueInterval: [
GenerateUniqueInterval,
GenerateUniqueIntervalV2,
],
GenerateString: [
GenerateString,
GenerateStringV2,
],
GenerateUniqueString: [
GenerateUniqueString,
GenerateUniqueStringV2,
],
GenerateUUID: [
GenerateUUID,
],
[entityKind]: [
GenerateVarchar,
GenerateVarcharV2,
GenerateVarcharV3,
GenerateFirstName: [
GenerateFirstName,
],
GenerateUniqueFirstName: [
GenerateUniqueFirstName,
],
GenerateLastName: [
GenerateLastName,
],
GenerateUniqueLastName: [
GenerateUniqueLastName,
],
GenerateFullName: [
GenerateFullName,
],
GenerateUniqueFullName: [
GenerateUniqueFullName,
],
GenerateEmail: [
GenerateEmail,
],
GeneratePhoneNumber: [
GeneratePhoneNumber,
],
GenerateCountry: [
GenerateCountry,
],
GenerateUniqueCountry: [
GenerateUniqueCountry,
],
GenerateCity: [
GenerateCity,
],
GenerateUniqueCity: [
GenerateUniqueCity,
],
GenerateStreetAddress: [
GenerateStreetAddress,
],
GenerateUniqueStreetAddress: [
GenerateUniqueStreetAddress,
],
GenerateJobTitle: [
GenerateJobTitle,
],
GeneratePostcode: [
GeneratePostcode,
],
GenerateUniquePostcode: [
GenerateUniquePostcode,
],
GenerateState: [
GenerateState,
],
GenerateCompanyName: [
GenerateCompanyName,
],
GenerateUniqueCompanyName: [
GenerateUniqueCompanyName,
],
GenerateLoremIpsum: [
GenerateLoremIpsum,
],
GeneratePoint: [
GeneratePoint,
],
GenerateUniquePoint: [
GenerateUniquePoint,
],
GenerateLine: [
GenerateLine,
],
GenerateUniqueLine: [
GenerateUniqueLine,
],
WeightedRandomGenerator: [
WeightedRandomGenerator,
],
GenerateArray: [
GenerateArray,
],
[entityKind]: [
GenerateVarchar,
GenerateVarcharV2,
GenerateVarcharV3,
GenerateWeightedCount: [
GenerateWeightedCount,
],
};
Loading

0 comments on commit ec5d35e

Please sign in to comment.