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+ #
19+ # NOTE: if you ever want to add a new type of database to be released,
20+ # just fix up this documentation, the error string in invalid_dbs,
21+ # and add it to the ALL_DBS array. Everything else should just work!
22+ #
823# INCLUDE_JAR_IN_GEM [default task - false, other taks - true]:
924# Note: This is something you should not normally have to set.
1025# For local development we always will end up including the jar file
85100
86101desc "Releasing AR-JDBC gems (use NOOP=true to disable gem pushing)"
87102task 'release:do' do
103+ unless ENV [ "DBS" ]
104+ puts "you must explicitly provide a DBS env var when calling release:do. An empty one will not default to 'all' " \
105+ "for this command\n \n "
106+ invalid_dbs!
107+ end
108+
88109 Rake ::Task [ 'build' ] . invoke
89110 Rake ::Task [ 'build:adapters' ] . invoke
90111
@@ -107,8 +128,41 @@ task 'release:push' do
107128 sh "for gem in `ls pkg/*-#{ current_version . call } -java.gem`; do gem push $gem; done"
108129end
109130
110- ADAPTERS = %w[ mysql postgresql sqlite3 ] . map { |a | "activerecord-jdbc#{ a } -adapter" }
111- DRIVERS = %w[ mysql postgres sqlite3 ] . map { |a | "jdbc-#{ a } " }
131+ ALL_DBS = [ "mysql" , "postgresql" , "sqlite3" ] #NOTE: if we add a new database type to be released, just add it here!
132+ DB_ALIASES = ALL_DBS . map { |db | [ db , db ] } . to_h . merge ( {
133+ "pg" => "postgresql" ,
134+ "postgres" => "postgresql" ,
135+ "sqlite" => "sqlite3"
136+ } )
137+
138+ def invalid_dbs!
139+ raise ArgumentError , "Invalid DBS env var\n The DBS env var must be set to a combination of mysql, postgres, or " \
140+ "sqlite, separated by commas. For example:\n \n mysql,postgres,sqlite\n \n You may use pg or " \
141+ "postgres as aliases for postgresql\n You may use sqlite3 as an alias for sqlite\n " \
142+ "You may use all as a shortcut to listing them all out"
143+ end
144+
145+ def make_db_list
146+ env_dbs = ENV [ "DBS" ]
147+ return ALL_DBS if !env_dbs || env_dbs == "all"
148+ requested = env_dbs . split ( "," ) . map ( &:strip ) . reject ( &:empty? ) . map ( &:downcase )
149+ invalid_dbs! unless requested . size > 0 && requested == requested . uniq
150+
151+ canonical = requested . map do |name |
152+ DB_ALIASES . fetch ( name ) { invalid_dbs! }
153+ end
154+
155+ invalid_dbs! unless canonical == canonical . uniq
156+
157+ canonical
158+ end
159+
160+ db_list = make_db_list
161+ ADAPTERS = db_list . map { |db | "activerecord-jdbc#{ db } -adapter" }
162+
163+ db_list . map! { |db | db == 'postgresql' ? 'postgres' : db } #naming convention for DRIVERS
164+ DRIVERS = db_list . map { |a | "jdbc-#{ a } " }
165+
112166TARGETS = ( ADAPTERS + DRIVERS )
113167
114168ADAPTERS . each do |target |
0 commit comments