tidy_reset 0.1.7 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee3b2f4de00346cb4d31fe33d07923462f021ffb
4
- data.tar.gz: f22b8181daff87cace62ea5b6f0070a13edfda45
3
+ metadata.gz: 2467525c189eb0dfdaa6214ba410575a054701b3
4
+ data.tar.gz: 61bb134500c23e1a8a300e60e342df0235296bf9
5
5
  SHA512:
6
- metadata.gz: 5a27f20e94423bfd79d304efd266ac515deb599d2af4faadb3d6d84ccfd39533666214c00bc05431d6f86fc03794ec17f763c27a754ef3ab9848119fe88d67cc
7
- data.tar.gz: 80de73d3dadc5073d950882733a99a9968c47568bdde2a63d1dd1c0e3b9d339f33c9bdba4f31a328b18f85d935f2af2db235bb9832c183752ec2e35e3bb96499
6
+ metadata.gz: 31a97e89ae24b52b236c5bdb93c3c60e08206038fbdec42b366d513c6e8db303f59acb53aa20287ac988e27126c9dbd2596cb95d3fb517d7f3d24fff1f8cb7c2
7
+ data.tar.gz: adaca1fcc6306bcc0dffb786b00956f6ddf51a4c357dff3af887b1c0cf97cf04907747b6a4d570e25d66053b702afadd61abf84d9f9356c3c84e2c3a81b8a35f
data/README.md CHANGED
@@ -70,4 +70,9 @@ test:
70
70
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
71
71
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
72
72
 
73
-
73
+ ## Releasing tidy_reset
74
+ ```
75
+ # Using the Ruby jeweler
76
+ rake version:bump:patch
77
+ rake release REMOTE=upstream
78
+ ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 0.1.11
data/lib/tidy_reset.rb CHANGED
@@ -27,12 +27,18 @@ module TidyReset
27
27
  end
28
28
 
29
29
  def database_purge(db_config)
30
- begin
31
- encoding = configuration.database_encoding
32
- ActiveRecord::Base.remove_connection
30
+ encoding = configuration.database_encoding
31
+ ActiveRecord::Base.remove_connection
32
+
33
+ # Choose proper connection method when ActiveRecord uses activerecord-import
34
+ if ActiveRecord::Base.respond_to?(:establish_connection_without_activerecord_import)
35
+ establish_connection_method = :establish_connection_without_activerecord_import
36
+ else
37
+ establish_connection_method = :establish_connection
38
+ end
33
39
 
34
- activerecord_import_exists = ActiveRecord::Base.respond_to?(:establish_connection_without_activerecord_import)
35
- establish_connection_method = activerecord_import_exists ? :establish_connection_without_activerecord_import : :establish_connection
40
+ begin
41
+ # Get connection to master/maintenance database 'postgres'
36
42
  pool = ActiveRecord::Base.send(establish_connection_method, db_config.merge(
37
43
  'database' => 'postgres',
38
44
  'schema_search_path' => 'public'
@@ -41,14 +47,36 @@ module TidyReset
41
47
  raise RuntimeError, "Pool an array size #{pool.size}. First: #{pool.first}"
42
48
  end
43
49
  master_connection = pool.connection
44
- master_connection.select_all("SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE datname='#{db_config['database']}' AND state='idle';")
50
+
51
+ # Test connection
52
+ master_connection.select_all("SELECT 1;")
53
+
54
+ # Disallow connections from thinknear user.
55
+ master_connection.select_all("ALTER DATABASE #{db_config['database']} CONNECTION LIMIT 0;")
56
+
57
+ # Terminate all connections to the database
58
+ master_connection.select_all("SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE datname='#{db_config['database']}' AND pid <> pg_backend_pid();")
59
+
60
+ # Drop the database
45
61
  master_connection.drop_database(db_config['database'])
62
+
63
+ # Create the database
46
64
  master_connection.create_database(db_config['database'], db_config.merge('encoding' => encoding))
65
+
66
+ # Enable connections from thinknear user
67
+ master_connection.select_all("ALTER DATABASE #{db_config['database']} CONNECTION LIMIT -1;")
68
+
69
+ # Connect to created database to set extensions
47
70
  ActiveRecord::Base.remove_connection
48
71
  ActiveRecord::Base.send(establish_connection_method, db_config).connection.execute("CREATE EXTENSION IF NOT EXISTS postgis")
72
+
49
73
  rescue ActiveRecord::StatementInvalid => error
50
74
  if /database .* already exists/ === error.message
51
75
  raise DatabaseAlreadyExists
76
+ elsif /database .* is being accessed by other users/ === error.message
77
+ result = ActiveRecord::Base.send(establish_connection_method, db_config).connection.select_all("SELECT * FROM pg_stat_activity;")
78
+ puts result.to_hash
79
+ raise
52
80
  else
53
81
  raise
54
82
  end
data/tidy_reset.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: tidy_reset 0.1.7 ruby lib
5
+ # stub: tidy_reset 0.1.11 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "tidy_reset"
9
- s.version = "0.1.7"
9
+ s.version = "0.1.11"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Thinknear"]
14
- s.date = "2014-07-31"
14
+ s.date = "2014-08-18"
15
15
  s.description = "Reset dynos, environment variables, deploys master git branch, and purges the database."
16
16
  s.email = "software@thinknear.com"
17
17
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tidy_reset
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thinknear
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-31 00:00:00.000000000 Z
11
+ date: 2014-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler