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.
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.