ididit
ididit
Explore posts from servers
PPrisma
Created by ididit on 2/4/2025 in #help-and-questions
creating a BM25 index
I have created a BM25 index by creating a migration file to create it and also added the schema to ignore the index.
model Post {
id Int @id @default(autoincrement())
name String?
/// @ignored
/// @schema-ignored-index(post_bm25_idx)
@@index(fields: [id, name], map: "post_bm25_idx")
}
model Post {
id Int @id @default(autoincrement())
name String?
/// @ignored
/// @schema-ignored-index(post_bm25_idx)
@@index(fields: [id, name], map: "post_bm25_idx")
}
and here is the custom migration file i created to run:
-- CreateIndex
-- prisma-ignore-index
CREATE INDEX post_bm25_idx ON "Post"
USING bm25 (id, name)
WITH (
key_field='id',
text_fields='{
"name": {"fast": true}
}'
);
-- CreateIndex
-- prisma-ignore-index
CREATE INDEX post_bm25_idx ON "Post"
USING bm25 (id, name)
WITH (
key_field='id',
text_fields='{
"name": {"fast": true}
}'
);
but the next time i run a migration or try to create a new one, it hangs with a message like:
prisma:schemaEngine:stderr {"timestamp":"2025-02-04T01:31:58.231558Z","level":"WARN","fields":{"message":"Unknown index algorithm on post_bm25_idx: bm25"},"target":"sql_schema_describer::postgres","span":{"namespaces":"None","name":"describe_schema"},"spans":[{"name":"DevDiagnostic"},{"namespaces":"None","name":"describe_schema"}]} +0ms
prisma:schemaEngine:stderr {"timestamp":"2025-02-04T01:31:58.231558Z","level":"WARN","fields":{"message":"Unknown index algorithm on post_bm25_idx: bm25"},"target":"sql_schema_describer::postgres","span":{"namespaces":"None","name":"describe_schema"},"spans":[{"name":"DevDiagnostic"},{"namespaces":"None","name":"describe_schema"}]} +0ms
this is blocking me from running or creating new migration file and the database is in a limbo. please help!
7 replies
TtRPC
Created by ididit on 9/1/2024 in #❓-help
how can i create a router off of a JSON?
is it possible to create a route dynamically off of a JSON? lets say i have:
appRouter = this.trpc.router({
findUser: this.trpc.procedure
.input(z.object({ name: z.string().optional() }))
.query(({ input }) => {
return this.userService.findUser({ name: input.name });
}),
findUsers: this.trpc.procedure
.query(({ input }) => {
return this.userService.findUsers();
}),
});
appRouter = this.trpc.router({
findUser: this.trpc.procedure
.input(z.object({ name: z.string().optional() }))
.query(({ input }) => {
return this.userService.findUser({ name: input.name });
}),
findUsers: this.trpc.procedure
.query(({ input }) => {
return this.userService.findUsers();
}),
});
but i want this created dynamically from a JSON that looks something like this:
const routes = [
{
name: 'fetchUsers',
input: { name: z.string() },
type: 'query',
},
{
name: 'createUser',
input: { name: z.string() },
type: 'mutation',
},
];
... convert routes to procedures ...
this.appRouter = this.router(procedures);
const routes = [
{
name: 'fetchUsers',
input: { name: z.string() },
type: 'query',
},
{
name: 'createUser',
input: { name: z.string() },
type: 'mutation',
},
];
... convert routes to procedures ...
this.appRouter = this.router(procedures);
afterwards i applied the routes to the middleware and it works on backend:
public async applyMiddleware(app: any) {
app.use(
'/trpc',
trpcExpress.createExpressMiddleware({
router: this.appRouter,
}),
);
}
public async applyMiddleware(app: any) {
app.use(
'/trpc',
trpcExpress.createExpressMiddleware({
router: this.appRouter,
}),
);
}
but from the client-side, i lost all type inference to these routes. anyone ever get this to work?
2 replies