autn/laravel-schema

Laravel 模式包。

安装数: 3,756

依赖项: 0

建议者: 0

安全: 0

星标: 5

关注者: 2

分支: 8

开放问题: 2

类型:项目

v3.0 2020-09-16 06:52 UTC

This package is auto-updated.

Last update: 2024-09-16 15:36:15 UTC


README

Latest Version on Packagist Build Status Total Downloads

1. 关于

本包可从迁移文件生成 Mysql 数据库模式。

更新时间:2020年9月:现在支持最新 Laravel 版本

2. 安装

通过 composer 安装 - 编辑您的 composer.json 文件以添加此包。

"require": {
    // ...
    "autn/laravel-schema": "*"
}

然后在您的终端中运行 composer update 来拉取包。完成后,您需要将命令添加到 app/Console/Kernel.php 配置文件中的 commands 数组,如下所示:

// ....
protected $commands = [
    // ...
    'db:schema' => \Autn\Schema\Console\Commands\DumpSql::class,
];
// ...

3. 使用方法

注意:该命令将刷新您的数据库,种子数据和实际数据将被删除。我建议使用 --dbconnect 与其他数据库一起运行。

在 Laravel 根项目中,输入

php artisan db:schema

文件将被生成到默认的 databases 路径(database/schema.sql)。

您可以通过在命令中添加 --path 选项来更改此路径。

示例

php artisan db:schema --path=public

默认数据库连接是 mysql,在 config/database.php 中。您可以通过在命令中添加 --dbconnect 来更改连接。

示例

php artisan db:schema --path=public --dbconnect=mysql2

注意:如果您添加了 --dbconnect 选项,则必须在 config/database.php 中添加配置。

示例

// ....
'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', 'localhost'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('DB_DATABASE', 'db'),
    'username' => env('DB_USERNAME', 'root'),
    'password' => env('DB_PASSWORD', 'root'),
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix' => '',
    'strict' => false,
    'engine' => null,
],

'mysql2' => [
    'driver' => 'mysql',
    'host' => 'localhost',
    'port' => '3306',
    'database' => 'db2',
    'username' => 'root',
    'password' => 'root',
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix' => '',
    'strict' => false,
    'engine' => null,
],
// ...

这里有完整选项

--path=: Path to save schema file

--dbconnect=: Database connect to run

--force: Run without confirmation

--method=: Name of method (mysqldump/php). If your server not install mysql (remote to other database server), you must select `php` method

--refresh=: Public migration files and refresh migrations (yes/no)

--type=: Type of file (sql/gzip/bzip2)

4. 更新日志

  • 版本 1.x
Supported mysqldump method
  • 版本 2.0.x
Supported php method (mysqldump version php)
  • 版本 2.1.x
Supported compress (type option)
  • 版本 3.x
Update to support latest Laravel version