psql_backups 1.0.0 → 1.0.1

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: c27379b979812d96141060b2cd4ac479ca6d7878
4
- data.tar.gz: 8b4aa952ea9c052641990d60aabf80a09248c73a
3
+ metadata.gz: 71de16ab1c76bc340318cd1401cd525e248a5e5c
4
+ data.tar.gz: 76be553efe6d182f74188433fde426c035afe4e5
5
5
  SHA512:
6
- metadata.gz: 54cb50985b6b16c76817939e602d183e22489030f88e73c05656cc10b281f031f4e464d4dbab0d0ee36edaad456c302c0d1837c75bdbdab7a9c3e88726be9149
7
- data.tar.gz: 634876737b4f9b1b24a46ee20ee04bde62db7aec4d489b62d7d11af1f13a370504232642a497edb85bc818ceb6f5debc350d2c954dc0172b9807e24f1628c9e2
6
+ metadata.gz: bafb2129c8313bbbc52d4aae384603d9603e474713e9bf549ae2bf1e2105f028d4970954c9ca603272ea9871f4f54e6f74a349ffa2cbeec31b84773e57d03f8a
7
+ data.tar.gz: a81c54b01779a870cf671fc7136a0319ebbd18ed2f3c116175ac3217658a3804d212fdbb3ce0927bdb1c65508e6df88e839da4bf021de83684f0365a9b91a297
@@ -1,3 +1,3 @@
1
1
  module PsqlBackups
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -67,13 +67,32 @@ namespace :psql_backups do
67
67
 
68
68
  puts "Your existing database will be replaced. Are you sure you want to continue? [y/N]"
69
69
  input = STDIN.gets.chomp
70
- raise Nope unless input.downcase == "y"
70
+ raise "User abort" unless input.downcase == "y"
71
71
 
72
72
  restore_dbname = "#{ dbname }_#{ args[:tag] }"
73
- backup_dbname = "#{ dbname }_#{ Time.current.strftime("%Y%m%d%H%M%S") }"
73
+ backup_dbname = "#{ dbname }_auto_#{ Time.current.strftime("%Y%m%d%H%M%S") }"
74
74
  ActiveRecord::Base.connection.disconnect!
75
75
  `psql -c "alter database #{ dbname } rename to #{ backup_dbname };"`
76
76
  `psql -c "create database #{ dbname } template #{ restore_dbname };"`
77
77
  end
78
+
79
+ desc "Clear auto backups"
80
+ task clear: :environment do
81
+ raise "Can only be run in development environment" unless Rails.env.development?
82
+ raise "Can only be run if configured for local database" unless ActiveRecord::Base.connection.raw_connection.conninfo_hash[:host].nil?
83
+
84
+ puts "All your auto-backups will be cleared. Are you sure you want to continue? [y/N]"
85
+ input = STDIN.gets.chomp
86
+ raise "User abort" unless input.downcase == "y"
87
+
88
+ dbname = ActiveRecord::Base.connection.raw_connection.conninfo_hash[:dbname]
89
+ lines = `psql -c "\\l" | grep #{ dbname }_auto_`.split("\n")
90
+ backups = lines.map{|l| l.split('|').first.strip}
91
+
92
+ ActiveRecord::Base.connection.disconnect!
93
+ backups.each do |backup_dbname|
94
+ `psql -c "drop database #{backup_dbname};"`
95
+ end
96
+ end
78
97
  end
79
98
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: psql_backups
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ajith Hussain