additionals/db/migrate/005_create_dashboard_defaults.rb
2022-01-10 18:09:34 +01:00

31 lines
1.1 KiB
Ruby

# frozen_string_literal: true
class CreateDashboardDefaults < ActiveRecord::Migration[5.2]
def up
User.current = User.find_by(id: ENV['DEFAULT_USER_ID'].presence || User.admin.active.first.id)
unless Dashboard.exists? dashboard_type: DashboardContentWelcome::TYPE_NAME
puts 'Creating welcome default dashboard'
Dashboard.create! name: 'Welcome dashboard',
dashboard_type: DashboardContentWelcome::TYPE_NAME,
system_default: true,
author_id: User.current.id,
visibility: 2
end
return if Dashboard.exists? dashboard_type: DashboardContentProject::TYPE_NAME
puts 'Creating project default dashboard'
Dashboard.create! name: 'Project dashboard',
dashboard_type: DashboardContentProject::TYPE_NAME,
system_default: true,
enable_sidebar: true,
author_id: User.current.id,
visibility: 2
raise 'Default dashboard are not created. Solve database problems and re-run migration!' unless Dashboard.count == 2
end
def down; end
end