Phoenix / TDS adapter keeps querying schema_migrations

I am using phoenix and the tds ecto adapter, on a controller i dont have any repo import or alias , and every time i call a controller action the tds adapter keeps querying the schema_migrations tables. I does the following 8 queries

IF NOT EXISTS (SELECT * FROM [INFORMATION_SCHEMA].[TABLES] WHERE [TABLE_NAME] = 'schema_migrations') CREATE TABLE [schema_migrations] ([version] bigint, [inserted_at] datetime, CONSTRAINT [schema_migrations_pkey] PRIMARY KEY CLUSTERED ([version])); 
go
exec sp_unprepare @handle=7
go
declare @p1 int
set @p1=4
exec sp_prepare @handle=@p1 output,@params=N'',@stmt=N'sp_getapplock @Resource = ''ecto_ApiSystem.Repo'', @LockMode = ''Exclusive'', @LockOwner = ''Transaction'', @LockTimeout = -1'
select @p1
go
sp_getapplock @Resource = 'ecto_ApiSystem.Repo', @LockMode = 'Exclusive', @LockOwner = 'Transaction', @LockTimeout = -1
go
exec sp_unprepare @handle=4
go
declare @p1 int
set @p1=5
exec sp_prepare @handle=@p1 output,@params=N'',@stmt=N'SELECT CAST(s0.[version] AS bigint) FROM [schema_migrations] AS s0'
select @p1
go
SELECT CAST(s0.[version] AS bigint) FROM [schema_migrations] AS s0
go
exec sp_unprepare @handle=5
go

I am fairly new on elixir and ecto , I know that this is a behaviour to allow migrations on distributed deployments, my question is why is it happening on a route that does not touch the database and why is it happen on every single call.

Hi @narf37! I went ahead and formatted your log messages with triple-backticks ``` so they’re more legible.

Regarding your question, that check is coming from the CheckRepoStatus plug:

which is included in the default endpoint.ex generated by Phoenix. It only runs in development mode; more discussion on that in the Plug guide.

Also i dont have any schemas defined or migrations pending my repo looks like this

defmodule ApiSystem.Repo do
use Ecto.Repo,
otp_app: :api_system,
adapter: Ecto.Adapters.Tds
end

scope “/api”, ApiSystemWeb do
pipe_through :api

get "/test", TestController, :testMethod

end

defmodule ApiSystemWeb.TestController do
use ApiSystemWeb, :controller
alias Jason

def testMethod(conn, _params) do
conn
|>json(%{test: “ok”})
end

end

thats it!, i commented and now it dont get query.

is there a reason why it was to be done on every request?

Most web frameworks (Phoenix included) will reload your application’s code when a change to the files is detected. In Phoenix, that check happens on every request.

But this can lead to unexpected behavior when the user creates a migration, adds a new field to a schema, but forgets to run the migration - the newly-loaded code expects a field that isn’t there!

CheckRepoStatus aims to prevent that problem by verifying that the development database is caught-up.