In Drupal 8, I am preparing a migration and at the same time, the users are adding nodes of content manually. For the migration I need to keep the same node ID as the source. Is there any way I can limit manually added content to a certain range of node ids so that it doesn't conflict with my migrated nodes which will be added afterwards.
How can I keep new nodes within a certain range of IDs so as to not conflict with migrated node IDs?
-
The only way to avoid conflicts is avoiding users can create new nodes until the migration is completed. Even drupal.org limits the operations users can do on the server, when data migrations or updates are done. When drupal.org migrated to git, nobody has been able to commit code in its CVS repository, until the migration had been completed.– avpaderno ♦Commented Nov 4, 2020 at 12:36
3 Answers
I have encountered the same problem and where there may be clashes you can set the value of AUTO_INCREMENT to a high value to ensure there is no overlap between new content items, which get higher node IDs, and old items, which keep their existing ones. For MySQL:
ALTER TABLE node AUTO_INCREMENT=100000;
ALTER TABLE node_revision AUTO_INCREMENT=100000;
Depending on your migration you may need to apply this to other items such as taxonomy term IDs as well.
-
In my case I also altered
file_managed
table,ALTER TABLE file_managed AUTO_INCREMENT=100000;
Someone maybe needs to adjustmedia
table too, if media was used on drupal 7 too. Commented Sep 13, 2021 at 16:36 -
To find what tables have auto increment fields you can run next sql query:
SELECT AUTO_INCREMENT, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'drupal8' AND AUTO_INCREMENT IS NOT NULL
Commented Sep 13, 2021 at 16:42
Why would you need to keep the same node ID for the migration?
When you use the Migrate module, it maps the old node ID with the new one; you just need to use the entity_lookup or migration_lookup process plugin to process your referenced entities. (See Understanding the entity_lookup and entity_generate process plugins from Migrate Tools for more details.)
-
for the migrate files to media module to attach the media to the nodes it needs to have the same nid.drupal.org/project/migrate_file_to_media/issues/…– DianaCommented Nov 2, 2020 at 15:30
-
1To me it sounds more like a bug needed to be fix on the module side than a trick to do on your side– MacSimCommented Nov 2, 2020 at 16:05
-
-
As usual lol. Good luck mate! You should still try to reopen the issue so somebody can either help you or fix it– MacSimCommented Nov 3, 2020 at 11:22
-
1as per your comment i have added an issue drupal.org/project/migrate_file_to_media/issues/3180466– DianaCommented Nov 3, 2020 at 14:55
Messing with nids is a tricky business. The Custom Nid module or this question might aid you but technically it's really hard and not advised to alter nids as the column is set to auto increment in the database. There are also a lot of references across the database so changing a nid will probably wreck some things.
You could implement a check in the node_save function which checks on node save what the current assigned nid is and if the next nid (+1) is still below the lowest nid from your migration data. If that check fails you could temporary prevent new nodes from being created until the migration is done.
-
Yes, other database tables containing the node ID is the reason for not altering the node ID from the table containing the node data. At least,
hook_node_update()
should be invoked, hoping the modules implementing that hook are prepared to handle a node that changes its node ID. Probably, it's better if modules that store node data think the node with the old ID is deleted and a new node is created.– avpaderno ♦Commented Nov 4, 2020 at 12:34