GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TML-3740: A MongoDB field with both @unique and @@index gets one unique index, and identical indexes in a collection merge instead of being refused by wmadden-electric · Pull Request #30894 · prisma/orm

TML-3740: A MongoDB field with both @unique and @@index gets one unique index, and identical indexes in a collection merge instead of being refused #30894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
wmadden-electric merged 23 commits into main from tml-3740-mongo-merge-covered-indexes
Oct 30, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

TML-3740: A MongoDB field with both @unique and @@index gets one unique index, and identical indexes in a collection merge instead of being refused #30894

Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
31aa97c
The MongoDB contract builder merges an index another index in its col…
wmadden-electric Oct 28, 2026
e9d781b
The parity suite emits the same merged indexes from TypeScript and PSL
wmadden-electric Oct 28, 2026
14b7528
Index merge tests cover a unique index on an earlier model and opposi…
wmadden-electric Oct 28, 2026
eee8372
A migration for @unique plus @@index on one MongoDB field creates one…
wmadden-electric Oct 28, 2026
165ab09
Docs say the MongoDB builder merges an index another index covers
wmadden-electric Oct 28, 2026
95c1a1a
An app upgrade note says MongoDB indexes another index covers are merged
wmadden-electric Oct 28, 2026
b34fd3f
The upgrade note says how to recover from a half-applied migration, a…
wmadden-electric Oct 28, 2026
0ecada1
Merge remote-tracking branch 'origin/main' into tml-3740-mongo-merge-…
wmadden-electric Oct 28, 2026
e1fd551
The MongoDB builder, planner and verifier identify an index by one fu…
wmadden-electric Oct 28, 2026
f480dd9
Code, docs and the upgrade note call merged MongoDB indexes identical…
wmadden-electric Oct 28, 2026
bb10462
The upgrade note covers a migration that created its collection, Pris…
wmadden-electric Oct 28, 2026
ffe9ece
An extension upgrade note says the indexDuplicate refusal kind is gone
wmadden-electric Oct 28, 2026
4d874fd
Both detection tests for the redundant-index note live in detection.t…
wmadden-electric Oct 28, 2026
7eda401
The extension upgrade note says the index identity names moved from s…
wmadden-electric Oct 28, 2026
e203049
The upgrade note quotes the db update error, says db verify only warn…
wmadden-electric Oct 28, 2026
cf17ea1
indexLookupKey encodes keys and options so no field name or option va…
wmadden-electric Oct 28, 2026
b6e1ce2
db verify pairs a live index with its contract index by an unambiguou…
wmadden-electric Oct 28, 2026
0796e32
Merge remote-tracking branch 'origin/main' into tml-3740-mongo-merge-…
wmadden-electric Oct 29, 2026
638c806
Merge branch 'main' of https://github.com/prisma/prisma into tml-3740…
wmadden-electric Oct 29, 2026
5d2f561
The upgrade note says how to keep data in a collection that must be d…
wmadden-electric Oct 29, 2026
6d9f5c0
The upgrade note resolves duplicate values before the restore, so no …
wmadden-electric Oct 29, 2026
9c56a04
Merge remote-tracking branch 'origin/main' into tml-3740-mongo-merge-…
wmadden-electric Oct 30, 2026
f47de80
Drop the Prisma 6 upgrade step: Prisma 6 never creates two indexes on…
wmadden-electric Oct 30, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

