cable8mm / xeed

Xeed旨在根据现有数据库表中的数据为Laravel生成新模型、种子、数据库种子、工厂和迁移文件。

维护者

详细信息

github.com/cable8mm/xeed

源代码

问题

安装: 320

依赖项: 0

建议者: 0

安全: 0

星标: 85

关注者: 1

分支: 8

开放性问题: 2

类型:项目

v1.5.0 2024-06-30 06:26 UTC

README

韩文(Korean) 👈

code-style run-tests Packagist Version Packagist Downloads Packagist Dependency Version Laravel Version Packagist Dependency Version Packagist Stars Packagist License

Xeed旨在根据现有数据库表中的数据为Laravel生成新模型、种子、数据库种子、工厂和迁移文件。

提示

它既可以作为Laravel的php artisan xeed:*命令,也可以作为独立应用程序的bin/console *命令,提供100%相同的功能。因此,您可以在自己的Laravel项目中或作为独立应用程序使用它。

我们在网站上提供了API文档。更多信息,请访问https://www.palgle.com/xeed/ ❤️

特性

  • 支持数据库测试
  • 为Laravel生成模型
  • 为Laravel生成种子文件
  • 为Laravel生成数据库种子文件
  • 为Laravel生成工厂
  • 为Laravel生成迁移
  • 为Laravel生成belongsTo和hasMany关系函数
  • 支持Laravel多列和保留列
  • 支持Laravel集成
  • 支持MySQL、SQLite和PostgreSQL

支持 & 测试

MySQL Supported SQLite Supported PostgreSQL Supported PHP 8.0.2+ Supported PHP 8.1.0+ Supported PHP 8.2.0+ Supported PHP 8.3.0+ Supported

注意

PostgreSQL支持处于测试阶段。如果您遇到任何问题,请通过GitHub问题报告。

预览

Laravel

Preview

独立

Preview

安装

composer require cable8mm/xeed --dev
# For Laravel
composer create-project cable8mm/xeed
# For Standalone

重要

编辑.env文件以配置您自己的数据库。您需要时可以手动将.env.example复制到.env

使用方法

生成模型

php artisan xeed:models
# Generate all models from database in `app/Models` folder

php artisan xeed:models -f -t xeeds
# Force to generate a model from `xeeds` table in `app/Models` folder
bin/console models
# Generate all models from database in `dist/app/Models` folder

bin/console models -f -t xeeds
# Force to generate a model from `xeeds` table in `app/Models` folder

生成种子

php artisan xeed:seeders
# Generate all seeds from database in `database/seeders` folder

php artisan xeed:seeders -f -t xeeds
# Force to generate a seeder from `xeeds` table in `database/seeders` folder
bin/console seeders
# Generate all seeds from database in `dist/database/seeders` folder

bin/console seeders -f -t xeeds
# Force to generate a seeder from `xeeds` table in `dist/database/seeders` folder

生成Faker种子

Faker种子在没有使用factory()方法的情况下使用来生成种子。此命令的创建是为了解决问题#61,提供其用途的见解。

php artisan xeed:faker-seeders
# Generate all seeds from database in `database/seeders` folder

php artisan xeed:faker-seeders -f -t xeeds
# Force to generate a seeder from `xeeds` table in `database/seeders` folder
bin/console faker-seeders
# Generate all seeds from database in `dist/database/seeders` folder

bin/console faker-seeders -f -t xeeds
# Force to generate a seeder from `xeeds` table in `dist/database/seeders` folder

生成DatabaseSeeder

php artisan xeed:database
# Generate a database seed from database in `database/seeders` folder
bin/console database
# Generate a database seed from database in `dist/database/seeders` folder

生成工厂

php artisan xeed:factories
# Generate all factories from database in `database/factories' folder

php artisan xeed:factories -f -t xeeds
# Force to generate a factory from `xeeds` table in `database/factories' folder
bin/console factories
# Generate all factories from database in `dist/database/factories' folder

bin/console factories -f -t xeeds
# Force to generate a factory from `xeeds` table in `database/factories' folder

生成迁移

php artisan xeed:migrations
# Generate all migrations from database in `database/migrations' folder

php artisan xeed:migrations -f -t xeeds
# Force to generate a migration from `xeeds` table in `database/migrations' folder
bin/console migrations
# Generate all migrations from database in `dist/database/migrations' folder

bin/console migrations -f -t xeeds
# Force to generate a migration from `xeeds` table in `database/migrations' folder

生成的文件存储在与您的Laravel项目相同的文件夹中。请检查dist文件夹。

生成关系

此命令只能在存在use HasFactory;的模型中使用,所有关系都将放置在其后。

php artisan xeed:relations
# Add the relation function to all models from database in `app/Models` folder

php artisan xeed:relations -m
# Runs xeed:models before running xeed:relations. Add -f to force to generate
bin/console relations
# Add the relation function to all models from database in `dist/app/Models` folder

bin/console relations -m
# Runs xeed:models before running xeed:relations. Add -f to force to generate

生成的关联使用laravels约定命名。一些名称可能重复

有用的命令

如果您要自己测试此包,请使用以下命令清理生成的文件。

php artisan xeed:clean
# Clean generated files, seeders, models, factories and migration files.
#=> Refer the below
Please select directory for you to want to clean.
  [0] seeder
  [1] model
  [2] factory
  [3] migration
  [4] all
  [5] exit
bin/console clean
# Clean generated files, seeders, models, factories and migration files.
#=> Refer the below
Please select directory for you to want to clean.
  [0] seeder
  [1] model
  [2] factory
  [3] migration
  [4] all
  [5] exit

格式化

composer lint
# Modify all files to comply with the PSR-12.

composer inspect
# Inspect all files to ensure compliance with PSR-12.

测试

它使用内置的SQLite数据库,而不是您自己的数据库。它永远不会损害您的数据。您不需要担心这一点。

composer testpack
# All tests with Laravel artisan commands
composer test
# All tests without Laravel artisan commands

变更日志

有关最近更改的更多信息,请参阅CHANGELOG

贡献

有关详细信息,请参阅CONTRIBUTING

以下内容可以帮助您贡献。

Xeed内置了SQLite数据库,允许您在不需要自己的数据库的情况下轻松贡献。只需为测试目的创建一个新文件并使用它。

touch database/database.sqlite
# Create a new empty file for SQLite database

然后,

composer test
# Run tests

数据库种子

对于迁移和工厂,当您需要为所有数据库字段类型执行测试时,请使用以下命令。

php artisan xeed
# Import an 'xeeds' Table into the Database

php artisan xeed drop
# Drop the 'xeeds' Table from the Database
bin/console xeed
# Import an 'xeeds' Table into the Database

bin/console xeed drop
# Drop the 'xeeds' Table from the Database

通过引用以下位置database/*.sql使用迁移文件来引用所有数据库字段类型,这些文件保存在指定的文件夹中。

使用testorchestral/testbench

您可以使用testorchestral/testbench来执行测试。当运行Laravel命令时,生成的文件将保存在vendor/orchestra/testbench-core/laravel/database文件夹中。

鸣谢

许可证

Xeed 项目是开源软件,遵循 MIT 许可协议