PHPackages                             nabeel030/schema-to-migrations - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. nabeel030/schema-to-migrations

ActiveLibrary[Database &amp; ORM](/categories/database)

nabeel030/schema-to-migrations
==============================

Generate Laravel migrations from a .sql dump by importing into a temp DB and introspecting schema.

v1.0.0(4mo ago)11MITPHPPHP ^8.2

Since Dec 31Pushed 4mo agoCompare

[ Source](https://github.com/nabeel030/schema-to-migrations)[ Packagist](https://packagist.org/packages/nabeel030/schema-to-migrations)[ RSS](/packages/nabeel030-schema-to-migrations/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

Schema to Migrations
====================

[](#schema-to-migrations)

Convert an existing MySQL `.sql` dump or schema into **Laravel migrations** automatically.

This package is designed for developers migrating legacy projects (Core PHP, CodeIgniter, WordPress, etc.) into Laravel and want **clean, accurate migrations** without rewriting everything manually.

---

✨ Features
----------

[](#-features)

- Import a MySQL `.sql` file into a temporary database
- Introspect schema using `information_schema`
- Generate **Laravel-native migrations**
- Supports:
    - Auto-increment IDs
    - ENUM columns (with defaults)
    - Nullable columns
    - Default values
    - Unsigned integers
    - Foreign keys (separate migration)
- Laravel **12 compatible**
- Windows (Laragon / XAMPP) friendly

---

📦 Installation
--------------

[](#-installation)

```
composer require nabeel030/schema-to-migrations
```

Laravel will auto-discover the service provider.

---

🚀 Basic Usage
-------------

[](#-basic-usage)

```
php artisan migrate:import-schema database/schema.sql
```

This will:

1. Create a temporary database
2. Import the `.sql` file
3. Read schema from `information_schema`
4. Generate migration files
5. (Optionally) drop the temporary database

---

🧾 Command Signature
-------------------

[](#-command-signature)

```
php artisan migrate:import-schema
```

### Example

[](#example)

```
php artisan migrate:import-schema database/legacy.sql
```

---

⚙️ Available Options
--------------------

[](#️-available-options)

OptionDescription`--connection`Database connection name (default: `mysql`)`--database`Temporary database name (default: `legacy_tmp`)`--output`Output directory for migrations`--fk`Foreign key mode: `separate` or `inline``--drop-temp`Drop temp database after generation`--mysql-bin`Full path to `mysql` executable---

📁 Example with All Options
--------------------------

[](#-example-with-all-options)

```
php artisan migrate:import-schema database/legacy.sql \
  --connection=mysql \
  --database=legacy_tmp \
  --output=database/migrations/imported \
  --fk=separate \
  --drop-temp
```

---

🪟 Windows (Laragon / XAMPP) Setup
---------------------------------

[](#-windows-laragon--xampp-setup)

On Windows, the `mysql` CLI is often **not available in PATH** even though MySQL works with Laravel migrations.

This package uses the **MySQL CLI** to safely import large `.sql` dumps.

### Option 1 (Recommended): Set environment variable

[](#option-1-recommended-set-environment-variable)

Add this to your `.env` file:

```
STM_MYSQL_BIN=D:/laragon/bin/mysql/mysql-8.0.xx-winx64/bin/mysql.exe
```

Adjust the path according to your Laragon/XAMPP installation.

### Option 2: Pass it directly to the command

[](#option-2-pass-it-directly-to-the-command)

```
php artisan migrate:import-schema database/legacy.sql \
  --mysql-bin="D:/laragon/bin/mysql/mysql-8.0.xx-winx64/bin/mysql.exe"
```

---

🧪 Running the Generated Migrations
----------------------------------

[](#-running-the-generated-migrations)

To run **only the generated migrations** on a fresh database:

```
php artisan migrate:fresh --path=database/migrations/imported
```

This is the **recommended** approach to avoid conflicts with Laravel’s default migrations.

---

⚠️ Important Notes
------------------

[](#️-important-notes)

- The `migrations` table is **NOT generated** by this package
    (Laravel creates it automatically — this is intentional)
- Foreign keys are generated in a **separate migration** when using `--fk=separate`
- Circular foreign keys may require manual adjustment (rare, legacy schemas)

---

🛠 Supported Column Types
------------------------

[](#-supported-column-types)

- `int`, `bigint`, `smallint`
- `varchar`, `text`, `longtext`
- `enum`
- `boolean`
- `timestamp`, `datetime`
- auto-increment primary keys

---

❌ Not Supported (yet)
---------------------

[](#-not-supported-yet)

- Stored procedures
- Triggers
- Views
- Check constraints
- Indexes / unique keys (planned)

---

🗺 Roadmap
---------

[](#-roadmap)

Planned improvements:

- Index &amp; unique key generation
- Live database introspection (no SQL file)
- PHP Enum generation
- Composite primary keys
- Test suite &amp; CI

---

🤝 Contributing
--------------

[](#-contributing)

Contributions, issues, and feature requests are welcome.

1. Fork the repository
2. Create a feature branch
3. Submit a pull request

---

📄 License
---------

[](#-license)

MIT License © 2025 Nabeel

---

⭐ Support
---------

[](#-support)

If this package saved you time, consider starring the repository on GitHub.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance76

Regular maintenance activity

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

132d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a837c1090317787f0bf1a570ecb86ad7c69d04f9c4929dc72725ae1e984c5a3e?d=identicon)[nabeel030](/maintainers/nabeel030)

---

Top Contributors

[![nabeel030](https://avatars.githubusercontent.com/u/24795874?v=4)](https://github.com/nabeel030 "nabeel030 (2 commits)")

### Embed Badge

![Health badge](/badges/nabeel030-schema-to-migrations/health.svg)

```
[![Health](https://phpackages.com/badges/nabeel030-schema-to-migrations/health.svg)](https://phpackages.com/packages/nabeel030-schema-to-migrations)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[ryangjchandler/orbit

A flat-file database driver for Eloquent.

922256.2k5](/packages/ryangjchandler-orbit)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[baril/bonsai

An implementation of the Closure Tables pattern for Eloquent.

3593.5k](/packages/baril-bonsai)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
