dotnet / dotnet/efcore

Cleanup output-path behavior when generating migrations

Open
#32,738 3 comments 2 reactions 0 assignees View on GitHub
area-migrations area-tools breaking-change customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

Adding a new, initial migration "M" results in three new files:

- `project/Migrations/11112233445566_M.cs`
- `project/Migrations/11112233445566_M.Designer.cs`
- `project/Migrations/GnomeContextModelSnapshot.cs`

However, using `--output-path` changes this in non-obvious ways. There are four subcategories:

### Relative output path

This is presumably the intended use, and the results seem reasonable:

- `project/outputPath/11112233445566_M.cs`
- `project/outputPath/11112233445566_M.Designer.cs`
- `project/outputPath/GnomeContextModelSnapshot.cs`

### Empty output path

Note that this is _not_ the same as a `null` output path, and is not blocked. Presumably, it should mean either the same as `null` or it should mean don't use `Migrations`, which is the default, and instead just put the files directly in the project root. We actually do half and half:

- `project/11112233445566_M.cs`
- `project/11112233445566_M.Designer.cs`
- `project/Migrations/GnomeContextModelSnapshot.cs`

Notice that the snapshot still goes into "Migrations", but the other files go in the project root.

### Absolute output path

It's not clear to me that this was ever intentional, but it is not blocked. I assume people will do this because they want to explicitly place the files somewhere outside the project.

Given the absolute output path `/mydrive`, the files generated are:

- `/mydrive/11112233445566_M.cs`
- `/mydrive/11112233445566_M.Designer.cs`
- `project/Migrations/GnomeContextModelSnapshot.cs`

Notice that snapshot file is not in the output path (it's still relative to the project) and is in the "Migrations" folder.

### Output path and namespace set

When the `--namespace` option is also used, then it impacts some paths but not others. For example, with `--namespace Acme.Packing --output-dir outputDir`:

- `project/outputPath/11112233445566_M.cs`
- `project/outputPath/11112233445566_M.Designer.cs`
- `project/Acme/Packing/GnomeContextModelSnapshot.cs`

Notice that the snapshot goes into a folder named for the namespace, but the other files go into the output path.

FYI, the result of using `namespace` without output-path is:

- `project/Acme/Packing/11112233445566_M.cs`
- `project/Acme/Packing/11112233445566_M.Designer.cs`
- `project/Acme/Packing/GnomeContextModelSnapshot.cs`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.