定制 rizkussef/laravel-sql-to-migration 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rizkussef/laravel-sql-to-migration

最新稳定版本:v1.0.9

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 --timestamps flag
  • ✔ 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->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

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 UPDATE cascade
  • ✅ Handle composite primary keys

📄 License

MIT © Rizk Ussef

统计信息

  • 总下载量: 184
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固