Buscar contenidos

jueves, 17 de septiembre de 2020

Working With Pre and Post Deployment Scripts + DataScriptWriter

Generador MERGE

https://github.com/SQLPlayer/DataScriptWriter

Explanation

https://www.mssqltips.com/sqlservertutorial/3006/working-with-pre-and-post-deployment-scripts/

-------------------

Overview

When databases are created or upgraded, data may need to be added, changed, or deleted. Moreover, certain actions may have to occur on the database before and/or after the process completes. Deployment scripts can be used to accomplish this.

Explanation

In our database project, we've defined a new table but we need a way to insert inital seed data into it. This can be accomplished by updating the Script.PostDeployment.sql script. In the Solution Explorer, we double click this file and modify it as shown

updating the Script.PostDeployment.sql script. In the Solution Explorer

Note the conditional logic. Pre and post deployment scripts always run irrespective of whether we're installing or upgrading. It's prudent to make your scripts idempotent (or re-runnable) so a refactor of your database doesn't fail.

When a database deployment occurs, 3 blocks of code are created within a central .sql script which is generated by Visual Studio. This final auto generated script is what is ultimately deployed to the database. This script has three main blocks of code produced in this order:

  • All code that makes up Scripts.PreDeployment.sql
  • Auto generated code representing database schema creates/drops/changes based on the contents of the project
  • All code that makes up Scripts.PostDeployment.sql

Additional code may also be added to this main script by Visual Studio depending on what deployment options that were chosen such as constraint checking.

Both the pre and post deployment scripts are SQLCMD aware which means you can create separate scripts within the Solution Explorer under it's Pre and Post Deployment folders and include them directly into the main Script.PostDeployment.sql script using the :r command of SQLCMD. This allows you the freedom to isolate specific tasks to specific scripts as opposed to maintaining one monolithic script. SQLCMD variables can be created inside Database.sqlcmdvars within the Solution Explorer.

You may be wondering how a pre deployment script could be useful. One situation to consider is a complex migration of data. Using the pre and post deployment scripts, you could perform some up front work prior to deployment occurring and then work on that data after the deployment occurs.


viernes, 11 de septiembre de 2020

Continuous Code Quality using SonarLint in Visual Studio 2017-19

 


https://www.thecodebuzz.com/continuous-code-quality-of-using-sonar/



Continuous Code Quality using SonarLint in Visual Studio 2017-19

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand”  -Martin Fowler

Most of us understand the importance of code quality. Good coding practices are language agnostics and help any organization to deliver clean, highly reliable, secure and maintainable code. Software maintenance is like a big fat elephant and often eats away a big chunk of project budget allocation. Re-engineering and refactoring of buggy code cost organization time, cost and quality. These small looking coding issues become bigger problems in the future and potentially affect the complete architecture and design of your application.

“Code is maintained more often than it is written”

Today in this article we shall see how to use the Sonar Lint IDE extension in Visual Studio 2017(or VS2019)

SonarLint is an IDE extension that helps to detect and fixing the code quality issues as you type the code in IDE.

SonarLint Visual Studio extension combines together all best of the linting process and supports multiple analyzers and multiple languages.

  • C# (.NET , .NET Core, .NET Standards) – Roslyn analyzer
  • VB.NET- Roslyn analyzer
  • JavaScript- SonarJS analyzer
  • C/C++ – SonarCFamily

Support for Typescript or Python language is supported through another SonarLint plugin works on Visual Studio Code IDE. Please see more details on below link,

Getting started

Prerequisites:

* Visual Studio 2015 or 2017 or 2019

* Install SonarLint extension

From Menu->Extension->Manage Extension, please search with keyword “Sonar” as below. Here I am installing this extension for VS2019.

Note-The first-time installation requires you to restart the Visual Studio to complete the installation.

After successful installation of the extension, IDE will start analyzing code and shall start reporting the issue as shown below,

As you type your code you shall be able to see best recommendation from SonarLint based on configured rules.

Connected Mode

SonarQube scan can be configured as part build and deploy process within the CICD pipeline. SonarQube provides the overall health of the portfolio within the organization with nice dashboards detailing about the overall health of the code.

SonarLint if used with the SonarQube server streamlines the code analysis process by using uniform rule set across the organization and avoids any ambiguity of issues reported on server vs developers Desktop/IDE. So far above we used the default rule set which comes with plugin installation now we shall see how to use the connected mode of sonar server.

Connected mode configuration is a simple 1-2 step process. Below we shall try connecting the application with a quality profile of the server.

  • Click on Team Explorer in Visual Studio and connect to SonarQube as shown below,

  • Provide Server URL and Password or Token to connect with sonar server from IDE,

After successful authentication, please select your organization.

Your application will be connected .

Establish the Sonar Server connection for the first time. Please click on “Bind” as shown below,

After successful binding, Quality profiles from Sonar Server will be downloaded locally in your projects which includes ruleset file and creation of .sonarlint folder as shown below,

  • Sonar rule set file will be created within project folder (.csproj)
  • Folder ‘.sonarlint’ will be created with ruleset file and configuration file as below,

That’s all! Once the project gets connected with the server, Your project will work in connected mode using the same Quality profiles as of Sonar Server. You will be able to see the same coding issues in IDE and in Pipeline and analyze your code against centralized configured rules.

Happy coding !!

Summary :

Today we learned about SonarLint extension set up and configuration for Visual Studio IDE(2017 and 2019). Good coding practices are language agnostics and help the organization to deliver clean, reliable, secure and maintainable code. Buggy code slipping through cracks has the potential to cost a company an entire business. Organizations can address these problems by following best practices of software development like continuous code quality and continuous code review processes.