feat(plugin/timestamps): add indexStrategy option for entity indexing
Introduced a new `indexStrategy` option in the timestamps plugin to configure index generation for `created_at` and `updated_at` fields. Supports "composite" and "individual" strategies for better control over database indexing. Added test coverage for different index strategies.
This commit is contained in:
@@ -71,4 +71,54 @@ describe("timestamps plugin", () => {
|
||||
expect(updatedData.updated_at).toBeDefined();
|
||||
expect(updatedData.updated_at).toBeInstanceOf(Date);
|
||||
});
|
||||
|
||||
test("index strategy", async () => {
|
||||
const app = createApp({
|
||||
config: {
|
||||
data: em({
|
||||
posts: entity("posts", {
|
||||
title: text(),
|
||||
}),
|
||||
}).toJSON(),
|
||||
},
|
||||
options: {
|
||||
plugins: [timestamps({ entities: ["posts"] })],
|
||||
},
|
||||
});
|
||||
await app.build();
|
||||
expect(app.em.indices.length).toBe(0);
|
||||
{
|
||||
const app = createApp({
|
||||
config: {
|
||||
data: em({
|
||||
posts: entity("posts", {
|
||||
title: text(),
|
||||
}),
|
||||
}).toJSON(),
|
||||
},
|
||||
options: {
|
||||
plugins: [timestamps({ entities: ["posts"], indexStrategy: "composite" })],
|
||||
},
|
||||
});
|
||||
await app.build();
|
||||
expect(app.em.indices.length).toBe(1);
|
||||
}
|
||||
|
||||
{
|
||||
const app = createApp({
|
||||
config: {
|
||||
data: em({
|
||||
posts: entity("posts", {
|
||||
title: text(),
|
||||
}),
|
||||
}).toJSON(),
|
||||
},
|
||||
options: {
|
||||
plugins: [timestamps({ entities: ["posts"], indexStrategy: "individual" })],
|
||||
},
|
||||
});
|
||||
await app.build();
|
||||
expect(app.em.indices.length).toBe(2);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user