What is the best practice for dealing with migrates?

I understand why you can’t run composer “require-dev”, but to run migrate on the server I would need these resources in the environment.
How can I proceed?
In this case my idea would be to temporarily raise require-dev as require and after work update “yii2-gii” to dev again.

Run tests in heroku:

heroku run "php yii migrate/up"

Error detected
class yii\gii\module does not exist

You don’t need gii to run migration. Most probably your configuration includes gii module while it should be switched off for the environment you are running it.

I liked the solution Yii2-heroku, but this solution only works in yii2 advance.

I’m creating a similar resource to run migration using remote base.
Example:

php yii heroku/migrate