FuelPHP already has excellent tools that help us implement data validation and integrity checks in at the Model level - as it should be! Nevertheless, many programmers have to specify data integrity constraints also at database level. In my case, for instance, this is a requirement at my workplace that I cannot get around.
It would be wonderful if a new 'magic migration' could be added to oil's already fantastic set, that would enable me to simply call:
oil g migration set_unique_email_in_users
The format for the call, obviously, is: set_unique_{fieldname}_in_{table name}. It seems to me that using the word 'set' is clearer than using, let's say, the word 'add', which makes it more ambiguous (makes it seem as if we're adding a field, rather than modifying an existing one).
This call would create a migration file with the following template:
<?php
namespace Fuel\Migrations;
class Set_unique_{fieldname}_in_{tablename} {
public function up()
{
//Adding UNIQUE constraint to '{fieldname}' column
\DB::query("ALTER TABLE `{tablename}` ADD CONSTRAINT `uk_{fieldname}` UNIQUE (`{fieldname}`)")->execute();
}
public function down()
{
//Removing UNIQUE constraint from '{fieldname}' column
\DB::query("ALTER TABLE `{tablename}` DROP INDEX `uk_{fieldname}`")->execute();
}
}
Thank you for your consideration, and for all your great work with oil.
FuelPHP already has excellent tools that help us implement data validation and integrity checks in at the Model level - as it should be! Nevertheless, many programmers have to specify data integrity constraints also at database level. In my case, for instance, this is a requirement at my workplace that I cannot get around.
It would be wonderful if a new 'magic migration' could be added to oil's already fantastic set, that would enable me to simply call:
The format for the call, obviously, is:
set_unique_{fieldname}_in_{table name}
. It seems to me that using the word 'set' is clearer than using, let's say, the word 'add', which makes it more ambiguous (makes it seem as if we're adding a field, rather than modifying an existing one).This call would create a migration file with the following template:
Thank you for your consideration, and for all your great work with oil.