postspec 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/postspec +6 -1
- data/lib/postspec/config.rb +8 -3
- data/lib/postspec/environment.rb +3 -2
- data/lib/postspec/version.rb +1 -1
- data/lib/postspec.rb +7 -4
- data/lib/share/postspec_schema.sql +6 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39ed181749e41623ce7791415874644656c2b44fe4a57db2241ba1dcb136cd35
|
4
|
+
data.tar.gz: 65c8afdda77cbc727159da796a04efa1d1b6134ca5ce198af30548cbdd2f3693
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee46e5636f9e632c126142a87bc796cbf19c29896bcb4a576b69776a50020ef30919682becece4242c97dd95897ae0ed8365fc633cd62b3416d0ade8a362a64f
|
7
|
+
data.tar.gz: 66d90244f8e1ac9a566112ab5e523e9804a3faf441e7a82efa64edc29b11072f4d25127147ba08d9bb330ccba6049051865dc78bd6681c43d623c49a6c814d68
|
data/exe/postspec
CHANGED
@@ -11,6 +11,11 @@ SPEC = "
|
|
11
11
|
|
12
12
|
-r,reflections=EFILE @ Reflections file
|
13
13
|
|
14
|
+
+i,ignore=SCHEMA
|
15
|
+
Exclude the given schemas from the type model. This is required for schemas
|
16
|
+
that doesn't follow PgGraph's naming convention when there is no
|
17
|
+
reflections file
|
18
|
+
|
14
19
|
-- DATABASE"
|
15
20
|
|
16
21
|
def timeit(label = nil, &block)
|
@@ -33,7 +38,7 @@ puts "Reading and writing the given database"
|
|
33
38
|
indent {
|
34
39
|
conn = PgConn.new(database)
|
35
40
|
meta = timeit("Meta") { PgMeta.new(conn) }
|
36
|
-
type = timeit("Type") { PgGraph::Type.new(meta, opts.reflections) }
|
41
|
+
type = timeit("Type") { PgGraph::Type.new(meta, opts.reflections, ignore: opts.ignore) }
|
37
42
|
data = timeit("Read data") { PgGraph::Data.new(type, conn) }
|
38
43
|
load_data = timeit("Write data") { data.write(conn) }
|
39
44
|
}
|
data/lib/postspec/config.rb
CHANGED
@@ -1,38 +1,43 @@
|
|
1
1
|
# Used to initialize postspec from spec/spec_helper.rb or spec/postspec_helper.rb
|
2
2
|
#
|
3
3
|
module Postspec
|
4
|
-
Config = Struct.new(:database, :mode, :reflections, :anchors, :fail_fast)
|
4
|
+
Config = Struct.new(:database, :mode, :reflections, :anchors, :fail_fast, :ignore)
|
5
5
|
|
6
6
|
@database = nil
|
7
7
|
@mode = nil
|
8
8
|
@reflections = nil
|
9
9
|
@anchors = nil
|
10
10
|
@fail_fast = nil
|
11
|
+
@ignore = nil
|
11
12
|
|
12
13
|
DEFAULT_MODE = :empty
|
13
14
|
DEFAULT_FAIL_FAST = true
|
15
|
+
DEFAULT_IGNORE = []
|
14
16
|
|
15
17
|
def self.database() @database end
|
16
18
|
def self.mode() @mode end
|
17
19
|
def self.reflections() @reflections end
|
18
20
|
def self.anchors() @anchors end
|
19
21
|
def self.fail_fast() @fail_fast end
|
22
|
+
def self.ignore() @ignore end
|
20
23
|
|
21
24
|
def self.configure(&block)
|
22
|
-
config = Config.new(@database, DEFAULT_MODE, nil, nil, DEFAULT_FAIL_FAST)
|
25
|
+
config = Config.new(@database, DEFAULT_MODE, nil, nil, DEFAULT_FAIL_FAST, DEFAULT_IGNORE)
|
23
26
|
yield(config)
|
24
27
|
@database = config.database
|
25
28
|
@mode = config.mode || DEFAULT_MODE
|
26
29
|
@reflections = config.reflections
|
27
30
|
@anchors = config.anchors
|
28
31
|
@fail_fast = config.fail_fast || DEFAULT_FAIL_FAST
|
32
|
+
@ignore = config.ignore || DEFAULT_IGNORE # FIXME: Why not rely on Config defaults?
|
29
33
|
self
|
30
34
|
end
|
31
35
|
|
32
36
|
def self.postspec()
|
33
37
|
!@database.nil? or raise Error, "Database unspecified"
|
34
38
|
@postspec ||= Postspec.new(
|
35
|
-
PgConn.new(@database),
|
39
|
+
PgConn.new(@database),
|
40
|
+
mode: mode, reflector: @reflections, anchors: @anchors, fail: @fail_fast, ignore: @ignore)
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
data/lib/postspec/environment.rb
CHANGED
@@ -11,8 +11,9 @@ module Postspec
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def table_sequence_ids(all: false)
|
14
|
+
ignore_list = "'" + (postspec.ignore + %w(prick)).join("', '") + "'"
|
14
15
|
conn.map \
|
15
|
-
"select table_uid, record_id from postspec.table_sequence_ids()" +
|
16
|
+
"select table_uid, record_id from postspec.table_sequence_ids(array[#{ignore_list}]::varchar[])" +
|
16
17
|
(all ? "" : " where record_id is not null")
|
17
18
|
end
|
18
19
|
|
@@ -53,7 +54,7 @@ module Postspec
|
|
53
54
|
conn.exist? "select 1 from pg_namespace where nspname = 'postspec'"
|
54
55
|
end
|
55
56
|
|
56
|
-
# Removes excess data and meta data, and resets sequences. It
|
57
|
+
# Removes excess data and meta data, and resets sequences. It doesn't change any triggers
|
57
58
|
def clean
|
58
59
|
# puts "Environment#clean"
|
59
60
|
@uids = {}
|
data/lib/postspec/version.rb
CHANGED
data/lib/postspec.rb
CHANGED
@@ -40,6 +40,9 @@ module Postspec
|
|
40
40
|
# the test run will terminate immediately. Default true
|
41
41
|
attr_reader :fail
|
42
42
|
|
43
|
+
# List of ignored schemas
|
44
|
+
attr_reader :ignore
|
45
|
+
|
43
46
|
# State
|
44
47
|
attr_reader :state
|
45
48
|
|
@@ -65,13 +68,13 @@ module Postspec
|
|
65
68
|
# TODO: PgMeta object
|
66
69
|
#
|
67
70
|
# +mode+ can be one of :seed, :empty (TODO :reseed, :keep)
|
68
|
-
def initialize(conn, reflector: nil, mode: :empty, anchors: [], fail: true)
|
69
|
-
# puts "Postspec#initialize"
|
71
|
+
def initialize(conn, reflector: nil, mode: :empty, anchors: [], fail: true, ignore: [])
|
70
72
|
constrain conn, PgConn
|
71
73
|
constrain reflector, NilClass, String, PgGraph::Reflector
|
72
74
|
constrain mode, lambda { |m| [:empty, :seed].include?(m) }
|
73
75
|
constrain anchors, [Hash], NilClass
|
74
76
|
constrain fail, TrueClass, FalseClass
|
77
|
+
constrain ignore, [String]
|
75
78
|
|
76
79
|
@conn = conn
|
77
80
|
@meta = PgMeta.new(@conn)
|
@@ -82,9 +85,10 @@ module Postspec
|
|
82
85
|
has_postspec = @meta.schemas.key?("postspec")
|
83
86
|
!has_postspec or (@meta.schemas["postspec"].hidden = true)
|
84
87
|
|
85
|
-
@type = PgGraph::Type.new(@meta, reflector, ignore: ["prick"])
|
88
|
+
@type = PgGraph::Type.new(@meta, reflector, ignore: ["prick"] + ignore)
|
86
89
|
@render = Render.new(self)
|
87
90
|
@tables = type.schemas.map(&:tables).flatten
|
91
|
+
@ignore = ignore
|
88
92
|
@fail = fail
|
89
93
|
@failed = false
|
90
94
|
@success = true
|
@@ -217,7 +221,6 @@ module Postspec
|
|
217
221
|
end
|
218
222
|
|
219
223
|
def use(rspec, *files)
|
220
|
-
|
221
224
|
# Closure variables
|
222
225
|
this = self
|
223
226
|
search_path = self.search_path
|
@@ -7,11 +7,14 @@ set search_path to postspec;
|
|
7
7
|
-- Return a map from table UID to last value of sequence. All user tables are
|
8
8
|
-- included but tables without sequences (subtables) have last value set to
|
9
9
|
-- null
|
10
|
-
create or replace function table_sequence_ids(
|
10
|
+
create or replace function table_sequence_ids(ignore_schemas varchar[])
|
11
|
+
returns table(table_uid text, record_id bigint)
|
12
|
+
as $$
|
11
13
|
declare
|
12
14
|
name varchar(255);
|
13
15
|
tuple record;
|
14
16
|
begin
|
17
|
+
ignore_schemas := ignore_schemas || array['information_schema', 'postspec']::varchar[];
|
15
18
|
for tuple in
|
16
19
|
select tc.relnamespace::regnamespace::text || '.' || tc.relname as table_uid,
|
17
20
|
s.relnamespace::regnamespace::text || '.' || s.relname as sequence_uid
|
@@ -27,8 +30,8 @@ create or replace function table_sequence_ids() returns table(table_uid text, re
|
|
27
30
|
and coalesce(sc.relnamespace::regnamespace::text != 'postspec', true)
|
28
31
|
) s on s.refobjid = tc.oid
|
29
32
|
where tc.relkind = 'r'
|
30
|
-
and tc.relnamespace::regnamespace::text not like 'pg_%'
|
31
|
-
and tc.relnamespace::regnamespace::text
|
33
|
+
and tc.relnamespace::regnamespace::text not like 'pg_%'
|
34
|
+
and tc.relnamespace::regnamespace::text != all(ignore_schemas)
|
32
35
|
loop
|
33
36
|
if tuple.sequence_uid is null then
|
34
37
|
table_uid := tuple.table_uid;
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-inflector
|