Laravel Migrations Naming Convention

时间:2015-04-27 13:16:13

标签: php laravel naming-conventions database-migration

Is there a naming convention or guide that one should follow while naming Laravel migrations or should the name only be descriptive enough ?

Also, suppose you are adding 12 columns to modify a table then in such a case the migration name would be too long if made descriptive so are there any guide lines to follow ?

3 个答案:

答案 0 :(得分:5)

实际上没有人关心迁移类名称。它应该具有足够的描述性,以便您在此次迁移中检查并了解您对DB的操作。

我通常根据功能命名迁移,例如implement_user_roles或make_employee_profile_editable

答案 1 :(得分:3)

请确保您不会在模型中使用相同的类名,但仍然有效,但需要了解,

如果您正在创建,请输入create_或

如果表格相互转动,请将其设置为article_comment,以确保您在5个月后尝试更改时将会理解:)

答案 2 :(得分:1)

根据\Illuminate\Database\Console\Migrations\TableGuesser类源,有两种默认模式可以猜测迁移表和存根类型。

const CREATE_PATTERNS = [
    '/^create_(\w+)_table$/',
    '/^create_(\w+)$/',
];

const CHANGE_PATTERNS = [
    '/_(to|from|in)_(\w+)_table$/',
    '/_(to|from|in)_(\w+)$/',
];