@@ -107,6 +107,34 @@ defmodule ErrorTrackerDevWeb.Endpoint do
107107 plug ErrorTrackerDevWeb.Router
108108end
109109
110+ defmodule Migration0 do
111+ use Ecto.Migration
112+
113+ def change do
114+ create table ( :error_tracker_errors ) do
115+ add :kind , :string , null: false
116+ add :reason , :text , null: false
117+ add :source , :text , null: false
118+ add :status , :string , null: false
119+ add :fingerprint , :string , null: false
120+
121+ timestamps ( )
122+ end
123+
124+ create unique_index ( :error_tracker_errors , :fingerprint )
125+
126+ create table ( :error_tracker_occurrences ) do
127+ add :context , :map , null: false
128+ add :stacktrace , :map , null: false
129+ add :error_id , references ( :error_tracker_errors , on_delete: :delete_all ) , null: false
130+
131+ timestamps ( updated_at: false )
132+ end
133+
134+ create index ( :error_tracker_occurrences , :error_id )
135+ end
136+ end
137+
110138Application . put_env ( :phoenix , :serve_endpoints , true )
111139
112140Task . async ( fn ->
@@ -117,6 +145,13 @@ Task.async(fn ->
117145 ]
118146
119147 { :ok , _ } = Supervisor . start_link ( children , strategy: :one_for_one )
148+
149+ # Automatically run the migrations on boot
150+ Ecto.Migrator . run ( ErrorTrackerDev.Repo , [ { 0 , Migration0 } ] , :up ,
151+ all: true ,
152+ log_migrations_sql: :debug
153+ )
154+
120155 Process . sleep ( :infinity )
121156end )
122157|> Task . await ( :infinity )
0 commit comments