I created a patch with an alternate naming convention for the field tables the Serial module creates/uses to do its auto-increment magic.
Previously, the module was using entity type + bundle + field name as the key for an MD5 hash and appending that to "serial_". This was to try to keep it under the 64 byte table name limit in MySQL. The result was a table named: serial_somelonghashstringwithnorelationtothefieldname. And if you didn't take the time to parse that long string in your head, my point is, you can't tell which table goes with which serial field you've created. This is important (to us, at least) because we want to start the auto-increment values at something higher than 1 to accommodate importing historical data.
Since field names have to be unique within each entity type, I say "bundle" is not necessary in this case. So that leaves us with entity type (32-byte limit) and field name (32-byte limit). Realistically, entity type will probably not come close to the 32-byte limit. The longest one I've seen is "field_collection_item", which is 21 bytes. So even if field name ends up using the full 32 bytes, I think it is unlikely that the combination of those plus the prefix of "serial_" will exceed the 64-byte limit.
And if ever those two values do add up to 64 bytes, Drupal core will also break because the field tables are named:
node__field_my_example_field
node_revision__field_my_example_field
The first one adds 2 to the count because of "__". The second one adds 10 to the count because of "_revision__".
So the patch causes the Serial Field module to create its tables as:
serial_node_field_my_example_field
PS. Sorry, I'm not sure of the naming convention for patches. :-(
Comment | File | Size | Author |
---|---|---|---|
#2 | table_name.patch | 723 bytes | ExTexan |
Comments
Comment #2
ExTexan CreditAttribution: ExTexan commentedComment #3
ExTexan CreditAttribution: ExTexan commentedSorry I had to replace the first file. It ended up with extra stuff in it that shouldn't be in the patch.
Comment #4
WorldFallz CreditAttribution: WorldFallz commentedI ran into and issue with the naming convention myself when I had to modify the auto_increment to restart a serial field.
I agree a new naming convention would be a good idea- but any patch would necessarily have to include a module update function to fix existing data.
That said however, I was able to work around it by using an online MD5 generator and entering the entity/bundle/fieldname to find the matching hash.
Just wanted to post that in case anyone else needs a workaround in the meantime.