{"id":"15e58d2dab363053","repo":"drizzle-team/drizzle-orm","slug":"count-exceeds-max-number-of-unique-intervals-max-15e58d","errorCode":null,"errorMessage":"count exceeds max number of unique intervals(${maxUniqueIntervalsNumber})","messagePattern":"count exceeds max number of unique intervals\\((.+?)\\)","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"drizzle-seed/src/services/versioning/v2.ts","lineNumber":78,"sourceCode":"\t\tlet fieldsToGenerate: string[] = allFields;\n\n\t\tif (this.params.fields !== undefined && this.params.fields?.includes(' to ')) {\n\t\t\tconst tokens = this.params.fields.split(' to ');\n\t\t\tconst endIdx = allFields.indexOf(tokens[1]!);\n\t\t\tfieldsToGenerate = allFields.slice(0, endIdx + 1);\n\t\t} else if (this.params.fields !== undefined) {\n\t\t\tconst endIdx = allFields.indexOf(this.params.fields);\n\t\t\tfieldsToGenerate = allFields.slice(0, endIdx + 1);\n\t\t}\n\n\t\tlet maxUniqueIntervalsNumber = 1;\n\t\tfor (const field of fieldsToGenerate) {\n\t\t\tconst from = this.config[field]!.from, to = this.config[field]!.to;\n\t\t\tmaxUniqueIntervalsNumber *= from - to + 1;\n\t\t}\n\n\t\tif (count > maxUniqueIntervalsNumber) {\n\t\t\tthrow new RangeError(`count exceeds max number of unique intervals(${maxUniqueIntervalsNumber})`);\n\t\t}\n\n\t\tconst rng = prand.xoroshiro128plus(seed);\n\t\tconst intervalSet = new Set<string>();\n\t\tthis.state = { rng, fieldsToGenerate, intervalSet };\n\t}\n\n\tgenerate() {\n\t\tif (this.state === undefined) {\n\t\t\tthrow new Error('state is not defined.');\n\t\t}\n\n\t\tlet interval, numb: number;\n\n\t\tfor (;;) {\n\t\t\tinterval = '';\n\n\t\t\tfor (const field of this.state.fieldsToGenerate) {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-seed/src/services/versioning/v2.ts#L60-L96","documentation":"GenerateIntervalV2 (the unique interval generator) computes the total number of distinct date/time intervals from the product of each field's range (from-to+1) across the selected fields. If the requested count exceeds this product, there are not enough unique interval combinations and init() throws a RangeError.","triggerScenarios":"Requesting a high count on a unique interval column while restricting the fields param to a narrow range (e.g. only 'minute' gives 60 unique values).","commonSituations":"Seeding a large number of rows with unique interval values; limiting the fields param to a small subset (e.g. 'second' only) which caps the combinatorial space at 60.","solutions":["Reduce count to at or below the maxUniqueIntervalsNumber printed in the error.","Expand the fields param to include more date/time components (e.g. 'year to second') to increase the combinatorial space.","Remove the unique constraint if uniqueness is not required."],"exampleFix":"// before — count 100 but only 'minute' field (max 60 unique)\nrefinements = { myTable: { columns: { interval: { generator: generators.interval({ fields: 'minute', isUnique: true }) } } } };\nawait seed(db, { schema }, { count: 100 });\n// after — expand fields or reduce count\nfields: 'year to minute',  // vastly larger space\n// or count: 50","handlingStrategy":"validation","validationCode":"// Estimate max unique intervals from field ranges before seeding.\n// config: year(1970-2030=61) * month(12) * day(31) * hour(24) * minute(60) * second(60)\nconst FIELD_RANGES: Record<string, number> = { year: 61, month: 12, day: 31, hour: 24, minute: 60, second: 60 };\nfunction maxUniqueIntervals(fields: string[]): number {\n  return fields.reduce((acc, f) => acc * (FIELD_RANGES[f] ?? 1), 1);\n}\n// fields 'year to second' => ['year','month','day','hour','minute','second']\nfunction parseFields(param: string): string[] {\n  const all = ['year','month','day','hour','minute','second'];\n  if (param.includes(' to ')) {\n    const tokens = param.split(' to ');\n    return all.slice(0, all.indexOf(tokens[1]!) + 1);\n  }\n  return all.slice(0, all.indexOf(param) + 1);\n}\n// Usage: if (count > maxUniqueIntervals(parseFields(fields))) reduce count or expand fields.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a broad fields range ('year to second') for high-count unique interval seeding.","Keep count within the combinatorial space of the selected fields.","Drop the unique constraint if interval uniqueness is not essential."],"tags":["unique","interval","count-limit","range-error","v2"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}