-
Like others, I'm now in the situation where I started with the default SQLite database and now need to switch to MariaDB for performance reasons. I do know #495 and https://docs.photoprism.org/getting-started/advanced/databases/#sqlite-to-mariadb But now I'm facing the issue, that database layout seems to have changed from the initial version where the SQLite DB was created (don't know witch version this was) and the current version I used to create the database layout. What I did, step by step:
The
Comparing SQLite (with DB Browser for SQLite) and MariaDB (phpmyadmin) databases shows the different in layout. My next hope was to you Is there any other way in migrating without starting from the scratch? And if there is no other way, what is it I will loose? Just time? Or data? Oh, did I mention that this software is awesome? Writing this issue to improve not to complain! |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Thank you! PhotoPrism migrates existing tables automatically when it starts. Also there is a |
Beta Was this translation helpful? Give feedback.
-
And migration seems to be the "problem" here: it seems not to delete obsolete colmns, at least not when migrating from version 20210523 to 20210925. I did some tests to verify:
So for my inital problem, the solution is to initialize the maridb with 20210523 and then updating to 20210925 (so, repeating the steps I did with the productive SQLite-db). After that I should be able to copy the data using The question is: shouldn't the layout after migration be like a brand new layout? Or is there any case where it is nessecary to keep old columns? |
Beta Was this translation helpful? Give feedback.
-
No, it should not. See Gorm docs. The danger would be that you lose data that was in these columns. The only way is to manually run SQL migration queries which we currently don't have the resources to provide for two different databases every time we release, so weekly. It's a tradeoff and we decided to go for more frequent releases, more time we can spend with support (right now) and feature development. |
Beta Was this translation helpful? Give feedback.
-
OK, thanks for your fast answere!
Thanks again! |
Beta Was this translation helpful? Give feedback.
-
You are right that we can improve this. We just don't have unlimited resources and we don't think doing it now will bring the most benefit to our users. Some of the unused columns may be from using development builds, as we try to avoid making changes to columns in our stable builds. You're welcome to contribute docs or migration scripts for other, less experienced users! 👍 |
Beta Was this translation helpful? Give feedback.
-
Ok, here is my contribution to the docs. I know there is already one but I hope this is more step by step and it's completely without any other requirements to the host than docker (+compose): Database migration from SQLite to MariaDBThis guide will show you a way to convert the database of an existing photoprism installation from SQLite to MariaDB. PrerequisitesTo complete this guide successfully, you will need to know the complete upgrade history of your photoprism installation, as you will need to "replay" all database schema changes to the new and empty MariaDB database. Start with the latest available version before you initially installed photoprism and use every version since then as a step. Let's assume that your current docker-file looks like this:
Step 0Backup all your data! So shut down your current instance and take a copy of at least the Step 1Start by creating an additional docker-compose-file
Make sure that the host part of the volume of the service Replace Replace Download all images by running:
Step 2Now run the following commands to initialize MariaDB:
If you see the message Step 3Now setup the photoprism database scheme in the empty database. Run:
It will stop after the database scheme is ready. Step 4Now replace the version tag in the migration docker-compose file with the next following version tag an re-run the command above. Do this for every version until your current version. Step 5Now that the scheme of both your current SQLite database and the future MariaDB are the same, you can migrate all data from the one to the other. Before doing this, make sure your current instance of photoprism is shut down. To copy your data, run the following command:
This will copy each and every table and its contents and will tell you the progress. It stops when it's done. If there is an error about a missing table you have probably missed one version in your upgrade path. Step 6Now stop your MariaDB by running:
Copy the complete service So it will look like this afterwards:
Run:
Afterwards delete your Step 7Now you can start up your photoprim instance using docker-compose and everything should be as before, but faster ;) |
Beta Was this translation helpful? Give feedback.
Ok, here is my contribution to the docs. I know there is already one but I hope this is more step by step and it's completely without any other requirements to the host than docker (+compose):
Database migration from SQLite to MariaDB
This guide will show you a way to convert the database of an existing photoprism installation from SQLite to MariaDB.
Prerequisites
To complete this guide successfully, you will need to know the complete upgrade history of your photoprism installation, as you will need to "replay" all database schema changes to the new and empty MariaDB database. Start with the latest available version before you initially installed photoprism and use every version since the…