cipherstash-pg 1.0.0.beta.4-arm64-darwin

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.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/.appveyor.yml +42 -0
  3. data/.gems +6 -0
  4. data/.gemtest +0 -0
  5. data/.github/workflows/binary-gems.yml +117 -0
  6. data/.github/workflows/source-gem.yml +137 -0
  7. data/.gitignore +19 -0
  8. data/.hgsigs +34 -0
  9. data/.hgtags +41 -0
  10. data/.irbrc +23 -0
  11. data/.pryrc +23 -0
  12. data/.tm_properties +21 -0
  13. data/.travis.yml +49 -0
  14. data/BSDL +22 -0
  15. data/Contributors.rdoc +46 -0
  16. data/Gemfile +14 -0
  17. data/Gemfile.lock +45 -0
  18. data/History.md +804 -0
  19. data/LICENSE +56 -0
  20. data/Manifest.txt +72 -0
  21. data/POSTGRES +23 -0
  22. data/README-OS_X.rdoc +68 -0
  23. data/README-Windows.rdoc +56 -0
  24. data/README.ja.md +266 -0
  25. data/README.md +272 -0
  26. data/Rakefile +76 -0
  27. data/Rakefile.cross +298 -0
  28. data/certs/ged.pem +24 -0
  29. data/certs/larskanis-2022.pem +26 -0
  30. data/certs/larskanis-2023.pem +24 -0
  31. data/cipherstash-pg.gemspec +0 -0
  32. data/lib/2.7/pg_ext.bundle +0 -0
  33. data/lib/3.0/pg_ext.bundle +0 -0
  34. data/lib/3.1/pg_ext.bundle +0 -0
  35. data/lib/3.2/pg_ext.bundle +0 -0
  36. data/lib/cipherstash-pg/basic_type_map_based_on_result.rb +11 -0
  37. data/lib/cipherstash-pg/basic_type_map_for_queries.rb +113 -0
  38. data/lib/cipherstash-pg/basic_type_map_for_results.rb +30 -0
  39. data/lib/cipherstash-pg/basic_type_registry.rb +206 -0
  40. data/lib/cipherstash-pg/binary_decoder.rb +21 -0
  41. data/lib/cipherstash-pg/coder.rb +82 -0
  42. data/lib/cipherstash-pg/connection.rb +467 -0
  43. data/lib/cipherstash-pg/constants.rb +3 -0
  44. data/lib/cipherstash-pg/exceptions.rb +19 -0
  45. data/lib/cipherstash-pg/result.rb +22 -0
  46. data/lib/cipherstash-pg/text_decoder.rb +43 -0
  47. data/lib/cipherstash-pg/text_encoder.rb +67 -0
  48. data/lib/cipherstash-pg/tuple.rb +24 -0
  49. data/lib/cipherstash-pg/type_map_by_column.rb +11 -0
  50. data/lib/cipherstash-pg/version.rb +3 -0
  51. data/lib/cipherstash-pg.rb +60 -0
  52. data/lib/libpq.5.dylib +0 -0
  53. data/misc/openssl-pg-segfault.rb +21 -0
  54. data/misc/postgres/History.txt +9 -0
  55. data/misc/postgres/Manifest.txt +5 -0
  56. data/misc/postgres/README.txt +21 -0
  57. data/misc/postgres/Rakefile +14 -0
  58. data/misc/postgres/lib/postgres.rb +12 -0
  59. data/misc/ruby-pg/History.txt +9 -0
  60. data/misc/ruby-pg/Manifest.txt +5 -0
  61. data/misc/ruby-pg/README.txt +21 -0
  62. data/misc/ruby-pg/Rakefile +14 -0
  63. data/misc/ruby-pg/lib/ruby/pg.rb +12 -0
  64. data/rakelib/task_extension.rb +32 -0
  65. data/sample/array_insert.rb +7 -0
  66. data/sample/async_api.rb +60 -0
  67. data/sample/async_copyto.rb +24 -0
  68. data/sample/async_mixed.rb +28 -0
  69. data/sample/check_conn.rb +9 -0
  70. data/sample/copydata.rb +21 -0
  71. data/sample/copyfrom.rb +29 -0
  72. data/sample/copyto.rb +13 -0
  73. data/sample/cursor.rb +11 -0
  74. data/sample/disk_usage_report.rb +92 -0
  75. data/sample/issue-119.rb +46 -0
  76. data/sample/losample.rb +51 -0
  77. data/sample/minimal-testcase.rb +6 -0
  78. data/sample/notify_wait.rb +26 -0
  79. data/sample/pg_statistics.rb +104 -0
  80. data/sample/replication_monitor.rb +123 -0
  81. data/sample/test_binary_values.rb +17 -0
  82. data/sample/wal_shipper.rb +202 -0
  83. data/sample/warehouse_partitions.rb +161 -0
  84. data/translation/.po4a-version +7 -0
  85. data/translation/po/all.pot +875 -0
  86. data/translation/po/ja.po +868 -0
  87. data/translation/po4a.cfg +9 -0
  88. data/vendor/database-extensions/install.sql +317 -0
  89. data/vendor/database-extensions/uninstall.sql +20 -0
  90. metadata +140 -0
