Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

laravel-migrations

/laravel-migrations

Pomaga projektować schemat bazy danych i zarządzać migracjami Laravel 13: Schema Builder, kolumny, indeksy, klucze obce i seedery.

Repozytorium
agents ↗
Licencja
MIT
Ostatnia zmiana repozytorium
12.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
15
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 12.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pomaga projektować schemat bazy danych i zarządzać migracjami Laravel 13: Schema Builder, kolumny, indeksy, klucze obce i seedery.

Oryginalny opis (EN)

Use when designing a database schema or managing Laravel 13 migrations — Schema Builder, columns, indexes, foreign keys, or seeders.

Jak działa

  1. Agent Workflow (MANDATORY)
  2. Overview
  3. Critical Rules
  4. Decision Guide
  5. Reference Guide
  6. Quick Reference
  7. Best Practices
  8. Laravel 13 Notes
Sekcje z nagłówków SKILL.md, w oryginale · 203 linii, 758 słów
Podgląd SKILL.md
---
name: laravel-migrations
description: Use when designing a database schema or managing Laravel 13 migrations — Schema Builder, columns, indexes, foreign keys, or seeders.
versions:
  laravel: "13.0"
  php: "8.3"
user-invocable: true
references: references/schema.md, references/columns.md, references/indexes.md, references/foreign-keys.md, references/commands.md, references/seeding.md, references/testing.md, references/production.md, references/troubleshooting.md, references/templates/CreateTableMigration.php.md, references/templates/ModifyTableMigration.php.md, references/templates/PivotTableMigration.php.md, references/templates/Seeder.php.md, references/templates/MigrationTest.php.md
related-skills: laravel-eloquent, laravel-testing, laravel-architecture
---

<objective>
Covers Laravel 13 database migrations: the Schema Builder API for
creating/modifying/dropping tables, the 50+ column types and modifiers,
index types (primary, unique, fulltext, spatial), foreign key constraints
with cascade options, Artisan migration commands, seeders, testing
migrations, safe production rollout, troubleshooting, and enabling pgvector
via Schema::ensureVectorExtensionExists() for vector columns (see
laravel-vector-search for querying them).
</objective>

# Laravel Migrations

## Agent Workflow (MANDATORY)

Before ANY implementation, spawn 3 agents in parallel, one `Agent` call each with a `name`:

1. **fuse-ai-pilot:explore-codebase** - Check existing migrations
2. **fuse-ai-pilot:research-expert** - Verify Laravel 13 patterns via Context7
3. **mcp__context7__query-docs** - Check specific Schema Builder features

After implementation, run **fuse-ai-pilot:sniper** for validation.

---

## Overview

| Feature | Description |
|---------|-------------|
| **Schema Builder** | Create, modify, drop tables |
| **Columns** | 50+ column types with modifiers |
| **Indexes** | Primary, unique, fulltext, spatial |
| **Foreign Keys** | Constraints with cascade options |
| **Seeders** | Populate tables with data |

---

## Critical Rules

1. **Always define down()** - Reversible migrations
2. **Use foreignId()->constrained()** - Not raw unsignedBigInteger
3. **Add indexes on foreign keys** - Performance critical
4. **Test rollback before deploy** - Validate down() works
5. **Never modify deployed migrations** - Create new ones

---

## Decision Guide

### Migration Type

```
Need schema change?
├── New table → make:migration create_X_table
├── Add column → make:migration add_X_to_Y_table
├── Modify column → make:migration modify_X_in_Y_table
├── Add index → make:migration add_index_to_Y_table
└── Seed data → make:seeder XSeeder
```

### Column Type Selection

| Use Case | Type | Example |
|----------|------|---------|
| Primary Key | `id()` | Auto-increment BIGINT |
| Foreign Key | `foreignId()->constrained()` | References parent |
| UUID Primary | `uuid()->primary()` | UUIDs |
| Boolean | `boolean()` | is_active |
| Enum | `enum('status', [...])` | order_status |
| JSON | `json()` | preferences |
| Money | `decimal('price', 10, 2)` | 99999999.99 |
| Timestamps | `timestamps()` | created_at, updated_at |
| Soft Delete | `softDeletes()` | deleted_at |

### Foreign Key Cascade

| Scenario | onDelete | Use Case |
|----------|----------|----------|
| Strict integrity | `restrictOnDelete()` | Financial records |
| Auto-cleanup | `cascadeOnDelete()` | Post → Comments |
| Preserve with null | `nullOnDelete()` | Optional relations |
| No action | `noActionOnDelete()` | Audit logs |

---

## Reference Guide

### Core Concepts

| Topic | Reference | When to Consult |
|-------|-----------|-----------------|
| **Schema** | [schema.md](references/schema.md) | Table operations |
| **Columns** | [columns.md](references/columns.md) | Column types |
| **Indexes** | [indexes.md](references/indexes.md) | Performance indexes |
| **Foreign Keys** | [foreign-keys.md](references/foreign-keys.md) | Constraints |
| **Commands** | [commands.md](references/commands.md) | Artisan commands |
| **Seeding** | [seeding.md](references/seeding.md) | Populate data |

