pg_conn 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pg_conn/rdbms_methods.rb +5 -5
- data/lib/pg_conn/role_methods.rb +4 -5
- data/lib/pg_conn/schema_methods.rb +6 -6
- data/lib/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c6b35126469d1a4c72a3ecdfe32502266eefce16574d91f0b00b9c969b586f8
|
4
|
+
data.tar.gz: ad15bf23023dad7d1a41716c7d3587e0b27400c4fee41bb3870f692adef9e908
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b49f50d2ceb9b87e55d6ae9a076bc477db4e5df474fa291d1c9f03747bb919996b209ec2bf15680651d93b1900f9067690a5653d2e492834348d6c4996b8d2de
|
7
|
+
data.tar.gz: 62ad8e07479117796196ff0cf8894a7d4562ab4d6f54eccf826830ba03df0d69897277fb307e7fb0e924e701b8bbe95ea5d81b9b5d0e964b36e879e318e2f11a
|
@@ -69,13 +69,13 @@ module PgConn
|
|
69
69
|
end
|
70
70
|
|
71
71
|
# Hollow-out a database by removing all schemas in the database. The public
|
72
|
-
# schema is recreated afterwards
|
73
|
-
# nil
|
72
|
+
# schema is recreated afterwards if :public is true. Uses the current
|
73
|
+
# database if @database is nil
|
74
74
|
#
|
75
75
|
# Note that the database can have active users logged in while the database
|
76
76
|
# is emptied
|
77
77
|
#
|
78
|
-
def empty!(database = nil, exclude: [])
|
78
|
+
def empty!(database = nil, public: true, exclude: [])
|
79
79
|
local = !database.nil?
|
80
80
|
begin
|
81
81
|
conn = local ? PgConn.new(database) : self.conn
|
@@ -84,11 +84,11 @@ module PgConn
|
|
84
84
|
.values("select nspname from pg_namespace where nspowner != 10 or nspname = 'public'")
|
85
85
|
.select { |schema| !exclude.include?(schema) }
|
86
86
|
.join(", ")
|
87
|
+
conn.exec "drop schema #{schemas} cascade"
|
87
88
|
conn.exec %(
|
88
|
-
drop schema #{schemas} cascade;
|
89
89
|
create schema public authorization postgres;
|
90
90
|
grant usage, create on schema public to public
|
91
|
-
)
|
91
|
+
) if public
|
92
92
|
ensure
|
93
93
|
conn&.terminate if local
|
94
94
|
end
|
data/lib/pg_conn/role_methods.rb
CHANGED
@@ -44,11 +44,10 @@ module PgConn
|
|
44
44
|
# Create a new role
|
45
45
|
def create(rolename, superuser: false, create_database: false, can_login: false, create_role: false)
|
46
46
|
user_decl = "create role \"#{rolename}\""
|
47
|
-
superuser_decl = superuser ? "
|
48
|
-
create_database_decl = create_database ? "
|
49
|
-
can_login_decl = can_login ? "
|
50
|
-
create_role_decl = create_role ? "
|
51
|
-
|
47
|
+
superuser_decl = superuser ? "superuser" : "nosuperuser"
|
48
|
+
create_database_decl = create_database ? "createdb" : "nocreatedb"
|
49
|
+
can_login_decl = can_login ? "login" : "nologin"
|
50
|
+
create_role_decl = create_role ? "createrole" : "nocreaterole"
|
52
51
|
stmt = [user_decl, superuser_decl, can_login_decl, create_role_decl].compact.join(" ")
|
53
52
|
conn.exec stmt
|
54
53
|
end
|
@@ -35,8 +35,8 @@ module PgConn
|
|
35
35
|
true
|
36
36
|
end
|
37
37
|
|
38
|
-
# List schemas.
|
39
|
-
#
|
38
|
+
# List schemas. Built-in schemas are not listed unless the :all option is
|
39
|
+
# true. The :exclude option can be used to exclude named schemas
|
40
40
|
def list(all: false, exclude: [])
|
41
41
|
conn.values(%(
|
42
42
|
select schema_name
|
@@ -53,7 +53,7 @@ module PgConn
|
|
53
53
|
|
54
54
|
# Return true if table exists
|
55
55
|
def exist_table?(schema, table)
|
56
|
-
conn.exist?(relation_exist_query(schema, table, kind: %w(r)))
|
56
|
+
conn.exist?(relation_exist_query(schema, table, kind: %w(r f)))
|
57
57
|
end
|
58
58
|
|
59
59
|
# Return true if view exists
|
@@ -73,7 +73,7 @@ module PgConn
|
|
73
73
|
|
74
74
|
# Return list of tables in the schema
|
75
75
|
def list_tables(schema)
|
76
|
-
conn.values relation_list_query(schema, kind: %w(r))
|
76
|
+
conn.values relation_list_query(schema, kind: %w(r f))
|
77
77
|
end
|
78
78
|
|
79
79
|
# Return list of view in the schema
|
@@ -103,7 +103,7 @@ module PgConn
|
|
103
103
|
|
104
104
|
private
|
105
105
|
def relation_exist_query(schema, relation, kind: nil)
|
106
|
-
kind_sql_list = "'" + (kind.nil? ? %w(r v m) : Array(kind).flatten).join("', '") + "'"
|
106
|
+
kind_sql_list = "'" + (kind.nil? ? %w(r f v m) : Array(kind).flatten).join("', '") + "'"
|
107
107
|
%(
|
108
108
|
select 1
|
109
109
|
from pg_class
|
@@ -114,7 +114,7 @@ module PgConn
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def relation_list_query(schema, kind: nil)
|
117
|
-
kind_sql_list = "'" + (kind.nil? ? %w(r v m) : Array(kind).flatten).join("', '") + "'"
|
117
|
+
kind_sql_list = "'" + (kind.nil? ? %w(r f v m) : Array(kind).flatten).join("', '") + "'"
|
118
118
|
%(
|
119
119
|
select relname
|
120
120
|
from pg_class
|
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
@@ -451,8 +451,7 @@ module PgConn
|
|
451
451
|
raise ArgumentError, "Unrecognized value: #{arg.inspect}"
|
452
452
|
end
|
453
453
|
}.join(", ")
|
454
|
-
|
455
|
-
r = pg_exec(query)
|
454
|
+
r = pg_exec "select * from #{name}(#{args_sql})"
|
456
455
|
if r.ntuples == 0
|
457
456
|
raise Error, "No records returned"
|
458
457
|
elsif r.ntuples == 1
|
@@ -478,7 +477,7 @@ module PgConn
|
|
478
477
|
# fail is false #exec instead return nil but note that postgres doesn't
|
479
478
|
# ignore it so that if you're inside a transaction, the transaction will be
|
480
479
|
# in an error state and if you're also using subtransactions the whole
|
481
|
-
# transaction stack
|
480
|
+
# transaction stack has collapsed
|
482
481
|
#
|
483
482
|
# TODO: Make sure the transaction stack is emptied on postgres errors
|
484
483
|
def exec(sql, commit: true, fail: true, silent: false)
|
@@ -583,6 +582,7 @@ module PgConn
|
|
583
582
|
rescue PgConn::Rollback
|
584
583
|
pop_trancaction(commit: false)
|
585
584
|
return nil
|
585
|
+
# FIXME: Rescue other postgres errors and wipe-out stack
|
586
586
|
end
|
587
587
|
pop_transaction(commit: commit)
|
588
588
|
result
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_conn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
|
-
rubygems_version: 3.1.
|
109
|
+
rubygems_version: 3.1.2
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: Gem pg_conn
|