-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add schemas for shuttles (#1017)
* feat: add schema for shuttle, with gtfs_routes dependency commented out * feat: add shuttle_routes schema * feat: add shuttle_route_stops schema * fix: add seeds for local development * fix: move files with renamed Shuttles context to new shuttles dir * fix: fix default timestamp to be timestamp with timezone * chore: run migrations to update database schema
- Loading branch information
Showing
14 changed files
with
524 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule Arrow.Shuttles.Route do | ||
@moduledoc "schema for a shuttle route for the db" | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
schema "shuttle_routes" do | ||
field :suffix, :string | ||
field :destination, :string | ||
field :direction_id, Ecto.Enum, values: [:"0", :"1"] | ||
field :direction_desc, :string | ||
field :waypoint, :string | ||
field :shuttle_id, :id | ||
field :shape_id, :id | ||
|
||
timestamps(type: :utc_datetime) | ||
end | ||
|
||
@doc false | ||
def changeset(route, attrs) do | ||
route | ||
|> cast(attrs, [:direction_id, :direction_desc, :destination, :waypoint, :suffix]) | ||
|> validate_required([:direction_id, :direction_desc, :destination]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule Arrow.Shuttles.RouteStop do | ||
@moduledoc "schema for a shuttle route stop for the db" | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
schema "shuttle_route_stops" do | ||
field :direction_id, Ecto.Enum, values: [:"0", :"1"] | ||
field :stop_id, :string | ||
field :stop_sequence, :integer | ||
field :time_to_next_stop, :decimal | ||
field :shuttle_route_id, :id | ||
|
||
timestamps(type: :utc_datetime) | ||
end | ||
|
||
@doc false | ||
def changeset(route_stop, attrs) do | ||
route_stop | ||
|> cast(attrs, [:direction_id, :stop_id, :stop_sequence, :time_to_next_stop]) | ||
|> validate_required([:direction_id, :stop_id, :stop_sequence, :time_to_next_stop]) | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule Arrow.Shuttles.Shuttle do | ||
@moduledoc "schema for a shuttle for the db" | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
schema "shuttles" do | ||
field :status, Ecto.Enum, values: [:draft, :active, :inactive] | ||
field :shuttle_name, :string | ||
field :disrupted_route_id, :string | ||
|
||
timestamps(type: :utc_datetime) | ||
end | ||
|
||
@doc false | ||
def changeset(shuttle, attrs) do | ||
shuttle | ||
|> cast(attrs, [:shuttle_name, :disrupted_route_id, :status]) | ||
|> validate_required([:shuttle_name, :disrupted_route_id, :status]) | ||
|> unique_constraint(:shuttle_name) | ||
end | ||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule Arrow.Repo.Migrations.CreateShuttles do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:shuttles) do | ||
add :shuttle_name, :string | ||
add :disrupted_route_id, :string | ||
# add :disrupted_route_id, references(:gtfs_routes, type: :varchar, on_delete: :nothing) | ||
add :status, :string | ||
|
||
timestamps(type: :timestamptz) | ||
end | ||
|
||
create unique_index(:shuttles, [:shuttle_name]) | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
priv/repo/migrations/20241010164455_create_shuttle_routes.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule Arrow.Repo.Migrations.CreateShuttleRoutes do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:shuttle_routes) do | ||
add :direction_id, :string | ||
add :direction_desc, :string | ||
add :destination, :string | ||
add :waypoint, :string | ||
add :suffix, :string | ||
add :shuttle_id, references(:shuttles, on_delete: :nothing) | ||
add :shape_id, references(:shapes, on_delete: :nothing) | ||
|
||
timestamps(type: :timestamptz) | ||
end | ||
|
||
create index(:shuttle_routes, [:shuttle_id]) | ||
create index(:shuttle_routes, [:shape_id]) | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
priv/repo/migrations/20241010164555_create_shuttle_route_stops.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule Arrow.Repo.Migrations.CreateShuttleRouteStops do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:shuttle_route_stops) do | ||
add :direction_id, :string | ||
add :stop_id, :string | ||
add :stop_sequence, :integer | ||
add :time_to_next_stop, :decimal | ||
add :shuttle_route_id, references(:shuttle_routes, on_delete: :nothing) | ||
|
||
timestamps(type: :timestamptz) | ||
end | ||
|
||
create index(:shuttle_route_stops, [:shuttle_route_id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
# Script for populating the database. You can run it as: | ||
# | ||
# mix run priv/repo/seeds.exs | ||
# | ||
# Inside the script, you can read and write to any of your | ||
# repositories directly: | ||
# | ||
# Arrow.Repo.insert!(%Arrow.SomeSchema{}) | ||
# | ||
# We recommend using the bang functions (`insert!`, `update!` | ||
# and so on) as they will fail if something goes wrong. | ||
|
||
alias Arrow.Repo | ||
# alias Arrow.Gtfs.Route | ||
alias Arrow.Shuttles.{Shape, Stop, Shuttle, Route, RouteStop} | ||
|
||
# For testing locally with dependency on /import-gtfs | ||
# Repo.insert %Route{ | ||
# id: "Red-dev", | ||
# agency_id: "1", | ||
# short_name: nil, | ||
# long_name: "Red Line", | ||
# desc: "Rapid Transit", | ||
# type: :heavy_rail, | ||
# url: "https://www.mbta.com/schedules/Red", | ||
# color: "DA291C", | ||
# text_color: "FFFFFF", | ||
# sort_order: 10010, | ||
# fare_class: "Rapid Transit", | ||
# line_id: "line-Red", | ||
# listed_route: nil, | ||
# network_id: "rapid_transit" | ||
# } | ||
# | ||
|
||
Repo.insert!(%Shape{ | ||
id: 1, | ||
name: "AlewifeToHarvardViaBrattle-S", | ||
bucket: "mbta-arrow", | ||
path: "dev/local/shape-uploads/AlewifeToHarvardViaBrattle-S.kml", | ||
prefix: "shape_uploads/" | ||
}) | ||
|
||
Repo.insert!(%Shape{ | ||
id: 2, | ||
name: "AlewifeToHarvardViaBrattle-Alewife-S", | ||
bucket: "mbta-arrow", | ||
path: "dev/local/shape-uploads/AlewifeToHarvardViaBrattle-Alewife-S.kml", | ||
prefix: "shape_uploads/" | ||
}) | ||
|
||
Repo.insert!(%Shuttle{ | ||
id: 1, | ||
status: :draft, | ||
shuttle_name: "AlewifeToHarvardViaBrattle", | ||
disrupted_route_id: "Red-dev" | ||
}) | ||
|
||
Repo.insert!(%Route{ | ||
id: 3, | ||
shuttle_id: 1, | ||
shape_id: 1, | ||
destination: "Harvard", | ||
direction_id: :"0", | ||
direction_desc: "Southbound", | ||
suffix: nil, | ||
waypoint: "Brattle" | ||
}) | ||
|
||
Repo.insert!(%Route{ | ||
id: 4, | ||
shuttle_id: 1, | ||
shape_id: 2, | ||
destination: "Alewife", | ||
direction_id: :"1", | ||
direction_desc: "Northbound", | ||
suffix: nil, | ||
waypoint: "Brattle" | ||
}) | ||
|
||
# direction_id=0 | ||
# route="Shuttle-AlewifeHarvardViaBrattle" | ||
# start_stop="70061" | ||
# end_stop="70067" | ||
Repo.insert!(%RouteStop{ | ||
direction_id: :"0", | ||
stop_sequence: 0, | ||
stop_id: "141", | ||
time_to_next_stop: 14, | ||
shuttle_route_id: 3 | ||
}) | ||
|
||
Repo.insert!(%RouteStop{ | ||
direction_id: :"0", | ||
stop_sequence: 1, | ||
stop_id: "2581", | ||
time_to_next_stop: 6, | ||
shuttle_route_id: 3 | ||
}) | ||
|
||
Repo.insert!(%RouteStop{ | ||
direction_id: :"0", | ||
stop_sequence: 2, | ||
stop_id: "9070065", | ||
time_to_next_stop: 6, | ||
shuttle_route_id: 3 | ||
}) | ||
|
||
Repo.insert!(%RouteStop{ | ||
direction_id: :"0", | ||
stop_sequence: 3, | ||
stop_id: "9070072", | ||
# last shuttle stop | ||
time_to_next_stop: nil, | ||
shuttle_route_id: 3 | ||
}) | ||
|
||
# direction_id=1 | ||
# route="Shuttle-AlewifeHarvardViaBrattle" | ||
# start_stop="70068" | ||
# end_stop="70061" | ||
Repo.insert!(%RouteStop{ | ||
direction_id: :"1", | ||
stop_sequence: 0, | ||
stop_id: "110", | ||
time_to_next_stop: 8, | ||
shuttle_route_id: 4 | ||
}) | ||
|
||
Repo.insert!(%RouteStop{ | ||
direction_id: :"1", | ||
stop_sequence: 1, | ||
stop_id: "23151", | ||
time_to_next_stop: 6, | ||
shuttle_route_id: 4 | ||
}) | ||
|
||
Repo.insert!(%RouteStop{ | ||
direction_id: :"1", | ||
stop_sequence: 2, | ||
stop_id: "5104", | ||
time_to_next_stop: 13, | ||
shuttle_route_id: 4 | ||
}) | ||
|
||
Repo.insert!(%RouteStop{ | ||
direction_id: :"1", | ||
stop_sequence: 3, | ||
stop_id: "141", | ||
# last shuttle stop | ||
time_to_next_stop: nil, | ||
shuttle_route_id: 4 | ||
}) | ||
|
||
Repo.insert!(%Stop{ | ||
id: 1, | ||
stop_id: "9070065", | ||
stop_name: "Porter - Massachusetts Avenue @ Mount Vernon St", | ||
stop_desc: | ||
"Porter - Red Line Ashmont/Braintree Shuttle - Massachusetts Avenue @ Mount Vernon St", | ||
platform_code: nil, | ||
platform_name: "Ashmont/Braintree Shuttle", | ||
parent_station: nil, | ||
level_id: nil, | ||
zone_id: nil, | ||
stop_lat: 42.38758, | ||
stop_lon: -71.11934, | ||
municipality: "Cambridge", | ||
stop_address: nil, | ||
on_street: "Massachusetts Avenue", | ||
at_street: "Mount Vernon Street" | ||
}) | ||
|
||
Repo.insert!(%Stop{ | ||
id: 2, | ||
stop_id: "9070072", | ||
stop_name: "Harvard - Brattle St @ Palmer St", | ||
stop_desc: "Harvard - Red Line Shuttle - Brattle St @ Palmer St", | ||
platform_code: nil, | ||
platform_name: "Red Line Shuttle", | ||
parent_station: nil, | ||
level_id: nil, | ||
zone_id: nil, | ||
stop_lat: 42.373396, | ||
stop_lon: -71.1202, | ||
municipality: "Cambridge", | ||
stop_address: nil, | ||
on_street: "Brattle Street", | ||
at_street: "Palmer Street" | ||
}) |
Oops, something went wrong.