Class: PGAssets::Services::PGAssetManager

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_assets/services/pg_asset_manager.rb

Class Method Summary collapse

Class Method Details

.assets_dumpObject



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
# File 'lib/pg_assets/services/pg_asset_manager.rb', line 33

def self.assets_dump
  newline = "\n"
  assets = ''

  assets << '------------------------------ PG ASSETS ------------------------------' + newline
  assets << '--  BRO, DON\'T MODIFY THIS DIRECTLY' + newline
  assets << '--  IF YOU MODIFY THIS DIRECTLY,' + newline
  assets << '--  YOU\'RE GONNA HAVE A BAD TIME' + newline
  assets << '-----------------------------------------------------------------------' + newline

  views.each do |v|
    assets << newline
    assets << newline
    assets << '-----------------------------------------------------------------------' + newline
    assets << '---------- VIEW: ' + v.identity + newline
    assets << '-----------------------------------------------------------------------' + newline
    assets << v.sql_for_reinstall
  end

  matviews.each do |mv|
    assets << newline
    assets << newline
    assets << '-----------------------------------------------------------------------' + newline
    assets << '---------- MATERIALIZED VIEW: ' + mv.identity + newline
    assets << '-----------------------------------------------------------------------' + newline
    assets << mv.sql_for_reinstall
  end

  functions.each do |f|
    assets << newline
    assets << newline
    assets << '-----------------------------------------------------------------------' + newline
    assets << '---------- FUNCTION: ' + f.identity + newline
    assets << '-----------------------------------------------------------------------' + newline
    assets << f.sql_for_reinstall + ';' + newline
  end

  triggers.each do |t|
    assets << newline
    assets << newline
    assets << '-----------------------------------------------------------------------' + newline
    assets << '---------- TRIGGER: ' + t.identity + newline
    assets << '-----------------------------------------------------------------------' + newline
    assets << t.sql_for_remove + ';' + newline
    assets << newline
    assets << t.sql_for_reinstall + ';' + newline
  end

  constraints.each do |c|
    assets << newline
    assets << newline
    assets << '-----------------------------------------------------------------------' + newline
    assets << '---------- CONSTRAINT: ' + c.identity + newline
    assets << '-----------------------------------------------------------------------' + newline
    assets << c.sql_for_reinstall + ';' + newline
  end

  assets
end

.assets_load(assets) ⇒ Object



93
94
95
96
97
# File 'lib/pg_assets/services/pg_asset_manager.rb', line 93

def self.assets_load(assets)
  ActiveRecord::Base.transaction do
    ActiveRecord::Base.connection.execute assets
  end
end

.constraintsObject



29
30
31
# File 'lib/pg_assets/services/pg_asset_manager.rb', line 29

def self.constraints
  PGConstraint.ours.to_a.sort_by { |f| f.identity }
end

.functionsObject



25
26
27
# File 'lib/pg_assets/services/pg_asset_manager.rb', line 25

def self.functions
  PGFunction.ours.to_a.sort_by { |f| f.identity }
end

.matviewsObject



13
14
15
# File 'lib/pg_assets/services/pg_asset_manager.rb', line 13

def self.matviews
  PGMatView.ours.to_a.sort_by { |v| v.identity }
end

.specific_matview(name) ⇒ Object



17
18
19
# File 'lib/pg_assets/services/pg_asset_manager.rb', line 17

def self.specific_matview(name)
  PGMatView.ours.by_name(name).first
end

.specific_view(name) ⇒ Object



9
10
11
# File 'lib/pg_assets/services/pg_asset_manager.rb', line 9

def self.specific_view(name)
  PGView.ours.by_name(name).first
end

.triggersObject



21
22
23
# File 'lib/pg_assets/services/pg_asset_manager.rb', line 21

def self.triggers
  PGTrigger.ours.to_a.sort_by { |t| t.identity }
end

.viewsObject



5
6
7
# File 'lib/pg_assets/services/pg_asset_manager.rb', line 5

def self.views
  PGView.ours.to_a.sort_by { |v| v.identity }
end