### Advanced Topics

| Topic | Reference | When to Consult |
|-------|-----------|-----------------|
| **Testing** | [testing.md](references/testing.md) | Test migrations |
| **Production** | [production.md](references/production.md) | Deploy safely |
| **Troubleshooting** | [troubleshooting.md](references/troubleshooting.md) | Fix errors |

### Templates

| Template | When to Use |
|----------|-------------|
| [CreateTableMigration.php.md](references/templates/CreateTableMigration.php.md) | New table |
| [ModifyTableMigration.php.md](references/templates/ModifyTableMigration.php.md) | Alter table |
| [PivotTableMigration.php.md](references/templates/PivotTableMigration.php.md) | Many-to-many |
| [Seeder.php.md](references/templates/Seeder.php.md) | Seed patterns |
| [MigrationTest.php.md](references/templates/MigrationTest.php.md) | Test migrations |

---

## Quick Reference

### Create Table

```php
Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->foreignId('user_id')->constrained()->cascadeOnDelete();
    $table->string('title');
    $table->text('content');
    $table->enum('status', ['draft', 'published'])->default('draft');
    $table->timestamps();
    $table->softDeletes();

    $table->index(['user_id', 'status']);
});
```

### Modify Table

```php
Schema::table('posts', function (Blueprint $table) {
    $table->string('slug')->after('title')->unique();
    $table->boolean('featured')->default(false);
});
```

### Commands

```bash
php artisan make:migration create_posts_table
php artisan migrate
php artisan migrate:rollback --step=1
php artisan migrate:fresh --seed
```

---

## Best Practices

### DO
- Use `foreignId()->constrained()` for foreign keys
- Add composite indexes for common queries
- Test down() method before deploying
- Use `--pretend` to preview SQL

### DON'T
- Modify already-deployed migrations
- Forget down() method
- Use raw SQL without Schema Builder
- Skip indexes on foreign keys

---

## Laravel 13 Notes

### Schema::ensureVectorExtensionExists() (pgvector)
Laravel 13 exposes a helper to enable the `pgvector` extension on PostgreSQL from a migration. Useful for embeddings and semantic search.

```php
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void
    {
        Schema::ensureVectorExtensionExists();

        Schema::create('documents', function (Blueprint $table) {
            $table->id();
            $table->text('content');
            $table->vector('embedding', dimensions: 1536)->index(); // OpenAI text-embedding-3-small; HNSW cosine vector index
            $table->timestamps();
            // equivalent: $table->vectorIndex('embedding'); — removal: dropVectorIndex() (13.30+)
        });
    }
};
```

`vector` columns/indexes also work on **MariaDB 11.7+** (no extension needed). See [[laravel-vector-search]] for `whereVectorSimilarTo()` queries.

### What's new in Schema Builder 13.x
- `$table->foreignUuidFor(User::class)` (13.9+) and `foreignUlidFor()` (13.25+)
- Lock-free indexes: `$table->string('email')->unique()->online();` (PostgreSQL / SQL Server)
- `->inplace()` (13.33+, MySQL) on an index or foreign key for the `INPLACE` DDL algorithm
Pliki w paczce (15)
  • SKILL.md 7 KB
  • references/columns.md 4 KB
  • references/commands.md 2 KB
  • references/foreign-keys.md 2 KB
  • references/indexes.md 2 KB
  • references/production.md 2 KB
  • references/schema.md 3 KB
  • references/seeding.md 2 KB
  • references/testing.md 2 KB
  • references/troubleshooting.md 2 KB
  • references/templates/CreateTableMigration.php.md 3 KB
  • references/templates/MigrationTest.php.md 6 KB
  • references/templates/ModifyTableMigration.php.md 5 KB
  • references/templates/PivotTableMigration.php.md 5 KB
  • references/templates/Seeder.php.md 5 KB

Wersje

W bazie nie ma innych skilli o nazwie laravel-migrations.

Migawka bazy z 13.11.2026 · wersja paczki 79e6337083c5 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100database-schema
    Wdraża i sprawdza zmiany schematu bazy SQLite w projekcie Cursor BYOK: tabele, kolumny, indeksy, klucze obce i migracje SQLx.
  • 100database
    Pomaga projektować schematy baz danych, pisać i optymalizować zapytania oraz zarządzać migracjami i indeksami.
  • 100managing-database-migrations
    Zarządza migracjami schematu bazy danych: tworzenie i uruchamianie migracji oraz zarządzanie wersjami schematu.
  • 100managing-database-migrations
    Zarządza migracjami schematu bazy danych: tworzenie i uruchamianie migracji oraz zarządzanie wersjami schematu.
  • 100designing-database-schemas
    Projektuje lub zmienia schemat relacyjnej bazy danych: tabele, klucze, ograniczenia, indeksy i migracje, które nie psują istniejących danych.
  • 90database-design
    Dobiera bazę danych i ORM, projektuje schemat oraz indeksy i planuje bezpieczne migracje.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.