2 changes: 1 addition & 1 deletion 2 ...ure docs/adrs/ADR 306 - One plain-data definition and one builder per family.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The builder checks the assembled contract last. Those refusals (kind `validator`
- One rule, one implementation. A rule added to the builder applies to every source.
- A source can report every refusal at once, at its own position, because refusals are data, not thrown errors.
- Sources cannot differ in what they accept. A parity suite writes each case in TypeScript and in PSL and checks that the two emitted `contract.json` files are byte-identical.
- Index order is the source's own. The builder does not reorder indexes, because the storage hash depends on their order.
- Index order is the source's own. The builder does not reorder indexes, because the storage hash depends on their order. When two indexes in one collection are identical, or one is a non-unique index made redundant by a unique index on the same keys and otherwise identical options, the builder removes one and keeps the survivor where it was written.

SQL does not follow this ADR fully yet. Its builder throws its first refusal, so SQL PSL places only the errors it catches and matches (TML-3730). SQL PSL also adds polymorphism to the contract after the builder runs, instead of carrying it in the definition (TML-2228).

Expand Down
2 changes: 1 addition & 1 deletion 2 docs/architecture docs/subsystems/10. MongoDB Family.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ The builder decides these behaviours the same way for every source:

| Behaviour | Every source |
| --- | --- |
| Two identical indexes in one collection, after variant scoping | Refused. The Prisma 6 reader first merges identical indexes, such as `@unique` and `@@unique` on one field, because the database holds one index for both |
| Identical or redundant indexes in one collection, after variant scoping | Merged into one. Two indexes are identical when they have the same keys and options, counting an option set to `false` as unset (`indexLookupKey`, which the planner also uses). A non-unique index is redundant beside a unique one that is otherwise identical. The unique one survives, else the first, and it keeps the position where it was written. `@unique` and `@@index` on one field give one unique index. The merge runs before the second text index is refused |
| `extensions` | The stack's extension packs |
| Roots | Explicit roots when the source gives them, else one per model with a collection, no owner and no base |
| A variant's collection | Its base's; another collection is refused |
Expand Down
2 changes: 1 addition & 1 deletion 2 docs/reference/error-reference.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ The contract module at the configured path loads but exposes neither a `default`

### CONTRACT.NAME_DUPLICATE

Two declarations claim the same name: duplicate namespace entries, model names, value objects, relations, tables (two models mapping to one table, two table nodes for one table, or duplicate table in a namespace), column mappings (two fields to one column, a field and a table node's column node for one column, or two column nodes for one column), stored names (two fields of one MongoDB model stored under one name with `.mongo({ field })`: `Model "<Model>" stores both "<a>" and "<b>" as "<name>".`, `kind: 'field'`), indexes, value-sets (enum and pack entity minting the same value-set), or pack entities of the same kind and name in one namespace. A Postgres extension is unique across the whole contract: one declared in two namespaces is refused while building a contract and again when a contract is read (`kind: 'extension'`, `namespaces`). Payload: `kind`, `name`, `namespaceId`, `tableName` (for a column), `first`, `second`. A MongoDB variant field stored under a name a field of its base is stored under, the discriminator included, is refused too (`reason: 'stored-name-shared-with-base'`, with `first` the base's field and `second` the variant's): a variant's documents hold its base's fields, so the two would overwrite each other. Mongo PSL reports it as `PSL_DUPLICATE_STORED_NAME`.
Two declarations claim the same name: duplicate namespace entries, model names, value objects, relations, tables (two models mapping to one table, two table nodes for one table, or duplicate table in a namespace), column mappings (two fields to one column, a field and a table node's column node for one column, or two column nodes for one column), stored names (two fields of one MongoDB model stored under one name with `.mongo({ field })`: `Model "<Model>" stores both "<a>" and "<b>" as "<name>".`, `kind: 'field'`), value-sets (enum and pack entity minting the same value-set), or pack entities of the same kind and name in one namespace. A Postgres extension is unique across the whole contract: one declared in two namespaces is refused while building a contract and again when a contract is read (`kind: 'extension'`, `namespaces`). Payload: `kind`, `name`, `namespaceId`, `tableName` (for a column), `first`, `second`. A MongoDB variant field stored under a name a field of its base is stored under, the discriminator included, is refused too (`reason: 'stored-name-shared-with-base'`, with `first` the base's field and `second` the variant's): a variant's documents hold its base's fields, so the two would overwrite each other. Mongo PSL reports it as `PSL_DUPLICATE_STORED_NAME`.

### CONTRACT.NAMESPACE_INVALID

Expand Down
1 change: 1 addition & 0 deletions 1 packages/2-mongo-family/1-foundation/mongo-contract/README.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Contract types and validation for the MongoDB family.
- **Contract types**: `MongoContract`, `MongoContractWithTypeMaps`, `MongoTypeMaps`, `MongoStorageShape` (raw-JSON storage shape) — the typed contract representation for MongoDB targets
- **Storage IR**: `MongoStorage` — the in-memory storage class instantiated by the per-target contract serializer; structurally satisfies `MongoStorageShape` and additionally carries the `namespaces` map
- **Type-level extraction**: `ExtractMongoTypeMaps`, `ExtractMongoCodecTypes`, `InferModelRow` — utility types for deriving codec types and row shapes from a contract
- **Index identity**: `MONGO_INDEX_OPTION_KEYS` lists every index option; the compiler rejects the list when an option of `MongoIndexInput` is missing. `indexLookupKey()` turns an index into a string from its keys and those options, with an option set to `false` counting as unset; `canonicalize()` writes option values with sorted keys. Two indexes are the same when their lookup keys are equal. The contract builder merges indexes, and the planner and the verifier match indexes, by this one function.
- **Structural schema + storage validation primitives**: `MongoContractSchema` (arktype envelope) and `validateMongoStorage()` — consumed by the family `ContractSerializerBase` to validate Mongo contracts at the deserializer seam. No freestanding `validateMongoContract` wrapper is exported; callers cross the seam via `familyInstance.deserializeContract(...)`.
0 ...oling/mongo-schema-ir/src/canonicalize.ts → ...dation/mongo-contract/src/canonicalize.ts
Show comments
View file
Open in desktop
File renamed without changes.
3 changes: 3 additions & 0 deletions 3 packages/2-mongo-family/1-foundation/mongo-contract/src/exports/index.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type {
} from '@internal/framework-components/runtime';
export { RelationKeys } from '@internal/framework-components/runtime';
export { buildMongoStorage } from '../build-mongo-storage';
export { canonicalize } from '../canonicalize';
export type { CollectionControlPolicies } from '../collection-control-policies';
export {
collectionControlPoliciesOf,
Expand Down Expand Up @@ -66,6 +67,8 @@ export type { FieldValueSets } from '../derive-json-schema';
export { documentIdRefusalReason } from '../document-id-refusal';
export type { FieldBsonTypeRefusal } from '../field-bson-type-refusal';
export { fieldBsonTypeRefusalOf } from '../field-bson-type-refusal';
export type { MongoIndexLookupInput, MongoIndexOptionKey } from '../index-lookup-key';
export { indexLookupKey, MONGO_INDEX_OPTION_KEYS } from '../index-lookup-key';
export { buildMongoNamespace } from '../ir/build-mongo-namespace';
export type { MongoChangeStreamPreAndPostImagesOptionsInput } from '../ir/mongo-change-stream-pre-and-post-images-options';
export { MongoChangeStreamPreAndPostImagesOptions } from '../ir/mongo-change-stream-pre-and-post-images-options';
Expand Down
47 changes: 47 additions & 0 deletions 47 packages/2-mongo-family/1-foundation/mongo-contract/src/index-lookup-key.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { canonicalize } from './canonicalize';
import type { MongoIndexKey } from './contract-types';
import type { MongoIndexInput } from './ir/mongo-index';

/**
* Returns a function that accepts a list of options only when it names every member of `Option`;
* a list missing one fails to compile, naming the missing option.
*/
export function listsEveryOption<Option extends string>() {
return <const T extends readonly Option[]>(
options: T &
([Exclude<Option, T[number]>] extends [never]
? unknown
: { readonly unlistedOption: Exclude<Option, T[number]> }),
): T => options;
}

/** The index options that tell two indexes on the same keys apart: every option of an index. */
export const MONGO_INDEX_OPTION_KEYS = listsEveryOption<Exclude<keyof MongoIndexInput, 'keys'>>()([
'unique',
'sparse',
'expireAfterSeconds',
'partialFilterExpression',
'wildcardProjection',
'collation',
'weights',
'default_language',
'language_override',
] as const);

export type MongoIndexOptionKey = (typeof MONGO_INDEX_OPTION_KEYS)[number];

/** An index as `indexLookupKey` reads it: the contract's `MongoIndex` and the schema IR's index both fit. */
export type MongoIndexLookupInput = { readonly keys: ReadonlyArray<MongoIndexKey> } & {
readonly [Option in MongoIndexOptionKey]?: MongoIndexInput[Option] | undefined;
};

/** Identifies an index by its keys and the options it sets; an option set to `false` counts as unset. No field name or option value can make two different indexes share a key. */
export function indexLookupKey(index: MongoIndexLookupInput): string {
const options = Object.fromEntries(
MONGO_INDEX_OPTION_KEYS.flatMap((option) => {
const value = index[option];
return value === undefined || value === null || value === false ? [] : [[option, value]];
}),
);
return canonicalize({ keys: index.keys.map((k) => [k.field, k.direction]), options });
}
38 changes: 38 additions & 0 deletions 38 packages/2-mongo-family/1-foundation/mongo-contract/test/canonicalize.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, expect, it } from 'vitest';
import { canonicalize } from '../src/canonicalize';

describe('canonicalize', () => {
it('produces same string for objects with different key order', () => {
expect(canonicalize({ b: 1, a: 2 })).toBe(canonicalize({ a: 2, b: 1 }));
});

it('handles nested objects with different key order', () => {
expect(canonicalize({ outer: { b: 1, a: 2 } })).toBe(canonicalize({ outer: { a: 2, b: 1 } }));
});

it('preserves array order', () => {
expect(canonicalize([1, 2, 3])).not.toBe(canonicalize([3, 2, 1]));
});

it('handles primitives', () => {
expect(canonicalize(42)).toBe('42');
expect(canonicalize('hello')).toBe('"hello"');
expect(canonicalize(true)).toBe('true');
});

it('handles null and undefined', () => {
expect(canonicalize(null)).toBe('null');
expect(canonicalize(undefined)).toBe('undefined');
});

it('handles empty objects and arrays', () => {
expect(canonicalize({})).toBe('{}');
expect(canonicalize([])).toBe('[]');
});

it('produces deterministic output for complex nested structures', () => {
const a = { z: [1, { y: 2, x: 3 }], a: { c: 1, b: 2 } };
const b = { a: { b: 2, c: 1 }, z: [1, { x: 3, y: 2 }] };
expect(canonicalize(a)).toBe(canonicalize(b));
});
});
6 changes: 3 additions & 3 deletions 6 ...go-schema-ir/test/index-options.test-d.ts → ...-contract/test/index-lookup-key.test-d.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expectTypeOf, test } from 'vitest';
import { listsEveryOption, MONGO_INDEX_OPTION_KEYS } from '../src/index-equivalence';
import type { MongoSchemaIndexOptions } from '../src/schema-index';
import { listsEveryOption, MONGO_INDEX_OPTION_KEYS } from '../src/index-lookup-key';
import type { MongoIndexInput } from '../src/ir/mongo-index';

type IndexOptionName = Exclude<keyof MongoSchemaIndexOptions, 'keys'>;
type IndexOptionName = Exclude<keyof MongoIndexInput, 'keys'>;

describe('listsEveryOption', () => {
test('accepts the list of every index option', () => {
Expand Down
69 changes: 69 additions & 0 deletions 69 packages/2-mongo-family/1-foundation/mongo-contract/test/index-lookup-key.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { describe, expect, expectTypeOf, it } from 'vitest';
import {
indexLookupKey,
MONGO_INDEX_OPTION_KEYS,
type MongoIndexOptionKey,
} from '../src/index-lookup-key';
import { MongoIndex, type MongoIndexInput } from '../src/ir/mongo-index';

const keys = [{ field: 'email', direction: 1 as const }];

describe('MONGO_INDEX_OPTION_KEYS', () => {
it('lists every index option', () => {
expectTypeOf<MongoIndexOptionKey>().toEqualTypeOf<Exclude<keyof MongoIndexInput, 'keys'>>();
expect(MONGO_INDEX_OPTION_KEYS).toHaveLength(9);
});
});

describe('indexLookupKey', () => {
const lookupKey = (options: Omit<MongoIndexInput, 'keys'>) =>
indexLookupKey(new MongoIndex({ keys, ...options }));

it('tells apart indexes that differ in any option, and ignores options set to false', () => {
expect({
plain: lookupKey({}),
notSparse: lookupKey({ sparse: false }),
reordered:
lookupKey({ collation: { locale: 'en', strength: 2 } }) ===
lookupKey({ collation: { strength: 2, locale: 'en' } }),
distinct: new Set(
[
{},
{ unique: true },
{ sparse: true },
{ expireAfterSeconds: 0 },
{ partialFilterExpression: { a: 1 } },
{ wildcardProjection: { a: 1 as const } },
{ collation: { locale: 'en' } },
{ weights: { a: 2 } },
{ default_language: 'french' },
{ language_override: 'lang' },
].map(lookupKey),
).size,
}).toEqual({ plain: lookupKey({}), notSparse: lookupKey({}), reordered: true, distinct: 10 });
});

it('gives unique set to false, sparse set to false and no options the same key, and a set option another', () => {
const unset = lookupKey({});
expect({
notUnique: lookupKey({ unique: false }) === unset,
notSparse: lookupKey({ sparse: false }) === unset,
sparse: lookupKey({ sparse: true }) === unset,
collation: lookupKey({ collation: { locale: 'fr' } }) === unset,
}).toEqual({ notUnique: true, notSparse: true, sparse: false, collation: false });
});

it.each([
['a comma and a colon', [{ field: 'a:1,b', direction: 1 as const }]],
['a pipe', [{ field: 'a:1|expireAfterSeconds', direction: 1 as const }]],
['a semicolon', [{ field: 'a:1|sparse:true;expireAfterSeconds', direction: 1 as const }]],
])('tells apart a stored field name with %s from the indexes its text spells', (_, oddKeys) => {
const a = [{ field: 'a', direction: 1 as const }];
const spelled = [
indexLookupKey(new MongoIndex({ keys: [...a, { field: 'b', direction: 1 }] })),
indexLookupKey(new MongoIndex({ keys: a, expireAfterSeconds: 1 })),
indexLookupKey(new MongoIndex({ keys: a, sparse: true, expireAfterSeconds: 1 })),
];
expect(spelled).not.toContain(indexLookupKey(new MongoIndex({ keys: oddKeys })));
});
});
19 changes: 2 additions & 17 deletions 19 packages/2-mongo-family/2-authoring/contract-prisma6/src/interpreter.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,9 @@ export function interpretPrisma6Documents(

const modelNodes: ModelNode[] = [];
const sites: Prisma6Sites = { fields: new Map(), indexes: new Map(), enums: enumSites };
const indexesByCollection = new Map<string, Set<string>>();
for (const [modelName, build] of builds) {
const { sourceId } = build.located;
const collectionIndexes = indexesByCollection.get(build.collection) ?? new Set<string>();
indexesByCollection.set(build.collection, collectionIndexes);
const indexes = buildIndexes(build, collectionIndexes, diagnostics);
const indexes = buildIndexes(build, diagnostics);
sites.indexes.set(modelName, indexes);
for (const fieldName of Object.keys(build.fields)) {
const symbol = build.located.symbol.fields[fieldName];
Expand Down Expand Up @@ -1490,12 +1487,9 @@ function readRelationFields(
}
}

/**
* A model's indexes as the builder takes them, with where each is written. An index that its collection already holds, such as `@unique` and `@@unique` on one field, is left out: the database holds one index for both.
*/
/** A model's indexes as the builder takes them, with where each is written. */
function buildIndexes(
build: ModelBuild,
collectionIndexes: Set<string>,
diagnostics: Diagnostics,
): (IndexSite & { readonly index: IndexNode })[] {
const { symbol, sourceId } = build.located;
Expand Down Expand Up @@ -1541,15 +1535,6 @@ function buildIndexes(
),
...(attribute.kind === 'unique' ? { options: { unique: true } } : {}),
};
const signature = JSON.stringify([
attribute.fields.map((field) => [
build.storedNames.get(field.name),
field.direction ?? (text ? 'text' : 1),
]),
attribute.kind === 'unique',
]);
if (collectionIndexes.has(signature)) continue;
collectionIndexes.add(signature);
indexes.push({ index, sourceId, span: attribute.span });
}
return indexes;
Expand Down
20 changes: 20 additions & 0 deletions 20 ...mily/2-authoring/contract-prisma6/test/builder-cases/fulltext-on-two-models/schema.prisma
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}

model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String

@@fulltext([name])
@@map("people")
}

model Admin {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String

@@fulltext([name])
@@map("people")
}
11 changes: 11 additions & 0 deletions 11 ...ngo-family/2-authoring/contract-prisma6/test/builder-cases/unique-and-index/schema.prisma
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}

model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique

@@index([email])
}
21 changes: 21 additions & 0 deletions 21 ...amily/2-authoring/contract-prisma6/test/builder-cases/unique-on-later-model/schema.prisma
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}

model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String
name String

@@index([email])
@@index([name])
@@map("people")
}

model Admin {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique

@@map("people")
}
43 changes: 36 additions & 7 deletions 43 packages/2-mongo-family/2-authoring/contract-prisma6/test/builder.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,48 @@ import { loadPrisma6Schema, serializeMongoContract } from './support';
const casesDir = join(dirname(fileURLToPath(import.meta.url)), 'builder-cases');

describe('the Prisma 6 reader on the contract builder', () => {
it('keeps one index for @unique and @@unique on one field, as the database holds one', async () => {
const result = await loadPrisma6Schema(join(casesDir, 'unique-twice', 'schema.prisma'));
it.each<[string, string, string, readonly unknown[]]>([
[
'@unique and @@unique on one field',
'unique-twice',
'User',
[{ kind: 'mongo-index', keys: [{ field: 'email', direction: 1 }], unique: true }],
],
[
'@unique and @@index on one field',
'unique-and-index',
'User',
[{ kind: 'mongo-index', keys: [{ field: 'email', direction: 1 }], unique: true }],
],
[
'@@fulltext on one field of two models in one collection',
'fulltext-on-two-models',
'people',
[{ kind: 'mongo-index', keys: [{ field: 'name', direction: 'text' }] }],
],
[
"@unique on a later model and @@index on an earlier model's field in one collection",
'unique-on-later-model',
'people',
[
{ kind: 'mongo-index', keys: [{ field: 'name', direction: 1 }] },
{ kind: 'mongo-index', keys: [{ field: 'email', direction: 1 }], unique: true },
],
],
])('merges an identical or redundant index for %s', async (_, caseName, collection, indexes) => {
const result = await loadPrisma6Schema(join(casesDir, caseName, 'schema.prisma'));
if (!result.ok) throw new Error(JSON.stringify(result.failure.diagnostics));
const serialized = serializeMongoContract(result.value) as {
storage: {
namespaces: { __unbound__: { entries: { collection: Record<string, unknown> } } };
namespaces: {
__unbound__: { entries: { collection: Record<string, { indexes?: unknown }> } };
};
};
};

expect(serialized.storage.namespaces.__unbound__.entries.collection['User']).toEqual({
kind: 'mongo-collection',
indexes: [{ kind: 'mongo-index', keys: [{ field: 'email', direction: 1 }], unique: true }],
});
expect(
serialized.storage.namespaces.__unbound__.entries.collection[collection]?.indexes,
).toEqual(indexes);
});

it('reports a builder refusal where the schema writes its subject', async () => {
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.