viewy 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/db/migrate/20151005150022_update_dependency_views.rb +75 -0
- data/lib/viewy.rb +12 -2
- data/lib/viewy/dependency_manager.rb +1 -0
- data/lib/viewy/models.rb +1 -0
- data/lib/viewy/models/materialized_view_dependency.rb +1 -1
- data/lib/viewy/models/view_dependency.rb +11 -0
- data/lib/viewy/version.rb +1 -1
- metadata +3 -2
- data/lib/viewy/materialized_views.rb +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8e8ccd085001708797e349fe6919ddcde5fa48b
|
|
4
|
+
data.tar.gz: 52b404095aab8d64a1a1405c9e60b7e5844bdab4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b1f64815917317f3003f19680a4a2672a5d8c125bf4e199e90fb10ebca8a10225a3ededad987ac35fc40eff2440912d82ecd661c67d954aad3993859abea29d9
|
|
7
|
+
data.tar.gz: f70abc7ff1750590aadf3a22f7ab2f8ae1e219a4da23fd0dbe896cb4294ea0a784355285e602827ad64074cdcd5d09e05f04b7dcb524bb4c6503b432ff366380
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
class UpdateDependencyViews < ActiveRecord::Migration
|
|
2
|
+
def up
|
|
3
|
+
dependency_sql = <<-SQL
|
|
4
|
+
DROP MATERIALIZED VIEW materialized_view_dependencies;
|
|
5
|
+
CREATE MATERIALIZED VIEW materialized_view_dependencies AS
|
|
6
|
+
SELECT
|
|
7
|
+
matviewname AS view_name,
|
|
8
|
+
view_dependencies(matviewname),
|
|
9
|
+
TRUE AS materialized_view
|
|
10
|
+
FROM pg_matviews
|
|
11
|
+
WHERE matviewname != 'materialized_view_dependencies' AND matviewname != 'all_view_dependencies'
|
|
12
|
+
;
|
|
13
|
+
CREATE MATERIALIZED VIEW all_view_dependencies AS
|
|
14
|
+
WITH normal_view_dependencies AS (
|
|
15
|
+
SELECT viewname AS view_name, view_dependencies(viewname) FROM pg_views
|
|
16
|
+
)
|
|
17
|
+
SELECT * FROM materialized_view_dependencies
|
|
18
|
+
UNION
|
|
19
|
+
SELECT normal_view_dependencies.*, FALSE AS materialized_view FROM normal_view_dependencies WHERE array_length(normal_view_dependencies.view_dependencies, 1) > 0;
|
|
20
|
+
SQL
|
|
21
|
+
execute dependency_sql
|
|
22
|
+
|
|
23
|
+
trigger_sql = <<-SQL
|
|
24
|
+
CREATE OR REPLACE FUNCTION refresh_materialized_view_dependencies() RETURNS EVENT_TRIGGER AS $$
|
|
25
|
+
DECLARE
|
|
26
|
+
materialized_dependencies_exists BOOLEAN := (SELECT TRUE FROM pg_class WHERE pg_class.relname = 'materialized_view_dependencies' AND pg_class.relkind = 'm');
|
|
27
|
+
all_dependencies_exists BOOLEAN := (SELECT TRUE FROM pg_class WHERE pg_class.relname = 'all_view_dependencies' AND pg_class.relkind = 'm');
|
|
28
|
+
BEGIN
|
|
29
|
+
RAISE NOTICE 'refreshing view dependency hierarchy';
|
|
30
|
+
IF materialized_dependencies_exists THEN
|
|
31
|
+
REFRESH MATERIALIZED VIEW materialized_view_dependencies;
|
|
32
|
+
END IF;
|
|
33
|
+
IF all_dependencies_exists THEN
|
|
34
|
+
REFRESH MATERIALIZED VIEW all_view_dependencies;
|
|
35
|
+
END IF;
|
|
36
|
+
END
|
|
37
|
+
$$ LANGUAGE plpgsql;
|
|
38
|
+
SQL
|
|
39
|
+
|
|
40
|
+
execute trigger_sql
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def down
|
|
44
|
+
dependency_sql = <<-SQL
|
|
45
|
+
DROP MATERIALIZED VIEW materialized_view_dependencies;
|
|
46
|
+
DROP MATERIALIZED VIEW all_view_dependencies;
|
|
47
|
+
|
|
48
|
+
CREATE MATERIALIZED VIEW materialized_view_dependencies AS
|
|
49
|
+
WITH normal_view_dependencies AS (
|
|
50
|
+
SELECT viewname AS view_name, view_dependencies(viewname) FROM pg_views
|
|
51
|
+
)
|
|
52
|
+
SELECT matviewname AS view_name, view_dependencies(matviewname), TRUE AS materialized_view FROM pg_matviews WHERE matviewname != 'materialized_view_dependencies'
|
|
53
|
+
UNION
|
|
54
|
+
SELECT normal_view_dependencies.*, FALSE AS materialized_view FROM normal_view_dependencies WHERE array_length(normal_view_dependencies.view_dependencies, 1) > 0;
|
|
55
|
+
;
|
|
56
|
+
SQL
|
|
57
|
+
execute dependency_sql
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
trigger_sql = <<-SQL
|
|
61
|
+
CREATE OR REPLACE FUNCTION refresh_materialized_view_dependencies() RETURNS EVENT_TRIGGER AS $$
|
|
62
|
+
DECLARE
|
|
63
|
+
view_exists BOOLEAN := (SELECT TRUE FROM pg_class WHERE pg_class.relname = 'materialized_view_dependencies' AND pg_class.relkind = 'm');
|
|
64
|
+
BEGIN
|
|
65
|
+
RAISE NOTICE 'refreshing view dependency hierarchy';
|
|
66
|
+
IF view_exists THEN
|
|
67
|
+
REFRESH MATERIALIZED VIEW materialized_view_dependencies;
|
|
68
|
+
END IF;
|
|
69
|
+
END
|
|
70
|
+
$$ LANGUAGE plpgsql;
|
|
71
|
+
SQL
|
|
72
|
+
|
|
73
|
+
execute trigger_sql
|
|
74
|
+
end
|
|
75
|
+
end
|
data/lib/viewy.rb
CHANGED
|
@@ -9,15 +9,25 @@ require 'viewy/dependency_manager'
|
|
|
9
9
|
# of views and their dependencies
|
|
10
10
|
module Viewy
|
|
11
11
|
# Calling this method will refresh the materialized view that stores the dependency information for other
|
|
12
|
-
# views in the system
|
|
12
|
+
# materialized views in the system
|
|
13
13
|
#
|
|
14
14
|
# @raise [ActiveRecord::StatementInvalidError] raised if a dependent view is somehow not refreshed correctly
|
|
15
15
|
# @return [PG::Result] the result of the refresh statement on the materialized view
|
|
16
|
-
def self.
|
|
16
|
+
def self.refresh_materialized_dependency_information
|
|
17
17
|
view_refresher = Viewy::DependencyManagement::ViewRefresher.new(connection)
|
|
18
18
|
view_refresher.refresh_materialized_view('materialized_view_dependencies')
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
# Calling this method will refresh the materialized view that stores the dependency information for other
|
|
22
|
+
# views in the system
|
|
23
|
+
#
|
|
24
|
+
# @raise [ActiveRecord::StatementInvalidError] raised if a dependent view is somehow not refreshed correctly
|
|
25
|
+
# @return [PG::Result] the result of the refresh statement on the materialized view
|
|
26
|
+
def self.refresh_all_dependency_information
|
|
27
|
+
view_refresher = Viewy::DependencyManagement::ViewRefresher.new(connection)
|
|
28
|
+
view_refresher.refresh_materialized_view('all_view_dependencies')
|
|
29
|
+
end
|
|
30
|
+
|
|
21
31
|
# The connection used by viewy to manage views
|
|
22
32
|
#
|
|
23
33
|
# @return [ActiveRecord::ConnectionAdapters::PostgreSQLAdapter] An ActiveRecord connection
|
|
@@ -8,6 +8,7 @@ module Viewy
|
|
|
8
8
|
#
|
|
9
9
|
# @raise [ActiveRecord::StatementInvalidError] raised if a view is somehow not refreshed correctly
|
|
10
10
|
def refresh_all_materialized_views
|
|
11
|
+
Viewy.refresh_materialized_dependency_information
|
|
11
12
|
view_refresher.refresh_all_materialized_views
|
|
12
13
|
end
|
|
13
14
|
|
data/lib/viewy/models.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module Viewy
|
|
2
2
|
module Models
|
|
3
|
-
# Provides a means of accessing information about view dependencies from within a Rails app.
|
|
3
|
+
# Provides a means of accessing information about view dependencies for a materialized view from within a Rails app.
|
|
4
4
|
# The foreign key of the dependency information table is the name of the view that a user needs
|
|
5
5
|
# dependency information about.
|
|
6
6
|
class MaterializedViewDependency < ActiveRecord::Base
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Viewy
|
|
2
|
+
module Models
|
|
3
|
+
# Provides a means of accessing information about view dependencies from within a Rails app.
|
|
4
|
+
# The foreign key of the dependency information table is the name of the view that a user needs
|
|
5
|
+
# dependency information about.
|
|
6
|
+
class ViewDependency < ActiveRecord::Base
|
|
7
|
+
self.table_name = 'all_view_dependencies'
|
|
8
|
+
self.primary_key = 'view_name'
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
data/lib/viewy/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: viewy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Emerson Huitt
|
|
@@ -79,6 +79,7 @@ files:
|
|
|
79
79
|
- config/routes.rb
|
|
80
80
|
- db/migrate/20150929144540_add_view_replace_function.rb
|
|
81
81
|
- db/migrate/20150929205301_add_view_dependencies.rb
|
|
82
|
+
- db/migrate/20151005150022_update_dependency_views.rb
|
|
82
83
|
- lib/tasks/viewy_tasks.rake
|
|
83
84
|
- lib/viewy.rb
|
|
84
85
|
- lib/viewy/acts_as_materialized_view.rb
|
|
@@ -87,9 +88,9 @@ files:
|
|
|
87
88
|
- lib/viewy/dependency_management/view_refresher.rb
|
|
88
89
|
- lib/viewy/dependency_manager.rb
|
|
89
90
|
- lib/viewy/engine.rb
|
|
90
|
-
- lib/viewy/materialized_views.rb
|
|
91
91
|
- lib/viewy/models.rb
|
|
92
92
|
- lib/viewy/models/materialized_view_dependency.rb
|
|
93
|
+
- lib/viewy/models/view_dependency.rb
|
|
93
94
|
- lib/viewy/version.rb
|
|
94
95
|
homepage: http://www.scimedsolutions.com
|
|
95
96
|
licenses:
|