20220829100535_create_public_links.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class CreatePublicLinks < ActiveRecord::Migration[6.1]
  3. def change
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. add_table
  7. add_index :public_links, [:link], unique: true
  8. add_foreign_key :public_links, :users, column: :created_by_id
  9. add_foreign_key :public_links, :users, column: :updated_by_id
  10. add_permission
  11. end
  12. private
  13. def add_table
  14. create_table :public_links do |t|
  15. t.string :link, limit: 500, null: false
  16. t.string :title, limit: 200, null: false
  17. t.string :description, limit: 200, null: true
  18. if Rails.application.config.db_column_array
  19. t.string :screen, null: false, array: true
  20. else
  21. t.json :screen, null: false
  22. end
  23. t.boolean :new_tab, null: false, default: true
  24. t.integer :prio, null: false
  25. t.column :updated_by_id, :integer, null: false
  26. t.column :created_by_id, :integer, null: false
  27. t.timestamps limit: 3, null: false
  28. end
  29. end
  30. def add_permission
  31. Permission.create_if_not_exists(
  32. name: 'admin.public_links',
  33. note: 'Manage %s',
  34. preferences: {
  35. translations: ['Public Links']
  36. },
  37. )
  38. end
  39. end