|
1 | | -# SQL-order-check-tools |
| 1 | +# sql-order-check-tools |
| 2 | + |
2 | 3 | A tool used to check the order of columns in SQL table structure. |
| 4 | + |
| 5 | +# Configuration description |
| 6 | + |
| 7 | +```php |
| 8 | +// SQL_PATH: Your table structure file path. |
| 9 | +define('SQL_PATH', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'mysql' . DIRECTORY_SEPARATOR . 'mysql.sql'); |
| 10 | +// CACHE_FILE_PATH: Save path and suffix of cache file when configuration `use_cache` is turned on. |
| 11 | +define('CACHE_FILE_PATH', getcwd() . '/.' . md5_file(SQL_PATH) . '.sql_report_cache'); |
| 12 | +const ERROR_CODE = 0; |
| 13 | +const SUCCESS_CODE = 1; |
| 14 | +// Message output when the program detects no abnormality. |
| 15 | +const SUCCESS_MESSAGE = 'Good job!'; |
| 16 | +// Unspecified remaining columns. |
| 17 | +const REMAINING_COLUMNS = '...'; |
| 18 | +const CONFIG = [ |
| 19 | + 'sql_file_path' => SQL_PATH, |
| 20 | + |
| 21 | + 'similar_adjacent' => true, // Open similar columns sorting, e.g. user_name, user_age, user. |
| 22 | + 'use_cache' => true, |
| 23 | + 'sql_order_rules' => [ |
| 24 | + 'id|_id', // If there is an `id` column in the table, it will be ranked first; if there is a field like `xxx_id`, it will be ranked after the `id`. |
| 25 | + // 'type|_type', |
| 26 | + // 'category|_category', |
| 27 | + // 'status', |
| 28 | + REMAINING_COLUMNS, // This is the only place where similar adjacent rules are used |
| 29 | + 'created_at', |
| 30 | + 'updated_at', |
| 31 | + 'deleted_at', |
| 32 | + ], |
| 33 | + 'ignore_tables' => [ |
| 34 | +// 'addresses', // Tables that ignore some special rules. |
| 35 | + ], |
| 36 | +]; |
| 37 | +``` |
| 38 | +# How to use |
| 39 | + |
| 40 | +Put your MySQL table structure file in the specified folder. |
| 41 | +Execute `/src/sql-order-analyse-tools` in the terminal. |
| 42 | + |
| 43 | +# Analysis report |
| 44 | + |
| 45 | +<img width="890" alt="report" src="https://user-images.githubusercontent.com/29700073/145230629-e8c8fb5d-3b29-4d3c-ae78-09761ce2310a.png"> |
| 46 | + |
0 commit comments