PHPackages                             cxuan1225/sql-laravel-schema-converter - 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. cxuan1225/sql-laravel-schema-converter

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

cxuan1225/sql-laravel-schema-converter
======================================

Convert MySQL or MariaDB CREATE TABLE SQL into Laravel migration schema code.

v1.1.0(2mo ago)01MITJavaScriptPHP ^8.2

Since May 6Pushed 2mo agoCompare

[ Source](https://github.com/Cxuan1225/SQL-Laravel-Schema-Converter)[ Packagist](https://packagist.org/packages/cxuan1225/sql-laravel-schema-converter)[ RSS](/packages/cxuan1225-sql-laravel-schema-converter/feed)WikiDiscussions master Synced 1w ago

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

SQL Laravel Schema Converter
============================

[](#sql-laravel-schema-converter)

Convert MySQL or MariaDB `CREATE TABLE` statements into Laravel migration code.

Use this when you have an existing SQL dump and want a faster starting point for Laravel migrations. The converter can run as an npm CLI, Laravel Artisan command, browser tool, or Vercel API. The npm and Composer package contents are kept separate so each installation gets only the files it needs.

Quick Start
-----------

[](#quick-start)

### Node CLI

[](#node-cli)

Install the standalone CLI:

```
npm install -g sql-laravel-schema-converter
```

Convert a SQL dump into a Laravel migration file:

```
sql-laravel convert dump.sql database/migrations --pk=laravel
```

Print generated PHP to stdout instead:

```
sql-laravel convert dump.sql --no-wrap
```

### Laravel Artisan

[](#laravel-artisan)

Install the Laravel package:

```
composer require cxuan1225/sql-laravel-schema-converter
```

Convert a SQL dump from inside a Laravel application:

```
php artisan schema:convert-sql dump.sql database/migrations --pk=laravel
```

When the output path is a directory, the CLI and Artisan command create a Laravel-style migration filename automatically.

Example
-------

[](#example)

Input SQL:

```
CREATE TABLE `users` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `email` varchar(255) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `users_email_unique` (`email`)
);
```

Command:

```
sql-laravel convert users.sql --pk=laravel
```

Output excerpt:

```
Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->string('email', 255);
    $table->timestamps();

    $table->unique('email', 'users_email_unique');
});
```

What It Converts
----------------

[](#what-it-converts)

- One or more MySQL/MariaDB `CREATE TABLE` blocks.
- Columns, nullable/default modifiers, primary keys, unique keys, indexes, and foreign keys.
- `created_at` and `updated_at` columns into `$table->timestamps()`.
- `deleted_at` columns into `$table->softDeletes()`.
- Optional `bigint unsigned` foreign key columns into `$table->foreignId()`.
- Optional anonymous Laravel migration class wrappers.
- Optional Laravel database connection names through `Schema::connection(...)`.

The converter also detects warnings, SQL size, table names, foreign keys, and conversion status while editing in the browser UI.

Safety Checks
-------------

[](#safety-checks)

By default, conversion is blocked when the input contains CRUD or data statements such as `SELECT`, `INSERT`, `UPDATE`, `DELETE`, or `REPLACE`. Use `--ignore-crud` when you want those statements skipped instead.

Foreign key constraints are moved into a second migration pass so referenced tables can be created first.

Installation From GitHub
------------------------

[](#installation-from-github)

If the packages have not been published to npm or Packagist yet, install directly from GitHub.

```
npm install -g github:Cxuan1225/SQL-Laravel-Schema-Converter
```

```
composer config repositories.sql-laravel-schema-converter vcs https://github.com/Cxuan1225/SQL-Laravel-Schema-Converter.git
composer require cxuan1225/sql-laravel-schema-converter:dev-master
```

Composer uses `composer require` to download a package into a Laravel project. `composer install` is only for installing dependencies from an existing `composer.lock`.

Node CLI Reference
------------------

[](#node-cli-reference)

Run the converter directly from the repository:

```
node bin/sql-laravel.js convert dump.sql generated.php --pk=laravel
```

Write to a migration directory:

```
node bin/sql-laravel.js convert dump.sql database/migrations --migration-name=create_imported_schema
```

Available CLI options:

```
--wrap / --no-wrap
--timestamps / --no-timestamps
--soft-deletes / --no-soft-deletes
--foreign-id
--pk=legacy|laravel
--tinyint=boolean|tinyInteger
--zero-date=nullable|preserve
--connection=
--ignore-crud
--migration-name=
--json
--quiet

```

Laravel Artisan Reference
-------------------------

[](#laravel-artisan-reference)

The Composer package registers this command in Laravel applications:

```
php artisan schema:convert-sql {sql_path} {output_path?}
```

Examples:

```
php artisan schema:convert-sql dump.sql database/migrations --pk=laravel
php artisan schema:convert-sql dump.sql database/migrations/2026_05_06_000000_imported_schema.php --foreign-id
php artisan schema:convert-sql dump.sql --no-wrap --json
```

The Artisan command supports the same conversion options as the Node CLI.

Browser Usage
-------------

[](#browser-usage)

Open `sql_to_laravel_schema_creator.html` in a browser.

No build step is required. The page loads Tailwind CSS from the CDN and uses the local files in `assets/`.

The browser app supports importing `.sql` or `.txt` files, pasting from the clipboard, copying output, and downloading the generated migration.

API Usage
---------

[](#api-usage)

Deploy the repository on Vercel and send JSON to:

```
POST /api/convert
```

Example request:

```
{
  "sql": "CREATE TABLE `users` (`id` bigint unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`));",
  "options": {
    "wrapMigration": true,
    "primaryKeyStrategy": "laravel",
    "ignoreCrud": false
  }
}
```

Example response shape:

```
{
  "code": "
