{"id":"8a63771a4b40ecd9","repo":"drizzle-team/drizzle-orm","slug":"count-exceeds-max-number-of-unique-company-names","errorCode":null,"errorMessage":"count exceeds max number of unique company names(${maxUniqueCompanyNameNumber}).","messagePattern":"count exceeds max number of unique company names\\((.+?)\\)\\.","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"drizzle-seed/src/services/Generators.ts","lineNumber":2680,"sourceCode":"\n\tprivate state: {\n\t\trng: prand.RandomGenerator;\n\t\ttemplates: {\n\t\t\ttemplate: string;\n\t\t\tplaceholdersCount: number;\n\t\t\tindicesGen: GenerateUniqueInt;\n\t\t\tmaxUniqueCompanyNameNumber: number;\n\t\t\tcount: number;\n\t\t\tarraysToChooseFrom: string[][];\n\t\t}[];\n\t} | undefined;\n\tpublic override isUnique = true;\n\n\toverride init({ count, seed }: { count: number; seed: number }) {\n\t\tconst maxUniqueCompanyNameNumber = lastNames.length * companyNameSuffixes.length + Math.pow(lastNames.length, 2)\n\t\t\t+ Math.pow(lastNames.length, 2) + Math.pow(lastNames.length, 3);\n\t\tif (count > maxUniqueCompanyNameNumber) {\n\t\t\tthrow new RangeError(\n\t\t\t\t`count exceeds max number of unique company names(${maxUniqueCompanyNameNumber}).`,\n\t\t\t);\n\t\t}\n\n\t\t// max( { template: '#', placeholdersCount: 1 }, { template: '#, # and #', placeholdersCount: 3 } )\n\t\tconst maxCompanyNameLength = Math.max(\n\t\t\tmaxLastNameLength + maxCompanyNameSuffixLength + 1,\n\t\t\t3 * maxLastNameLength + 7,\n\t\t);\n\t\tif (this.stringLength !== undefined && this.stringLength < maxCompanyNameLength) {\n\t\t\tthrow new Error(\n\t\t\t\t`You can't use company name generator with a db column length restriction of ${this.stringLength}. Set the maximum string length to at least ${maxCompanyNameLength}.`,\n\t\t\t);\n\t\t}\n\n\t\tconst rng = prand.xoroshiro128plus(seed);\n\t\t// when count reach maxUniqueCompanyNameNumber template will be deleted from array\n\t\tconst templates = [","sourceCodeStart":2662,"sourceCodeEnd":2698,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-seed/src/services/Generators.ts#L2662-L2698","documentation":"GenerateUniqueCompanyName draws from a finite combinatorial space of last-name, suffix, and template permutations. The maximum unique names equals lastNames.length * companyNameSuffixes.length + lastNames.length^2 + lastNames.length^2 + lastNames.length^3. When the requested row count exceeds this ceiling there are simply not enough distinct names, so init() throws a RangeError.","triggerScenarios":"Setting a high count (e.g. 500000) on a table whose column has a unique constraint and is auto-assigned (or refined to) GenerateUniqueCompanyName, so that count > maxUniqueCompanyNameNumber.","commonSituations":"Seeding a large production-scale dataset where a unique company-name column is required but the count outgrows the built-in name dictionary; stress-test scripts that bump count without checking generator limits.","solutions":["Lower the table's count to at or below the maxUniqueCompanyNameNumber printed in the error.","Remove the unique constraint on the column if uniqueness is not truly required, which lets the non-unique GenerateCompanyName be used.","Switch the column to a generator with a larger combinatorial space, such as GenerateUniqueString."],"exampleFix":"// before\nawait seed(db, { schema }, { count: 500000 });\n// after\nawait seed(db, { schema }, { count: 10000 });","handlingStrategy":"validation","validationCode":"// The unique company-name space is finite. Check count before seeding.\n// maxUniqueCompanyNameNumber = L*S + L^2 + L^2 + L^3 (L=lastNames.length, S=suffixes.length)\n// Use a conservative cap; the error gives the exact number.\nconst SAFE_UNIQUE_COMPANY_NAME_CAP = 500_000; // adjust after reading the error's actual ceiling\nfunction countFitsUniqueCompanyNames(count: number): boolean {\n  return count <= SAFE_UNIQUE_COMPANY_NAME_CAP;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid very high counts on tables with unique company-name columns.","Prefer GenerateUniqueString for large-scale unique text seeding.","Run seed with a small count first to confirm the generator resolves, then scale up cautiously."],"tags":["unique","company-name","count-limit","range-error"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}