Skip to content

Document database migration process #1033

@dpw13

Description

@dpw13

Is your feature request related to a problem? Please describe.
I recently migrated from SQLite to postgresql 17.6 for my database backend on PartDB. I ran into a few small issues along the way that others might encounter in the future.

Describe the solution you'd like
The process is relatively standard for those who are familiar with that kind of migration, but it would be ideal to have a little more info in the docs besides the existing backup/restore documentation, which really only applies if you are restoring using the same database backend as the backup.

I have notes on my process below, but whoever picks up this issue should identify the recommended migration process and document it (maybe under Usage, maybe under Upgrade? I'm not actually sure where it should go).

Describe alternatives you've considered
The alternative would be to leave the docs unchanged.

Additional context
NOTE: See below. I do not recommend using this method!

I was able to migrate from SQLite to pg using pgloader (after manually provisioning a new pg user and creating the database):

pgloader .../partdb/db/app.db 'postgresql://partdb:<password>@<postgres-ip>:5432/partdb'

This worked super well except that it migrated all the timestamps to timestamptz which Symfony did not like. For anyone else searching for a similar error, this was the log produced:

Uncaught PHP Exception Doctrine\DBAL\Types\Exception\InvalidFormat: "Could not convert database value "2025-09-08 14:13:22+00" to Doctrine Type App\Doctrine\Types\UTCDateTimeImmutableType. Expected format "Y-m-d H:i:s"." at InvalidFormat.php line 26 {"exception":"[object] (Doctrine\\DBAL\\Types\\Exception\\InvalidFormat(code: 0): Could not convert database value \"2025-09-08 14:13:22+00\" to Doctrine Type App\\Doctrine\\Types\\UTCDateTimeImmutableType. Expected format \"Y-m-d H:i:s\". at /var/www/html/vendor/doctrine/dbal/src/Types/Exception/InvalidFormat.php:26)

I manually altered all the timestamptz columns to timestamp, but I think a better solution would be to configure pgloader to use the correct type (see https://pgloader.readthedocs.io/en/latest/ref/sqlite.html):

type timestamp to timestamp using sqlite-timestamp-to-timestamp

I also received the following error because the collation did not exist:

ERROR: collation \"numeric\" for encoding \"UTF8\" does not exist

which was solving by manually recreating the collation:

CREATE COLLATION numeric (provider = icu, locale = 'en-u-kn-true');

Both of these probably may have been avoided had I used the php command-line to recreate the database before importing the data using pgloader, though I haven't tested that. Note that I don't guarantee that either of the above fixes are "correct" and match the schema Symfony would create by running doctrine:database:create, only that the changes above allowed me to log in and interact with my parts.

Note that #164 discusses migrating from SQLite to MariaDB using a somewhat generic (and slightly tedious) method, though it should guarantee the proper database schema.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions