Skip to content

Commit a6d0efb

Browse files
authored
更新說明文件 (#3)
* 增加動畫 * 增加更詳細的說明
1 parent 26fe12d commit a6d0efb

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

.github/animation.gif

217 KB
Loading

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
# A2Workspace/Laravel-Database-Patcher
22

3+
<p align="center"><img src="/.github/animation.gif" alt="Laravel-Database-Patcher demo animation"></p>
4+
35
一個基於專案的資料庫補丁管理工具。
46

7+
隨著專案的進行,難免需要對現有的資料表修修補補,但檔案過於複雜的 `database/migrations` 可能會產生一些問題。`a2workspace/laravel-database-patcher` 提供簡易的管理工具,讓你可以使用獨立的 `database/patches` 資料夾,來放置額外的 **遷移檔 (Migration)**
8+
9+
本套件可以解決以下問題:
10+
- 開發者想增加某些修復用的 **遷移檔 (Migration)** ,但又不想放進 `database/migrations` 影響開發或測試的情形
11+
- 運維人員想編寫一些資料修正的腳本,又不想影響開發或測試的情形
12+
- 運維人員想編寫一些資料修正的腳本,並在測試機環境執行一遍,待測試過了才在正式機環境運行的情形
513

614
## Installation | 安裝
715

@@ -12,10 +20,35 @@ composer config repositories.laravel-database-patcher vcs https://github.com/A2W
1220
composer require "a2workspace/laravel-database-patcher:*"
1321
```
1422

23+
接著使用 `vendor:publish` 命令生成 `database/patches` 資料夾:
24+
25+
```bash
26+
php artisan vendor:publish --tag=@a2workspace/laravel-database-patcher
27+
```
28+
1529
## Usage | 如何使用
1630

17-
現在你可以使用 `db:patch` [Artisan 命令](https://laravel.com/docs/9.x/artisan)來管理資料庫遷移補丁。該命令將會讀取 `database/patches` 下的 [Migrations 遷移檔](https://laravel.com/docs/9.x/migrations)
31+
現在你可以使用 `db:patch` [Artisan 命令](https://laravel.com/docs/9.x/artisan)來管理資料庫遷移補丁。
1832

19-
```
33+
```bash
2034
php artisan db:patch
2135
```
36+
37+
該命令將會讀取 `database/patches` 下的 [Migrations 遷移檔](https://laravel.com/docs/9.x/migrations),並列出可用選項。
38+
39+
### Reverting Back Patches | 還原已安裝的補丁
40+
使用 `--revert` 或簡寫 `-r` 參數,可將已安裝的遷移檔進行 **滾回 (rollback)** 動作:
41+
42+
```bash
43+
php artisan db:patch --revert
44+
```
45+
46+
## Generating Patches | 如何產生補丁檔
47+
48+
補丁與原生的 **遷移檔 (Migration)** 完全相同,你可以參考 [Generating Migrations](https://laravel.com/docs/9.x/migrations#generating-migrations)[Updating Tables](https://laravel.com/docs/9.x/migrations#updating-tables) 的說明生成 **遷移檔 (Migration)** ,接著再把檔案移至 `database/patches` 資料夾內。
49+
50+
或直接用 `make` 命令生成:
51+
52+
```bash
53+
php artisan make:migration --path=database/patches add_soft_deletes_to_users_table
54+
```

0 commit comments

Comments
 (0)