dboehmer / coocook

👨‍🍳🦉 Web application for collecting recipes and making food plans
https://coocook.org/
Other
11 stars 2 forks source link

Add DDL files for PostgreSQL and migrate production to PostgreSQL #117

Closed dboehmer closed 3 years ago

dboehmer commented 4 years ago

This is especially desirable for the Docker images where you usually have no persistent storage for the SQLite file.

dboehmer commented 3 years ago

While developing on this I notice: This is looong overdue! I found several inconsistencies in the SQLite data:

dboehmer commented 3 years ago

@moseschmiedel Can you please try to migrate existing SQLite file(s) in your work dir to Pgsql?

Steps required:

As I wrote before I had to fix some issues in production data. This is my fix script:

-- German number format with comma
UPDATE   dish_ingredients SET value=REPLACE(value, ',' , '.') WHERE value LIKE '%,%';
UPDATE recipe_ingredients SET value=REPLACE(value, ',' , '.') WHERE value LIKE '%,%';
UPDATE items              SET value=REPLACE(value, ',' , '.') WHERE value LIKE '%,%';

-- boolean columns with empty string
UPDATE   dish_ingredients SET prepare=0 WHERE prepare='';
UPDATE recipe_ingredients SET prepare=0 WHERE prepare='';
UPDATE units              SET   space=0 WHERE   space='';

-- dangling dish_ingredients with dish not existing (17 rows on 2020-12-23)
DELETE FROM dish_ingredients
WHERE NOT EXISTS (
    SELECT * FROM dishes
    WHERE dishes.id = dish_ingredients.dish_id
);

-- dangling dishes_tags with dish not existing (4 rows on 2020-12-23)
DELETE FROM dishes_tags
WHERE NOT EXISTS (
    SELECT * FROM dishes
    WHERE dishes.id = dishes_tags.dish_id
);

-- dangling roles_users with user not existing (1 row on 2020-12-23)
DELETE FROM roles_users
WHERE NOT EXISTS (
    SELECT * FROM users
    WHERE users.id = roles_users.user_id
);