pg_conn 0.56.0 → 0.57.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 +4 -4
- data/lib/pg_conn/rdbms_methods.rb +15 -10
- data/lib/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +5 -35
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 76fdcf256d3aad348c24f37835e191c54c79b2b50a18cb188a4f1617012bd98c
|
|
4
|
+
data.tar.gz: ff82f8edad653121fde93d3742ea5cec1b23d9959a9c01550331a465e4eaa9d3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0ba5bb473f0483b9df83d657b061f57b8afd43f69372e81f02e88564b0eaa5af3aa0924e2500294f5ff9f77b798fef9000be924c383d50d8bc3c3e8f6261f69f
|
|
7
|
+
data.tar.gz: 127c0070c97925da62ee3dbc2251da49c7185fb07ac39f96bc4a80f6b477a7e438bcee5e8c07402a6b8e4beb781d3059bdf1f01ddaa80a4944dd6e160417face
|
|
@@ -72,26 +72,31 @@ module PgConn
|
|
|
72
72
|
# schema is recreated afterwards unless :public is false. Uses the current
|
|
73
73
|
# database if @database is nil
|
|
74
74
|
#
|
|
75
|
+
# :include lists schemas to drop, the default is every schema. :exclude
|
|
76
|
+
# lists schemas to keep, the default is to drop all schemas
|
|
77
|
+
#
|
|
75
78
|
# Note that the database can have active users logged in while the database
|
|
76
79
|
# is emptied. TODO Explain what happens if the users have active
|
|
77
80
|
# transactions. Should the be terminated?
|
|
78
81
|
#
|
|
79
|
-
def empty!(database = nil, public: true, exclude: [])
|
|
82
|
+
def empty!(database = nil, public: true, include: [], exclude: [])
|
|
80
83
|
local = !database.nil?
|
|
81
84
|
begin
|
|
82
85
|
conn = local ? PgConn.new(database) : self.conn
|
|
83
86
|
schemas =
|
|
84
87
|
conn
|
|
85
88
|
.values("select nspname from pg_namespace where nspowner != 10 or nspname = 'public'")
|
|
86
|
-
.select { |schema|
|
|
87
|
-
.
|
|
88
|
-
conn.exec "drop schema #{schemas} cascade"
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
.select { |schema| include.empty? || include.include?(schema) }
|
|
90
|
+
.reject { |schema| exclude.include?(schema) }
|
|
91
|
+
conn.exec "drop schema #{schemas.join(", ")} cascade"
|
|
92
|
+
|
|
93
|
+
if public && schemas.include?("public")
|
|
94
|
+
# FIXME FIXME FIXME SECURITY Why grant 'create' to public?
|
|
95
|
+
conn.exec %(
|
|
96
|
+
create schema public authorization postgres;
|
|
97
|
+
grant usage, create on schema public to public
|
|
98
|
+
)
|
|
99
|
+
end
|
|
95
100
|
ensure
|
|
96
101
|
conn&.terminate if local
|
|
97
102
|
end
|
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require "pg"
|
|
2
2
|
require 'ostruct'
|
|
3
|
+
require 'open3'
|
|
3
4
|
require 'json'
|
|
4
5
|
|
|
5
6
|
require_relative "pg_conn/version"
|
|
@@ -156,7 +157,7 @@ module PgConn
|
|
|
156
157
|
|
|
157
158
|
# Name of database
|
|
158
159
|
def name() @pg_connection.db end
|
|
159
|
-
alias_method :database, :name # Obsolete FIXME Is it?
|
|
160
|
+
alias_method :database, :name # Obsolete FIXME Is it? No
|
|
160
161
|
|
|
161
162
|
# Database manipulation methods: #exist?, #create, #drop, #list
|
|
162
163
|
attr_reader :rdbms
|
|
@@ -1066,7 +1067,7 @@ module PgConn
|
|
|
1066
1067
|
end
|
|
1067
1068
|
end
|
|
1068
1069
|
|
|
1069
|
-
# Execute SQL
|
|
1070
|
+
# Execute SQL or pgsql file. The file must be pure SQL or pgsql statements,
|
|
1070
1071
|
# not psql meta commands. Any output from the file is ignored
|
|
1071
1072
|
def sqlexec(file, **opts)
|
|
1072
1073
|
source = IO.read(file) or error "Can't read #{file}"
|
|
@@ -1081,46 +1082,14 @@ module PgConn
|
|
|
1081
1082
|
output, errors, status = Open3.capture3 %(
|
|
1082
1083
|
psql -U #{username} -d #{database} --no-psqlrc -c '\\set ON_ERROR_STOP on' -f #{file}
|
|
1083
1084
|
)
|
|
1084
|
-
|
|
1085
1085
|
status.success? or raise PG::Error.new(errors)
|
|
1086
|
-
|
|
1087
1086
|
output
|
|
1088
|
-
|
|
1089
1087
|
rescue PG::Error => ex
|
|
1090
1088
|
if @error.nil?
|
|
1091
1089
|
@error = ex
|
|
1092
1090
|
@err = nil
|
|
1093
1091
|
end
|
|
1094
|
-
|
|
1095
|
-
# Process message
|
|
1096
|
-
if !silent
|
|
1097
|
-
$stderr.puts errors
|
|
1098
|
-
end
|
|
1099
|
-
|
|
1100
|
-
# puts "-------------------"
|
|
1101
|
-
# puts "ERRORS"
|
|
1102
|
-
# puts errors
|
|
1103
|
-
# puts "OUTPUT"
|
|
1104
|
-
# puts output
|
|
1105
|
-
# puts "EXCEPTION"
|
|
1106
|
-
# puts ex.message
|
|
1107
|
-
# puts "-------------------"
|
|
1108
|
-
#
|
|
1109
|
-
# if @error.message =~ /^\S* (ERROR.*)/
|
|
1110
|
-
# puts "BING #{silent}"
|
|
1111
|
-
# message = $1
|
|
1112
|
-
# puts "MESSAGE: #{message}"
|
|
1113
|
-
# saved_silent = self.silent
|
|
1114
|
-
# self.silent = silent
|
|
1115
|
-
# message_processor(message, file)
|
|
1116
|
-
# self.silent = saved_silent
|
|
1117
|
-
# elsif !silent
|
|
1118
|
-
# puts "BANG"
|
|
1119
|
-
# $stderr.puts errors
|
|
1120
|
-
# else
|
|
1121
|
-
# puts "NOTHING"
|
|
1122
|
-
# end
|
|
1123
|
-
|
|
1092
|
+
$stderr.puts errors if !silent
|
|
1124
1093
|
raise if fail
|
|
1125
1094
|
nil
|
|
1126
1095
|
end
|
|
@@ -1322,6 +1291,7 @@ module PgConn
|
|
|
1322
1291
|
def commit() pop_transaction(fail: false) end
|
|
1323
1292
|
def rollback() pop_transaction(commit: false, fail: false) end
|
|
1324
1293
|
|
|
1294
|
+
# FIXME: Columns with the same name are collapsed
|
|
1325
1295
|
def dump(*query)
|
|
1326
1296
|
records = self.records(*query)
|
|
1327
1297
|
|