forked from dotnet/efcore
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
and PS>Script-DbContext fixes issue dotnet#10378
- Loading branch information
Showing
15 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.DotNet.Cli.CommandLine; | ||
using Microsoft.EntityFrameworkCore.Tools.Properties; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Tools.Commands | ||
{ | ||
internal partial class DbContextScriptCommand : ContextCommandBase | ||
{ | ||
private CommandOption _output; | ||
|
||
public override void Configure(CommandLineApplication command) | ||
{ | ||
command.Description = Resources.MigrationsScriptDescription; | ||
|
||
_output = command.Option("-o|--output <FILE>", Resources.OutputDescription); | ||
|
||
base.Configure(command); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.IO; | ||
using System.Text; | ||
using Microsoft.EntityFrameworkCore.Tools.Properties; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Tools.Commands | ||
{ | ||
// ReSharper disable once ArrangeTypeModifiers | ||
internal partial class DbContextScriptCommand | ||
{ | ||
protected override int Execute() | ||
{ | ||
var sql = CreateExecutor().ScriptDbContext( | ||
Context.Value()); | ||
|
||
if (!_output.HasValue()) | ||
{ | ||
Reporter.WriteData(sql); | ||
} | ||
else | ||
{ | ||
var output = _output.Value(); | ||
if (WorkingDir.HasValue()) | ||
{ | ||
output = Path.Combine(WorkingDir.Value(), output); | ||
} | ||
|
||
var directory = Path.GetDirectoryName(output); | ||
if (!string.IsNullOrEmpty(directory)) | ||
{ | ||
Directory.CreateDirectory(directory); | ||
} | ||
|
||
Reporter.WriteVerbose(Resources.WritingFile(_output.Value())); | ||
File.WriteAllText(output, sql, Encoding.UTF8); | ||
} | ||
|
||
return base.Execute(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters