adly-nady/php-my-migration 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

adly-nady/php-my-migration

最新稳定版本:2.0.0

Composer 安装命令:

composer require adly-nady/php-my-migration

包简介

It converts all existing tables in MySQL that do not have migration files to migration files. If they exist, it compares the columns and their data types with the existing ones and syncs the existing ones to MySQL.

README 文档

README

PHP Version Laravel Version License

A powerful Laravel package that automatically generates migration files and Eloquent models from your existing database tables. Perfect for legacy projects or when you need to version control your database structure.

InstallationUsageExamplesFeatures

🌟 Features

  • Smart Migration Generation

    • Automatically detects column types and properties
    • Handles primary keys (single and composite)
    • Supports foreign key relationships
    • Manages indexes and unique constraints
    • Includes timestamps and soft deletes
  • 🎯 Eloquent Model Generation

    • Creates models with proper relationships
    • Adds comprehensive PHPDoc comments
    • Implements type casting
    • Supports soft deletes
    • Manages fillable fields
  • 🚀 Performance & Flexibility

    • Batch processing for large databases
    • Custom output paths
    • Force overwrite option
    • Multiple database connection support

📋 Requirements

  • PHP 8.1 or higher
  • Laravel 9.x, 10.x, or 11.x
  • MySQL database

🚀 Installation

Install the package via Composer:

composer require adly-nady/php-my-migration

The package will automatically register its service provider.

💡 Usage

Basic Usage

Generate migration files for all tables:

php artisan phpmymigration:generate

Generate Migrations and Models

Generate both migrations and Eloquent models:

php artisan phpmymigration:generate --with-models

Generate Only Migrations

Generate only migration files (default behavior):

php artisan phpmymigration:generate --only-migrations

Specify Database Connection

Use a specific database connection:

php artisan phpmymigration:generate --connection=mysql

Force Overwrite

Overwrite existing migration/model files:

php artisan phpmymigration:generate --force

Custom Output Path

Specify custom paths for migrations and models:

php artisan phpmymigration:generate --path=/custom/path

This will create:

  • /custom/path/migrations/ for migration files
  • /custom/path/Models/ for model files

📝 Examples

Generated Migration Example

For a users table with relationships:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
            $table->softDeletes();
        });
    }

    public function down()
    {
        Schema::dropIfExists('users');
    }
};

Generated Model Example

For the same users table:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * User Model
 *
 * @property int $id
 * @property string $name
 * @property string $email
 * @property \DateTime|null $email_verified_at
 * @property string $password
 * @property string|null $remember_token
 * @property \DateTime $created_at
 * @property \DateTime $updated_at
 * @property \DateTime|null $deleted_at
 */
class User extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'name',
        'email',
        'password',
    ];

    protected $casts = [
        'email_verified_at' => 'datetime',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
        'deleted_at' => 'datetime',
    ];
}

👨‍💻 About Me

Hi! I'm Adly Nady, a passionate Laravel developer. I love creating tools that make developers' lives easier. This package is one of my contributions to the Laravel ecosystem.

Connect With Me

LinkedIn Facebook GitHub

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Made with ❤️ by Adly Nady

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-03