Skip to content

Commit

Permalink
Use change instead of up/down
Browse files Browse the repository at this point in the history
  • Loading branch information
leifmetcalf authored Jan 21, 2025
1 parent 61b3b47 commit adfe169
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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
```
Expand All @@ -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
```
Expand Down

0 comments on commit adfe169

Please sign in to comment.