I have deployed a Laravel App with a sqlite DB. I am seeing some unexpected behaviour:
When I enter some data, there should be a message popping up after a successful storage in the database. I don’t see this message. Nevertheless, when I go to the app view which shows the stored data, the data is there, so I assume it was successfully stored somehow.
Now, what’s even stranger, is that, after a few minutes, this recently saved data disappears. How can that be possible? How do I fix that?
A mounted volume is required to persist SQLite data. Mounting a volume on the storage folder will ensure everything it contains gets persisted, including data on the SQLite database located inside.
You can update your [env] for DB_DATABASE to volume mount destination like this DB_DATABASE=“/var/www/html/storage/database/database.sqlite”
You’ll need to update your start-up script
# .fly/scripts/1_storage_init.sh
# Add this below the storage folder initialization snippet
FOLDER=/var/www/html/storage/database
if [ ! -d "$FOLDER" ]; then
echo "$FOLDER is not a directory, initializing database"
mkdir /var/www/html/storage/database
touch /var/www/html/storage/database/database.sqlite
fi
DB_DATABASE looked like that in the first place, but I got connection errors, so I removed ‘storage’ from the path and it then worked, but now I am facing the current problem.
I’ll give it a spin though and report back, thanks.
I updated DB_DATABASE like you said and added your snippet, which I understand creates the database. Naturally, even to my small understanding of Laravel, the database is empty. So I have to run the migrations again. I am having trouble with one migration, but that is another problem. It seems that Laravel connects to the db, so I’ll work now on fixing the faulty migration.