How to approach changing field structure?

Created on 3 July 2023, 12 months ago
Updated 9 August 2023, 11 months ago

While evaluating this module for use, I have a question regarding schema updates. Say that we have a "Custom Field" that consists of a textfield "A", and textfield "B". 3 months after configuring this and 5000 pieces of content later, a design decision requires that the field now contains textfield "C" as well.

What does the recommended process to add this new field look like? Is it a data migration? Update hooks that do SQL things? Something else?

Thanks!

πŸ’¬ Support request
Status

Fixed

Version

1.0

Component

Documentation

Created by

πŸ‡ΊπŸ‡ΈUnited States Luke.Leber Pennsylvania

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Luke.Leber
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    @Luke.Leber, great question and one I need to prioritize as a documentation task soon. I'll put this on my list of todo's.

  • πŸ‡ΊπŸ‡ΈUnited States Luke.Leber Pennsylvania

    Re-triaged issue component to documentation, thanks!

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    @Luke.Leber - I've made some progress in a separate branch: https://git.drupalcode.org/project/custom_field/-/tree/updater_service?r.... That branch provides a custom field updater service. Right now it only supports adding a new column and I'm not yet sure how to handle tables with existing data but the column does get added to the db and is reflected in the UI field settings. If you or anyone else wants to try out and offer some help, I think I can get this workable. To try the service in a custom module, add an update to yourmodule.install like the following example. This is nowhere near fit for a release obviously... but it's a decent POC to build off of (I think).

    addColumn($entity_type_id, $field_name, $new_column_name, $data_type, array($options))

    /**
     * Test adding a new column to custom_field.
     */
    function mc_core_update_9045(): void {
      /** @var \Drupal\custom_field\CustomFieldUpdateManagerInterface $update_manager */
      $update_manager = Drupal::service('custom_field.update_manager');
      $update_manager->addColumn('node', 'field_custom', 'new_decimal_column', 'decimal', ['scale' => 3, 'precision' => 6]);
    }
  • Status changed to Fixed 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    Documentation provided here for handling this with the new service provided in the upcoming release: https://www.drupal.org/docs/extending-drupal/contributed-modules/contrib... β†’

  • Status changed to Fixed 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner
Production build 0.69.0 2024