Migration from V3 to V4 - Script Error

Hi,

I am trying to migrate db of v3 to db of v4 using the below script.

I keep getting errors as shown below

error: SELECT SETVAL ('strapi_core_store_settings_id_seq', (SELECT MAX(id) + 1 FROM 'strapi_core_store_settings')) - syntax error at or near "'strapi_core_store_settings'"

error: SELECT SETVAL ('admin_roles_id_seq', (SELECT MAX(id) + 1 FROM 'admin_roles')) - syntax error at or near "'admin_roles'"

I tracked down the source code file responsible for that; its path is as below.

Filename : migrate/migrateCoreStore.js

I dont know what the error means and how to fix it.
Please help me!

Thanks!

1 Like

I’m getting this too! I’m unsure what the cause of the issue is either but I just wanted to see if you had made any progress since posting @ryucoder?

the error code says syntax error, i assume there isnt an actual syntax error in the script, so it must be some compatibily issue.
Are you sure the new db has the same compatiblity as the old db?

@ [JamieBradders] I have not made any progress.

I think that code is trying to update the id field of the table to the max id of the table in question and increase it by 1.

@ [sven_folkerts] What do you mean by same compatibility?
Both the databases are postgres and same version of the postgres.

Original code in the script -

async function resetTableSequence(destination) { if (isPGSQL) { const hasId = await dbV4.schema.hasColumn(destination, "id");

if (hasId) { const seq = `${destination.slice(0, 56)}_id_seq`;

await dbV4.raw(
    `SELECT SETVAL ('${seq}', (SELECT MAX(id) + 1 FROM '${destination}'))`
);

} } } 

My modifications to the code -

async function resetTableSequence(destination) { if (isPGSQL) { const hasId = await dbV4.schema.hasColumn(destination, "id");

if (hasId) { const seq = `${destination.slice(0, 56)}_id_seq`;

await dbV4.raw(
    `SELECT SETVAL ('${seq}', (SELECT MAX(id) + 1 FROM ${destination}))`
);

} } }

I changed ‘${destination}’ to ${destination}.
It worked! It solved my problem!

1 Like

Allright nice!