rizkussef/laravel-sql-to-migration
Composer 安装命令:
composer require rizkussef/laravel-sql-to-migration
包简介
A Laravel package to convert raw SQL CREATE TABLE statements into Laravel migrations automatically.
关键字:
README 文档
README
Laravel SQL to Migration is a Laravel package that automatically converts raw SQL CREATE TABLE statements into fully functional Laravel migration files.
✅ 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--timestampsflag - ✔ Generates Laravel migration files inside
database/migrations
📦 Installation
composer require rizkussef/laravel-sql-to-migration
🚀 Usage
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
bash
php artisan sql:sql-to-migration database/schema.sql --timestamps
✅ Generated Migration
Schema::create('orders', function (Blueprint $table) { $table->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
| Option | Description |
|---|---|
--timestamps |
Adds created_at & updated_at columns |
✅ Supported
✔ Laravel 9.x & 10.x
✔ PHP 8.0+
🔥 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
- ✅ Support
ON DELETE/ON UPDATEcascade - ✅ Handle composite primary keys
📄 License
MIT © Rizk Ussef
rizkussef/laravel-sql-to-migration 适用场景与选型建议
rizkussef/laravel-sql-to-migration 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 351 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 07 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「convert sql to laravel migration」 「sql to migration」 「laravel migration generator」 「mysql to laravel migration」 「php artisan migration generator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rizkussef/laravel-sql-to-migration 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rizkussef/laravel-sql-to-migration 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rizkussef/laravel-sql-to-migration 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provides a simple decimal/roman number converter
A library that provides a simple infrastructure to create your own converters and to perform any conversion you want
Query filtering in your frontend
Convert xml to array
Database/ORM-agnostic query construction helper
Convert doctrine dbal query result to dto
统计信息
- 总下载量: 351
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-17