SQLITE error after update from 2.5.1 to 2.6.0
The application was created with spin 2.5.1 and was runnable with spin up. The following steps were taken:
spin_manifest_version = 2
[application]
name = "TEST-PROCESSOR"
version = "0.1.0"
authors = ["*********"]
description = "*************"
[[trigger.http]]
route = "/api/vehicle/..."
component = "vehicle"
[[trigger.http]]
route = "/api/updates/..."
component = "update-status"
[component.vehicle]
source = "vehicle/target/wasm32-wasi/release/vehicle.wasm"
allowed_outbound_hosts = []
sqlite_databases = ["vehicle"]
[component.vehicle.build]
command = "cargo build --target wasm32-wasi --release"
workdir = "vehicle"
watch = ["src/**/*.rs", "Cargo.toml"]
[component.update-status]
source = "update_status/target/wasm32-wasi/release/update_status.wasm"
allowed_outbound_hosts = []
sqlite_databases = ["update-status"]
[component.update-status.build]
command = "cargo build --target wasm32-wasi --release"
workdir = "update_status"
watch = ["src/**/*.rs", "Cargo.toml"]
Building and Starting with
spin build --up --sqlite @migration_vehicle.sql --sqlite @migration_update_status.sql
In the .spin folder, an sqlite_db.db is created. The migration data was also correctly created.
After updating via brew to spin 2.6.0, the application can no longer be started.
spin up
Finished building all Spin components Error: One or more components use SQLite databases which are not defined. Check the spelling, or pass a runtime configuration file that defines these stores. See https://developer.fermyon.com/spin/dynamic-configuration#sqlite-storage-runtime-configuration Details:
- Component vehicle uses database 'vehicle'
- Component update-status uses database 'update-status'
As a test, the .spin/sqlite_db.db was deleted and called with the command
spin build --up --sqlite @migration_vehicle.sql --sqlite @migration_update_status.sql
The sqlite_db.db is correctly created, but the application does not start, same error.
Let me know if you need any further adjustments!
- Spin version (
2.6.0) - Installed plugin versions: ** loud 0.9.0 [installed] ** js2wasm 0.6.1 [installed] ** py2wasm 0.3.2 [installed]
Thanks for filing the issue!
So, I'm not surprised that it doesn't work with Spin v2.6.0, but I am surprised that it seemed to have worked in Spin v2.5.1. I tried to reproduce the error with Spin v2.6.0 and v2.5.1, and I received the error message using both versions.
I believe the route cause is that you're missing a runtime-config-file that specifies where these databases live.
You can see a link in the error message to the docs that describe this:
Check the spelling, or pass a runtime configuration file that defines these stores. See https://developer.fermyon.com/spin/dynamic-configuration#sqlite-storage-runtime-configuration
You'll need to define your databases like so in a runtime-config.toml file:
[sqlite_database.vehicle]
type = "spin"
path = "path/to/your/database.db"
[sqlite_database.update-status]
type = "spin"
path = "path/to/your/database.db"
And then you run the app with the runtime config file:
spin up --runtime-config-file runtime-config.toml
Let me know if this helps, or if you're still running into issues.
Thank you very much, it's actually running as usual again.
But what puzzles me is that with the "runtime-config.toml", there should be a "database.db" in each target folder?
# This defines a new store named vehicle
[sqlite_database.vehicle]
type = "spin"
path = "vehicle/database.db"
# This defines a new store named update-status
[sqlite_database.update-status]
type = "spin"
path = "update_status/database.db"
When calling the command line
spin up --runtime-config-file runtime-config.toml
nothing happens at first (no db files are created).
So I called my migration scripts.
spin build --up --sqlite @migration_vehicle.sql --sqlite @migration_update_status.sql --runtime-config-file runtime-config.toml
This has the effect of creating a file “sqlite_db.db” in the “.spin” folder, in which two tables are created:
• update-status • vehicle
I suspect that the error occurred when updating from 2.5.1 to 2.6 because I created the sqlite_db.db using the migration scripts.
- Am I using the “spin.toml” and the “runtime-config.toml” incorrectly?
- Unfortunately, the documentation does not indicate how to create a physical separation with a migration.
Best regards
Ah yes, I see where the issue is now. Currently all migration files passed to --sqlite are executed against the "default" database - i.e., the database that is always available under the "default" label.
You, however, would like to run migrations against other databases (which is a very reasonable thing to want to do). I've opened https://github.com/fermyon/spin/pull/2610 which would change spin up such that the name of the migration file is used to specify which database to run the sql file against.
Once that PR lands, you would run spin up like this:
spin build --up --sqlite @vehicle.sql --sqlite @update-status.sql --runtime-config-file runtime-config.toml
note the change to the sql files so that they match the names of the databases they're supposed to be run against