Skip to content

Commit

Permalink
jruby fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel Giddins <[email protected]>
  • Loading branch information
segiddins committed Oct 3, 2024
1 parent e763968 commit 6bf4489
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
4 changes: 2 additions & 2 deletions gemstash.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ you push your own private gems as well."
spec.add_runtime_dependency "lru_redux", "~> 1.1"
spec.add_runtime_dependency "psych", ">= 3.2.1"
spec.add_runtime_dependency "puma", "~> 6.1"
spec.add_runtime_dependency "sequel", "~> 5.0"
spec.add_runtime_dependency "sequel", "~> 5.85"
spec.add_runtime_dependency "server_health_check-rack", "~> 0.1"
spec.add_runtime_dependency "sinatra", ">= 1.4", "< 5.0"
spec.add_runtime_dependency "terminal-table", "~> 3.0"
Expand All @@ -53,7 +53,7 @@ you push your own private gems as well."
# spec.add_runtime_dependency "mysql2", "~> 0.4"

if RUBY_PLATFORM == "java"
spec.add_runtime_dependency "jdbc-sqlite3", "~> 3.8"
spec.add_runtime_dependency "jdbc-sqlite3", "~> 3.46"
else
# SQLite 3.44+ is required for string_agg support
spec.add_runtime_dependency "sqlite3", ">= 1.68", "< 3.0"
Expand Down
26 changes: 8 additions & 18 deletions lib/gemstash/compact_index_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def build_result(force_rebuild: false)
else
ts = Time.now.iso8601
versions_file.create(
compact_index_public_versions(ts), ts
compact_index_public_versions(ts), ts.to_s.sub(/\+00:00\z/, "Z")
)
@result = file.read
resource.save("versions.list" => @result)
Expand Down Expand Up @@ -176,14 +176,11 @@ def fetch_resource

def build_result
@result = CompactIndex.info(requirements_and_dependencies)
rescue Sequel::DatabaseError => e
raise "Error building info for #{@name}\n\n```sql\n#{e.sql}\n```\n"
end

private

def requirements_and_dependencies
db_type = DB::Rubygem.db.database_type
DB::Rubygem.association_left_join(versions: :dependencies).
where(name: @name).
where { versions[:indexed] }.
Expand All @@ -192,24 +189,17 @@ def requirements_and_dependencies
[versions[:number], versions[:platform], versions[:sha256], versions[:info_checksum], versions[:required_ruby_version], versions[:required_rubygems_version], versions[:created_at]]
end. # rubocop:disable Style/MultilineBlockChain
select_more do
sa = case db_type
when :sqlite then ->(a, b) { string_agg(a, b) }
else ->(a, b) { Sequel.string_agg(a, b) }
end
[sa.call(dependencies[:requirements], "@").order(dependencies[:rubygem_name], dependencies[:id]).as(:dep_req_agg),
sa.call(dependencies[:rubygem_name], ",").order(dependencies[:rubygem_name]).as(:dep_name_agg)]
[coalesce(Sequel.string_agg(dependencies[:requirements], "@").order(dependencies[:rubygem_name], dependencies[:id]), "").as(:dep_req_agg),
coalesce(Sequel.string_agg(dependencies[:rubygem_name], ",").order(dependencies[:rubygem_name]), "").as(:dep_name_agg)]
end. # rubocop:disable Style/MultilineBlockChain
map do |row|
reqs = row[:dep_req_agg]&.split("@")
dep_names = row[:dep_name_agg]&.split(",")
reqs = row[:dep_req_agg].split("@")
dep_names = row[:dep_name_agg].split(",")

raise "Dependencies and requirements are not the same size:\n reqs: #{reqs.inspect}\n dep_names: #{dep_names.inspect}\n row: #{row.inspect}" if dep_names&.size != reqs&.size
raise "Dependencies and requirements are not the same size:\n reqs: #{reqs.inspect}\n dep_names: #{dep_names.inspect}\n row: #{row.inspect}" if dep_names.size != reqs.size

deps = []
if reqs
dep_names.zip(reqs).each do |name, req|
deps << CompactIndex::Dependency.new(name, req)
end
deps = dep_names.zip(reqs).map! do |name, req|
CompactIndex::Dependency.new(name, req)
end

CompactIndex::GemVersion.new(
Expand Down
3 changes: 2 additions & 1 deletion lib/gemstash/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def db
Sequel.connect("jdbc:sqlite:#{db_path}", config.database_connection_config)
else
Sequel.connect("sqlite://#{CGI.escape(db_path)}", config.database_connection_config)
end.tap {|db| raise "SQLite 3.44+ required, have #{db.sqlite_version}" unless db.sqlite_version >= 34_400 }
end
raise "SQLite 3.44+ required, have #{db.sqlite_version}" unless db.sqlite_version >= 34_400
when "postgres", "mysql", "mysql2"
db_url = config[:db_url]
raise "Missing DB URL" unless db_url
Expand Down
2 changes: 1 addition & 1 deletion spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
it "is a conformant gem server", db_transaction: false do
@gemstash.env.cache.flush
expect(
execute("gem_server_conformance", ["--fail-fast", "--format", "progress", "--tag=~content_length_header"],
execute("gem_server_conformance", ["--format", "progress", "--tag=~content_length_header"],
env: { "UPSTREAM" => host, "GEM_HOST_API_KEY" => auth_key })
).
to exit_success
Expand Down

0 comments on commit 6bf4489

Please sign in to comment.