PHPackages                             rizkussef/laravel-sql-to-migration - 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. rizkussef/laravel-sql-to-migration

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

rizkussef/laravel-sql-to-migration
==================================

A Laravel package to convert raw SQL CREATE TABLE statements into Laravel migrations automatically.

v1.0.9(9mo ago)2140MITPHPPHP ^8.0

Since Jul 17Pushed 9mo agoCompare

[ Source](https://github.com/RizkUssef/laravel-sql-to-migration)[ Packagist](https://packagist.org/packages/rizkussef/laravel-sql-to-migration)[ RSS](/packages/rizkussef-laravel-sql-to-migration/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (11)Used By (0)

**Laravel SQL to Migration**
============================

[](#laravel-sql-to-migration)

**Laravel SQL to Migration** is a Laravel package that automatically converts raw SQL `CREATE TABLE` statements into fully functional **Laravel migration files**.

---

✅ **Features**
--------------

[](#-features)

- ✔ Parse **multiple tables** from a single SQL file
- ✔ Supports **column types**: `INT`, `BIGINT`, `VARCHAR`, `TEXT`, `DECIMAL`, `TIMESTAMP`, etc.
- ✔ Detect **auto-increment** and convert to `bigIncrements()`
- ✔ Add **primary keys**, **foreign keys**, and **indexes**
- ✔ Handles:
    - `nullable()`
    - `unique()`
    - `default()`
- ✔ Supports **DECIMAL precision** (e.g., `DECIMAL(8,2)`)
- ✔ Optional `timestamps()` via `--timestamps` flag
- ✔ Generates Laravel migration files inside `database/migrations`

---

📦 **Installation**
------------------

[](#-installation)

```
composer require rizkussef/laravel-sql-to-migration
```

---

🚀 **Usage**
-----------

[](#-usage)

### **1. Place your SQL file**

[](#1-place-your-sql-file)

Example:

```
database/schema.sql
```

With content:

```
CREATE TABLE IF NOT EXISTS `orders` (
  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `user_id` BIGINT(20) UNSIGNED NOT NULL,
  `product_name` VARCHAR(255) NOT NULL,
  `price` DECIMAL(8,2) DEFAULT 0.00,
  PRIMARY KEY (`id`),
  INDEX `product_idx` (`product_name`),
  CONSTRAINT `fk_orders_users` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
);
```

---

### **2. Run the command**

[](#2-run-the-command)

bash

```
php artisan sql:sql-to-migration database/schema.sql --timestamps
```

---

### ✅ **Generated Migration**

[](#-generated-migration)

```
Schema::create('orders', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->unsignedBigInteger('user_id');
    $table->string('product_name', 255);
    $table->decimal('price', 8, 2)->default('0.00');
    $table->timestamps();

    // Indexes
    $table->index(['product_name'], 'product_idx');

    // Foreign Keys
    $table->foreign('user_id', 'fk_orders_users')
        ->references('id')
        ->on('users')
        ->onDelete('cascade')
        ->onUpdate('cascade');
});
```

---

⚙ **Options**
-------------

[](#-options)

OptionDescription`--timestamps`Adds `created_at` &amp; `updated_at` columns---

✅ **Supported**
---------------

[](#-supported)

✔ Laravel 9.x &amp; 10.x
✔ PHP 8.0+

---

🔥 **When to Use**
-----------------

[](#-when-to-use)

- Migrating **legacy SQL schema** to Laravel
- Converting **raw SQL dumps** to Laravel migrations
- Automating **third-party database setup** in Laravel projects

---

📌 **Roadmap**
-------------

[](#-roadmap)

- ✅ Support `ON DELETE` / `ON UPDATE` cascade
- ✅ Handle composite primary keys

---

📄 **License**
-------------

[](#-license)

MIT © [Rizk Ussef](https://github.com/rizkussef)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance56

Moderate activity, may be stable

Popularity15

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

Every ~0 days

Total

10

Last Release

293d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f71fc860d07c78f9ceb026be3ea529c3cc27957b6e2631f778c68a2d01761ed?d=identicon)[RizkUssef](/maintainers/RizkUssef)

---

Top Contributors

[![RizkUssef](https://avatars.githubusercontent.com/u/139924623?v=4)](https://github.com/RizkUssef "RizkUssef (19 commits)")

---

Tags

laravelsql-to-migrationconvert sql to laravel migrationlaravel migration generatormysql to laravel migrationphp artisan migration generator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rizkussef-laravel-sql-to-migration/health.svg)

```
[![Health](https://phpackages.com/badges/rizkussef-laravel-sql-to-migration/health.svg)](https://phpackages.com/packages/rizkussef-laravel-sql-to-migration)
```

###  Alternatives

[rtconner/laravel-likeable

Trait for Laravel Eloquent models to allow easy implementation of a 'like' or 'favorite' or 'remember' feature.

394388.0k5](/packages/rtconner-laravel-likeable)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121130.3k](/packages/highsolutions-eloquent-sequence)[cybercog/laravel-nova-ban

A Laravel Nova banning functionality for your application.

40199.8k](/packages/cybercog-laravel-nova-ban)[hpolthof/laravel-translations-db

A database translations implementation for Laravel 5.

545.8k](/packages/hpolthof-laravel-translations-db)[cubettech/lacassa

Cassandra based query builder for laravel.

358.5k](/packages/cubettech-lacassa)[phaza/single-table-inheritance

Single Table Inheritance Trait

1515.8k](/packages/phaza-single-table-inheritance)

PHPackages © 2026

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