Migrate Sqlite to Postgresql #433
-
A few weeks ago, I did set up Tandoor on unraid using the template provided by @CorneliousJD. It's a really simple setup btw! But now that I used the app for some time, I would like to migrate to postgres (it now uses sqlite). Any advice on this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
migrating different database types is a little tricky. You could use the management commands from django If all of that fails you could at least use the exporter to move over your recipes, i havent gotten around to adding an "export all" button but if you dont have tons of recipes selecting them manually should work |
Beta Was this translation helpful? Give feedback.
-
Sooo, migration from sqlite to postgres is actually quite simple. Here's how I did it:
sqlite.load sample:
EDIT: I ran into an issue (#700) with invite and share links not working properly and it turned out it was caused by how I did the migration. So here is how I fixed it (all the glory goes to @vabene1111 for his awesome support): I used a
Why did I go through this hell you may ask. I just wanted that fuzzy search. EDIT2: something with that pg_restore screwd things up around id sequences inside the db. I was unable to do change ingredients on recipes. This Thread saved me: https://stackoverflow.com/a/244265 -- Login to psql and run the following
-- What is the result?
SELECT MAX(id) FROM your_table;
-- Then run...
-- This should be higher than the last result.
SELECT nextval('your_table_id_seq');
-- If it's not higher... run this set the sequence last to your highest id.
-- (wise to run a quick pg_dump first...)
BEGIN;
-- protect against concurrent inserts while you update the counter
LOCK TABLE your_table IN EXCLUSIVE MODE;
-- Update the sequence
SELECT setval('your_table_id_seq', COALESCE((SELECT MAX(id)+1 FROM your_table), 1), false);
COMMIT; At this point I don't know anymore if the migration was worth the effort. If it wasn't for the user accounts and other configuration, a simple recipe export to a zip-file (from within tandoor) and import (again inside tandoor) on the new database would have been way easier. |
Beta Was this translation helpful? Give feedback.
-
You can use this to sort out sequencing errors, working fine for me at the moment.
|
Beta Was this translation helpful? Give feedback.
Sooo, migration from sqlite to postgres is actually quite simple. Here's how I did it:
pgloader sqlite.load
and hope for no errorssqlite.load sample: