Anonymous migration class and table exists check
ccarlosm opened this issue · comments
Hi!,
For some reason running dusk tests always told me that class XXX already existed and I discovered the previous person working in the project had used the feature for creating anonymous migration classes (which solves that problem):
return new class extends Migration {
....
};
I think it would be great if the new feature could be added at migrations creation with a flag for example.
Another interesting feature would be to add a flag for checking existing tables before creation since it is another problem I am encountering.
if (!Schema::hasTable('tblCategory'))
{
Schema::create('tblCategory', function($table){
//...
}
}
Thanks!
Hi @ccarlosm , thanks for the suggestion.
return new class extends Migration {
....
};
I will take a look into this. Mainly I have to consider fallback compatibility.
if (!Schema::hasTable('tblCategory'))
{
Schema::create('tblCategory', function($table){
//...
}
}
For this, could you please elaborate more on how a hasTable
check could help?
Because, in normal circumstances, any migrated tables are logged in the migrations
, migrated migrations will not execute twice.
Mostly, I wish to know in which use case your migration gets executed twice.
Yes, of course. I should I have explained more before.
If you migrate all tables with php artisan migrate:generate
there might be some tables that are already migrated. In my case, Laravel sanctum has a migration in vendor (personal_access_tokens) that creates that conflict. I could have removed that table from the migration with php artisan migrate:generate --ignore="table3,table4,table5"`` but I did not know it until I ran them and found the conflict.
Thanks!