casperw/laravel-tidy-tables

整理数据库列,使其整洁有序。

1.0.1 2018-10-10 17:13 UTC

This package is auto-updated.

Last update: 2024-09-24 05:51:10 UTC


README

Latest Version on Packagist Total Downloads Software License StyleCI

此包提供了一种重新排列现有所有数据库表列的方法。排序算法将按照以下结构对表列进行排序

  • 主键
  • 全局唯一标识符
  • 外键
  • 本地列
  • 时间戳

示例

例如,我创建了一个'products'表。您可能认出了左边的情景,其中表变得杂乱无序。

右边的表显示了运行整理命令后列的分组情况。

Alt text

安装

通过Composer

$ composer require casperw/laravel-tidy-tables --dev

配置

默认设置在config/laraveltidytables.php中。将此文件复制到您的配置目录以修改值。您可以使用以下命令发布配置

$ php artisan vendor:publish --tag=laraveltidytables.config

配置文件包含一个字段数组和一个数据类型数组。

可用字段

    /*
    |--------------------------------------------------------------------------
    | Fields
    |--------------------------------------------------------------------------
    |
    | The following fields are configurable and are used during
    | sorting of the configured database. Change these existing fields to your liking.
    | Note, that it's possible to add timestamps and change order to your liking.
    |
    */
    'fields' => [
        'primary_key' => 'id',
        'universally_unique_identifier' => 'uuid',
        'foreign_key_affix' => '_id',
        'timestamps' => [
            'deleted_at',
            'updated_at',
            'created_at',
        ],
    ],

可用数据类型

注意: 默认情况下,配置支持laravel的默认数据类型。请检查您的数据库是否与默认值对应,如有必要,请更改它们!

    /*
    |--------------------------------------------------------------------------
    | Data types
    |--------------------------------------------------------------------------
    |
    | Here are all the datatypes that are used by the sorting algoritm.
    | It's important to note that these values are based on laravel's default migration data types.
    | You might not use a CHAR(36) for uuid's in your configuration. Change these values if so.
    |
    */
    'data_types' => [
        'universally_unique_identifier' => 'CHAR(36)',
        'foreign_keys' => 'INTEGER UNSIGNED',
        'timestamps' => 'TIMESTAMP NULL'
    ]

用法

以下命令将排序您数据库的所有表。

注意: 确保在操作之前备份您的数据库。

$ php artisan migrate --tidy

变更日志

请参阅变更日志以获取最近更改的更多信息。

许可证

MIT。有关更多信息,请参阅许可证文件