Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The tool contains the following features.
- **Schema compare** - compare your database project with a live database and get a script to update the database or your project
- **Analyze** - report with static code analysis result of your database project
- **Create Mermaid E/R diagram** - create an Entity/Relationship diagram of selected tables from your database project
- **Unpack dacpac** - extract a .dacpac into a single .sql file
- **Script Database Model** - extract a .dacpac into a single .sql file

### Power Pack

Expand All @@ -38,7 +38,7 @@ I have also published [SQL Project Power Pack](https://marketplace.visualstudio.

Have a look at our extensive [user guide](https://github.com/rr-wfm/MSBuild.Sdk.SqlProj/blob/master/README.md) for more information on topics like:

- reference user and system database
- reference user and system databases
- set database and build properties
- use pre- and post-deployment scripts
- pack and publish dacpacs
Expand Down
23 changes: 1 addition & 22 deletions src/Vsix/Handlers/CompareHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static async Task GenerateAsync(Project project)
DatabaseType = DatabaseType.SQLServerDacpac,
};

var dacpacInfo = await GetDacpacInfoAsync(dacOptions);
var dacpacInfo = await HandlerHelper.GetDatabaseInfoAsync(dacOptions);

if (dacpacInfo == null)
{
Expand Down Expand Up @@ -129,27 +129,6 @@ private static async Task<DatabaseConnectionModel> GetDatabaseInfoAsync(DataApiB
return dbInfo;
}

private static async Task<DatabaseConnectionModel> GetDacpacInfoAsync(DataApiBuilderOptions options)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

var dbInfo = new DatabaseConnectionModel();

dbInfo.DatabaseType = DatabaseType.SQLServerDacpac;
dbInfo.ConnectionString = $"Data Source=(local);Initial Catalog={Path.GetFileNameWithoutExtension(options.Dacpac)};Integrated Security=true;";
options.ConnectionString = dbInfo.ConnectionString;
options.DatabaseType = dbInfo.DatabaseType;

options.Dacpac = await SqlProjHelper.BuildSqlProjectAsync(options.Dacpac);
if (string.IsNullOrEmpty(options.Dacpac))
{
VSHelper.ShowMessage("Unable to build the database project");
return null;
}

return dbInfo;
}

private static async Task<(DatabaseConnectionModel DatabaseModel, bool DatabaseIsSource)> ChooseDataBaseConnectionAsync(DataApiBuilderOptions options)
{
var vsDataHelper = new VsDataHelper();
Expand Down
23 changes: 1 addition & 22 deletions src/Vsix/Handlers/DabBuilderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static async Task BuildDabConfigAsync(Project project)

DatabaseConnectionModel dbInfo = null;

dbInfo = await GetDatabaseInfoAsync(options);
dbInfo = await HandlerHelper.GetDatabaseInfoAsync(options);

if (dbInfo == null)
{
Expand Down Expand Up @@ -77,27 +77,6 @@ public static async Task BuildDabConfigAsync(Project project)
}
}

private static async Task<DatabaseConnectionModel> GetDatabaseInfoAsync(DataApiBuilderOptions options)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

var dbInfo = new DatabaseConnectionModel();

dbInfo.DatabaseType = DatabaseType.SQLServerDacpac;
dbInfo.ConnectionString = $"Data Source=(local);Initial Catalog={Path.GetFileNameWithoutExtension(options.Dacpac)};Integrated Security=true;";
options.ConnectionString = dbInfo.ConnectionString;
options.DatabaseType = dbInfo.DatabaseType;

options.Dacpac = await SqlProjHelper.BuildSqlProjectAsync(options.Dacpac);
if (string.IsNullOrEmpty(options.Dacpac))
{
VSHelper.ShowMessage("Unable to build the database project");
return null;
}

return dbInfo;
}

private static async Task GenerateFilesAsync(string optionsPath, string connectionString)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
Expand Down
23 changes: 1 addition & 22 deletions src/Vsix/Handlers/ErDiagramHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static async System.Threading.Tasks.Task BuildErDiagramAsync(Project proj

options.Dacpac = project.FullPath;

var dbInfo = await GetDatabaseInfoAsync(options);
var dbInfo = await HandlerHelper.GetDatabaseInfoAsync(options);

if (dbInfo == null)
{
Expand Down Expand Up @@ -70,27 +70,6 @@ public static async System.Threading.Tasks.Task BuildErDiagramAsync(Project proj
}
}

private static async Task<DatabaseConnectionModel> GetDatabaseInfoAsync(DataApiBuilderOptions options)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

var dbInfo = new DatabaseConnectionModel();

dbInfo.DatabaseType = DatabaseType.SQLServerDacpac;
dbInfo.ConnectionString = $"Data Source=(local);Initial Catalog={Path.GetFileNameWithoutExtension(options.Dacpac)};Integrated Security=true;";
options.ConnectionString = dbInfo.ConnectionString;
options.DatabaseType = dbInfo.DatabaseType;

options.Dacpac = await SqlProjHelper.BuildSqlProjectAsync(options.Dacpac);
if (string.IsNullOrEmpty(options.Dacpac))
{
VSHelper.ShowMessage("Unable to build the database project");
return null;
}

return dbInfo;
}

private static async System.Threading.Tasks.Task GenerateFilesAsync(string optionsPath, string connectionString)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
Expand Down
30 changes: 30 additions & 0 deletions src/Vsix/Handlers/HandlerHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.IO;
using System.Threading.Tasks;
using DacFXToolLib.Common;
using DacFXToolLib.Dab;

namespace SqlProjectsPowerTools;

public static class HandlerHelper
{
public static async Task<DatabaseConnectionModel> GetDatabaseInfoAsync(DataApiBuilderOptions options)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

var dbInfo = new DatabaseConnectionModel();

dbInfo.DatabaseType = DatabaseType.SQLServerDacpac;
dbInfo.ConnectionString = $"Data Source=(local);Initial Catalog={Path.GetFileNameWithoutExtension(options.Dacpac)};Integrated Security=true;";
options.ConnectionString = dbInfo.ConnectionString;
options.DatabaseType = dbInfo.DatabaseType;

options.Dacpac = await SqlProjHelper.BuildSqlProjectAsync(options.Dacpac);
if (string.IsNullOrEmpty(options.Dacpac))
{
VSHelper.ShowMessage("Unable to build the database project");
return null;
}

return dbInfo;
}
}
2 changes: 1 addition & 1 deletion src/Vsix/VSCommandTable.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>TextChanges</CommandFlag>
<Strings>
<ButtonText>Unpack</ButtonText>
<ButtonText>Script Database Model</ButtonText>
</Strings>
</Button>

Expand Down
1 change: 1 addition & 0 deletions src/Vsix/Vsix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<Compile Include="Handlers\DabBuilderHandler.cs" />
<Compile Include="Handlers\DacpacAnalyzerHandler.cs" />
<Compile Include="Handlers\CompareHandler.cs" />
<Compile Include="Handlers\HandlerHelper.cs" />
<Compile Include="Handlers\ImportHandler.cs" />
<Compile Include="Handlers\ErDiagramHandler.cs" />
<Compile Include="Handlers\PackageManager.cs" />
Expand Down
Loading