From adfe1696ee2960122769b9fbf68974fb69d1da7a Mon Sep 17 00:00:00 2001 From: Leif Metcalf Date: Tue, 21 Jan 2025 14:25:00 +1300 Subject: [PATCH] Use change instead of up/down --- README.md | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index e110d45..e1d17c5 100644 --- a/README.md +++ b/README.md @@ -97,16 +97,12 @@ end defmodule Repo.Migrations.Init do use Ecto.Migration - def up do + def change do create table(:test) do add :name, :string add :geom, :geometry end end - - def down do - drop table(:test) - end end ``` @@ -116,21 +112,17 @@ Ecto migrations can also use more elaborate [PostGIS GIS Objects](http://postgis defmodule Repo.Migrations.AdvancedInit do use Ecto.Migration - def up do + def change do create table(:test) do add :name, :string end # Add a field `lng_lat_point` with type `geometry(Point,4326)`. # This can store a "standard GPS" (epsg4326) coordinate pair {longitude,latitude}. - execute("SELECT AddGeometryColumn ('test','lng_lat_point',4326,'POINT',2);") + execute("SELECT AddGeometryColumn ('test','lng_lat_point',4326,'POINT',2);", "") # Once a GIS data table exceeds a few thousand rows, you will want to build an index to speed up spatial searches of the data # Syntax - CREATE INDEX [indexname] ON [tablename] USING GIST ( [geometryfield] ); - execute("CREATE INDEX test_geom_idx ON test USING GIST (lng_lat_point);") - end - - def down do - drop table(:test) + execute("CREATE INDEX test_geom_idx ON test USING GIST (lng_lat_point);", "") end end ``` @@ -141,12 +133,8 @@ Be sure to enable the PostGIS extension if you haven't already done so: defmodule MyApp.Repo.Migrations.EnablePostgis do use Ecto.Migration - def up do - execute "CREATE EXTENSION IF NOT EXISTS postgis" - end - - def down do - execute "DROP EXTENSION IF EXISTS postgis" + def change do + execute "CREATE EXTENSION IF NOT EXISTS postgis", "DROP EXTENSION IF EXISTS postgis" end end ```