monocle-views 0.1.7 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71b4dae54e7413c864bc7647293313599525af68
4
- data.tar.gz: c8b2ca16c6ead7b30f01c34ef6c9faaae7f0b02f
3
+ metadata.gz: 53586f4daaba8fb51c88c7e6a21120a3f4e6ab16
4
+ data.tar.gz: f76088758289e841ff8b6d1d90a12963b41995c9
5
5
  SHA512:
6
- metadata.gz: b4e071b3599073aa7390b8cc6e31f551b001cd6dba47568469e7a3896db7728efeb1405a256a668cc082ae24258f06367acddefc82f3272e4e5b4aafb287902a
7
- data.tar.gz: 79c9f5e9c97f8382fde8d7448811425a1519254ea2c5f36a1d96648beb3e2dba7388ebebaf2ec0a83806cd3ac2574ba1ca2f8316b352ec52885b9bfa1bb43fa9
6
+ metadata.gz: f04d6a94c484e8c9f9fafb6d60128ed532c294494d67608dfca41e1c521964bfdb0c52520c1ffc3a046c7fad25ce93b2ad9001d1eed30f3f8dec260c83eb1b42
7
+ data.tar.gz: 8eb2112b7f67c0883cdcda43469b076e846e829a93abdc7b27ad2e54389db2ba23566b4d90b212a1778179505d8a0e5d105bb2c7fa5a57e00dbd317a06089692
@@ -11,6 +11,7 @@ require "monocle/view"
11
11
  require "monocle/migration"
12
12
 
13
13
  require "monocle/bump_command"
14
+ require "monocle/drop_command"
14
15
  require "monocle/list_command"
15
16
 
16
17
  module Monocle
@@ -47,6 +48,10 @@ module Monocle
47
48
  BumpCommand.new(fetch(view_name)).call
48
49
  end
49
50
 
51
+ def drop(view_name)
52
+ DropCommand.new(fetch(view_name)).call
53
+ end
54
+
50
55
  def refresh(view_name, concurrently: false)
51
56
  fetch(view_name).refresh concurrently: concurrently
52
57
  end
@@ -9,6 +9,7 @@ module Monocle::Generators
9
9
  create_file "db/views/#{file_name}.sql" do
10
10
  <<-EOF
11
11
  -- Timestamp: #{Time.now}
12
+ DROP MATERIALIZED VIEW IF EXISTS #{file_name};
12
13
  CREATE MATERIALIZED VIEW #{file_name} AS
13
14
  -- Add your stuff here
14
15
  ;
@@ -1,3 +1,3 @@
1
1
  module Monocle
2
- VERSION = "0.1.7"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -9,10 +9,16 @@ module Monocle
9
9
 
10
10
  def generate
11
11
  timestamp = File.open path, &:readline
12
- fail "can't read timestamp of #{path}! Aborting..." unless timestamp.starts_with? "-- Timestamp: "
13
- # Get only the digits out of the timestamp line
14
- timestamp.gsub!(/[^\d]/, '')
15
- "#{view}_#{timestamp}"
12
+ case timestamp
13
+ when /^-- Timestamp:/
14
+ # Get only the digits out of the timestamp line
15
+ timestamp.gsub!(/[^\d]/, '')
16
+ return "#{view}_#{timestamp}"
17
+ when /^-- Drop/
18
+ return :drop
19
+ else
20
+ fail "can't read timestamp of #{path}! Aborting..."
21
+ end
16
22
  end
17
23
  end
18
24
  end
@@ -16,6 +16,9 @@ module Monocle
16
16
  !!(@materialized ||= create_command =~ /MATERIALIZED VIEW/i)
17
17
  end
18
18
 
19
+ def drop_requested?
20
+ end
21
+
19
22
  def drop
20
23
  debug "Dropping #{name}..."
21
24
  self.dependants = get_dependants_from_pg
@@ -46,6 +49,11 @@ module Monocle
46
49
  end
47
50
 
48
51
  def migrate
52
+ if :drop == slug
53
+ drop
54
+ info "#{name} dropped."
55
+ return true
56
+ end
49
57
  if versions.include?(slug)
50
58
  debug "Skipping #{name} as it's already up to date."
51
59
  true
@@ -57,6 +65,11 @@ module Monocle
57
65
  end
58
66
 
59
67
  def refresh(concurrently: false)
68
+ if :drop == slug
69
+ drop
70
+ info "#{name} dropped."
71
+ return true
72
+ end
60
73
  # We don't refresh normal views
61
74
  return false unless materialized?
62
75
  _concurrently = " CONCURRENTLY" if concurrently
@@ -20,7 +20,7 @@ namespace :monocle do
20
20
  Monocle.refresh(args.view_name)
21
21
  end
22
22
 
23
- desc "Refreshes a given monocle view"
23
+ desc "Refreshes all monocle views"
24
24
  task :refresh_all => :environment do |t, args|
25
25
  Monocle.refresh_all
26
26
  end
@@ -31,4 +31,10 @@ namespace :monocle do
31
31
  view_name = args.view_name
32
32
  Monocle.bump(view_name)
33
33
  end
34
+
35
+ desc "drop a monocle view"
36
+ task :drop, [:view_name] => :environment do |t, args|
37
+ view_name = args.view_name
38
+ Monocle.drop(view_name)
39
+ end
34
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monocle-views
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonardo Bighetti