#TablePlus and connecting to Turso (2 issues)

30 messages · Page 1 of 1 (latest)

gloomy ice
#

Two different issues…

I'm attempting to get astrodb working on my computer, I have a few questions. I've got it installed, built my config.ts, started a seed.ts, the content.db generated file has content in it now. I'm trying to do two things: (1) view the database in Table Plus, and (2) connect to Turso.
(1) Basically, for adding a database to Table Plus, it asks for a URL. I'm trying to use file:/Users/foo/code/bar/.astro/content.db as the URL, but Table Plus just returns "error".
(2) I followed the Getting Started with Turso steps (it's beta docs but seems correct)--installed Turso CLI, connected to Turso, created the db using cli, got the remote URL and token, put them in my .env.development file. Ran yarn astro db push --remote, and the message is Directory not linked. To link this directory to an Astro Studio project, run astro link
Any help is appreciated.

snow orchid
#

I love TablePlus. Lets start with that and then we can work on the 2nd one.

#

So for loading the DB in TablePlus. You dont want to do it as a URL. You want to do New Connection and then SQLite. And then navigate to the file.

gloomy ice
snow orchid
#

I think the libsql would be for if you wanted to connect it to your Turso DB

gloomy ice
#

Cool cool. What about pushing to turso? I feel like I missed a step somewhere, but I followed the beta docs exactly.

snow orchid
#

Does your .env have ASTRO_DB_REMOTE_URL=[your-database-url] ?

gloomy ice
#

Yes. I’ll double check my spelling for it. I did the token too.

snow orchid
#

Let me know if those are there and correct

gloomy ice
#

OK, table plus works with the sqlite selection, thank you so much.
As for the other, here is what is in my .env.development:

ASTRO_DB_REMOTE_URL=libsql://foo.turso.io
ASTRO_DB_APP_TOKEN=reallylongsecrettokenishere
snow orchid
#

Okay great. And when you run astro db push --remote its wanting to push to Studio instead of Turso ?

gloomy ice
#

just ran it again, this is the message:

❯ yarn astro db push --remote                                                                                                                                                                                                                                                          01:18:26 PM
▶ Directory not linked.

  To link this directory to an Astro Studio project, run
  astro link
#
    "@astrojs/check": "0.9.4",
    "@astrojs/db": "^0.14.2",
    "@astrojs/react": "3.6.2",
    "@astrojs/sitemap": "3.2.0",
    "@astrojs/tailwind": "5.1.1",
    "@astrojs/vercel": "8.0.0-beta.2",

This is the @astrojs portion of my package.json

#

Oh and this: "astro": "5.0.0-beta.3"

#

As a side note, but possibly relevant, I'm getting this error when I run yarn astro build:

❯ yarn astro build                                                                                                                                                                                                                                                                     01:25:52 PM
13:26:07 [content] Syncing content
13:26:07 [content] Synced content
13:26:07 [types] Generated 167ms
[Astro DB Error] Attempting to build without the --remote flag or the ASTRO_DATABASE_FILE environment variable defined. You probably want to pass --remote to astro build.
  Hint:
    Learn more connecting to Studio: https://docs.astro.build/en/guides/astro-db/#connect-to-astro-studio
  Stack trace:
    at astro:build:start (file:///Users/mikeearley/code/learnit/node_modules/@astrojs/db/dist/core/integration/index.js:139:17)
    at AstroBuilder.build (file:///Users/mikeearley/code/learnit/node_modules/astro/dist/core/build/index.js:111:11)
    at async build (file:///Users/mikeearley/code/learnit/node_modules/astro/dist/core/build/index.js:44:3)
    at async runCommand (file:///Users/mikeearley/code/learnit/node_modules/astro/dist/cli/index.js:147:7)
snow orchid
#

Pass the --remote flag to the Astro Build like it says. But not sure why its wanting to link to a studio project still. <@&1129102257422610512> Anyone got any ideas?

crude seal
gloomy ice
#

Ah--yeah, I figured that part out--I set the env in terminal instead of trying to set it in .env, I saw in a reddit post that you can't set it in .env, it doesn't pick it up. Once I set it in the terminal it worked.
The turso issue persists though.

#

i.e. yarn astro db push --remote is still wanting to connect to astro studio, not turso

marble tree
gloomy ice
#

yeah I got that one fixed with ❯ set -x ASTRO_DATABASE_FILE /srv/files/database.db

crude seal
gloomy ice
crude seal
#

Can you add a console.log(process.env) in your astro.config.mjs file and check whether the two env vars are logged?
The conditional for switching out of Studio is super simple, just checks whether that ASTRO_DB_REMOTE_URL is set

#

Just tested with same versions (Astro v5 beta 3 and DB 0.14.2).
Setting the env var work fine:

ASTRO_DB_REMOTE_URL=file:foo.db yarn astro build --remote

Can you share a repo reproducing the issue? You can use a file URL instead of a Turso URL and token for the reproduction

gloomy ice
#

I can share a repo, it's currently private, so I may need to copy it or something first. Also, the .env files are in .gitignore, so I'll need to fix that in the copied version too...

gloomy ice
# crude seal Just tested with same versions (Astro v5 beta 3 and DB 0.14.2). Setting the env ...

You inadvertently taught me how to fix the issue. So, of course I followed the instructions for connecting to turso remotely here:
https://5-0-0-beta.docs.astro.build/en/guides/astro-db/#migrate-from-astro-studio-to-turso
So in my .env.development file, I had the ASTRO_DB_REMOTE_URL pointed to the turso URL that those instructions produced. So, there was nowhere in my setup that pointed the app to its own db file locally. Which--I didn't realize I needed to do, as for sure doing that step is for sure not listed anywhere on this page that I can find:
https://5-0-0-beta.docs.astro.build/en/guides/integrations-guide/db/#astro-db-cli-reference
Once I updated my .env.development to point to the local content.db file, everything on that side is working.
Now, what I don't know is how to set up the Turso connection still. Do I put the remote_url and app_token that turso cli shows to me into .env.production? How do I trigger that push? Or am I misunderstanding this fundamentally...

Docs

Learn how to use the @astrojs/db integration in your Astro project.

Docs

Learn how to use Astro DB, a fully-managed SQL database designed exclusively for Astro.

snow orchid
#

So wherever you are hosting your site. You can put your environment variables there. Then in your package.json. You modify the build command to have —remote and then when it builds on the server. It would point to the Turso DB.

Once you initially push up your schema. You don’t need to push again unless it changes. In which case you could set up a GitHub action to do that.

gloomy ice
#

OK. I'm slowly getting there. I haven't tried to set up turso yet if I'm being honest--I'm still working through seeding the db successfully. I've got a mildly complex seed.ts file, so it's taking a minute to work out.