From de16bfbea22ec0d18a7b547d050d944bc35bdf83 Mon Sep 17 00:00:00 2001 From: Mohamed Hafez Date: Mon, 6 Oct 2025 19:52:45 +0100 Subject: [PATCH 1/6] DB env var Limits the rake command performed to only work for one of the database types listed in the DB env var --- Rakefile | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 6e4aa10a1..05c19825c 100644 --- a/Rakefile +++ b/Rakefile @@ -5,6 +5,17 @@ # # Environment variables used by this Rakefile: # +# DBS +# Limits the command performed to only work for one of the database +# types listed in this env var. You can set to a combination of mysql, +# postgres, or sqlite, separated by commas. For example: +# +# mysql,postgres,sqlite +# +# You may use pg or postgres as aliases for postgresql +# You may use sqlite3 as an alias for sqlite +# You may use all to mean all three +# # INCLUDE_JAR_IN_GEM [default task - false, other taks - true]: # Note: This is something you should not normally have to set. # For local development we always will end up including the jar file @@ -107,8 +118,42 @@ task 'release:push' do sh "for gem in `ls pkg/*-#{current_version.call}-java.gem`; do gem push $gem; done" end -ADAPTERS = %w[mysql postgresql sqlite3].map { |a| "activerecord-jdbc#{a}-adapter" } -DRIVERS = %w[mysql postgres sqlite3].map { |a| "jdbc-#{a}" } +DB_ALIASES = { + 'mysql' => 'mysql', + 'postgresql' => 'postgresql', + 'postgres' => 'postgresql', + 'pg' => 'postgresql', + 'sqlite3' => 'sqlite3', + 'sqlite' => 'sqlite3' +} + +def invalid_dbs! + raise ArgumentError, "Invalid DBS env var\nThe DBS env var must be set to a combination of mysql, postgres, or " \ + "sqlite, separated by commas. For example:\n\nmysql,postgres,sqlite\n\nYou may use pg or " \ + "postgres as aliases for postgresql\nYou may use sqlite3 as an alias for sqlite\n" \ + "You may use all to mean all three" +end + +def make_db_list +ENV["DBS"] = "mysql,postgresql,sqlite3" if ENV["DBS"] == "all" || ENV["DBS"].nil? || ENV["DBS"].strip.empty? +requested = ENV["DBS"].split(",").map(&:strip).reject(&:empty?).map(&:downcase) + invalid_dbs! unless requested.size > 0 && requested.size <= 3 && requested == requested.uniq + + canonical = requested.map do |name| + DB_ALIASES.fetch(name) { invalid_dbs! } + end + + invalid_dbs! unless canonical == canonical.uniq + + canonical +end + +db_list = make_db_list +ADAPTERS = db_list.map { |db| "activerecord-jdbc#{db}-adapter" } + +db_list.map! {|db| db == 'postgresql' ? 'postgres' : db } #naming convention for DRIVERS +DRIVERS = db_list.map { |a| "jdbc-#{a}" } + TARGETS = ( ADAPTERS + DRIVERS ) ADAPTERS.each do |target| From d29239409a7d56d93b53de1bfe0851b3a86949af Mon Sep 17 00:00:00 2001 From: Mohamed Hafez Date: Mon, 6 Oct 2025 20:02:41 +0100 Subject: [PATCH 2/6] require an explicit DBS for release:do --- Rakefile | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 05c19825c..7a1ccb1f4 100644 --- a/Rakefile +++ b/Rakefile @@ -96,6 +96,12 @@ end desc "Releasing AR-JDBC gems (use NOOP=true to disable gem pushing)" task 'release:do' do + if !ENV["DBS"] || ENV["DBS"].strip.empty? + puts "you must explicitly provide a DBS env var when calling release:do. An empty one will not default to 'all' " \ + "for this command\n\n" + invalid_dbs! + end + Rake::Task['build'].invoke Rake::Task['build:adapters'].invoke @@ -135,8 +141,9 @@ def invalid_dbs! end def make_db_list -ENV["DBS"] = "mysql,postgresql,sqlite3" if ENV["DBS"] == "all" || ENV["DBS"].nil? || ENV["DBS"].strip.empty? -requested = ENV["DBS"].split(",").map(&:strip).reject(&:empty?).map(&:downcase) + env_dbs = ENV["DBS"] + env_dbs = "mysql,postgresql,sqlite3" if env_dbs == "all" || env_dbs.nil? || env_dbs.strip.empty? + requested = env_dbs.split(",").map(&:strip).reject(&:empty?).map(&:downcase) invalid_dbs! unless requested.size > 0 && requested.size <= 3 && requested == requested.uniq canonical = requested.map do |name| From 18ee3b99741a883903cae55da722c8ba81f36ebb Mon Sep 17 00:00:00 2001 From: Mohamed Hafez Date: Mon, 6 Oct 2025 21:11:59 +0100 Subject: [PATCH 3/6] don't make an empty DBS string default to all A unset DBS will still default to all, but not a blank string --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 7a1ccb1f4..81d91cccf 100644 --- a/Rakefile +++ b/Rakefile @@ -142,7 +142,7 @@ end def make_db_list env_dbs = ENV["DBS"] - env_dbs = "mysql,postgresql,sqlite3" if env_dbs == "all" || env_dbs.nil? || env_dbs.strip.empty? + env_dbs = "mysql,postgresql,sqlite3" if env_dbs == "all" || env_dbs.nil? requested = env_dbs.split(",").map(&:strip).reject(&:empty?).map(&:downcase) invalid_dbs! unless requested.size > 0 && requested.size <= 3 && requested == requested.uniq From 0ddd0a9af83e7d0fbf608db3213786b5ab51920c Mon Sep 17 00:00:00 2001 From: Mohamed Hafez Date: Mon, 6 Oct 2025 21:16:58 +0100 Subject: [PATCH 4/6] Remove unnecessary check removes unnecessary check for a blank string DBS env var in release:do. That will now be caught as an error elsewhere --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 81d91cccf..fce9a46bc 100644 --- a/Rakefile +++ b/Rakefile @@ -96,7 +96,7 @@ end desc "Releasing AR-JDBC gems (use NOOP=true to disable gem pushing)" task 'release:do' do - if !ENV["DBS"] || ENV["DBS"].strip.empty? + if !ENV["DBS"] puts "you must explicitly provide a DBS env var when calling release:do. An empty one will not default to 'all' " \ "for this command\n\n" invalid_dbs! From c1542c7730fee5e3196b411708e9770b6de94c0c Mon Sep 17 00:00:00 2001 From: Mohamed Hafez Date: Mon, 6 Oct 2025 21:27:18 +0100 Subject: [PATCH 5/6] small tweaks in DBS validity checks --- Rakefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index fce9a46bc..a8816bd06 100644 --- a/Rakefile +++ b/Rakefile @@ -96,7 +96,7 @@ end desc "Releasing AR-JDBC gems (use NOOP=true to disable gem pushing)" task 'release:do' do - if !ENV["DBS"] + unless ENV["DBS"] puts "you must explicitly provide a DBS env var when calling release:do. An empty one will not default to 'all' " \ "for this command\n\n" invalid_dbs! @@ -142,7 +142,7 @@ end def make_db_list env_dbs = ENV["DBS"] - env_dbs = "mysql,postgresql,sqlite3" if env_dbs == "all" || env_dbs.nil? + env_dbs = "mysql,postgresql,sqlite3" if !env_dbs || env_dbs == "all" requested = env_dbs.split(",").map(&:strip).reject(&:empty?).map(&:downcase) invalid_dbs! unless requested.size > 0 && requested.size <= 3 && requested == requested.uniq From 21fa5b7ac4cc0ad1623bab70f2fbef56bdcc0844 Mon Sep 17 00:00:00 2001 From: Mohamed Hafez Date: Mon, 6 Oct 2025 22:50:41 +0100 Subject: [PATCH 6/6] Make it easier to add a DB type to release --- Rakefile | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Rakefile b/Rakefile index a8816bd06..753e633b7 100644 --- a/Rakefile +++ b/Rakefile @@ -16,6 +16,10 @@ # You may use sqlite3 as an alias for sqlite # You may use all to mean all three # +# NOTE: if you ever want to add a new type of database to be released, +# just fix up this documentation, the error string in invalid_dbs, +# and add it to the ALL_DBS array. Everything else should just work! +# # INCLUDE_JAR_IN_GEM [default task - false, other taks - true]: # Note: This is something you should not normally have to set. # For local development we always will end up including the jar file @@ -124,27 +128,25 @@ task 'release:push' do sh "for gem in `ls pkg/*-#{current_version.call}-java.gem`; do gem push $gem; done" end -DB_ALIASES = { - 'mysql' => 'mysql', - 'postgresql' => 'postgresql', - 'postgres' => 'postgresql', - 'pg' => 'postgresql', - 'sqlite3' => 'sqlite3', - 'sqlite' => 'sqlite3' -} +ALL_DBS = ["mysql", "postgresql", "sqlite3"] #NOTE: if we add a new database type to be released, just add it here! +DB_ALIASES = ALL_DBS.map {|db| [db, db]}.to_h.merge({ + "pg" => "postgresql", + "postgres" => "postgresql", + "sqlite" => "sqlite3" +}) def invalid_dbs! raise ArgumentError, "Invalid DBS env var\nThe DBS env var must be set to a combination of mysql, postgres, or " \ "sqlite, separated by commas. For example:\n\nmysql,postgres,sqlite\n\nYou may use pg or " \ "postgres as aliases for postgresql\nYou may use sqlite3 as an alias for sqlite\n" \ - "You may use all to mean all three" + "You may use all as a shortcut to listing them all out" end def make_db_list env_dbs = ENV["DBS"] - env_dbs = "mysql,postgresql,sqlite3" if !env_dbs || env_dbs == "all" + return ALL_DBS if !env_dbs || env_dbs == "all" requested = env_dbs.split(",").map(&:strip).reject(&:empty?).map(&:downcase) - invalid_dbs! unless requested.size > 0 && requested.size <= 3 && requested == requested.uniq + invalid_dbs! unless requested.size > 0 && requested == requested.uniq canonical = requested.map do |name| DB_ALIASES.fetch(name) { invalid_dbs! }