1

I want to migrate some entries and its content to a new table in our plugin. Below is a simplified SQL that seems to do the trick.

insert into craft_myplugintable(id, field1, field2, field3, dateCreated, dateUpdated, uid)
select entries.id, content.field_field1, content.field_field2, content.field_field3, entries.dateCreated, entries.dateUpdated, entries.uid
from craft_elements elements
  join craft_entries entries on elements.id = entries.id
  join craft_entrytypes types on entries.typeId = types.id
  join craft_content content on entries.id = content.elementId
where types.handle = 'mySection';

update craft_elements elements
  join craft_myplugintable myplugin on elements.id = myplugin.id
set type = 'Plugin_ElementType';

Is this method safe? Should i use a migration file and let craft set the UID? I'm not sure what the UID field is for. Keep in mind that we no longer need the entries, so they can be deleted if this is wrong.

1 Answer 1

1

If you want to be future-proof, then yes - you should create a new UUID for each new row.

You can use MySQL's uuid() method for that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.