Michael Schaufelberger
Michael Schaufelberger
Explore posts from servers
XXata
Created by Michael Schaufelberger on 1/24/2025 in #help
Drizzle pull/push: Permission denied for view pg_stat_user_indexes
Hi 👋 Sorry to bother you again. Quick question: After a long while I'm using the drizzle commands again and now I'm receiving the following error:
XATA_BRANCH test-template2
Pulling from ['public'] list of schemas

Using 'pg' driver for database querying
[✓] 15 tables fetched
[⣻] 207 columns fetching
[✓] 0 enums fetched
[⣻] 0 indexes fetching
[⣻] 0 foreign keys fetching
[✓] 0 policies fetched
[⣻] 0 check constraints fetching
[⣻] 0 views fetching
error: permission denied for view pg_stat_user_indexes
at /home/michael/repos/monorepo/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:45:11
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Object.query (/home/michael/repos/monorepo/node_modules/.pnpm/[email protected][email protected]_@[email protected]_@[email protected]_@t_4xfdxdbonwo2l5u4y5cl47zhfu/node_modules/drizzle-kit/bin.cjs:78762:26)
at async <anonymous> (/home/michael/repos/monorepo/node_modules/.pnpm/[email protected][email protected]_@[email protected]_@[email protected]_@t_4xfdxdbonwo2l5u4y5cl47zhfu/node_modules/drizzle-kit/bin.cjs:37743:43) {
length: 107,
severity: 'ERROR',
code: '42501',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'aclchk.c',
line: '3770',
routine: 'aclcheck_error'
}
XATA_BRANCH test-template2
Pulling from ['public'] list of schemas

Using 'pg' driver for database querying
[✓] 15 tables fetched
[⣻] 207 columns fetching
[✓] 0 enums fetched
[⣻] 0 indexes fetching
[⣻] 0 foreign keys fetching
[✓] 0 policies fetched
[⣻] 0 check constraints fetching
[⣻] 0 views fetching
error: permission denied for view pg_stat_user_indexes
at /home/michael/repos/monorepo/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:45:11
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Object.query (/home/michael/repos/monorepo/node_modules/.pnpm/[email protected][email protected]_@[email protected]_@[email protected]_@t_4xfdxdbonwo2l5u4y5cl47zhfu/node_modules/drizzle-kit/bin.cjs:78762:26)
at async <anonymous> (/home/michael/repos/monorepo/node_modules/.pnpm/[email protected][email protected]_@[email protected]_@[email protected]_@t_4xfdxdbonwo2l5u4y5cl47zhfu/node_modules/drizzle-kit/bin.cjs:37743:43) {
length: 107,
severity: 'ERROR',
code: '42501',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'aclchk.c',
line: '3770',
routine: 'aclcheck_error'
}
It seems like a Xata permission issue. But I'm not sure if the error is on drizzle's side.
4 replies
TtRPC
Created by Michael Schaufelberger on 1/17/2025 in #❓-help
How to make prefetching/RSC suspense work with auth?
Hi 👋 I'm using the rsc-rq-prefetch pattern in my project. It worked quite well - up until I added auth to my tRPC procedures. During SSR a server error gets thrown because the useSuspenseQuery request fails (there's no auth because SSR does not use the request's context/headers https://github.com/vercel/next.js/discussions/60640). I'm wondering if there's a workaround that allows prefetching on the server for auth-protected procedures. Am I missing something obvious? I've seen the rsc-links example... Maybe I could make use of this? There it seems the server can use the request headers in a procedure. But since it should be a prefetch (and if pending, should be streamed in later) I'm not sure how I can pass such a rsc-linked call to the client in a possible pending state.
2 replies
DTDrizzle Team
Created by Michael Schaufelberger on 1/17/2025 in #help
How can I skip columns I don't want to have generated?
I'm using drizzle-seed (btw, there's no tag yet in the Discord help space) and I don't want some columns generated (default). How can I specify this? Currently, the script fails with column with type xata_file is not supported for now. Even though the table that has a count > 0 has no such columns.
import { seed } from 'drizzle-seed';
import { db } from '..';
import * as schema from '../schema';

