~ihabunek/triglav

ref: f66c43139d76b7a26925de4e29498ff1473c0950 triglav/priv/repo/migrations/20210227082725_create_public_transport_tables.exs -rw-r--r-- 1.2 KiB
f66c4313Ivan Habunek Store sample trip ID in derived data, simplify schemas 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
defmodule Triglav.Repo.Migrations.CreatePublicTransportTables do
  use Ecto.Migration

  def up do
    create table("public_transport_trips") do
      add :relation_id, :bigint, null: false
      add :route_id, :string
      add :geometry, :geometry, null: false
      add :exact, :boolean, null: false
      add :stop_ids, {:array, :string}
      add :sample_trip_id, :string
    end

    create table("public_transport_platforms") do
      add :trip_id, references("public_transport_trips")
      add :relation_id, :bigint, null: false
      add :route_id, :string
      add :stop_id, :string
      add :node_id, :bigint
      add :way_id, :bigint
      add :sequence_id, :integer, null: false
      add :geometry, :geometry, null: false
    end

    create index("public_transport_trips", [:sample_trip_id], unique: true)
    create index("public_transport_trips", [:geometry], using: :gist)

    create index("public_transport_platforms", [:relation_id, :sequence_id], unique: true)
    create index("public_transport_platforms", [:geometry], using: :gist)
  end

  def down do
    drop table("public_transport_trips")
    drop table("public_transport_platforms")
  end
end