Skip to content

Commit de16bfb

Browse files
authored
DB env var
Limits the rake command performed to only work for one of the database types listed in the DB env var
1 parent ea479d1 commit de16bfb

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

Rakefile

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
#
66
# Environment variables used by this Rakefile:
77
#
8+
# DBS
9+
# Limits the command performed to only work for one of the database
10+
# types listed in this env var. You can set to a combination of mysql,
11+
# postgres, or sqlite, separated by commas. For example:
12+
#
13+
# mysql,postgres,sqlite
14+
#
15+
# You may use pg or postgres as aliases for postgresql
16+
# You may use sqlite3 as an alias for sqlite
17+
# You may use all to mean all three
18+
#
819
# INCLUDE_JAR_IN_GEM [default task - false, other taks - true]:
920
# Note: This is something you should not normally have to set.
1021
# For local development we always will end up including the jar file
@@ -107,8 +118,42 @@ task 'release:push' do
107118
sh "for gem in `ls pkg/*-#{current_version.call}-java.gem`; do gem push $gem; done"
108119
end
109120

110-
ADAPTERS = %w[mysql postgresql sqlite3].map { |a| "activerecord-jdbc#{a}-adapter" }
111-
DRIVERS = %w[mysql postgres sqlite3].map { |a| "jdbc-#{a}" }
121+
DB_ALIASES = {
122+
'mysql' => 'mysql',
123+
'postgresql' => 'postgresql',
124+
'postgres' => 'postgresql',
125+
'pg' => 'postgresql',
126+
'sqlite3' => 'sqlite3',
127+
'sqlite' => 'sqlite3'
128+
}
129+
130+
def invalid_dbs!
131+
raise ArgumentError, "Invalid DBS env var\nThe DBS env var must be set to a combination of mysql, postgres, or " \
132+
"sqlite, separated by commas. For example:\n\nmysql,postgres,sqlite\n\nYou may use pg or " \
133+
"postgres as aliases for postgresql\nYou may use sqlite3 as an alias for sqlite\n" \
134+
"You may use all to mean all three"
135+
end
136+
137+
def make_db_list
138+
ENV["DBS"] = "mysql,postgresql,sqlite3" if ENV["DBS"] == "all" || ENV["DBS"].nil? || ENV["DBS"].strip.empty?
139+
requested = ENV["DBS"].split(",").map(&:strip).reject(&:empty?).map(&:downcase)
140+
invalid_dbs! unless requested.size > 0 && requested.size <= 3 && requested == requested.uniq
141+
142+
canonical = requested.map do |name|
143+
DB_ALIASES.fetch(name) { invalid_dbs! }
144+
end
145+
146+
invalid_dbs! unless canonical == canonical.uniq
147+
148+
canonical
149+
end
150+
151+
db_list = make_db_list
152+
ADAPTERS = db_list.map { |db| "activerecord-jdbc#{db}-adapter" }
153+
154+
db_list.map! {|db| db == 'postgresql' ? 'postgres' : db } #naming convention for DRIVERS
155+
DRIVERS = db_list.map { |a| "jdbc-#{a}" }
156+
112157
TARGETS = ( ADAPTERS + DRIVERS )
113158

114159
ADAPTERS.each do |target|

0 commit comments

Comments
 (0)