| 
									
										
										
										
											2016-01-10 11:29:30 +00:00
										 |  |  | defmodule Mix.Tasks.Isn.Gen.Migration do | 
					
						
							|  |  |  |   use Mix.Task | 
					
						
							|  |  |  |   import Mix.Ecto | 
					
						
							| 
									
										
										
										
											2022-05-10 18:33:49 +00:00
										 |  |  |   import Mix.EctoSQL | 
					
						
							| 
									
										
										
										
											2016-01-10 11:29:30 +00:00
										 |  |  |   import Mix.Generator | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @migration_name "CreateISNExtension" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @shortdoc "Generate an Ecto migration to add the `isn` extension" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @moduledoc """
 | 
					
						
							|  |  |  |   Generate an Ecto migration to add the `isn` extension to your database. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ## Example | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       mix isn.gen.migration | 
					
						
							|  |  |  |   """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @doc false | 
					
						
							|  |  |  |   def run(args) do | 
					
						
							| 
									
										
										
										
											2018-01-26 16:55:15 +00:00
										 |  |  |     Mix.Task.run("app.start", args) | 
					
						
							| 
									
										
										
										
											2022-05-10 18:33:49 +00:00
										 |  |  |     now = Calendar.strftime(DateTime.utc_now(), "%Y%m%d%H%M%S") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     with [repo] <- parse_repo(args), | 
					
						
							|  |  |  |          filename <- "#{now}_create_isn_extension.exs", | 
					
						
							|  |  |  |          path <- Path.join(source_repo_priv(repo), "migrations"), | 
					
						
							|  |  |  |          file <- Path.join(path, filename), | 
					
						
							|  |  |  |          mod <- Module.concat([repo, Migrations, @migration_name]) do | 
					
						
							|  |  |  |       create_directory(path) | 
					
						
							|  |  |  |       create_file(file, migration_template(mod: mod)) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-01-10 11:29:30 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-26 16:55:15 +00:00
										 |  |  |   embed_template(:migration, """
 | 
					
						
							| 
									
										
										
										
											2016-01-10 11:29:30 +00:00
										 |  |  |   defmodule <%= inspect @mod %> do | 
					
						
							|  |  |  |     use Ecto.Migration | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def up do | 
					
						
							|  |  |  |       execute "CREATE EXTENSION IF NOT EXISTS isn;" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def down do | 
					
						
							|  |  |  |       execute "DROP EXTENSION IF EXISTS isn;" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-01-26 16:55:15 +00:00
										 |  |  |   """)
 | 
					
						
							| 
									
										
										
										
											2016-01-10 11:29:30 +00:00
										 |  |  | end |