Closed vitormanfredini closed 1 year ago
I should also point out that I do have the plugin-users-permissions installed.
"dependencies": {
"pg": "^8.7.1",
"@strapi/strapi": "4.3.8",
"@strapi/plugin-documentation": "4.3.8",
"@strapi/plugin-i18n": "4.3.8",
"@strapi/plugin-users-permissions": "4.3.8",
"@strapi/provider-upload-aws-s3": "4.3.8"
},
Ok, I figured it out.
First thing that I did was to change table names in v3-sql-v4-sql/migrate/migrateUsers.js
to match the right ones:
async function migrateUsersData() {
- const source = "users-permissions_user";
- const destination = "up_users";
- const destinationLinks = "up_users_role_links";
+ const source = 'users-permissions_user';
+ const destination = 'users-permissions_user';
+ const destinationLinks = 'users_permissions_user_role_links';
I don't know if the current names are valid in other circunstances, tho.
I also added double quotes to this SQL query in v3-sql-v4-sql/migrate/helpers/migrate.js
(otherwise it throws an error if the tablename has "-"):
- await dbV4.raw(
- `SELECT SETVAL ('${seq}', (SELECT MAX(id) + 1 FROM ${destination}))`
- );
+ await dbV4.raw(`SELECT SETVAL ('${seq}', (SELECT MAX(id) + 1 FROM "${destination}"))`);
Unrelated to this particular issue but also important:
In v3-sql-v4-sql/migrate/helpers/migrateValues.js
, I applied the same pluralize.singular function as strapi/codemods does when migrating code. Now the migration doesn't lose all upload relations in files_related_morphs
.
+ if (result.substring(0, 5) == 'api::') {
+ const arrParts = result.substring(5).split('.');
+ if (arrParts.length == 2) {
+ result = `api::${_.kebabCase(pluralize.singular(arrParts[0]))}.${_.kebabCase(
+ pluralize.singular(arrParts[1])
+ )}`;
+ }
+ }
That might be useful to others. Should I submit a pull request?
I've been having this issue for a while and was the only bottle neck on my migration process.
Thanks for sharing this solution.
You're welcome.
Until my pull request isn't processed you can use this fork with the mentioned changes: https://github.com/vitormanfredini/strapi-v3tov4-modified-migration-scripts
migrating this to the migration scripts repo, not here.
I believe I found the root cause of this issue here. The problem comes from codemods in https://github.com/strapi/codemods/issues/47
Can you confirm that your extensions of users-permissions has the proper collectionName
value of up_users
No, it's using the old ones. Good catch.
When I get the time, I'll try to redo the database migration with the right ones.
Thank you
For now I'll go ahead and close this but if anyone hits the issue please let us know.
Bug report
Required System information
Describe the bug
After following the steps to migrate database from v3 to v4, the scripts fails with the following error:
error: delete from "up_users_role_links" - relation "up_users_role_links" does not exist
Steps to reproduce the behavior
Expected behavior
Database should be fully migrated to v4.
yarn start
entire outputAdditional context
The error seems to originate in https://github.com/strapi/migration-scripts/blob/main/v3-sql-v4-sql/migrate/migrateUsers.js on line 64, where it tries to delete everything from the table
up_users_role_links
but this table doesn't exist.