const main = async () => {
await seed(db, schema, {
count: 0,
}).refine((f) => ({
usersTbl: {
count: 1,
},
}));
};

main();
import { seed } from 'drizzle-seed';
import { db } from '..';
import * as schema from '../schema';

const main = async () => {
await seed(db, schema, {
count: 0,
}).refine((f) => ({
usersTbl: {
count: 1,
},
}));
};

main();
1 replies
XXata
Created by Michael Schaufelberger on 1/17/2025 in #help
Branch copy has old schema version
Hi 👋 I have an issue that a new branch does not include all columns of the base branch. Workspace ID: 5713tr New branch: test-template Base branch: dev test-template has previously existed, and I recreated it soon after deleting it. Could it be that it was restored instead of recreated? Edit: This is a postgres enabled database.
15 replies
TtRPC
Created by Michael Schaufelberger on 1/15/2025 in #❓-help
How do *you* structure the tRPC router when dealing with isolated components?
Hi 👋 I'm wondering how other people handle their tRPC router for cases where a component deep in the Next.js file tree (e.g. /[locale]/(dashboard)/categories/posts/comments/list-component/my-procedure.ts ) has a procedure. Everything inside the folder /[locale]/(dashboard)/categories/posts/comments/list-component is a single react component (tree). I.e. I don't share this component anywhere else. But it still has a query procedure to fetch the data we need for it. Now, since the component's usage is very local, it makes little sense to put it into some global list like the tRPC router, but we have to for tRPC to work. How do you structure the tRPC router to make sure such local components are well maintainable?
5 replies
XXata
Created by Michael Schaufelberger on 12/3/2024 in #help
Cannot install Xata CLI in Linux using the script or homebrew
No description
5 replies
TtRPC
Created by Michael Schaufelberger on 11/27/2024 in #❓-help
Hydration error when using useQuery instead of useSuspenseQuery when prefetching
I have a page
export const PostsPage = async ({ params }: PostsPageProps) => {
trpc.posts.getAll.prefetch({ userId: user.id });

return (
<HydrateClient>
<PostsTable userId={user.id} />
</HydrateClient>
);
};
export const PostsPage = async ({ params }: PostsPageProps) => {
trpc.posts.getAll.prefetch({ userId: user.id });

return (
<HydrateClient>
<PostsTable userId={user.id} />
</HydrateClient>
);
};
and a component
export const PostsTable = ({ userId }: PostsTableProps) => {
const { data: posts, isPending } = trpc.posts.getAll.useQuery({
userId,
});

const { table } = useDataTable({
data: posts ?? [],
});

return (
<DataTable table={table} isLoading={isPending}>
{ /* ... */ }
</DataTable>
);
};
export const PostsTable = ({ userId }: PostsTableProps) => {
const { data: posts, isPending } = trpc.posts.getAll.useQuery({
userId,
});

const { table } = useDataTable({
data: posts ?? [],
});

return (
<DataTable table={table} isLoading={isPending}>
{ /* ... */ }
</DataTable>
);
};
Where the DataTable has some logic like
return isLoading ? (
<TableRow className="hover:bg-transparent">
{table.getLeafHeaders().map((_, i) => (
<TableCell key={i}>
<Skeleton className="h-6 w-full" />
</TableCell>
))}
</TableRow>
) : (
<TableRow>
<TableCell
colSpan={table.getAllColumns().length}
className="h-24 text-center"
>
No results.
</TableCell>
</TableRow>
)}
return isLoading ? (
<TableRow className="hover:bg-transparent">
{table.getLeafHeaders().map((_, i) => (
<TableCell key={i}>
<Skeleton className="h-6 w-full" />
</TableCell>
))}
</TableRow>
) : (
<TableRow>
<TableCell
colSpan={table.getAllColumns().length}
className="h-24 text-center"
>
No results.
</TableCell>
</TableRow>
)}
Using a useQuery in the PostsTable component results in a Hydration error. Can I prevent this without having to use Suspense? I found using the isPending flag to be a way simpler solution to rendering the skeleton in a deeply nested component.
2 replies
XXata
Created by Michael Schaufelberger on 11/22/2024 in #help
Xata Dashboard error when trying to delete a file
Hi 👋 I remember this working a few months ago, but now I'm getting an error whenever I try to update a record in the Dashboard that has a file. The error message:
Error updating record
invalid SQL: cannot update file and array type directly, use Xata API instead
Error updating record
invalid SQL: cannot update file and array type directly, use Xata API instead
Is this a bug or am I doing something wrong?
17 replies
XXata
Created by Michael Schaufelberger on 11/19/2024 in #help
How can I get data from a different table when adding a column? - Multi Schema Migrations
Hi 👋 Say I want to store a user's full name inside a post. For this, I would add a column to the posts table userFullName using pgroll:
[
{
"add_column": {
"table": "posts",
"column": {
"name": "userFullName",
"type": "text",
"nullable": false
},
"up": "select \"fullName\" from users where users.id = ???"
}
}
]
[
{
"add_column": {
"table": "posts",
"column": {
"name": "userFullName",
"type": "text",
"nullable": false
},
"up": "select \"fullName\" from users where users.id = ???"
}
}
]
How can I make sure pgroll fills the new column with the data of the user? Can I do something like this?
select "fullName" from users where users.id = "userId"
-- meaning, match the user with the post's foreign key userId
select "fullName" from users where users.id = "userId"
-- meaning, match the user with the post's foreign key userId
Edit: I'm getting an error if I try this: unable to execute start operation: failed to create trigger: pq: syntax error at or near "SELECT"
8 replies
XXata
Created by Michael Schaufelberger on 11/4/2024 in #help
FetcherError: Internal Error
Hi 👋 When trying to write to our non-postgres DB, we are currently getting the cryptic error:
FetcherError: Internal Error (Request ID: f347ce16-76ee-945f-81df-51cf8d1f6e59)

