diff --git a/priv/repo/migrations/20241112190520_create_route_patterns_table.exs b/priv/repo/migrations/20241112190520_create_route_patterns_table.exs index f9ef3b37c..44658299d 100644 --- a/priv/repo/migrations/20241112190520_create_route_patterns_table.exs +++ b/priv/repo/migrations/20241112190520_create_route_patterns_table.exs @@ -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 diff --git a/priv/repo/migrations/20241125171540_add_unique_constraint_route_pattern.exs b/priv/repo/migrations/20241125171540_add_unique_constraint_route_pattern.exs new file mode 100644 index 000000000..08b5e8d80 --- /dev/null +++ b/priv/repo/migrations/20241125171540_add_unique_constraint_route_pattern.exs @@ -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 diff --git a/priv/repo/migrations/20241112235628_detour_has_one_route_pattern.exs b/priv/repo/migrations/20241125171541_detour_has_one_route_pattern.exs similarity index 100% rename from priv/repo/migrations/20241112235628_detour_has_one_route_pattern.exs rename to priv/repo/migrations/20241125171541_detour_has_one_route_pattern.exs