You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Readme.md
+32-26Lines changed: 32 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,15 +38,15 @@
38
38
39
39
## What It Is
40
40
41
-
This package is a tool that creates Laravel migration files by inspecting the application's models with the command `php artisan implicit-migrations:generate`. Even after you change the model classes, you can run the command to generate a migration with the necessary update operations.
41
+
This package is a tool that creates Laravel migration files by inspecting the application's models with the command `php artisan implicit-migrations:generate`. Even after you change the model classes, you can run the command and generate a migration with the necessary update operations.
42
42
43
43
## How It Works
44
44
45
-
With the most basic configuration, the `implicit-migrations:generate` artisan command looks at the Eloquent model and finds necessary information about the table properties such as the table name, primary key etc. Then it goes over the properties of the model and collects the name, type and default value information if provided. With the information collected, it creates a migration file and populates the `up()` and `down()` methods with the appropriate definitions.
45
+
With the most basic configuration, the `implicit-migrations:generate` artisan command looks at a Eloquent model and finds necessary information about the table properties such as the table name, primary key etc. Then it goes over the properties of the model and collects the name, type and default value information if provided. With the information collected, it creates a migration file and populates the `up()` and `down()` methods with the appropriate definitions.
46
46
47
47
### Implications
48
48
49
-
For further details, the generator refers to some additional data in the model class which we call "Implications". These can be specified with either annotations or attributes on the class, properties and methods.
49
+
For further details, the generator refers to some additional data in the model class which we call "Implications". These can be specified with either annotations or attributes on the class, its properties and methods.
50
50
51
51
#### Annotations
52
52
@@ -108,12 +108,12 @@ return new class extends Migration
108
108
};
109
109
```
110
110
111
-
You can find out more on other implications are available in the [Implication Reference](#implication-reference) section.
111
+
You can find out more on other implications in the [Implication Reference](#implication-reference) section.
112
112
113
113
114
114
#### PHP Attributes
115
115
116
-
Another way of specifying implications is using PHP's attributes. The very same implications are avaliable as attributes with the same notation. This is the same model definition as above as far as the generator is concerned:
116
+
Another way of specifying implications is using PHP attributes. The very same implications are avaliable as attributes with the same notation. This is the same model definition as above as far as the generator is concerned:
117
117
118
118
```php
119
119
<?php
@@ -132,7 +132,7 @@ class OrderItem extends Model
132
132
133
133
The advantage of this option is that your IDE/Editor will recognize the attributes as the classes they are and provide autocompletion and descriptions. The down side is that the classes have to be referenced in the models and now they need to be existent in the production environment too.
134
134
135
-
The obvious approach to this is just adding the `implicit-migrations` package to the `require` instead of `require-dev`. The neat approachis to get the attribute classes to the `database/migrations/attributes` directory in the project by publishing them with the `php artisan vendor:publish --tag=implication-attributes` command and add `"database/attributes/composer.json"` to the `composer.json` file like this:
135
+
The obvious approach to tackling this is just adding the `implicit-migrations` package to the `require` instead of `require-dev`. The neat approach, on the other hand, is to get the attribute classes to the `database/migrations/attributes` directory of the project by publishing them with the `php artisan vendor:publish --tag=implication-attributes` command and add `"database/attributes/composer.json"` to the `composer.json` file like this:
136
136
137
137
```json
138
138
...
@@ -146,11 +146,11 @@ The obvious approach to this is just adding the `implicit-migrations` package to
146
146
...
147
147
```
148
148
149
-
This way, you can have the package in the `require` section of your `composer.json` and still have the attribute classes available in production.
149
+
This way, you can have the package in the `require-dev` section of your `composer.json` and still have the attribute classes available in production.
150
150
151
151
### Updates
152
152
153
-
This tool doesn't only work for creating a table for a model. If you change your model and run `implicit-migrations:generate` again, it will resolve the changes in the model by referring to the already generated migrations (**Only** the generated migrations that is. [See: Manual Migrations](#manual-migrations)) and generate a new migration that applies the changes to the table structure.
153
+
This tool doesn't only work for creating a table for a model. If you change your model and run `implicit-migrations:generate` again, it will resolve the changes by referring to the already generated migrations (**Only** the generated migrations that is. [See: Manual Migrations](#manual-migrations)) and generate a new migration that applies the changes to the table structure.
154
154
155
155
For example if you update the above model and add another property to it:
156
156
@@ -220,9 +220,9 @@ return new class extends Migration
220
220
221
221
# Installation
222
222
223
-
The recommended installation is using `composer require --dev toramanlis/implicit-migrations` command. Since **this will make the implication attributes unavailable in production**, if you want to use attributes for implications you have to take one of these approaches:
223
+
The recommended installation is using `composer require --dev toramanlis/implicit-migrations` command. Since **this will make the implication attributes unavailable in production**, if you want to use attributes for implications you have to take one of the following approaches:
224
224
225
-
## Publishing The Attributes
225
+
###Publishing The Attributes
226
226
227
227
You can publish the attribute classes with `php artisan vendor:publish --tag=implication-attributes` and add the line `"database/attributes/composer.json"` in the `composer.json` file like this:
228
228
@@ -238,34 +238,40 @@ You can publish the attribute classes with `php artisan vendor:publish --tag=imp
238
238
...
239
239
```
240
240
241
-
## Opting Out From Attributes
241
+
###Opting Out From Attributes
242
242
243
243
Each and every one of the implications are available as both attributes and annotations. You can completely give up using attributes and switch to the annotation notation with no missing functionality.
244
244
245
245
246
-
## Installing To Production
246
+
###Installing To Production
247
247
248
248
Alternatively, you can always install the package with `composer install toramanlis/implicit-migrations` without the `--dev` option. Having a tool like this in production sure is unnecessary, but it's just that, unnecessary.
249
249
250
250
251
251
# Configuration
252
252
253
253
## `database.model_paths`
254
+
##### Type: *`array`*
255
+
##### Default: *`['app/Models']`*
254
256
255
-
An `array` of paths relative to the project directory where application models reside. The default is a single path the same as Laravel' default model path: `['app/Models']`
257
+
An `array` of paths relative to the project directory where application models reside. If there are multiple model and migration paths in a project, the migration files are created in the migration path that is closest to the source model in the directory tree (complicit with [nWidart/laravel-modules](https://github.com/nWidart/laravel-modules)).
256
258
257
259
## `database.auto_infer_migrations`
260
+
##### Type: *`bool`*
261
+
##### Default: *`true`*
258
262
259
-
This is a `boolean` value that controls, you guessed it, whether or not to infer the migration information automatically. What this means is basically, unless specified otherwise with an implication, none of the models, properties or methods are going to be inspected for migration information. If a property or method of a model has an implication, that model will also be inspected. The default is `true`.
263
+
This is a `boolean` value that controls, you guessed it, whether or not to infer the migration information automatically. What this means is basically, unless specified otherwise with an implication, none of the models, properties or methods are going to be inspected for migration information. However, if a property or method of a model has an implication, that model will be inspected. The default is `true`.
These are `boolean` values that can be used to enable or disable implications. The implication names have to be in snake case as per Laravel's convention of configuration keys e.g. `database.implications.foreign_key`. This set to `true` by default for all the implications.
269
+
These are `boolean` values that can be used to enable or disable each implication. The implication names have to be in snake case as per Laravel's convention for configuration keys e.g. `database.implications.foreign_key`. This set to `true` by default for all the implications.
264
270
265
271
266
272
# Manual Migrations
267
273
268
-
It's always a good idea to have a backup plan. You might come accross some more intricate or complicated requirements from a migration. For this reason, this tool doesn't take into account any migrations that does not have a `getSource()` method. This way, you can add your own custom migrations that are processed with Laravel's `migrate` command, but completely invisible to `implicit-migrations:generate`.
274
+
It's always a good idea to have a backup plan. You might come accross some more intricate or complicated requirements from a migration. For this reason, this tool doesn't take into account any migrations that does not have a `getSource()` method. This way, you can add your own custom migrations that are processed by Laravel's `migrate` command, but completely invisible to `implicit-migrations:generate`.
269
275
270
276
If a manual migration happens to have a method named `getSource`, the [Off](#off) implication can be utilized to indicate that it is in fact a manual migration.
271
277
@@ -275,16 +281,16 @@ If a manual migration happens to have a method named `getSource`, the [Off](#off
275
281
276
282
All the PHP attributes for the implications reside in the namespace `Toramanlis\ImplicitMigrations\Attributes`. If you choose to utilize them, make sure they're available in your production environment as well. See the [installation section](#installation) for details.
277
283
278
-
Generally, the parameters of the implications are optional as they often have default values or can possibly be inferred from the rest of the information available in the application such as the native PHP definitions of models, properties and methods or other implications' details.
284
+
Generally, the parameters of the implications are optional as they often have default values or can possibly be inferred from the rest of the information available in the application, such as the native PHP definitions of models, properties and methods or other implications' details.
279
285
280
-
Best to keep in mind that these details still might not be sufficient to create the migration and some of the *optional* parameters might, in fact, be required.
286
+
Best to keep in mind that these details still might not be sufficient to make a definition and some of the *optional* parameters might, in fact, be required.
Used with classes for specifying the table details. When the `database.auto_infer_migrations` configuration option is set to `true`, using this implication lets the class processed.
293
+
Used with classes for specifying the table details. When the `database.auto_infer_migrations` configuration option is set to `true`, using this implication lets the class get processed.
288
294
289
295
290
296
## `Column`
@@ -293,7 +299,7 @@ Used with classes for specifying the table details. When the `database.auto_infe
Can be used with both classes and properties to define columns. The `name` parameter is mandatory when used with classes as it won't be able to infer the column name. In contrast, when used with a property, column name defaults to the name of the property. Either by using it on a property or providing a `name` that matches a property allows it to infer whatever information available in the definition of said property.
302
+
Can be used both on classes and properties to define columns. The `name` parameter is mandatory when used on classes as it won't be able to infer the column name. In contrast, when used on a property, column name defaults to the name of the property. Either by using it on a property or providing a `name` that matches a property allows it to infer whatever information available in the definition of said property.
297
303
298
304
299
305
## `Index`
@@ -302,9 +308,9 @@ Can be used with both classes and properties to define columns. The `name` param
Just like `Column`, this can also be used with both classes and properties. The `column` parameter is optional when used with a property and defaults to the column name associated with that property even if the property doesn't have a `Column` implication of its own. When used with a class, the `column` parameter is mandatory.
311
+
Just like `Column`, this can also be used both on classes and properties. The `column` parameter is optional when used on a property and defaults to the column name associated with that property even if the property doesn't have a `Column` implication of its own. When used on a class, the `column` parameter is mandatory.
306
312
307
-
When `Index` is associated with a single column name by either using it with a property or having given one value to the `column` parameter, it will try and ensure the existence of a column with that name, using any information available in the model definition.
313
+
When `Index` is associated with a single column name by either using it on a property or having given a value to the `column` parameter, it will try and ensure the existence of a column with that name, using any information available in the model definition.
308
314
309
315
310
316
## `Unique`
@@ -331,7 +337,7 @@ Alias for `Index($column, type: 'primary', ...$args)`
331
337
332
338
`Relationship()`
333
339
334
-
Specifies that a method is a Laravel relationship. What kind of relationship it is will always be inferred by the return type of the method. This implication is redundant if the `database.auto_infer_migrations` configuration option is on, as the return type of a `public` method is already taken as an implication of whether or not it's a relationship method.
340
+
Specifies that a method is a Laravel relationship. What kind of relationship it is will always be inferred by the return type of the method. This implication is redundant if the `database.auto_infer_migrations` configuration option is set to `true`, as the return type of a `public` method is already taken as an implication of whether or not it's a relationship method.
335
341
336
342
If the type of relationship requires tables and columns that are not defined, `Relationship` will try to ensure them in the migration using whatever information is available.
337
343
@@ -342,7 +348,7 @@ If the type of relationship requires tables and columns that are not defined, `R
Defines a column on a pivot table of a relationship. Just like [`PivotTable`](#pivottable), having this implication lets the generator know it's a relationship method. Since pivot tables typically don't have models of their own, we define any extra columns on the relationship method they are required by.
371
+
Defines a column on a pivot table of a relationship. Just like [`PivotTable`](#pivottable), having this implication lets the generator know it's a relationship method. Since pivot tables typically don't have models of their own, we define any **extra** columns on the relationship method they are required by. Only the columns other than the foreign keys need this implicaiton, foreign keys are already covered with the relationship. It's still allowed to use this implication to fine tune them, though.
366
372
367
373
368
374
## `Off`
@@ -371,4 +377,4 @@ Defines a column on a pivot table of a relationship. Just like [`PivotTable`](#p
371
377
372
378
`Off()`
373
379
374
-
Lets the generator know that the given class, property or method should be ignored. This includes `getSource` method a migration. If you have a manually written migration that happens to have a method name`getSource`, you can add this implication to that method to keep the generator off that migration.
380
+
Lets the generator know that the given class, property or method should be ignored. This includes `getSource` method a migration. If you have a manually written migration that happens to have a method named`getSource`, you can add this implication to that method to keep the generator off of that migration.
0 commit comments