{
status: 500,
errors: [
{
message: 'Internal Error (Request ID: f347ce16-76ee-945f-81df-51cf8d1f6e59)',
status: 500
}
],
requestId: 'f347ce16-76ee-945f-81df-51cf8d1f6e59',
cause: undefined
}
FetcherError: Internal Error (Request ID: f347ce16-76ee-945f-81df-51cf8d1f6e59)

{
status: 500,
errors: [
{
message: 'Internal Error (Request ID: f347ce16-76ee-945f-81df-51cf8d1f6e59)',
status: 500
}
],
requestId: 'f347ce16-76ee-945f-81df-51cf8d1f6e59',
cause: undefined
}
How can we identify the cause? We currently cannot write to the database anymore (Edit: for some requests, some others still seem to work).
20 replies
XXata
Created by Michael Schaufelberger on 9/3/2024 in #help
What is good practice with Xata's (Multi-version Schema) Migrations?
For now, we have used mainly Drizzle Kit for our migration needs. However, we are at a point where we would like to use Xata's Multi-Version schema feature. What's a good workflow that allows for good DX and safe migrations? With "normal" Xata migrations, every single schema change is a migration and results in its own file. This is suboptimal DX since during development you may have to add a field, rename it and delete it again until you have found the best schema for a feature and have many files in the end that are difficult to review. Do you have any experience/recommendations on how we could handle the experimentation vs. migration phase? Multi-version Schemas have a lifecycle. Is this something we can use to solve this problem? I need to be honest that I don't know how other tools handle it.
4 replies
XXata
Created by Michael Schaufelberger on 8/30/2024 in #help
When are connections to the cluster available during the moving of a branch?
For several minutes the branches are moving to a newly provisioned cluster. When are new connections to the branch made to the cluster?
50 replies
DTDrizzle Team
Created by Michael Schaufelberger on 8/29/2024 in #help
How can I create a `nulls not distinct` index in Postgres 15 for `push`?
Hi 👋 I'm having trouble to create such an index. This
(table) => ({
uniqueIdx: unique("mytable_uniq_idx_composite").on(table.foo, table.bar).nullsNotDistinct(),
}),
(table) => ({
uniqueIdx: unique("mytable_uniq_idx_composite").on(table.foo, table.bar).nullsNotDistinct(),
}),
somehow does not create an index that has the nulls not distinct constraint. Whereas a query like this would work.
(table) => ({
uniqueIdx: uniqueIndex('mytable_uniq_idx_composite')
.on(table.foo, table.bar)
.where(sql`NULLS NOT DISTINCT`),
}),
(table) => ({
uniqueIdx: uniqueIndex('mytable_uniq_idx_composite')
.on(table.foo, table.bar)
.where(sql`NULLS NOT DISTINCT`),
}),
However, there's a WHERE clause that breaks it.
CREATE UNIQUE INDEX IF NOT EXISTS "mytable_uniq_idx_composite" ON "mytable" USING btree ("foo","bar") WHERE NULLS NOT DISTINCT;
CREATE UNIQUE INDEX IF NOT EXISTS "mytable_uniq_idx_composite" ON "mytable" USING btree ("foo","bar") WHERE NULLS NOT DISTINCT;
2 replies
TtRPC
Created by Michael Schaufelberger on 7/25/2024 in #❓-help
Is there a way to call procedures more directly without a router?
I read the blog post about server actions and wondered if there's a way to use a query or mutation more directly. Does it even make sense to use a procedure more directly? I was just wondering how to more closely colocate a procedures usage near a component. About 80% of the time only a single component will need a mutation (e.g. specific form or a certain data table with component specific data).
2 replies
XXata
Created by Michael Schaufelberger on 7/17/2024 in #help
Issues connecting to the database
Hi We are currently experiencing issues when connecting to the Postgres database on eu-central. Mainly, schema changes are not working. But we also had disconnects when reading data or rather when trying to connect to read data.
XATA_BRANCH dev
Using 'pg' driver for database querying
[✓] Pulling schema from database...

