How to deploy a SvelteKit app using SQLite as a database.

Hi.

I was trying to deploy a SvelteKit app following the docs and ran into a problem.

For additional context, I am using better-sqlite3.

The problem I am facing is at the final step when hitting fly deploy.
I am currently getting this: Error: failed to provision seed volumes: failed creating volume: The GraphQL API no longer supports volume operations, please use the machines API instead (or update your flyctl version): https://docs.machines.dev/swagger/index.html#/Volumes

I am new to fly, this is my very first app, actually, so please help out if you can.

Thank you.

Hey hi @davis
Welcome to the fly’s community
In order for the sqlite to store the database you need persistent volumes or else the database is deleted when you restart.

For this you might have to create a volume using Fly Volumes overview · Fly Docs

Hey, @darkcheftar007

Thanks for getting back to me so quickly. And thanks for the welcome.

I’ll definitely take a look at those docs.

Quick question: Since I’m not persisting anything, is that the reason why my deployment is failing?

Even If you are not persisting that should not be a problem it has to deploy normally,

Can you share more details like the config file?

This is my Dockerfile. Is there any other relevant file you’d like to take a look at? I’m happy to accomodate.

# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=18.18.0
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="Node.js"

# Node.js app lives here
WORKDIR /app

# Set production environment
ENV NODE_ENV="production"

# Install pnpm
ARG PNPM_VERSION=8.8.0
RUN npm install -g pnpm@$PNPM_VERSION


# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build node modules
RUN apt-get update -qq && \
    apt-get install -y build-essential pkg-config python-is-python3

# Install node modules
COPY --link .npmrc package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile --prod=false

# Copy application code
COPY --link . .

# Build application
RUN pnpm run build

# Remove development dependencies
RUN pnpm prune --prod


# Final stage for app image
FROM base

# Copy built application
COPY --from=build /app /app

# Setup sqlite3 on a separate volume
RUN mkdir -p /data
VOLUME /data

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
ENV DATABASE_URL="file:///data/sqlite.db"
CMD [ "pnpm", "run", "start" ]

Here’s some other bits of info I think could give you more context. This logs at the end after hitting fly deploy.

Creating 1GB volume 'data' for process group 'app'. Use 'fly vol extend' to increase its size
Error: failed to provision seed volumes: failed creating volume: The GraphQL API no longer supports volume operations, please use the machines API instead (or update your flyctl version): https://docs.machines.dev/swagger/index.html#/Volumes

This part is probably causing error
The volume thing I mentioned above

Can you share fly.toml file

Sure. Here you go.

# fly.toml app configuration file generated for yuhi on 2023-10-07T09:00:26+02:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "yuhi"
primary_region = "cdg"

[[mounts]]
  source = "data"
  destination = "/data"

[http_service]
  internal_port = 3000
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ["app"]

Thats probably it

You are asking it to mount volume to /data

I assume you haven’t created a volume

I guess thats the problem

Where are you storing the sqlite database?

It’s nothing remote. It’s embedded. I’m using better-sqlite3 package.

And about that previous reply, I didn’t create a volume myself. I thought it was automatic.

But, allow me to ask. What are the best ways to handle databases here on fly?

I don’t want to worry about backing up and/or replications, or configuration. I came here because a friend recommended that Fly.io and sqlite is a great combo, if that’s not case, I’m really open to alternatives.

1 Like

A good combo indeed

There are alot of ways but sqlite I great too
You just need to setup volume for the database to persist

Let me see If I can deploy a sample app for you

Please make sure you are on the latest version of flyctl. That error message indicates it’s using a deprecated/removed GraphQL endpoint for creating a volume.

1 Like

Tried could not get any progress
How about you @davis ?

Hey, @darkcheftar007

I got it to work.

I followed @JP_Phillips 's advice and tried upgrading flyctl.

A problem, though, is that when using brew it failed. It’s like it was stuck on version v0.1.62 and I tried uninstalling it and installing again, and then upgrading, but the version remained the same. Not sure if the problem is with brew or flyctl.

After using curl -L https://fly.io/install.sh | sh and the guide in the documentation here, it worked just fine.

Thanks for helping out, @darkcheftar007 & @JP_Phillips .

Now, as a goodbye note, may anyone point me in the right direction, doc-wise, so that I can learn about managing my database, because this has me worried.

In order for the sqlite to store the database you need persistent volumes or else the database is deleted when you restart.

Again, thanks for the help.

P.S: @JP_Phillips if you do ever find a fix for flyctl from brew, is there a way you might let us know. Because I want for an easier way to upgrade to the newest version whenever its out. Thanks.

1 Like

Go to JavaScript on Fly.io · Fly Docs and review The Basics on the left side bar. Quick summary: if you want the data in your sqlite3 database to survive restarts of your machine including deploying new versions of your software you will want to put that database on a volume.

If those pages don’t answer your questions, ask them here.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.