Skip to main content

Overview

Dashboard Laravel uses Laravel’s migration system to manage database schema changes. Migrations are version control for your database, allowing your team to define and share the application’s database schema definition.

Available Migrations

The application includes the following migration files:

users, password_reset_tokens, sessions

File: 0001_01_01_000000_create_users_table.phpCreates the authentication system tables including users, password reset tokens, and session management.

cache

File: 0001_01_01_000001_create_cache_table.phpCreates cache storage tables for improved performance.

jobs

File: 0001_01_01_000002_create_jobs_table.phpCreates queue job tables for background processing.

homes

File: 2026_03_03_021430_create_homes_table.phpCreates the homes table for managing homepage content.

estadisticas

File: 2026_03_03_022050_create_estadisticas_table.phpCreates the statistics table for tracking product sales and analytics.

clientes

File: 2026_03_03_191644_create_clientes_table.phpCreates the clients/customers table with segmentation support.

ventas

File: 2026_03_03_191659_create_ventas_table.phpCreates the sales table with foreign key relationship to clients.

facturas

File: 2026_03_03_191710_create_facturas_table.phpCreates the invoices table linked to clients and sales.

mensajes

File: 2026_03_03_191720_create_mensajes_table.phpCreates the messages table for client communication.

nosotros

File: 2026_03_04_014709_create_nosotros_table.phpCreates the about us table for company information.

Running Migrations

php artisan migrate
Executes all pending migrations in chronological order.

Migration Commands

migrate:status
command
Check the status of all migrations
php artisan migrate:status
migrate:rollback
command
Rollback the last batch of migrations
php artisan migrate:rollback
migrate:reset
command
Rollback all migrations
php artisan migrate:reset
migrate:refresh
command
Rollback all migrations and re-run them
php artisan migrate:refresh

Example Migration

Here’s a real example from the clientes table migration:
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('clientes', function (Blueprint $table) {
            $table->id();
            $table->string('nombre');
            $table->string('apellido');
            $table->string('email')->unique();
            $table->string('telefono')->nullable();
            $table->enum('estado', ['activo', 'inactivo'])->default('activo');
            $table->enum('segmento', ['premium', 'regular', 'ocasional'])->default('regular');
            $table->integer('total_compras')->default(0);
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('clientes');
    }
};

Creating New Migrations

To create a new migration:
php artisan make:migration create_table_name
For creating a table:
php artisan make:migration create_products_table --create=products
For modifying an existing table:
php artisan make:migration add_column_to_table --table=table_name

Best Practices

  1. Never modify existing migrations that have been committed and run in production
  2. Always create new migrations for schema changes
  3. Use descriptive names for your migration files
  4. Test rollback functionality to ensure down() methods work correctly
  5. Use foreign key constraints to maintain referential integrity
  6. Set default values where appropriate to avoid null issues
  7. Index frequently queried columns for better performance

Foreign Key Example

The ventas table demonstrates proper foreign key usage:
Schema::create('ventas', function (Blueprint $table) {
    $table->id();
    $table->string('numero_orden')->unique();
    $table->foreignId('cliente_id')
          ->constrained('clientes')
          ->onDelete('cascade');
    $table->string('producto');
    $table->decimal('total', 10, 2);
    $table->enum('estado', ['completado', 'pendiente', 'en_camino', 'devuelto'])
          ->default('pendiente');
    $table->timestamps();
});
The onDelete('cascade') ensures that when a client is deleted, all their sales are also deleted automatically.

Build docs developers (and LLMs) love