Warning You are about to execute current statements:

DROP INDEX IF EXISTS "fields_unique_idx";
DROP INDEX IF EXISTS "tags_unique_idx";
CREATE UNIQUE INDEX IF NOT EXISTS "fields_unique_idx" ON "fields" USING btree (LOWER(label),"eventSeriesId");
CREATE UNIQUE INDEX IF NOT EXISTS "tags_unique_idx" ON "tags" USING btree (LOWER(label),"owner","eventSeriesId");

Error: Connection terminated unexpectedly
XATA_BRANCH dev
Using 'pg' driver for database querying
[✓] Pulling schema from database...

Warning You are about to execute current statements:

DROP INDEX IF EXISTS "fields_unique_idx";
DROP INDEX IF EXISTS "tags_unique_idx";
CREATE UNIQUE INDEX IF NOT EXISTS "fields_unique_idx" ON "fields" USING btree (LOWER(label),"eventSeriesId");
CREATE UNIQUE INDEX IF NOT EXISTS "tags_unique_idx" ON "tags" USING btree (LOWER(label),"owner","eventSeriesId");

Error: Connection terminated unexpectedly
Is there currently something unstable? Username: 5713tr
27 replies
XXata
Created by Michael Schaufelberger on 7/13/2024 in #help
Vercel connections timeout when using a transaction
Hi We are using Drizzle together with the TCP Pool pg client.
import { drizzle as drizzlePg } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';

import * as schema from './schema';
import { getXataClient } from './xata';

export const xata = getXataClient();

const pool = new Pool({
connectionString: xata.sql.connectionString,
max: 1,
});

export const db = drizzlePg(pool, {
schema,
});
import { drizzle as drizzlePg } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';

import * as schema from './schema';
import { getXataClient } from './xata';

export const xata = getXataClient();

