sqldef 0.3.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfe9780ec8742c8a847fb663d777402691f498ae9e9350e1320d07988baaee4b
4
- data.tar.gz: '0058fc62cf4890e10c654e0aba80917ed3b3c690751954da7b3a9164ee2930e5'
3
+ metadata.gz: ddfef886cc9f1cb82ea3d734ca36b31e73b2138f9b523a317320ad5ffc533dcd
4
+ data.tar.gz: ac9aecdf26e546fd917f76b30a8b6cd8113a1208f6f4e42e9dade39b84c963bd
5
5
  SHA512:
6
- metadata.gz: '08366e2312fdb2bbf11f76b3531f7cfc6277c14cfe47aa684627593dcdba568a4bfcb622966f4a5531b1c7350d181c964f4f549d1ddcf5e9bec5fb8afb0bbe89'
7
- data.tar.gz: acf6dc9b174b389913ed8ec2ed2af7b8b5ed8ba2f184a08c6ce432967147f53f81bcd2d3e2cfdbdd270e07360f4ff7b85946bfbf5235b26502790f2a349e88f3
6
+ metadata.gz: f0c3a4b41f1e34997d6ffbe306dfffb89584acad127b3ee6cd34d77f2cc76fc5e6bc44b2398d5c65ab333542eb5a05a8222dcaa348983b9f65b5aae316536829
7
+ data.tar.gz: 4eed1e00892ffc4a03049d60793f44283353a893a2a0c08ebe3671b83c26e36e5b7f67bbe235d1d922bce68967932392a21ac471984d0dfe99726ac093fbdcb9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
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
+
1
7
  ## v0.3.0
2
8
 
3
9
  - Remove the `PGSSLMODE=disable` workaround of v0.2.x
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sqldef
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
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,6 +25,13 @@ module Sqldef
24
25
  ]
25
26
  private_constant :COMMANDS
26
27
 
28
+ OS_ARCHIVE = {
29
+ 'linux' => 'tar.gz',
30
+ 'windows' => 'zip',
31
+ 'darwin' => 'zip',
32
+ }
33
+ private_constant :OS_ARCHIVE
34
+
27
35
  @bin = Dir.pwd
28
36
 
29
37
  class << self
@@ -79,16 +87,24 @@ module Sqldef
79
87
  return path if File.executable?(path)
80
88
 
81
89
  print("Downloading '#{command}' under '#{bin}'... ")
82
- resp = get(build_url(command), code: 302) # Latest
83
- resp = get(resp['location'], code: 302) # vX.Y.Z
84
- resp = get(resp['location'], code: 200) # Binary
85
-
86
- gzip = Zlib::GzipReader.new(StringIO.new(resp.body))
87
- Gem::Package::TarReader.new(gzip) do |tar|
88
- unless file = tar.find { |f| f.full_name == command }
89
- raise "'#{command}' was not found in the archive"
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)
90
107
  end
91
- File.binwrite(path, file.read)
92
108
  end
93
109
 
94
110
  FileUtils.chmod('+x', path)
@@ -109,20 +125,26 @@ module Sqldef
109
125
  raise "Unexpected sqldef command: #{command}"
110
126
  end
111
127
  os = Etc.uname.fetch(:sysname).downcase
112
- arch = GOARCH.fetch(Etc.uname.fetch(:machine))
113
- "https://github.com/k0kubun/sqldef/releases/latest/download/#{command}_#{os}_#{arch}.tar.gz"
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}"
114
132
  end
115
133
 
116
134
  # TODO: Retry transient errors
117
- def get(url, code: nil)
135
+ def get(url, code: nil, max_retries:)
118
136
  uri = URI.parse(url)
119
- 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|
120
138
  http.get("#{uri.path}?#{uri.query}")
121
- end.tap do |resp|
122
- if code && resp.code != code.to_s
123
- raise "Expected '#{url}' to return #{code}, but got #{resp.code}: #{resp.body}"
124
- end
125
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
126
148
  end
127
149
  end
128
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.3.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: 2022-03-09 00:00:00.000000000 Z
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.3.7
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: []