seeds.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. # This file should contain all the record creation needed to seed the database with its default values.
  3. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
  4. #
  5. # Examples:
  6. #
  7. # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
  8. # Mayor.create(:name => 'Emanuel', :city => cities.first)
  9. if User.any?
  10. warn 'Database already has data, skipping seed.'
  11. return
  12. end
  13. # clear old caches to start from scratch
  14. Rails.cache.clear
  15. # this is the __ordered__ list of seed files
  16. # extend only if needed - try to add your changes
  17. # to the matching one of the existing files
  18. seeds = %w[settings user_nr_1 signatures roles permissions groups links ticket_state_types ticket_states ticket_priorities ticket_article_types ticket_article_senders macros community_user_resources overviews channels report_profiles chats object_manager_attributes schedulers triggers core_workflow]
  19. # loop over and load all seedfiles
  20. # files will get executed automatically
  21. seeds.each do |seed|
  22. # we use load here to be able to re-seed in one process (test env)
  23. load Rails.root.join('db', 'seeds', "#{seed}.rb")
  24. end
  25. # set basic Rails server settings via environment variables
  26. Setting.set('http_type', ENV['ZAMMAD_HTTP_TYPE']) if ENV['ZAMMAD_HTTP_TYPE']
  27. Setting.set('fqdn', ENV['ZAMMAD_FQDN']) if ENV['ZAMMAD_FQDN']
  28. # reset primary key sequences
  29. DbHelper.import_post
  30. # install locales and translations
  31. Locale.create_if_not_exists(
  32. locale: 'en-us',
  33. alias: 'en',
  34. name: __('English (United States)'),
  35. )
  36. Locale.sync
  37. Translation.sync
  38. Calendar.init_setup
  39. # install all packages in auto_install
  40. Package.auto_install