Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Migrations Naming Convention

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 ?

like image 993
Noman Ur Rehman Avatar asked Apr 27 '15 13:04

Noman Ur Rehman


2 Answers

According to \Illuminate\Database\Console\Migrations\TableGuesser class source there are two default patterns to guess migration table and stub type.

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

const CHANGE_PATTERNS = [
    '/_(to|from|in)_(\w+)_table$/',
    '/_(to|from|in)_(\w+)$/',
];
like image 69
Vitalii Avatar answered Oct 04 '22 04:10

Vitalii


It should be descriptive enough for you to check back and understand what did you do with DB in this migration.

If you start migration with table_ then Laravel adds Schema::create. If you have to or from or in then Laravel creates Schema::table for you. This makes you life easier.

I usually name the migrations based on feature eg implement_user_roles or make_employee_profile_editable.

like image 29
Margus Pala Avatar answered Oct 04 '22 04:10

Margus Pala