This PR updates the UpdateQueueMonitorTable migration to use DB::table everywhere rather than Eloquent to select existing items in the \UpdateQueueMonitorTable::upgradeColumns method.
It's usually preferable to avoid referencing Eloquent models during migrations - the definition, fields, methods etc. of the model may change over time such that it no longer aligns with the state of the database as of when the migration was introduced.
Additionally, since the Monitor model may in fact be configured to use a specific connection, using it breaks the migration when for whatever reason the migration needs to run using a different connection -- note that DB::table()->update() on line 48 will always use the current default connection (which is, in my opinion, the desired behaviour), so there was a fundamental inconsistency there regardless;
Updating the migration as proposed in the PR fixed a problem for me in a multitenant application that runs database migration tests in a separate (temporary) database upon every release. I have the Monitor model configured to use the central database in the context of an application that has a central database and several tenant-specific databases, where the queue_monitor table goes in the central database.
This PR updates the
UpdateQueueMonitorTable
migration to useDB::table
everywhere rather than Eloquent to select existing items in the\UpdateQueueMonitorTable::upgradeColumns
method.It's usually preferable to avoid referencing Eloquent models during migrations - the definition, fields, methods etc. of the model may change over time such that it no longer aligns with the state of the database as of when the migration was introduced.
Additionally, since the
Monitor
model may in fact be configured to use a specific connection, using it breaks the migration when for whatever reason the migration needs to run using a different connection -- note thatDB::table()->update()
on line 48 will always use the current default connection (which is, in my opinion, the desired behaviour), so there was a fundamental inconsistency there regardless;Updating the migration as proposed in the PR fixed a problem for me in a multitenant application that runs database migration tests in a separate (temporary) database upon every release. I have the
Monitor
model configured to use the central database in the context of an application that has a central database and several tenant-specific databases, where the queue_monitor table goes in the central database.