aldeebhasan/migration-mapper
Composer 安装命令:
composer require aldeebhasan/migration-mapper
包简介
This package is designed to enable the developer to generate the migration files by just building his model
关键字:
README 文档
README
Automatically generate you migration files from your models
Why
One of the most important and critical part of laravel application is the migration files. Each time you need to add s single column to your table, you need to go to the console, create your migration file, add your migration commands and finally run the migrations.
This package will hide this over head from you, you only need to define the blueprint of you model and we will handle everything automatically.
Installation
Install using composer:
composer require aldeebhasan/migration-mapper
After installation run the following code to publish the config:
php artisan vendor:publish --tag=migration-mapper-config
Basic Usage
Let's suppose that you have a model named as Product with three parameters [id,name,description,category_id,visisble] as Follow:
#[Table(
name: 'x_models', // optional
columns: [
new Id(),
new String_('name', length:255, default: "admin"),
new Text('description', length:255, default: "admin"),
new BigInteger('category_id', nullable: true, index: true, unsigned: true),
new Enum('visible', ['off', 'on'], default: 'off', comment: 'status of the product'),
]
)]
class XModel extends Model
{
protected $fillable = [
'name', 'description', 'category_id'
];
}
Each time you want to generate the migration files, you simply need to call:
php artisan mapper:generate
The result of the above command will be:
database
migrations
2024_02_19_1708369156_create_x_models_table_m.php
Note that the name parameter of table is optional. If it doesn't provided we will detect the table name from the model
If you want to discard all previous changes and migratin and start again from scratch, you can use the following command:
php artisan mapper:regenerate
By calling it we will delete all the migration files, all our logs and start again from zero.
At any point of time, if you want to rollback the last generation process, you can use the following command:
php artisan mapper:rollback
Supported Column Type
- Boolean()
- Date()
- DateTme()
- Time()
- TinyInteger()
- SmallInteger()
- Integer()
- MediumInteger()
- BigInteger()
- Decimal()
- Double()
- Float_()
- Enum()
- Id()
- String_()
- TinyText()
- SmallText()
- MediumText()
- Text()
- LongText()
Each of these types has a specific parameters that represent the operation the can handle.
Relations:
This package can also handle the relation between models.
The relation that we may interest in is Many To One and Many To Many relations, since they have direct effect on the model itself
lets consider that we have the following model:
#[Table(
columns: [
new Id(),
new String_('name', length:255, default: "admin"),
new BigInteger('category_id',unsigned: true,index: true),
]
)]
class Product extends Model
{
protected $fillable = [
'name','category_id'
];
#[ManyToOne(related: Category::class)]
public function category(): HasMany
{
return $this->belongsTo(Category::class, 'category_id')
}
#[ManyToMany(related: Product::class, table: 'product_related', foreignKey: 'source_id', localKey: 'id', targetForeignKey: 'target_id', targetLocalKey: 'id')]
public function related_products(): BelongsToMany
{
return $this->belongsToMany(Product::class,'product_related', 'source_id', 'target_id');
}
}
By calling php artisan mapper:generate,
the package will generate two tables for you
and we will get the followings:
database
migrations
2024_02_19_1708369156_create_products_table_m.php
2024_02_19_1708369157_create_product_related_table_m.php
Please Note the other kind of relation has no effect over the model, so there is no idea of handling them.
License
Laravel Migration Mapper package is licensed under The MIT License (MIT).
Security contact information
To report a security vulnerability, contact directly to the developer contact email Here.
aldeebhasan/migration-mapper 适用场景与选型建议
aldeebhasan/migration-mapper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「migrate」 「laravel migrate」 「model migrate」 「handle modle」 「migration mapper」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 aldeebhasan/migration-mapper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aldeebhasan/migration-mapper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 aldeebhasan/migration-mapper 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Custom migrate in laravel. You can individual file migrate here
This extension allows you to easily create large migrations associated with many foreign keys.
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Interfaces for web resource models and services to retrieve and create them
This module extends Drupal Migrate framework.
MySQL Database Migration
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-19