|
| 1 | + |
1 | 2 | # laravel-nomadic
|
2 | 3 | [](https://travis-ci.org/chrishalbert/laravel-nomadic)
|
3 | 4 | [](https://coveralls.io/github/chrishalbert/laravel-nomadic?branch=master)
|
4 | 5 | [](https://packagist.org/packages/chrishalbert/laravel-nomadic)
|
5 | 6 | [](https://packagist.org/packages/chrishalbert/laravel-nomadic)
|
6 | 7 | [](https://packagist.org/packages/chrishalbert/laravel-nomadic)
|
7 | 8 |
|
8 |
| - |
9 |
| -A configuration based tool kit of enhancements to Laravel's migrations. Exposes functionality so that developers can customize how migrations are generated. |
| 9 | +A powerful configuration based toolkit of enhancements to Laravel's migrations. This exposes an event driven design so that developers can create reusable functionality that executes automatically using the same developer workflow. |
10 | 10 |
|
11 | 11 | ## Features
|
12 |
| -* **Nomadic Schema** - Associate data with each migration. Maybe you want to save the date and time the migration was run, |
13 |
| -how long it ran for, or specific data with regards to nature of the migration itself. |
14 |
| -* **Nomadic Traits** - Inject your own custom traits into your migrations so that you can reuse common code. |
15 |
| -* **Nomadic Hooks** - Apply hooks before or after a migration is generated. |
16 |
| -* More to come... |
17 |
| - |
18 |
| -## Installation - |
19 |
| - |
20 |
| -1. Installation: |
21 |
| - |
22 |
| -``` |
23 |
| -composer require chrishalbert/laravel-nomadic |
24 |
| -``` |
25 |
| - |
26 |
| -or manually add it to the require-dev section of your composer file. |
27 |
| - |
28 |
| -```json |
29 |
| -{ |
30 |
| - "require" : { |
31 |
| - "chrishalbert/laravel-nomadic": "1.*" |
32 |
| - } |
33 |
| -} |
34 |
| -``` |
35 |
| - |
36 |
| -2. Next, add the Service Provider to the config/app.php |
| 12 | +* [**Hooks**](docs/NomadicHooks.md) - Use pre/post hooks for migration commands: `make:migration`, `migrate`, and `migrate:rollback` |
| 13 | + |
| 14 | +* **Stubs** - Add developer notes to the generated migration |
| 15 | + |
| 16 | +* [**Schema**](docs/NomadicSchema.md) - Associate extra data within your `migrations` table |
| 17 | + |
| 18 | +| id | migration | batch | author | comments | rollback | |
| 19 | +|----|:-------------------:|------:|-------:|---------------------------:|-----------:| |
| 20 | +| 1 | 20200811_CreateTable| 1 | John | Stores data for product x | NULL | |
| 21 | +| 2 | 20200812_AddData | 1 | Jack | Populate product x features| NULL | |
| 22 | +| 3 | 20200812_UpdateData | 2 | Jane | Fix description typo | {desc: "Grate product."}| |
| 23 | + |
| 24 | +* [**Traits**](docs/NomadicTraits.md) - Add reusable functionality to every migration, via traits. Bonus: You can use hooks here too! |
| 25 | + |
| 26 | + |
| 27 | +## Installation |
| 28 | +1. ```composer require chrishalbert/laravel-nomadic``` |
| 29 | +2. Add the Service Provider to the config/app.php: |
37 | 30 | ```php
|
38 | 31 | 'providers' => [
|
39 |
| - |
40 | 32 | /**
|
41 | 33 | * Custom Providers...
|
42 | 34 | */
|
43 | 35 | ChrisHalbert\LaravelNomadic\NomadicServiceProvider::class,
|
44 | 36 | ]
|
45 | 37 | ```
|
46 |
| - |
47 |
| -3. Lastly, publish some default configs into your application. |
48 |
| -``` |
49 |
| -php artisan vendor:publish // Installs the nomadic.php config |
50 |
| -``` |
51 |
| - |
52 |
| - |
53 |
| -## Nomadic Schema |
54 |
| -* Use Case: A developer wants to track the migration's runtime. |
55 |
| -* Use Case: A developer wants to know exactly when a migration started or ended. |
56 |
| -* Use Case: A developer deletes records from a table. To rollback this migration, the down() function would include |
57 |
| -hardcoded values. While this could work for some simple applications, any randomized or scrubbed database will not |
58 |
| -necessarily translate across tables. |
59 |
| -* Use Case: A developer inserts new records into a table. To rollback this migration, the down() function would need |
60 |
| -to query the exact records that were inserted. If the developer's database is a lean version of production, the query |
61 |
| -may not be accurate. |
62 |
| -* Use Case: A developer updates records in table. Similarly, to rollback, the down() function would need to know the |
63 |
| -exact values of the records prior to updating. This could differ for randomized data. |
64 |
| - |
65 |
| -### Setup |
66 |
| -1. First, you will need to add the field(s) to your migration table - this is on you to do :) |
67 |
| -2. Open up the nomadic.php and add the fields in the schema array |
68 |
| -``` |
69 |
| -return [ |
70 |
| - // Just some examples below - these would be the additional columns in your migration table. |
71 |
| - 'schema' => [ |
72 |
| - 'flag', |
73 |
| - 'author', |
74 |
| - 'runTime', |
75 |
| - 'migrationInfo' |
76 |
| - ], |
77 |
| -]; |
78 |
| -``` |
79 |
| - |
80 |
| -Now, verify the configurations are complete. |
81 |
| -``` |
82 |
| -php artisan make:migration VerifyNomadicInstalled |
83 |
| -``` |
84 |
| - |
85 |
| -In your migration, you should now see that your migration `extends NomadicMigration`. |
86 |
| - |
87 |
| -As noted above in your new migration's comments: |
88 |
| -```php |
89 |
| - /** |
90 |
| - * @return void |
91 |
| - */ |
92 |
| - public function up() |
93 |
| - { |
94 |
| - // Use $this->setProperty($migrationColumn, $insertedIds); |
95 |
| - // The $migrationColumn MUST be added to the configs/nomadic.php |
96 |
| - } |
97 |
| - |
98 |
| - /** |
99 |
| - * Reverse the migrations. |
100 |
| - * |
101 |
| - * @return void |
102 |
| - */ |
103 |
| - public function down() |
104 |
| - { |
105 |
| - // And now you can $insertedIds = $this->getProperty($migrationColumn) and delete |
106 |
| - } |
107 |
| -``` |
108 |
| - |
109 |
| -## Nomadic Traits |
110 |
| -* Use Case: Reuse common functionality that your migrations tend to use. |
111 |
| - |
112 |
| -### Usage |
113 |
| -Open up the nomadic.php and add your custom traits |
114 |
| -``` |
115 |
| -return [ |
116 |
| - 'traits' => [ |
117 |
| - \My\Custom\Trait::class |
118 |
| - ], |
119 |
| -]; |
120 |
| -``` |
121 |
| -Now when you create migrations, you should see your stubbed migration using your custom traits. |
122 |
| - |
123 |
| -## Nomadic Hooks |
124 |
| -* Use Case: You would like to alert the developer to run all migrations before creating a new one. |
125 |
| -* Use Case: After a migration is generated, you want to remind the user to add schema changes to the release notes. |
126 |
| - |
127 |
| -### Usage |
128 |
| -Open up the nomadic.php where you can add 2 different types of hooks. |
129 |
| - |
130 |
| -#### Create Hooks |
131 |
| -These are hooks used when you run `php artisan make:migration`. These hooks can ONLY be defined here in the config file. You can pass a closure, or you can pass a NomadicHookInterface. The benefit of passing the NomadicCreateHookInterface, is that you get the same data passed to the create(). These arguments are |
132 |
| -passed to the execute() method, which is what is called. |
133 |
| -``` |
134 |
| -return [ |
135 |
| - 'hooks' => [ |
136 |
| - 'preCreate' => [ |
137 |
| - function() { |
138 |
| - \Log::info('Make sure to run all migrations'); |
139 |
| - }, |
140 |
| - ], |
141 |
| - 'postCreate' => [ |
142 |
| - new NomadicCreateHookInterfaceImplementation() |
143 |
| - ] |
144 |
| - ], |
145 |
| -]; |
146 |
| -``` |
147 |
| - |
148 |
| -#### Migration Hooks |
149 |
| -These hooks are excuted when the migration runs. The construct hook can only be set in the config file. Everything else can be set here in the configuration |
150 |
| -or modified at runtime. |
151 |
| -``` |
152 |
| -return [ |
153 |
| -
|
154 |
| - // Hooks executed with the migrations |
155 |
| - 'hooks' => [ |
156 |
| - 'construct' => [ // Can only be defined in the configs |
157 |
| - ], |
158 |
| - 'preMigrate' => [ // Executed before up() |
159 |
| - ], |
160 |
| - 'postMigrate' => [ // Executed after up() |
161 |
| - ], |
162 |
| - 'preRollback' => [ // Executed before rolling down() |
163 |
| - ], |
164 |
| - 'postRollback' => [ // Executed after rolling down() |
165 |
| - ], |
166 |
| - 'destruct' => [ // Executed during destruction |
167 |
| - ] |
168 |
| - ], |
169 |
| -]; |
170 |
| -``` |
171 |
| - |
| 38 | +3, Publish default configs/nomadic.php: ```php artisan vendor:publish``` |
172 | 39 |
|
173 | 40 | ## Feature Requests/Bugs
|
174 |
| - Submit feature requests or bugs to [laravel-nomadic Issues](https://github.com/chrishalbert/laravel-nomadic/issues). |
| 41 | + Submit feature requests or bugs to [laravel-nomadic issues](https://github.com/chrishalbert/laravel-nomadic/issues). |
| 42 | + |
| 43 | +## Services |
| 44 | +_Do you have an internal need or enhancement you care not to share with the world?_ |
| 45 | +####I can help! |
| 46 | +Reach out to me directly for rates, scope and your business needs. I can furnish an NDA as needed. |
0 commit comments