Skip to content

Commit

Permalink
fix: migration safety
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahpurcell committed Nov 25, 2024
1 parent 6571983 commit 9751804
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@ defmodule Skate.Repo.Migrations.CreateRoutePatternsTable do
use Ecto.Migration

def change do
execute("CREATE TYPE direction_name AS ENUM ('Inbound', 'Outbound')")

create table(:route_patterns) do
add :gtfs_route_pattern_id, :string
add :gtfs_route_pattern_name, :string
add :gtfs_route_pattern_headsign, :string
add :gtfs_route_pattern_direction_name, :direction_name
add :gtfs_route_pattern_direction_name, :string
add :gtfs_route_id, :string
add :gtfs_route_name, :string
add :gtfs_route_pattern_time_description, :string
timestamps()
end

execute(
"CREATE UNIQUE INDEX route_patterns_unique_index ON route_patterns (gtfs_route_pattern_id, gtfs_route_pattern_name, gtfs_route_pattern_headsign, gtfs_route_pattern_direction_name, gtfs_route_id, gtfs_route_name, coalesce(gtfs_route_pattern_time_description, ''))"
)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule Skate.Repo.Migrations.AddUniqueConstraintRoutePattern do
use Ecto.Migration

@disable_ddl_transaction true
@disable_migration_lock true

def change do
create(
index(
:route_patterns,
[
:gtfs_route_pattern_id,
:gtfs_route_pattern_name,
:gtfs_route_pattern_headsign,
:gtfs_route_pattern_direction_name,
:gtfs_route_id,
:gtfs_route_name,
:gtfs_route_pattern_time_description
],
unique: true,
nulls_distinct: false,
concurrently: true,
name: "route_patterns_unique_index"
)
)
end
end

0 comments on commit 9751804

Please sign in to comment.