@@ -0,0 +1,161 @@
1
+ require("date")
2
+ require("ostruct")
3
+ require("optparse")
4
+ require("pathname")
5
+ require("etc")
6
+ require("cipherstash-pg")
7
+ class PGWarehouse
8
+ def initialize(opts)
9
+ @opts = opts
10
+ @db = CipherStashPG.connect(:dbname => opts.database, :host => opts.host, :port => opts.port, :user => opts.user, :password => opts.pass, :sslmode => "prefer")
11
+ @db.exec(("SET search_path TO %s" % [opts.schema])) if opts.schema
12
+ @relations = self.relations
13
+ end
14
+
15
+ attr_reader(:db)
16
+
17
+ public
18
+
19
+ def migrate
20
+ if @relations.empty? then
21
+ $stderr.puts("No tables were found for warehousing.")
22
+ return
23
+ end
24
+ $stderr.puts(("Found %d relation%s to move." % [relations.length, (relations.length == 1) ? ("") : ("s")]))
25
+ @relations.sort_by { |_, v| v[:name] }.each do |_, val|
26
+ $stderr.print((" - Moving table '%s' to '%s'... " % [val[:name], @opts.tablespace]))
27
+ if @opts.dryrun then
28
+ $stderr.puts("(not really)")
29
+ else
30
+ age = self.timer do
31
+ db.exec(("ALTER TABLE %s SET TABLESPACE %s;" % [val[:name], @opts.tablespace]))
32
+ end
33
+ puts(age)
34
+ end
35
+ val[:indexes].each do |idx|
36
+ $stderr.print((" - Moving index '%s' to '%s'... " % [idx, @opts.tablespace]))
37
+ if @opts.dryrun then
38
+ $stderr.puts("(not really)")
39
+ else
40
+ age = self.timer do
41
+ db.exec(("ALTER INDEX %s SET TABLESPACE %s;" % [idx, @opts.tablespace]))
42
+ end
43
+ puts(age)
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ protected
50
+
51
+ def relations
52
+ return @relations if @relations
53
+ relations = {}
54
+ query = "\n\t\t\tSELECT c.oid AS oid,\n\t\t\t\tc.relname AS name,\n\t\t\t\tc.relkind AS kind,\n\t\t\t\tt.spcname AS tspace\n\t\t\tFROM pg_class AS c\n\t\t\tLEFT JOIN pg_namespace n ON n.oid = c.relnamespace\n\t\t\tLEFT JOIN pg_tablespace t ON t.oid = c.reltablespace\n\t\t\tWHERE c.relkind = 'r' "
55
+ (query << "AND n.nspname='#{@opts.schema}'") if @opts.schema
56
+ self.db.exec(query) do |res|
57
+ res.each do |row|
58
+ relations[row["oid"]] = { :name => row["name"], :tablespace => row["tspace"], :indexes => ([]), :parent => nil }
59
+ end
60
+ end
61
+ db.exec("SELECT inhrelid AS oid, inhparent AS parent FROM pg_inherits") do |res|
62
+ res.each { |row| relations[row["oid"]][:parent] = row["parent"] }
63
+ end
64
+ relations.reject! do |oid, val|
65
+ begin
66
+ (val[:parent].nil? or ((val[:tablespace] == @opts.tablespace) or ((val[:name] == Time.now.strftime(@opts.format)) or (not DateTime.strptime(val[:name], @opts.format)))))
67
+ rescue ArgumentError
68
+ true
69
+ end
70
+ end
71
+ query = "\n\t\t\tSELECT c.oid AS oid,\n\t\t\t\ti.indexname AS name\n\t\t\tFROM pg_class AS c\n\t\t\tINNER JOIN pg_indexes AS i\n\t\t\t\tON i.tablename = c.relname "
72
+ (query << "AND i.schemaname='#{@opts.schema}'") if @opts.schema
73
+ db.exec(query) do |res|
74
+ res.each do |row|
75
+ (relations[row["oid"]][:indexes] << row["name"]) if relations[row["oid"]]
76
+ end
77
+ end
78
+ return relations
79
+ end
80
+
81
+ def timer
82
+ start = Time.now
83
+ yield
84
+ age = (Time.now - start)
85
+ diff = age
86
+ secs = (diff % 60)
87
+ diff = ((diff - secs) / 60)
88
+ mins = (diff % 60)
89
+ diff = ((diff - mins) / 60)
90
+ hour = (diff % 24)
91
+ return ("%02d:%02d:%02d" % [hour, mins, secs])
92
+ end
93
+ end
94
+ def parse_args(args)
95
+ options = OpenStruct.new
96
+ options.database = Etc.getpwuid(Process.uid).name
97
+ options.host = "127.0.0.1"
98
+ options.port = 5432
99
+ options.user = Etc.getpwuid(Process.uid).name
100
+ options.sslmode = "prefer"
101
+ options.tablespace = "warehouse"
102
+ opts = OptionParser.new do |opts|
103
+ opts.banner = "Usage: #{$0} [options]"
104
+ opts.separator("")
105
+ opts.separator("Connection options:")
106
+ opts.on("-d", "--database DBNAME", "specify the database to connect to (default: \"#{options.database}\")") do |db|
107
+ options.database = db
108
+ end
109
+ opts.on("-h", "--host HOSTNAME", "database server host") do |host|
110
+ options.host = host
111
+ end
112
+ opts.on("-p", "--port PORT", Integer, "database server port (default: \"#{options.port}\")") do |port|
113
+ options.port = port
114
+ end
115
+ opts.on("-n", "--schema SCHEMA", String, "operate on the named schema only (default: none)") do |schema|
116
+ options.schema = schema
117
+ end
118
+ opts.on("-T", "--tablespace SPACE", String, "move old tables to this tablespace (default: \"#{options.tablespace}\")") do |tb|
119
+ options.tablespace = tb
120
+ end
121
+ opts.on("-F", "--tableformat FORMAT", String, "The naming format (strftime) for the inherited tables (default: none)") do |format|
122
+ options.format = format
123
+ end
124
+ opts.on("-U", "--user NAME", "database user name (default: \"#{options.user}\")") do |user|
125
+ options.user = user
126
+ end
127
+ opts.on("-W", "force password prompt") do |pw|
128
+ print("Password: ")
129
+ begin
130
+ (system("stty -echo")
131
+ options.pass = gets.chomp)
132
+ ensure
133
+ (system("stty echo")
134
+ puts)
135
+ end
136
+ end
137
+ opts.separator("")
138
+ opts.separator("Other options:")
139
+ opts.on_tail("--dry-run", "don't actually do anything") do
140
+ options.dryrun = true
141
+ end
142
+ opts.on_tail("--help", "show this help, then exit") do
143
+ $stderr.puts(opts)
144
+ exit
145
+ end
146
+ opts.on_tail("--version", "output version information, then exit") do
147
+ puts(Stats::VERSION)
148
+ exit
149
+ end
150
+ end
151
+ opts.parse!(args)
152
+ return options
153
+ end
154
+ if ("(string)" == $0) then
155
+ opts = parse_args(ARGV)
156
+ unless opts.format then
157
+ raise(ArgumentError, "A naming format (-F) is required.")
158
+ end
159
+ $stdout.sync = true
160
+ PGWarehouse.new(opts).migrate
161
+ end
@@ -0,0 +1,7 @@
1
+ po4a version 0.69.
2
+ Written by Martin Quinson and Denis Barbier.
3
+
4
+ Copyright © 2002-2022 Software in the Public Interest, Inc.
5
+ This is free software; see source code for copying
6
+ conditions. There is NO warranty; not even for
7
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.