@@ -162,8 +162,8 @@ if Code.ensure_loaded?(Igniter) do
162162 "config/runtime.exs" ,
163163 default_runtime ,
164164 fn zipper ->
165- if Igniter.Project.Config . configures_key? ( zipper , otp_app , [ repo , :url ] ) do
166- zipper
165+ if Igniter.Project.Config . configures_key? ( zipper , otp_app , [ repo ] ) do
166+ { :ok , zipper }
167167 else
168168 patterns = [
169169 """
@@ -182,47 +182,51 @@ if Code.ensure_loaded?(Igniter) do
182182 |> Igniter.Code.Common . move_to_cursor_match_in_scope ( patterns )
183183 |> case do
184184 { :ok , zipper } ->
185- case Igniter.Code.Function . move_to_function_call_in_current_scope (
186- zipper ,
187- := ,
188- 2 ,
189- fn call ->
190- Igniter.Code.Function . argument_matches_pattern? (
191- call ,
192- 0 ,
193- { :database_url , _ , ctx } when is_atom ( ctx )
194- )
195- end
196- ) do
197- { :ok , _zipper } ->
198- zipper
199- |> Igniter.Project.Config . modify_configuration_code (
200- [ repo , :url ] ,
201- otp_app ,
202- { :database_url , [ ] , nil }
203- )
204- |> Igniter.Project.Config . modify_configuration_code (
205- [ repo , :pool_size ] ,
206- otp_app ,
207- Sourceror . parse_string! ( """
208- String.to_integer(System.get_env("POOL_SIZE") || "10")
185+ if Igniter.Project.Config . configures_key? ( zipper , "runtime.exs" , otp_app , [ repo ] ) do
186+ { :ok , zipper }
187+ else
188+ case Igniter.Code.Function . move_to_function_call_in_current_scope (
189+ zipper ,
190+ := ,
191+ 2 ,
192+ fn call ->
193+ Igniter.Code.Function . argument_matches_pattern? (
194+ call ,
195+ 0 ,
196+ { :database_url , _ , ctx } when is_atom ( ctx )
197+ )
198+ end
199+ ) do
200+ { :ok , _zipper } ->
201+ zipper
202+ |> Igniter.Project.Config . modify_configuration_code (
203+ [ repo , :url ] ,
204+ otp_app ,
205+ { :database_url , [ ] , nil }
206+ )
207+ |> Igniter.Project.Config . modify_configuration_code (
208+ [ repo , :pool_size ] ,
209+ otp_app ,
210+ Sourceror . parse_string! ( """
211+ String.to_integer(System.get_env("POOL_SIZE") || "10")
212+ """ )
213+ )
214+ |> then ( & { :ok , & 1 } )
215+
216+ _ ->
217+ Igniter.Code.Common . add_code ( zipper , """
218+ database_url =
219+ System.get_env("DATABASE_URL") ||
220+ raise \" \" \"
221+ environment variable DATABASE_URL is missing.
222+ For example: ecto://USER:PASS@HOST/DATABASE
223+ \" \" \"
224+
225+ config #{ inspect ( otp_app ) } , #{ inspect ( repo ) } ,
226+ url: database_url,
227+ pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
209228 """ )
210- )
211- |> then ( & { :ok , & 1 } )
212-
213- _ ->
214- Igniter.Code.Common . add_code ( zipper , """
215- database_url =
216- System.get_env("DATABASE_URL") ||
217- raise \" \" \"
218- environment variable DATABASE_URL is missing.
219- For example: ecto://USER:PASS@HOST/DATABASE
220- \" \" \"
221-
222- config #{ inspect ( otp_app ) } , Helpdesk.Repo,
223- url: database_url,
224- pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
225- """ )
229+ end
226230 end
227231
228232 :error ->
@@ -235,7 +239,7 @@ if Code.ensure_loaded?(Igniter) do
235239 For example: ecto://USER:PASS@HOST/DATABASE
236240 \" \" \"
237241
238- config #{ inspect ( otp_app ) } , Helpdesk.Repo ,
242+ config #{ inspect ( otp_app ) } , #{ inspect ( repo ) } ,
239243 url: database_url,
240244 pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
241245 end
0 commit comments