const pool = new Pool({
connectionString: xata.sql.connectionString,
max: 1,
});

export const db = drizzlePg(pool, {
schema,
});
I have also tried
const pool = new Pool({
connectionString: xata.sql.connectionString,
max: 1,
maxUses: 1,
connectionTimeoutMillis: 5000,
idleTimeoutMillis: 1000,
allowExitOnIdle: true,
});
const pool = new Pool({
connectionString: xata.sql.connectionString,
max: 1,
maxUses: 1,
connectionTimeoutMillis: 5000,
idleTimeoutMillis: 1000,
allowExitOnIdle: true,
});
which just makes at least the serverless function not run until its own timeout is reached. However, the serverless function times out when we want to use a transaction. This only happens when deployed to Vercel. I tried to check how many connections we have using pgAdmin. But there are none, which I think we are just not allowed to see, because my current one should show up. How can I use transactions on Vercel using Drizzle? This is currently a major blocker. I read some threads here of a 40 connection limit. When reading stuff like this https://neon.tech/docs/connect/connection-pooling#connection-pooling it makes me question if Xata can even handle TCP in serverless functions. Would a dedicated Cluster solve this issue?
7 replies
DTDrizzle Team
Created by Michael Schaufelberger on 7/10/2024 in #help
RQB: Why is a where clause inside a many-to-many relation not allowed?
Say we have posts and tags. Every post can have multiple tags, but a tag can have many posts. So a classical many-to-many relation. Note: we have a junction table to store the relation posts 1-n postsToTags n-1 tag Now we want to fetch a post with all the tags. We can just do this:
db.query.postsTbl.findMany({
where: (postsTbl, { eq }) => {
return eq(postsTbl.owner, authId)
},
with: {
postsToTags: {
with: {
tag: {
columns: {
id: true,
label: true,
},
},
},
},
},
});
db.query.postsTbl.findMany({
where: (postsTbl, { eq }) => {
return eq(postsTbl.owner, authId)
},
with: {
postsToTags: {
with: {
tag: {
columns: {
id: true,
label: true,
},
},
},
},
},
});
But say we only want the tags that contain "hello" in the label:
db.query.postsTbl.findMany({
where: (postsTbl, { eq }) => {
return eq(postsTbl.owner, authId);
},
with: {
postsToTags: {
with: {
tag: {
// @ts-ignore
where: (_, { like }) => like(tagsTbl.label, "%hello%"),
columns: {
id: true,
label: true,
},
},
},
},
},
});
db.query.postsTbl.findMany({
where: (postsTbl, { eq }) => {
return eq(postsTbl.owner, authId);
},
with: {
postsToTags: {
with: {
tag: {
// @ts-ignore
where: (_, { like }) => like(tagsTbl.label, "%hello%"),
columns: {
id: true,
label: true,
},
},
},
},
},
});
Why is it not allowed in the types? Is there something that could easily break if we add a where clause to the subquery?
1 replies
XXata
Created by Michael Schaufelberger on 7/5/2024 in #help
How can I restrict the API access to a specific branch?
Is this even possible? I can't find anything in the docs.
8 replies
TtRPC
Created by Michael Schaufelberger on 6/21/2024 in #❓-help
How do I use the rsc-rq-prefetch example with a protected procedure?
Thank you for this implementation! It looks sooo promising 😀 However, I ran into an issue when trying it out: https://github.com/trpc/trpc/blob/next/examples/.experimental/next-app-dir/src/app/rsc-rq-prefetch/page.tsx If we have a protected procedure instead of a public one, the server is not authenticated during SSR and an error is thrown. How can we solve this? Can we just ignore the error and will it still work?
24 replies
TtRPC
Created by Michael Schaufelberger on 6/12/2024 in #❓-help
Can I use the "Streaming with Server Components" strategy with tRPC?
https://tanstack.com/query/latest/docs/framework/react/guides/advanced-ssr#streaming-with-server-components has a neat example on how to prefetch queries without having to await them. Is this something we can use with tRPC?
68 replies