New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Migration: index to columns that generate timestamps #4728

Closed
smgladkovskiy opened this Issue Jun 16, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@smgladkovskiy

smgladkovskiy commented Jun 16, 2014

Timestamps columns that are created with timestamps(), nullableTimestamps() and softDeletes() methods are then used in queries that have conditions that uses these columns. For better SQL performance it will be better to set index to that columns. Framework could help with it by automaticly setting index to that columns in their creation in migrations. This functional can be provided with the opportunity to ignore index setting while creating timestamps.

/**
 * Add nullable creation and update timestamps to the table.
 *
 * @param  bool $with_index
 * @return void
 */
public function nullableTimestamps($with_index = true)
{
    $this->timestamp('created_at')->nullable();

    $this->timestamp('updated_at')->nullable();

    if($with_index)
    {
        $table->index('created_at');
        $table->index('updated_at');
    }
}

/**
 * Add creation and update timestamps to the table.
 *
 * @param  bool $with_index
 * @return void
 */
public function timestamps($with_index = true)
{
    $this->timestamp('created_at');

    $this->timestamp('updated_at');

    if($with_index)
    {
        $table->index('created_at');
        $table->index('updated_at');
    }
}

/**
 * Add a "deleted at" timestamp for the table.
 *
 * @param  bool $with_index
 * @return void
 */
public function softDeletes($with_index = true)
{
    $this->timestamp('deleted_at')->nullable();

    if($with_index)
        $this->index('deleted_at');
}
@taylorotwell

This comment has been minimized.

Show comment
Hide comment
@taylorotwell

taylorotwell Jun 27, 2014

Member

You can set them if you wish.

Member

taylorotwell commented Jun 27, 2014

You can set them if you wish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment