seeds.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (C) 2012-2024 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. ApplicationModel.reset_column_information
  16. # this is the __ordered__ list of seed files
  17. # extend only if needed - try to add your changes
  18. # to the matching one of the existing files
  19. 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]
  20. # loop over and load all seedfiles
  21. # files will get executed automatically
  22. seeds.each do |seed|
  23. # we use load here to be able to re-seed in one process (test env)
  24. load Rails.root.join('db', 'seeds', "#{seed}.rb")
  25. end
  26. # set basic settings via environment variables
  27. Setting.set('http_type', ENV['ZAMMAD_HTTP_TYPE']) if ENV['ZAMMAD_HTTP_TYPE']
  28. Setting.set('fqdn', ENV['ZAMMAD_FQDN']) if ENV['ZAMMAD_FQDN']
  29. Setting.set('storage_provider', 'S3') if ENV['S3_URL'] && Rails.env.production?
  30. # reset primary key sequences
  31. DbHelper.import_post
  32. # install locales and translations
  33. Locale.create_if_not_exists(
  34. locale: 'en-us',
  35. alias: 'en',
  36. name: __('English (United States)'),
  37. )
  38. Locale.sync
  39. Translation.sync
  40. Calendar.init_setup
  41. # install all packages in auto_install
  42. Package.auto_install