20210918163819_create_knowledge_base_permissions.rb 969 B

12345678910111213141516171819202122
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. # Using older 5.0 migration to stick to Integer primary keys. Otherwise migration fails in MySQL.
  3. class CreateKnowledgeBasePermissions < ActiveRecord::Migration[5.0]
  4. def change
  5. return if !Setting.exists?(name: 'system_init_done')
  6. create_table :knowledge_base_permissions do |t|
  7. t.references :permissionable, polymorphic: true, null: false, index: { name: 'index_knowledge_base_permissions_on_permissionable' }
  8. t.references :role, null: false, foreign_key: { to_table: :roles }
  9. t.string 'access', limit: 50, default: 'full', null: false
  10. t.index 'access'
  11. t.index %i[role_id permissionable_id permissionable_type], unique: true, name: 'knowledge_base_permissions_uniqueness'
  12. t.timestamps limit: 3
  13. end
  14. Permission.where(name: 'knowledge_base.reader').update_all(allow_signup: true) # rubocop:disable Rails/SkipsModelValidations
  15. end
  16. end