connection->executeStatement( 'ALTER TABLE user_active_context ADD db_type VARCHAR(10) NULL' ); $this->connection->executeStatement( "UPDATE user_active_context uac JOIN clinics c ON c.uuid = uac.db_uuid SET uac.db_type = 'clinic'" ); $this->connection->executeStatement( "UPDATE user_active_context uac JOIN doctors d ON d.uuid = uac.db_uuid SET uac.db_type = 'doctor' WHERE uac.db_type IS NULL" ); $orphans = (int) $this->connection->executeStatement( 'DELETE FROM user_active_context WHERE db_type IS NULL' ); if ($orphans > 0) { $this->write("Dropped {$orphans} active-context rows whose db_uuid no longer resolves."); } $this->connection->executeStatement( 'ALTER TABLE user_active_context MODIFY db_type VARCHAR(10) NOT NULL' ); } public function down(Schema $schema): void { $this->addSql('ALTER TABLE user_active_context DROP db_type'); } /** DDL on MariaDB commits implicitly; wrapping up() in a transaction would be a lie. */ public function isTransactional(): bool { return false; } }