pg_meta 0.2.4 → 0.2.5

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
  SHA256:
3
- metadata.gz: 41bfef6f94d3f36e05970e1e7894f7cbf31a5658d424186caa10deb6b14adc5d
4
- data.tar.gz: 2c2b1e00874ee2d7c33ca83fd22a10a6367b21656ef0d4653a6289b3e2874814
3
+ metadata.gz: c7966e9947304b5a6e8791b4999872f971281939cbaffffc6ff9e9209d15d591
4
+ data.tar.gz: 49e9f380718521b2a15464f81a5d69d4910bd942da850bbc7aac79a07ca24443
5
5
  SHA512:
6
- metadata.gz: c7815f55fea97137928df544fb2456ab4c7aa10e4eee0727491ed18904c63ed9c48c4a024e56db48e5c669b9e6c3fecb83bcfacb13ff6a0dfe8bd8eb57a4a0b3
7
- data.tar.gz: 022334e098b1f5cd42ea2a503421a46c5ced08637ff4d50414e9e77e8b482fac9fe976b5e507224828b4ae0fc9e2dba46e1559b8b5d7332a7197e8db9cbd10e3
6
+ metadata.gz: a1526933d5aac0efcd167138feae536c28df46bd519aa09b0af6cd56038e06adb5d0d283da1fee3f79d263d7468d00172b7735821486426cd90ae6ac88198ee2
7
+ data.tar.gz: 363136bb3e83e1067997ccf99d6b60666fb3c49ccd0a9f75a1a36afc51d8fd4f9e3cc42c633fcb67b33e00a3e51f570fadf1f539ef95e47e1b49e0bdedcef314
data/exe/pg_meta CHANGED
@@ -6,6 +6,15 @@ require 'pg_meta'
6
6
  include ShellOpts
7
7
 
8
8
  SPEC = %(
9
+ @dump meta data
10
+
11
+ Dumps read database meta data. The source can be a live database or a cached
12
+ file in yaml or marshal format. The output is in human readable form but yaml
13
+ and marshal formats are also available
14
+
15
+ If a file is given as argument, the format is inferred from the extension:
16
+ .yml and .yaml vs. .marshal
17
+
9
18
  +e,exclude=SCHEMA
10
19
  Exclude SCHEMA. This option can be repeated
11
20
 
@@ -13,14 +22,25 @@ SPEC = %(
13
22
  Control format of output. FORMAT can be one of 'yaml', 'marshal' or the
14
23
  human-readable 'dump' format (the default)
15
24
 
16
- -- DATABASE
25
+ -- DATABASE|FILE
17
26
  )
18
27
 
19
28
  opts, args = ShellOpts.process(SPEC, ARGV, exception: false)
20
- database = args.expect(1)
21
-
22
- conn = PgConn.new(database)
23
- meta = PgMeta.new(conn, exclude_schemas: opts.exclude)
29
+ arg = args.expect(1)
30
+ p arg
31
+ if arg =~ /\.([^.]*)$/
32
+ p :gryf
33
+ ext = $1
34
+ case ext = $1
35
+ when "yaml", "yml"; meta = PgMeta.load_file(arg)
36
+ when "marshal"; meta = PgMeta.load_marshal(arg)
37
+ else
38
+ ShellOpts.error "Illegal file type: 'ext', expected 'yml', 'yaml', or 'marshall'"
39
+ end
40
+ else
41
+ conn = PgConn.new(arg)
42
+ meta = PgMeta.new(conn, exclude_schemas: opts.exclude)
43
+ end
24
44
 
25
45
  case opts.format
26
46
  when "yaml"; puts meta.to_yaml
@@ -4,7 +4,7 @@ module PgMeta
4
4
  using Ext::Hash
5
5
 
6
6
  # Create a Database object from the given YAML representation and return
7
- # it. The YAML representation can be generated by Database#to_h
7
+ # it. The YAML representation can be generated by Database#to_yaml
8
8
  def self.load_yaml(database_yaml)
9
9
  database = Database.new *database_yaml.project(:name, :owner)
10
10
 
@@ -60,7 +60,7 @@ module PgMeta
60
60
  referenced_constraint.table.send(:add_depending_table, table)
61
61
  }
62
62
 
63
- # Second pass: Build defining tables
63
+ # Third pass: Build defining tables
64
64
  views.each { |view, defining_relation_uids|
65
65
  defining_relation_uids.each { |uid|
66
66
  relation = database[uid]
@@ -1,3 +1,3 @@
1
1
  module PgMeta
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
data/lib/pg_meta.rb CHANGED
@@ -2,13 +2,13 @@
2
2
  require "pg"
3
3
  require "pg_conn"
4
4
 
5
- require "ext/hash.rb"
5
+ require_relative "pg_meta/ext/hash.rb"
6
6
 
7
- require "pg_meta/version.rb"
8
- require "pg_meta/meta.rb"
9
- require "pg_meta/load_conn.rb"
10
- require "pg_meta/load_yaml.rb"
11
- require "pg_meta/dump.rb"
7
+ require_relative "pg_meta/version.rb"
8
+ require_relative "pg_meta/meta.rb"
9
+ require_relative "pg_meta/load_conn.rb"
10
+ require_relative "pg_meta/load_yaml.rb"
11
+ require_relative "pg_meta/dump.rb"
12
12
 
13
13
  module PgMeta
14
14
  class Error < StandardError; end
@@ -23,6 +23,22 @@ module PgMeta
23
23
  Database.load_conn(PgConn.ensure(*args), exclude_schemas: exclude_schemas)
24
24
  end
25
25
 
26
+ def self.cache(*args, yaml: nil, marshal: nil, **opts)
27
+ yaml.nil? != marshal.nil? or raise ArgumentError, "Require either of :yaml or :marshal"
28
+ file = yaml || marshal
29
+ kind = yaml ? :yaml : :marshal
30
+ if File.exist?(file)
31
+ if yaml
32
+ load_file(file)
33
+ else
34
+ load_marshal(file)
35
+ end
36
+ else
37
+ db = self.new(*args, **opts)
38
+ IO.write(file, db.to_yaml)
39
+ end
40
+ end
41
+
26
42
  # Load data from a YAML object
27
43
  def self.load_yaml(yaml)
28
44
  Database.load_yaml(yaml)
@@ -30,6 +46,7 @@ module PgMeta
30
46
 
31
47
  # Load data from a YAML file
32
48
  def self.load_file(file)
49
+ exit
33
50
  load_yaml(YAML.load(IO.read file))
34
51
  end
35
52
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_meta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-10 00:00:00.000000000 Z
11
+ date: 2024-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: indented_io
@@ -141,9 +141,9 @@ files:
141
141
  - bin/console
142
142
  - bin/setup
143
143
  - exe/pg_meta
144
- - lib/ext/hash.rb
145
144
  - lib/pg_meta.rb
146
145
  - lib/pg_meta/dump.rb
146
+ - lib/pg_meta/ext/hash.rb
147
147
  - lib/pg_meta/load_conn.rb
148
148
  - lib/pg_meta/load_yaml.rb
149
149
  - lib/pg_meta/meta.rb
File without changes