2

So I have a custom module with a module.schema file, defining a configuration schema for that module, not talking about database/field schema.

module.settings:
type: config_object
label: 'Settings for Module'
mapping:
  my_ids:
   type: sequence
   label: 'Ids from config'
   sequence:
    type: string
    label: 'ids'

I provided a module.settings file like:

my_ids:
 - 1
 - 2
 - 3
 - 4

As you can see, my mistake is that I needed a type: int in my schema not type: string.

On the configuration synchronization page I see Drupal has taken care of this and corrected this in its active configuration, by setting string values for "my_ids", and of course producing a diff between the staged and active configuration. The active conf has now strings:

my_ids:
 - "1"
 - "2"
 - "3"
 - "4"

I would like to update the schema of that configuration to int, without re-installing that module.Is this possible.

Tried to write to schema service in an update hook like:

  $name = 'module.schema';
  $path = '/home/user/Drupal/docroot/modules/module/config/schema';
  $source = new FileStorage($path);
  /** @var \Drupal\Core\Config\ExtensionInstallStorage $active_schema */
  $active_schema = \Drupal::service('config.storage.schema');
  $active_schema->write($name, $source->read($name));

But it turns out that "Write operation is not allowed." and that does not sound like a surprise.. :)

So is there another solution for this schema update, except re-installing the module?

Thank you.

  • 1
    Possible duplicate of How to update the database schema without losing existing data – leymannx Nov 29 '18 at 12:56
  • Thanks @leymannx, I think its not, im talking about configuration schema and not field schema, but I may be wrong – Pan Chrono Nov 29 '18 at 12:59
  • 1
    The database schema is something different. – kiamlaluno Nov 29 '18 at 14:45
  • 1
    See hook_post_update_NAME which allows to modify configuration. You would change the schema in code, and write a post update to modify existing config I think. Theoretically... – mradcliffe Nov 29 '18 at 18:22
  • 1
    The schema is a file provied by your module, just like routing.yml, permissions.yml and so on. You don't have to update that, it just needs a cache clear. If you do want to update something, then you could update the actual config with the regular config API, but not sure that's really worth it, as you said yourself, the next resave should take care of it. – Berdir Dec 1 '18 at 0:08
1

Well it turns out I spent some time here because I tried to update the schema file, by typing int not integer LOL. All I needed was integer and clear caches after all :)

0

I think everything you need is here: https://www.drupal.org/docs/8/api/update-api/updating-configuration-in-drupal-8

The second example should be your case

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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