X
Xata6d ago
Oreki

Help with Drizzle

Hey team, i would like to run introspect and pull commands from drizzle-kit, but i seem to be running into an error the config:-
import { defineConfig } from 'drizzle-kit';

import { getXataClient } from './src';

export default defineConfig({
dialect: 'postgresql',
out: './drizzle',
dbCredentials: {
url: getXataClient().sql.connectionString,
},
verbose: true,
});
import { defineConfig } from 'drizzle-kit';

import { getXataClient } from './src';

export default defineConfig({
dialect: 'postgresql',
out: './drizzle',
dbCredentials: {
url: getXataClient().sql.connectionString,
},
verbose: true,
});
The error :-
error: unable to connect to the appropriate database
error: unable to connect to the appropriate database
Additional Information :- Driver: pg Beta Direct Access Enabled: false
10 Replies
cmck
cmck6d ago
Hi Oreki, I suspect the issue is due to Beta Direct Access Enabled: false . Without this setting enabled you can't connect directly to your database with a postgres connection string. https://xata.io/docs/postgres#postgres-can-not-be-enabled-on-already-existing-databases you could test this by creating a test db with that setting enabled and see if the connection works.
Connect to Postgres
Learn how to connect to Postgres directly via the wire protocol
Oreki
OrekiOP6d ago
so if i have to export my data completely and create beta enabled database, i will have to go over one by one table by table, export to csv?
cmck
cmck6d ago
Unfortunately, there's no way currently to convert an existing database to a direct-postgres-access-enabled database.
Oreki
OrekiOP6d ago
yeah quite annoying tbh, should there not be a feature to export entire database?
cmck
cmck6d ago
I appreciate that it's annoying. We're looking into that feature for the non-pg-enabled databases. For the pg-enabled dbs, you can use pgdump.
Oreki
OrekiOP6d ago
Thank you for the quick reply tho
cmck
cmck6d ago
Let me double-check just to make sure I'm right about Beta Direct Access Enabled: false before you go exporting anything. Did you test it with a postgres-enabled db?
Oreki
OrekiOP6d ago
actually, what i am trying to do is replicate the schema in a local database for testing purposes it would've been quite helpful if i could just do pull on one db and push on another but it appears, i will have to wait for xata to come out of that beta access thing for me to be able to use it in production
cmck
cmck6d ago
With your non-postgres-enabled database, you might need to change the client you're using. Looks like you're using the TCP client. Did you try the HTTP client?
import { drizzle } from 'drizzle-orm/xata-http';
import { getXataClient } from './xata'; // Generated client

const xata = getXataClient();
const db = drizzle(xata);
import { drizzle } from 'drizzle-orm/xata-http';
import { getXataClient } from './xata'; // Generated client

const xata = getXataClient();
const db = drizzle(xata);
https://xata.io/docs/integrations/drizzle
Oreki
OrekiOP6d ago
i need to replicate the schema only, not the whole database, only need the drizzle-kit

Did you find this page helpful?