mohamedhekal/laravel-schema-track

Smart Version-Controlled Schema History & Change Logger for Laravel Projects

v1.0.0 2025-07-26 23:20 UTC

This package is auto-updated.

Last update: 2025-07-26 23:31:46 UTC


README

Smart Version-Controlled Schema History & Change Logger for Laravel Projects

Latest Version on Packagist Tests Total Downloads

๐Ÿš€ Overview

Laravel SchemaTrack is a developer-focused package that brings schema versioning, change tracking, and visual diffs to Laravel's database structure โ€” turning your migrations and database changes into a clear, documented, and reversible timeline.

Think of it as Git for your database schema, fully integrated into Laravel.

๐Ÿ’ก Key Features

  • ๐Ÿง  Auto Snapshot: Automatically takes a snapshot of your entire database schema after each migrate operation
  • ๐Ÿงพ Schema Diff Viewer: Shows visual differences between schema versions
  • ๐Ÿ“š Changelog Generator: Generates Markdown or JSON changelog with human-readable schema changes
  • ๐ŸŒ Multi-Environment Compare: Compare schema state between environments
  • ๐Ÿ“ฆ Custom Artisan Commands: Complete CLI interface for schema management
  • ๐Ÿ› ๏ธ Schema Explorer Dashboard: Web UI for browsing schema versions (Optional)
  • ๐Ÿ” Safe by Design: Never alters your schema, only reads metadata

๐Ÿ“ฆ Installation

composer require mohamedhekal/laravel-schema-track

Publish the configuration file:

php artisan vendor:publish --provider="MohamedHekal\LaravelSchemaTrack\SchemaTrackServiceProvider"

๐Ÿงฐ Usage

Basic Commands

# Take a manual snapshot
php artisan schema:track

# View differences between snapshots
php artisan schema:diff --from=2024_07_01 --to=latest

# Compare with another environment
php artisan schema:compare --env=staging

# Generate changelog
php artisan schema:changelog --format=markdown --output=CHANGELOG.md

# List all snapshots
php artisan schema:list

Auto-Snapshot on Migrations

The package automatically takes snapshots after each migration. You can disable this in the config:

// config/schema-track.php
'auto_snapshot' => true,

๐Ÿงช Use Case Examples

Scenario Value
๐Ÿข Large teams Ensure developers don't override each other's migration logic
๐Ÿงช QA testing Communicate DB changes clearly across versions
๐Ÿ•ต๏ธ Debugging Quickly inspect when a schema column was added/changed
๐Ÿš€ CI/CD Detect unintentional or risky schema changes before deployment

๐Ÿ“ Directory Structure

storage/schema-track/
โ”œโ”€โ”€ 2024_07_01_123000_initial_snapshot.json
โ”œโ”€โ”€ 2024_07_10_093000_add_users_table.json
โ”œโ”€โ”€ ...

๐Ÿ“œ Sample Output

Changelog (Markdown)

## ๐Ÿ—‚ Schema Changes (2024-07-26)

### Modified Table: `users`
- Added Column: `is_verified` โ†’ boolean, default: false
- Changed Column: `email` โ†’ now unique

### New Table: `user_profiles`
- `id`, `user_id`, `bio`, `avatar`, timestamps

Diff Output

$ php artisan schema:diff --from=2024_07_01 --to=latest

๐Ÿ“Š Schema Diff Report
====================

๐Ÿ†• New Tables:
  - user_profiles

๐Ÿ“ Modified Tables:
  - users:
    + Added: is_verified (boolean, default: false)
    + Changed: email (now unique)

โš™๏ธ Configuration

// config/schema-track.php

return [
    'storage_path' => storage_path('schema-track'),
    'auto_snapshot' => true,
    'snapshot_prefix' => 'schema_snapshot',
    'supported_databases' => ['mysql', 'pgsql', 'sqlite'],
    'exclude_tables' => ['migrations', 'failed_jobs'],
    'changelog_formats' => ['markdown', 'json'],
];

๐Ÿง  How It's Better Than Migrations Alone

Laravel Migrations SchemaTrack
Code-first schema Snapshot of actual DB
Doesn't track change history Tracks every change
Manual diffing Auto-diff between any two states
Can become out-of-sync Always reflects real DB state

๐Ÿ”ฎ Roadmap

  • โœ… Auto-generate test cases for schema constraints
  • โœ… Slack/Discord notifications on critical changes
  • โœ… Integration with Laravel Nova or Filament dashboard
  • โœ… Detect risky changes (dropping indexed columns, foreign keys)

๐Ÿงช Testing

# Run all tests
composer test

# Run tests with coverage
composer test-coverage

# Run static analysis
composer analyse

# Format code
composer format

# Check code style
composer format-check

Using Makefile

# Setup development environment
make setup

# Run all CI checks
make ci

# Show available commands
make help

Using Docker for Testing

# Start test databases
docker-compose up -d

# Run tests
composer test

๐Ÿ“„ License

The MIT License (MIT). Please see License File for more information.

๐Ÿค Contributing

Please see CONTRIBUTING.md for details.

๐Ÿ› ๏ธ Development

Prerequisites

  • PHP 8.1+
  • Composer
  • Laravel 10+ or 11+

Setup

# Clone the repository
git clone https://github.com/mohamedhekal/laravel-schema-track.git
cd laravel-schema-track

# Install dependencies
composer install

# Setup development environment
make setup

Running Tests

# Run all tests
make test

# Run tests with coverage
make test-coverage

# Run static analysis
make analyse

# Format code
make format

Contributing

Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

Prerequisites

  • PHP 8.1+
  • Composer
  • Laravel 10+ or 11+

Setup

# Clone the repository
git clone https://github.com/mohamedhekal/laravel-schema-track.git
cd laravel-schema-track

# Install dependencies
composer install

# Setup development environment
make setup

Running Tests

# Run all tests
make test

# Run tests with coverage
make test-coverage

# Run static analysis
make analyse

# Format code
make format

Contributing

Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

๐Ÿ“ž Support