sqldef 0.2.1 → 0.4.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/CHANGELOG.md +11 -0
- data/lib/sqldef/version.rb +1 -1
- data/lib/sqldef.rb +40 -27
- data/sqldef.gemspec +2 -0
- metadata +18 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddfef886cc9f1cb82ea3d734ca36b31e73b2138f9b523a317320ad5ffc533dcd
|
4
|
+
data.tar.gz: ac9aecdf26e546fd917f76b30a8b6cd8113a1208f6f4e42e9dade39b84c963bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0c3a4b41f1e34997d6ffbe306dfffb89584acad127b3ee6cd34d77f2cc76fc5e6bc44b2398d5c65ab333542eb5a05a8222dcaa348983b9f65b5aae316536829
|
7
|
+
data.tar.gz: 4eed1e00892ffc4a03049d60793f44283353a893a2a0c08ebe3671b83c26e36e5b7f67bbe235d1d922bce68967932392a21ac471984d0dfe99726ac093fbdcb9
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## v0.4.0
|
2
|
+
|
3
|
+
- Follow redirects during downloading
|
4
|
+
- Follow the repository move from k0kubun to sqldef
|
5
|
+
- Add support for zip archive type for Windows and macOS
|
6
|
+
|
7
|
+
## v0.3.0
|
8
|
+
|
9
|
+
- Remove the `PGSSLMODE=disable` workaround of v0.2.x
|
10
|
+
- You should use psqldef v0.11.41 or newer
|
11
|
+
|
1
12
|
## v0.2.1
|
2
13
|
|
3
14
|
- Fix a weird error message introduced at v0.2.0
|
data/lib/sqldef/version.rb
CHANGED
data/lib/sqldef.rb
CHANGED
@@ -7,6 +7,7 @@ require 'rubygems/package'
|
|
7
7
|
require 'stringio'
|
8
8
|
require 'uri'
|
9
9
|
require 'zlib'
|
10
|
+
require 'zip'
|
10
11
|
require_relative 'sqldef/version'
|
11
12
|
|
12
13
|
module Sqldef
|
@@ -24,10 +25,12 @@ module Sqldef
|
|
24
25
|
]
|
25
26
|
private_constant :COMMANDS
|
26
27
|
|
27
|
-
|
28
|
-
'
|
28
|
+
OS_ARCHIVE = {
|
29
|
+
'linux' => 'tar.gz',
|
30
|
+
'windows' => 'zip',
|
31
|
+
'darwin' => 'zip',
|
29
32
|
}
|
30
|
-
private_constant :
|
33
|
+
private_constant :OS_ARCHIVE
|
31
34
|
|
32
35
|
@bin = Dir.pwd
|
33
36
|
|
@@ -40,7 +43,7 @@ module Sqldef
|
|
40
43
|
sqldef = download(command)
|
41
44
|
schema = IO.popen(
|
42
45
|
[
|
43
|
-
|
46
|
+
sqldef,
|
44
47
|
"--user=#{user}", *(["--password=#{password}"] if password),
|
45
48
|
"--host=#{host}", *(["--port=#{port}"] if port),
|
46
49
|
'--export', database,
|
@@ -56,7 +59,7 @@ module Sqldef
|
|
56
59
|
def dry_run(command:, path:, host:, port: nil, user:, password: nil, database:)
|
57
60
|
sqldef = download(command)
|
58
61
|
execute(
|
59
|
-
|
62
|
+
sqldef,
|
60
63
|
"--user=#{user}", *(["--password=#{password}"] if password),
|
61
64
|
"--host=#{host}", *(["--port=#{port}"] if port),
|
62
65
|
'--dry-run', database,
|
@@ -69,7 +72,7 @@ module Sqldef
|
|
69
72
|
def apply(command:, path:, host:, port: nil, user:, password: nil, database:)
|
70
73
|
sqldef = download(command)
|
71
74
|
execute(
|
72
|
-
|
75
|
+
sqldef,
|
73
76
|
"--user=#{user}", *(["--password=#{password}"] if password),
|
74
77
|
"--host=#{host}", *(["--port=#{port}"] if port),
|
75
78
|
database,
|
@@ -84,16 +87,24 @@ module Sqldef
|
|
84
87
|
return path if File.executable?(path)
|
85
88
|
|
86
89
|
print("Downloading '#{command}' under '#{bin}'... ")
|
87
|
-
|
88
|
-
resp = get(
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
90
|
+
url = build_url(command)
|
91
|
+
resp = get(url, code: 200, max_retries: 4)
|
92
|
+
|
93
|
+
if url.end_with?('.zip')
|
94
|
+
Zip::File.open_buffer(resp.body) do |zip|
|
95
|
+
unless entry = zip.find_entry(command)
|
96
|
+
raise "'#{command}' was not found in the archive"
|
97
|
+
end
|
98
|
+
File.binwrite(path, zip.read(entry))
|
99
|
+
end
|
100
|
+
else
|
101
|
+
gzip = Zlib::GzipReader.new(StringIO.new(resp.body))
|
102
|
+
Gem::Package::TarReader.new(gzip) do |tar|
|
103
|
+
unless file = tar.find { |f| f.full_name == command }
|
104
|
+
raise "'#{command}' was not found in the archive"
|
105
|
+
end
|
106
|
+
File.binwrite(path, file.read)
|
95
107
|
end
|
96
|
-
File.binwrite(path, file.read)
|
97
108
|
end
|
98
109
|
|
99
110
|
FileUtils.chmod('+x', path)
|
@@ -109,29 +120,31 @@ module Sqldef
|
|
109
120
|
end
|
110
121
|
end
|
111
122
|
|
112
|
-
def env(command)
|
113
|
-
ENVS.fetch(command.to_s, {})
|
114
|
-
end
|
115
|
-
|
116
123
|
def build_url(command)
|
117
124
|
unless COMMANDS.include?(command)
|
118
125
|
raise "Unexpected sqldef command: #{command}"
|
119
126
|
end
|
120
127
|
os = Etc.uname.fetch(:sysname).downcase
|
121
|
-
|
122
|
-
|
128
|
+
archive = OS_ARCHIVE.fetch(os)
|
129
|
+
arch = Etc.uname.fetch(:machine)
|
130
|
+
goarch = GOARCH.fetch(arch, arch)
|
131
|
+
"https://github.com/sqldef/sqldef/releases/latest/download/#{command}_#{os}_#{goarch}.#{archive}"
|
123
132
|
end
|
124
133
|
|
125
134
|
# TODO: Retry transient errors
|
126
|
-
def get(url, code: nil)
|
135
|
+
def get(url, code: nil, max_retries:)
|
127
136
|
uri = URI.parse(url)
|
128
|
-
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
137
|
+
resp = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
129
138
|
http.get("#{uri.path}?#{uri.query}")
|
130
|
-
end.tap do |resp|
|
131
|
-
if code && resp.code != code.to_s
|
132
|
-
raise "Expected '#{url}' to return #{code}, but got #{resp.code}: #{resp.body}"
|
133
|
-
end
|
134
139
|
end
|
140
|
+
if resp.is_a?(Net::HTTPRedirection) && max_retries > 0
|
141
|
+
# Follow redirects that lead to the current repository (if sqldef/sqldef is moved),
|
142
|
+
# Latest, vX.Y.Z, and to the binary
|
143
|
+
return get(resp['location'], code: code, max_retries: max_retries - 1)
|
144
|
+
elsif code && resp.code != code.to_s
|
145
|
+
raise "Expected '#{url}' to return #{code}, but got #{resp.code}: #{resp.body}"
|
146
|
+
end
|
147
|
+
resp
|
135
148
|
end
|
136
149
|
end
|
137
150
|
end
|
data/sqldef.gemspec
CHANGED
@@ -17,6 +17,8 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.metadata['homepage_uri'] = spec.homepage
|
18
18
|
spec.metadata['source_code_uri'] = spec.homepage
|
19
19
|
|
20
|
+
spec.add_runtime_dependency 'rubyzip'
|
21
|
+
|
20
22
|
# Specify which files should be added to the gem when it is released.
|
21
23
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
24
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
metadata
CHANGED
@@ -1,15 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqldef
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: rubyzip
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
13
26
|
description: Idempotent MySQL/PostgreSQL schema management by SQL
|
14
27
|
email:
|
15
28
|
- takashikkbn@gmail.com
|
@@ -35,7 +48,6 @@ licenses:
|
|
35
48
|
metadata:
|
36
49
|
homepage_uri: https://github.com/sqldef/sqldef-ruby
|
37
50
|
source_code_uri: https://github.com/sqldef/sqldef-ruby
|
38
|
-
post_install_message:
|
39
51
|
rdoc_options: []
|
40
52
|
require_paths:
|
41
53
|
- lib
|
@@ -50,8 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
62
|
- !ruby/object:Gem::Version
|
51
63
|
version: '0'
|
52
64
|
requirements: []
|
53
|
-
rubygems_version: 3.
|
54
|
-
signing_key:
|
65
|
+
rubygems_version: 3.6.7
|
55
66
|
specification_version: 4
|
56
67
|
summary: Idempotent MySQL/PostgreSQL schema management by SQL
|
57
68
|
test_files: []
|