File: schema.rb

package info (click to toggle)
puppet 3.7.2-4+deb8u1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 18,912 kB
  • ctags: 13,168
  • sloc: ruby: 210,410; sh: 2,050; xml: 1,554; lisp: 300; makefile: 142; python: 108; sql: 103; yacc: 72
file content (136 lines) | stat: -rw-r--r-- 4,782 bytes parent folder | download | duplicates (2)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
require 'stringio'

class Puppet::Rails::Schema
  def self.init
    oldout = nil
    text = ''
    Puppet::Util.benchmark(Puppet, :notice, "Initialized database") do
      # We want to rewrite stdout, so we don't get migration messages.
      oldout = $stdout
      $stdout = StringIO.new(text, 'w')
      ActiveRecord::Schema.define do
        create_table :resources do |t|
          t.column :title, :text, :null => false
          t.column :restype,  :string, :null => false
          t.column :host_id, :integer
          t.column :source_file_id, :integer
          t.column :exported, :boolean
          t.column :line, :integer
          t.column :updated_at, :datetime
          t.column :created_at, :datetime
        end
        add_index :resources, :host_id
        add_index :resources, :source_file_id

        # Thanks, mysql!  MySQL requires a length on indexes in text fields.
        # So, we provide them for mysql and handle everything else specially.
        # Oracle doesn't index on CLOB fields, so we skip it
        if ['mysql','mysql2'].include? Puppet[:dbadapter]
          execute "CREATE INDEX typentitle ON resources (restype,title(50));"
        elsif Puppet[:dbadapter] != "oracle_enhanced"
          add_index :resources, [:title, :restype]
        end

        create_table :source_files do |t|
          t.column :filename, :string
          t.column :path, :string
          t.column :updated_at, :datetime
          t.column :created_at, :datetime
        end
        add_index :source_files, :filename

        create_table :resource_tags do |t|
          t.column :resource_id, :integer
          t.column :puppet_tag_id, :integer
          t.column :updated_at, :datetime
          t.column :created_at, :datetime
        end
        add_index :resource_tags, :resource_id
        add_index :resource_tags, :puppet_tag_id

        create_table :puppet_tags do |t|
          t.column :name, :string
          t.column :updated_at, :datetime
          t.column :created_at, :datetime
        end

        # Oracle automatically creates a primary key index
        add_index :puppet_tags, :id if Puppet[:dbadapter] != "oracle_enhanced"

        create_table :hosts do |t|
          t.column :name, :string, :null => false
          t.column :ip, :string
          t.column :environment, :text
          t.column :last_compile, :datetime
          t.column :last_freshcheck, :datetime
          t.column :last_report, :datetime
          #Use updated_at to automatically add timestamp on save.
          t.column :updated_at, :datetime
          t.column :source_file_id, :integer
          t.column :created_at, :datetime
        end
        add_index :hosts, :source_file_id
        add_index :hosts, :name

        create_table :fact_names do |t|
          t.column :name, :string, :null => false
          t.column :updated_at, :datetime
          t.column :created_at, :datetime
        end
        add_index :fact_names, :name

        create_table :fact_values do |t|
          t.column :value, :text, :null => false
          t.column :fact_name_id, :integer, :null => false
          t.column :host_id, :integer, :null => false
          t.column :updated_at, :datetime
          t.column :created_at, :datetime
        end
        add_index :fact_values, :fact_name_id
        add_index :fact_values, :host_id

        create_table :param_values do |t|
          t.column :value,  :text, :null => false
          t.column :param_name_id, :integer, :null => false
          t.column :line, :integer
          t.column :resource_id, :integer
          t.column :updated_at, :datetime
          t.column :created_at, :datetime
        end
        add_index :param_values, :param_name_id
        add_index :param_values, :resource_id

        create_table :param_names do |t|
          t.column :name, :string, :null => false
          t.column :updated_at, :datetime
          t.column :created_at, :datetime
        end
        add_index :param_names, :name

        create_table :inventory_nodes do |t|
          t.column :name, :string, :null => false
          t.column :timestamp, :datetime, :null => false
          t.column :updated_at, :datetime
          t.column :created_at, :datetime
        end

        add_index :inventory_nodes, :name, :unique => true

        create_table :inventory_facts do |t|
          t.column :node_id, :integer, :null => false
          t.column :name, :string, :null => false
          t.column :value, :text, :null => false
        end

        add_index :inventory_facts, [:node_id, :name], :unique => true
      end
    end
  rescue Exception => e
    $stderr.puts e
    $stderr.puts "The output from running the code was:", text
    raise e
  ensure
    $stdout = oldout if oldout
  end
end