ariga / atlas

Manage your database schema as code
https://atlasgo.io
Apache License 2.0
5.76k stars 260 forks source link

Can't connect to LibSQL local file database #2198

Closed KamWithK closed 10 months ago

KamWithK commented 11 months ago

I'm trying to use Atlas but if I set up my atlas.hcl as such:

env "local" {
  src = "file://schema.sql"
  url = "libsql://data/local.db"
  dev = "libsql://data/atlas.db"
}

Then I get this error (when for example I run a command like atlas migrate diff --env local):

Error: sqlite: query version pragma: failed to WebSocket dial: failed to send handshake request: Get "https://data/atlas.db": dial tcp: lookup data on 172.27.240.1:53: no such host

Does atlas only support LibSQL when run with Turso or as a server?

I could modify it to just use sqlite instead of libsql for local tests but then libsql supports some features which libsql does not (for example random row id), and so atlas would give an error when trying to use one of those

penberg commented 11 months ago

The libsql:// protocol implies remote access right now. @haaawk, is this use case supported where you use local files only?

KamWithK commented 11 months ago

The libsql:// protocol implies remote access right now. @haaawk, is this use case supported where you use local files only?

Ah I see, makes sense Would definitely be useful to be able to use it from a file as well though! Maybe you could do libsql+file:// for file databases or something

KamWithK commented 11 months ago

From a quick search through your code you've imported libsql-client-go, sql.open("libsql", "file:/local.db") allows you to read a local libsql database Guessing the problem is here, libsql by itself isn't registered as a flavour (unlike for sqlite above): https://github.com/ariga/atlas/blob/2b47d884c6383bbc4e8a283d01cea85fb0b6c2f2/sql/sqlite/driver.go#L68-L71 Looks like memory mode is also not supported for libsql either

haaawk commented 11 months ago

Maybe adding sqlclient.RegisterFlavours("libsql+file", "libsql+file"), would solve the problem.

haaawk commented 11 months ago

That should fix the problem https://github.com/ariga/atlas/pull/2203