Skip to content

Commit

Permalink
Merge pull request #5 from max-ieremenko/release/2.1.3
Browse files Browse the repository at this point in the history
Release/2.1.3
  • Loading branch information
max-ieremenko committed Jan 10, 2021
2 parents 228e43c + 8678bb9 commit 8da786a
Show file tree
Hide file tree
Showing 24 changed files with 196 additions and 90 deletions.
9 changes: 2 additions & 7 deletions Build/build-tasks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Include ".\build-scripts.ps1"
Task default -Depends Initialize, Clean, Build, Pack, UnitTest, Test
Task Pack -Depends PackGlobalTool, PackNet452, PackChoco, PackManualDownload
Task UnitTest -Depends InitializeTests `
, UnitTest452 `
, UnitTest472 `
, UnitTestcore22 `
, UnitTestcore31 `
Expand Down Expand Up @@ -159,7 +158,7 @@ Task PackManualDownload {

Task InitializeTests {
Copy-Item -Path (Join-Path $sourceDir "SqlDatabase.Test\IntegrationTests") -Destination $binDir -Force -Recurse
Copy-Item -Path (Join-Path $binDir "Tests\net452\2.1_2.2.*") -Destination (Join-Path $binDir "IntegrationTests\Upgrade") -Force -Recurse
Copy-Item -Path (Join-Path $binDir "Tests\net472\2.1_2.2.*") -Destination (Join-Path $binDir "IntegrationTests\Upgrade") -Force -Recurse

# fix unix line endings
$test = $moduleIntegrationTests + ":/test"
Expand All @@ -171,10 +170,6 @@ Task InitializeTests {
}
}

Task UnitTest452 {
Test-Unit "net452"
}

Task UnitTest472 {
Test-Unit "net472"
}
Expand Down Expand Up @@ -240,7 +235,7 @@ Task TestPowerShellCore710 {
}

Task TestPowerShellCore720 {
Test-PowerShellCore "mcr.microsoft.com/powershell:7.2.0-preview.1-ubuntu-20.04"
Test-PowerShellCore "mcr.microsoft.com/powershell:7.2.0-preview.2-ubuntu-20.04"
}

Task TestPublishModule {
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018-2020 max-ieremenko
Copyright (c) 2018-2021 max-ieremenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Sources/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers.Unstable" Version="1.2.0.261" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers.Unstable" Version="1.2.0.321" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Sources/GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

[assembly: AssemblyVersion("2.1.2.0")]
[assembly: AssemblyFileVersion("2.1.2.0")]
[assembly: AssemblyVersion("2.1.3.0")]
[assembly: AssemblyFileVersion("2.1.3.0")]
2 changes: 1 addition & 1 deletion Sources/SqlDatabase.Package/choco/sqldatabase.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<description>SqlDatabase is a tool for SQL Server, allows to execute scripts, database migrations and export data.
Requires Powershell Core 6.1+ or PowerShell Desktop 5.1.</description>
<releaseNotes>https://github.com/max-ieremenko/SqlDatabase/releases</releaseNotes>
<copyright>(C) 2018-2020 Max Ieremenko.</copyright>
<copyright>(C) 2018-2021 Max Ieremenko.</copyright>
<tags>sqlserver sqlcmd migration-tool c-sharp command-line-tool miration-step sql-script sql-database database-migrations export-data</tags>
</metadata>

Expand Down
2 changes: 1 addition & 1 deletion Sources/SqlDatabase.Package/nuget/package.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<summary>Command-line tool and PowerShell module for SQL Server.</summary>
<description>SqlDatabase is a tool for SQL Server, allows to execute scripts, database migrations and export data.</description>
<releaseNotes>https://github.com/max-ieremenko/SqlDatabase/releases</releaseNotes>
<copyright>(C) 2018-2020 Max Ieremenko.</copyright>
<copyright>(C) 2018-2021 Max Ieremenko.</copyright>
<tags>sqlserver sqlcmd migration-tool c-sharp command-line-tool miration-step sql-script sql-database database-migrations export-data</tags>
</metadata>

Expand Down
23 changes: 18 additions & 5 deletions Sources/SqlDatabase.PowerShell.Test/CreateCmdLetTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using System.IO;
using NUnit.Framework;
using Shouldly;
using SqlDatabase.Configuration;
using SqlDatabase.PowerShell.TestApi;
Expand Down Expand Up @@ -29,8 +30,16 @@ public void BuildCommandLine(string commandName)

commandLine.Command.ShouldBe(CommandLineFactory.CommandCreate);
commandLine.Connection.ShouldBe("connection string");
commandLine.Scripts.ShouldBe(new[] { "file 1", "file 2" });
commandLine.ConfigurationFile.ShouldBe("app.config");

commandLine.Scripts.Count.ShouldBe(2);
Path.IsPathRooted(commandLine.Scripts[0]).ShouldBeTrue();
Path.GetFileName(commandLine.Scripts[0]).ShouldBe("file 1");
Path.IsPathRooted(commandLine.Scripts[1]).ShouldBeTrue();
Path.GetFileName(commandLine.Scripts[1]).ShouldBe("file 2");

Path.IsPathRooted(commandLine.ConfigurationFile).ShouldBeTrue();
Path.GetFileName(commandLine.ConfigurationFile).ShouldBe("app.config");

commandLine.WhatIf.ShouldBeTrue();

commandLine.Variables.Keys.ShouldBe(new[] { "x", "y" });
Expand All @@ -53,12 +62,16 @@ public void BuildPipeCommandLine(string commandName)

commandLines[0].Command.ShouldBe(CommandLineFactory.CommandCreate);
commandLines[0].Connection.ShouldBe("connection string");
commandLines[0].Scripts.ShouldBe(new[] { "file 1" });
commandLines[0].Scripts.Count.ShouldBe(1);
Path.IsPathRooted(commandLines[0].Scripts[0]).ShouldBeTrue();
Path.GetFileName(commandLines[0].Scripts[0]).ShouldBe("file 1");
commandLines[0].InLineScript.Count.ShouldBe(0);

commandLines[1].Command.ShouldBe(CommandLineFactory.CommandCreate);
commandLines[1].Connection.ShouldBe("connection string");
commandLines[1].Scripts.ShouldBe(new[] { "file 2" });
commandLines[1].Scripts.Count.ShouldBe(1);
Path.IsPathRooted(commandLines[1].Scripts[0]).ShouldBeTrue();
Path.GetFileName(commandLines[1].Scripts[0]).ShouldBe("file 2");
commandLines[1].InLineScript.Count.ShouldBe(0);
}
}
Expand Down
24 changes: 19 additions & 5 deletions Sources/SqlDatabase.PowerShell.Test/ExecuteCmdLetTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using System.IO;
using NUnit.Framework;
using Shouldly;
using SqlDatabase.Configuration;
using SqlDatabase.PowerShell.TestApi;
Expand Down Expand Up @@ -31,10 +32,19 @@ public void BuildCommandLine(string commandName)

commandLine.Command.ShouldBe(CommandLineFactory.CommandExecute);
commandLine.Connection.ShouldBe("connection string");
commandLine.Scripts.ShouldBe(new[] { "file 1", "file 2" });

commandLine.Scripts.Count.ShouldBe(2);
Path.IsPathRooted(commandLine.Scripts[0]).ShouldBeTrue();
Path.GetFileName(commandLine.Scripts[0]).ShouldBe("file 1");
Path.IsPathRooted(commandLine.Scripts[1]).ShouldBeTrue();
Path.GetFileName(commandLine.Scripts[1]).ShouldBe("file 2");

commandLine.InLineScript.ShouldBe(new[] { "sql text 1", "sql text 2" });
commandLine.Transaction.ShouldBe(TransactionMode.PerStep);
commandLine.ConfigurationFile.ShouldBe("app.config");

Path.IsPathRooted(commandLine.ConfigurationFile).ShouldBeTrue();
Path.GetFileName(commandLine.ConfigurationFile).ShouldBe("app.config");

commandLine.WhatIf.ShouldBeTrue();

commandLine.Variables.Keys.ShouldBe(new[] { "x", "y" });
Expand All @@ -57,12 +67,16 @@ public void BuildPipeCommandLine(string commandName)

commandLines[0].Command.ShouldBe(CommandLineFactory.CommandExecute);
commandLines[0].Connection.ShouldBe("connection string");
commandLines[0].Scripts.ShouldBe(new[] { "file 1" });
commandLines[0].Scripts.Count.ShouldBe(1);
Path.IsPathRooted(commandLines[0].Scripts[0]).ShouldBeTrue();
Path.GetFileName(commandLines[0].Scripts[0]).ShouldBe("file 1");
commandLines[0].InLineScript.Count.ShouldBe(0);

commandLines[1].Command.ShouldBe(CommandLineFactory.CommandExecute);
commandLines[1].Connection.ShouldBe("connection string");
commandLines[1].Scripts.ShouldBe(new[] { "file 2" });
commandLines[1].Scripts.Count.ShouldBe(1);
Path.IsPathRooted(commandLines[1].Scripts[0]).ShouldBeTrue();
Path.GetFileName(commandLines[1].Scripts[0]).ShouldBe("file 2");
commandLines[1].InLineScript.Count.ShouldBe(0);
}
}
Expand Down
15 changes: 12 additions & 3 deletions Sources/SqlDatabase.PowerShell.Test/ExportCmdLetTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using System.IO;
using NUnit.Framework;
using Shouldly;
using SqlDatabase.Configuration;
using SqlDatabase.PowerShell.TestApi;
Expand Down Expand Up @@ -29,11 +30,19 @@ public void BuildCommandLine()

commandLine.Command.ShouldBe(CommandLineFactory.CommandExport);
commandLine.Connection.ShouldBe("connection string");
commandLine.Scripts.ShouldBe(new[] { "file 1", "file 2" });

commandLine.Scripts.Count.ShouldBe(2);
Path.IsPathRooted(commandLine.Scripts[0]).ShouldBeTrue();
Path.GetFileName(commandLine.Scripts[0]).ShouldBe("file 1");
Path.IsPathRooted(commandLine.Scripts[1]).ShouldBeTrue();
Path.GetFileName(commandLine.Scripts[1]).ShouldBe("file 2");

commandLine.InLineScript.ShouldBe(new[] { "sql text 1", "sql text 2" });
commandLine.ExportToFile.ShouldBe("to file");
commandLine.ExportToTable.ShouldBe("to table");
commandLine.ConfigurationFile.ShouldBe("app.config");

Path.IsPathRooted(commandLine.ConfigurationFile).ShouldBeTrue();
Path.GetFileName(commandLine.ConfigurationFile).ShouldBe("app.config");

commandLine.Variables.Keys.ShouldBe(new[] { "x", "y" });
commandLine.Variables["x"].ShouldBe("1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Moq" Version="4.15.1" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="Moq" Version="4.15.2" />
<PackageReference Include="NUnit" Version="3.13.0" />
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Shouldly" Version="3.0.2" />
<PackageReference Include="Shouldly" Version="4.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void CreateProgram(string psEdition, Type expected)

var owner = new Mock<ICmdlet>(MockBehavior.Strict);

var actual = SqlDatabaseProgramFactory.CreateProgram(psVersionTable, owner.Object);
var actual = SqlDatabaseProgramFactory.CreateProgram(new PSVersionTable(psVersionTable), owner.Object);

actual.ShouldBeOfType(expected);
}
Expand Down
24 changes: 19 additions & 5 deletions Sources/SqlDatabase.PowerShell.Test/UpgradeCmdLetTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using System.IO;
using NUnit.Framework;
using Shouldly;
using SqlDatabase.Configuration;
using SqlDatabase.PowerShell.TestApi;
Expand Down Expand Up @@ -31,9 +32,18 @@ public void BuildCommandLine(string commandName)

commandLine.Command.ShouldBe(CommandLineFactory.CommandUpgrade);
commandLine.Connection.ShouldBe("connection string");
commandLine.Scripts.ShouldBe(new[] { "file 1", "file 2" });

commandLine.Scripts.Count.ShouldBe(2);
Path.IsPathRooted(commandLine.Scripts[0]).ShouldBeTrue();
Path.GetFileName(commandLine.Scripts[0]).ShouldBe("file 1");
Path.IsPathRooted(commandLine.Scripts[1]).ShouldBeTrue();
Path.GetFileName(commandLine.Scripts[1]).ShouldBe("file 2");

commandLine.Transaction.ShouldBe(TransactionMode.PerStep);
commandLine.ConfigurationFile.ShouldBe("app.config");

Path.IsPathRooted(commandLine.ConfigurationFile).ShouldBeTrue();
Path.GetFileName(commandLine.ConfigurationFile).ShouldBe("app.config");

commandLine.WhatIf.ShouldBeTrue();
commandLine.FolderAsModuleName.ShouldBeTrue();

Expand All @@ -57,12 +67,16 @@ public void BuildPipeCommandLine(string commandName)

commandLines[0].Command.ShouldBe(CommandLineFactory.CommandUpgrade);
commandLines[0].Connection.ShouldBe("connection string");
commandLines[0].Scripts.ShouldBe(new[] { "file 1" });
commandLines[0].Scripts.Count.ShouldBe(1);
Path.IsPathRooted(commandLines[0].Scripts[0]).ShouldBeTrue();
Path.GetFileName(commandLines[0].Scripts[0]).ShouldBe("file 1");
commandLines[0].InLineScript.Count.ShouldBe(0);

commandLines[1].Command.ShouldBe(CommandLineFactory.CommandUpgrade);
commandLines[1].Connection.ShouldBe("connection string");
commandLines[1].Scripts.ShouldBe(new[] { "file 2" });
commandLines[1].Scripts.Count.ShouldBe(1);
Path.IsPathRooted(commandLines[1].Scripts[0]).ShouldBeTrue();
Path.GetFileName(commandLines[1].Scripts[0]).ShouldBe("file 2");
commandLines[1].InLineScript.Count.ShouldBe(0);
}
}
Expand Down
55 changes: 55 additions & 0 deletions Sources/SqlDatabase.PowerShell/CmdletExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.IO;
using System.Management.Automation;
using SqlDatabase.Configuration;

namespace SqlDatabase.PowerShell
{
internal static class CmdletExtensions
{
public static string GetWorkingDirectory(this PSCmdlet cmdlet)
{
var root = cmdlet.MyInvocation.PSScriptRoot;
if (string.IsNullOrEmpty(root))
{
root = cmdlet.CurrentProviderLocation("FileSystem").ProviderPath;
}

return root;
}

public static string RootPath(this PSCmdlet cmdlet, string path)
{
if (string.IsNullOrEmpty(path) || Path.IsPathRooted(path))
{
return path;
}

return Path.Combine(GetWorkingDirectory(cmdlet), path);
}

public static bool TryGetPSVersionTable(this PSCmdlet cmdlet, out PSVersionTable value)
{
var psVersionTable = cmdlet.GetVariableValue("PSVersionTable");
if (psVersionTable == null)
{
value = default;
return false;
}

value = new PSVersionTable(psVersionTable);
return true;
}

public static void AppendFrom(this PSCmdlet cmdlet, string[] from, GenericCommandLineBuilder target)
{
if (from != null)
{
for (var i = 0; i < from.Length; i++)
{
target.SetScripts(cmdlet.RootPath(from[i]));
}
}
}
}
}
10 changes: 2 additions & 8 deletions Sources/SqlDatabase.PowerShell/CreateCmdLet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,10 @@ public CreateCmdLet()

internal override void BuildCommandLine(GenericCommandLineBuilder cmd)
{
if (From != null && From.Length > 0)
{
foreach (var from in From)
{
cmd.SetScripts(from);
}
}
this.AppendFrom(From, cmd);

cmd
.SetConfigurationFile(Configuration)
.SetConfigurationFile(this.RootPath(Configuration))
.SetWhatIf(WhatIf);
}
}
Expand Down
10 changes: 2 additions & 8 deletions Sources/SqlDatabase.PowerShell/ExecuteCmdLet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ public ExecuteCmdLet()

internal override void BuildCommandLine(GenericCommandLineBuilder cmd)
{
if (From != null && From.Length > 0)
{
foreach (var from in From)
{
cmd.SetScripts(from);
}
}
this.AppendFrom(From, cmd);

if (FromSql != null && FromSql.Length > 0)
{
Expand All @@ -52,7 +46,7 @@ internal override void BuildCommandLine(GenericCommandLineBuilder cmd)

cmd
.SetTransaction(Transaction)
.SetConfigurationFile(Configuration)
.SetConfigurationFile(this.RootPath(Configuration))
.SetWhatIf(WhatIf);
}
}
Expand Down
Loading

0 comments on commit 8da786a

Please sign in to comment.