aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/webapp/WEB-INF/db/migrate/151_create_dashboards.rb
blob: 80af98ef785e42c4541f7684830032b92252fe3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#
# Sonar, entreprise quality control tool.
# Copyright (C) 2009 SonarSource SA
# mailto:contact AT sonarsource DOT com
#
# Sonar is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# Sonar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with Sonar; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
#

class CreateDashboards < ActiveRecord::Migration
  def self.up

    create_table :active_dashboards do |t|
      t.column :dashboard_id, :integer, :null => false
      t.column :user_id, :integer, :null => true
      t.column :order_index, :integer, :null => true
    end
    add_index :active_dashboards, [:user_id], :name => 'active_dashboards_userid'
    add_index :active_dashboards, [:dashboard_id], :name => 'active_dashboards_dashboardid'

    create_table :dashboards do |t|
      t.column :user_id, :integer, :null => true
      t.column :name, :string, :null => true, :limit => 256
      t.column :description, :string, :null => true, :limit => 1000
      t.column :column_layout, :string, :null => true, :limit => 10
      t.column :shared, :boolean, :null => true
      t.timestamps
    end

    create_table :widgets do |t|
      t.column :dashboard_id, :integer, :null => false
      t.column :widget_key, :string, :null => false, :limit => 256
      t.column :name, :string, :null => true, :limit => 256
      t.column :description, :string, :null => true, :limit => 1000
      t.column :column_index, :integer, :null => true
      t.column :row_index, :integer, :null => true
      t.column :configured, :boolean, :null => true
      t.timestamps
    end
    add_index :widgets, [:dashboard_id], :name => 'widgets_dashboards'
    add_index :widgets, [:widget_key], :name => 'widgets_widgetkey'

    create_table :widget_properties do |t|
      t.column :widget_id, :integer, :null => false
      t.column :kee, :string, :null => true, :limit => 100
      t.column :text_value, :string, :null => true, :limit => 4000
      t.column :value_type, :string, :null => true, :limit => 20
    end
    add_index :widget_properties, [:widget_id], :name => 'widget_properties_widgets'

    add_default_dashboards()
  end

  private

  def self.create_dashboard
    dashboard=::Dashboard.new(:name => 'Dashboard', :shared => true, :description => 'Default dashboard', :column_layout => "50-50")
    dashboard.widgets.build(:widget_key => 'static_analysis', :name => 'Static analysis', :column_index => 1, :row_index => 1, :configured => true)
    dashboard.widgets.build(:widget_key => 'comments_duplications', :name => 'Comments duplications', :column_index => 1, :row_index => 2, :configured => true)
    dashboard.widgets.build(:widget_key => 'extended_analysis', :name => 'Extended analysis', :column_index => 1, :row_index => 3, :configured => true)
    dashboard.widgets.build(:widget_key => 'code_coverage', :name => 'Code coverage', :column_index => 1, :row_index => 4, :configured => true)
    dashboard.widgets.build(:widget_key => 'events', :name => 'Events', :column_index => 1, :row_index => 5, :configured => true)
    dashboard.widgets.build(:widget_key => 'description', :name => 'Description', :column_index => 1, :row_index => 6, :configured => true)
    dashboard.widgets.build(:widget_key => 'rules', :name => 'Rules', :column_index => 2, :row_index => 1, :configured => true)
    dashboard.widgets.build(:widget_key => 'alerts', :name => 'Alerts', :column_index => 2, :row_index => 2, :configured => true)
    dashboard.widgets.build(:widget_key => 'custom_measures', :name => 'Custom measures', :column_index => 2, :row_index => 3, :configured => true)
    dashboard.widgets.build(:widget_key => 'file-design', :name => 'File design', :column_index => 2, :row_index => 4, :configured => true)
    dashboard.widgets.build(:widget_key => 'package-design', :name => 'Package design', :column_index => 2, :row_index => 5, :configured => true)
    dashboard.widgets.build(:widget_key => 'ckjm', :name => 'CKJM', :column_index => 2, :row_index => 6, :configured => true)

    dashboard.save
    dashboard
  end

  def self.add_default_dashboards
    dashboard=create_dashboard()
    ActiveDashboard.create(:dashboard => dashboard, :user_id => nil, :order_index => 1)
  end
end