Zammad Package database migration

Hello, how I can add settings to database from .zpm?
I have code in db/seed (.zpm package), but it don’t create & update records in database.

Setting.create_or_update(
  title:       __('Ticket Number Format'),
  name:        'ticket_number',
  area:        'Ticket::Number',
  description: __("Selects the ticket number generator module.
* **Increment** increments the ticket number, the SystemID and the counter are used with SystemID.Counter format (e.g. 1010138, 1010139).
* With **Date** the ticket numbers will be generated by the current date, the SystemID and the counter. The format looks like Year.Month.Day.SystemID.counter (e.g. 201206231010138, 201206231010139)."),
  options:     {
    form: [
      {
        display:   '',
        null:      true,
        name:      'ticket_number',
        tag:       'select',
        translate: true,
        options:   {
          'Ticket::Number::Increment' => __('Increment (SystemID.Counter)'),
          'Ticket::Number::Date'      => __('Date (Year.Month.Day.SystemID.Counter)'),
          'Ticket::Number::Year'      => __('Date (Year.Month.Day.SystemID.Counter)'),
        },
      },
    ],
  },
  state:       'Ticket::Number::Increment',
  preferences: {
    settings_included: %w[ticket_number_increment ticket_number_date ticket_number_year],
    controller:        'SettingsAreaTicketNumber',
    permission:        ['admin.ticket'],
  },
  frontend:    false
)

Setting.create_if_not_exists(
  title:       __('Ticket Number Year'),
  name:        'ticket_number_year',
  area:        'Ticket::Number',
  description: '-',
  options:     {
    form: [
      {
        display: __('Checksum'),
        null:    true,
        name:    'checksum',
        tag:     'boolean',
        options: {
          true  => 'yes',
          false => 'no',
        },
      },
      {
        display: __('Min. size of number'),
        null:    true,
        name:    'min_size',
        tag:     'select',
        options: {
          1  => ' 1',
          2  => ' 2',
          3  => ' 3',
          4  => ' 4',
          5  => ' 5',
          6  => ' 6',
          7  => ' 7',
          8  => ' 8',
          9  => ' 9',
          10 => '10',
          11 => '11',
          12 => '12',
          13 => '13',
          14 => '14',
          15 => '15',
          16 => '16',
          17 => '17',
          18 => '18',
          19 => '19',
          20 => '20',
        },
      },
    ],
  },
  state:       {
    checksum: false,
    min_size: 5,
  },
  preferences: {
    permission: ['admin.ticket'],
    hidden:     true,
  },
  frontend:    false
)

What is wrong?

Ok! I solved it.
Solve: I need add to file db/seeds.rb in array name of seed file.
Unfortunately, in this way, it is necessary to tracking and make all zammad updates manually

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

Here is an example how to setup a setting via package migration properly:

example-test_setting.szpm

{
  "name": "Example-TestSetting",
  "version": "6.0.0",
  "vendor": "Example GmbH",
  "license": "GNU AFFERO GENERAL PUBLIC LICENSE",
  "url": "http://example.com/",
  "change_log": [

  ],
  "description": [
    {
      "language": "en",
      "text": "This package shows how to setup a setting via package."
    },
    {
      "language": "de",
      "text": "Dieses Paket zeigt wie man ein Setting via Paket anlegt."
    }
  ],
  "files": [
    {
      "location": "db/addon/example_test_setting/20220622100100_create_base.rb",
      "permission": 644
    }
  ]
}

db/addon/example_test_setting/20220622100100_create_base.rb

class CreateBase < ActiveRecord::Migration[4.2]
  def self.up
    # return if it's a new setup
    return if !Setting.exists?(name: 'system_init_done')

    Setting.create_or_update(
      title:       __('Ticket Number Format'),
      name:        'ticket_number',
      area:        'Ticket::Number',
      description: __("Selects the ticket number generator module.
* **Increment** increments the ticket number, the SystemID and the counter are used with SystemID.Counter format (e.g. 1010138, 1010139).
* With **Date** the ticket numbers will be generated by the current date, the SystemID and the counter. The format looks like Year.Month.Day.SystemID.counter (e.g. 201206231010138, 201206231010139)."),
      options:     {
        form: [
          {
            display:   '',
            null:      true,
            name:      'ticket_number',
            tag:       'select',
            translate: true,
            options:   {
              'Ticket::Number::Increment' => __('Increment (SystemID.Counter)'),
              'Ticket::Number::Date'      => __('Date (Year.Month.Day.SystemID.Counter)'),
              'Ticket::Number::Year'      => __('Date (Year.Month.Day.SystemID.Counter)'),
            },
          },
        ],
      },
      state:       'Ticket::Number::Increment',
      preferences: {
        settings_included: %w[ticket_number_increment ticket_number_date ticket_number_year],
        controller:        'SettingsAreaTicketNumber',
        permission:        ['admin.ticket'],
      },
      frontend:    false
    )

    Setting.create_if_not_exists(
      title:       __('Ticket Number Year'),
      name:        'ticket_number_year',
      area:        'Ticket::Number',
      description: '-',
      options:     {
        form: [
          {
            display: __('Checksum'),
            null:    true,
            name:    'checksum',
            tag:     'boolean',
            options: {
              true  => 'yes',
              false => 'no',
            },
          },
          {
            display: __('Min. size of number'),
            null:    true,
            name:    'min_size',
            tag:     'select',
            options: {
              1  => ' 1',
              2  => ' 2',
              3  => ' 3',
              4  => ' 4',
              5  => ' 5',
              6  => ' 6',
              7  => ' 7',
              8  => ' 8',
              9  => ' 9',
              10 => '10',
              11 => '11',
              12 => '12',
              13 => '13',
              14 => '14',
              15 => '15',
              16 => '16',
              17 => '17',
              18 => '18',
              19 => '19',
              20 => '20',
            },
          },
        ],
      },
      state:       {
        checksum: false,
        min_size: 5,
      },
      preferences: {
        permission: ['admin.ticket'],
        hidden:     true,
      },
      frontend:    false
    )
  end

  def self.down
    Setting.find_by(name: 'ticket_number').destroy
    Setting.find_by(name: 'ticket_number_year').destroy
  end
end