zaterdag 10 oktober 2020

Azure DevOps and Git integration with DBeaver

Introduction

One of the nice things about working with software is that there is always something new to explore. Now, I'm looking into the possibillities of DBeaver and the integration with Git. The reason is that I want to explore connecting Snowflake and DBeaver/Git for my (local) development environment. This way I have version controlled code locally and I can deploy the code to Snowflake. I have a richer GUI instead of the webbased editor of Snowflake itself. But, it's experiment with DBeaver and Git to learn how it works and whether it is usable for projects I'm involved.


Git plug-in

Now it seems that Git is not fully integrated into DBeaver but you have to install a plugin into DBeaver to have Git integration. Now it was kind of puzzle but I managed to install the plugin. Here is the walkthrough. 


There seems to be more Git plugins, one of Dbeaver itself and one Eclipse and it seems that the Eclipse plugin is breaking the Dbeaver code, but as you may see later in this blogpost, when I select the DBBeaver Git support a couple of Eclipse code is installed. Not sure whether this is the right one. 


Configure

Let's walkthrough the steps I took in order to make it work. A small disclaimer, I'm not stating that I executed the most efficient steps to configure the setup with Git, DBeaver, DevOps. May be there is a better sequence of steps to perform the configuration. Try out yourself. 


1. First start DBeaver, select "Help" and then select "Install New Software".


This will open the install new software window. 


2. In the next step a window opens and here you can choose the repository. I chose the DBeaver Git integration. 




3. When you are done, press the Next button and an overview window is presented. Here you can see that some Git software of Eclipse is installed, also.


4. Click on Next and the next screen is shown. Here you have to review the licenses and accept the licenses.


5. Press on finish when the licenses are reviewed and then a warning appears that authenticy can not be established. 


6. DBeaver is restarted and it appears again. When DBeaver returns nothing seems really changed, when you look closer there are some elements added in the File menu


And below on the screen an extra pane appeared. 


7. Press on the "Create a new local Git repository" and enter a directory name for Git in a folder. In my case it is D:\tmp\git.


Git

8. Now go to your Git folder and start CMD.exe and write the following statements.


I saved the script "Script.sql" that I have created in this folder and with Git status I'm notified that the file is untracked.

9. The next step is to add the file to the local git repository with "Git add". 



10. After the "Git add" execute a "git commit" as you can see in the following screenshot. 


11. Next set up the remote repository Url with Git Remote command.



Next, when I try to push the code to the remote repository, I recieved the following error message because the remote repository contains work that I haven't included in my local repository. It seems that Git thinks that I 'm mixing up repositories.


"Git Pull" gave me a "Fatal" because of unrelated histories. 


Now, I have created a local repository and a remote repository and I commited some code to the repositories and Git doesn't seems to understand how the two projects are related. The error is resolved by toggling the allow-unrelated-histories switch. After a git pull or git merge command, add the following tag: git pull origin master --allow-unrelated-histories

12. Enter "git pull origin master --allow-unrelated-histories".



13. Change something in the code and check if the configuration of Git is correctly done.


14. Commit and push the code to the remote repository. 


Okay, that seems to be working well.


DBeaver

But why did I need to install the Plugin in DBeaver? I configured Git but I didn't use any functionality of the Git plug-in in DBeaver. Let's take a closer look at DBeaver and the Git plug in. 


15. Now in the projects pane there is a little icon, and if you look closely it says "Git". Press on the icon with your mouse.

16. Select the "Existing local repository" and press Next.


17. Select the folder where the Git repository resides. In my case D:\tmp\Git.



18. Choose "Import using the New Project Wizard" and press on Finish.



19. And now a new project is created in DBeaver with the script.sql file in the project.



20. One step is to check whether the code is commited from DBeaver. I Changed something in the code and committed the code the remote repository



21. In the File menu, Choose Git and then "Commit changes to Git"





22. And in the next window press the button "commit and push" to push the changed code to the remote repository. 



23. For the login, create a PAT in Azure Devops and use that as a password with your user account. Press log in.



24. And the code is pushed to the remote repository. Press Close to close the window.


25. And voila! The change is commited into Git and Azure DevOps shows this perfectly.



Final Thoughts

This blogpost is about building a develpoment environment with Git, Azure DevOps and DBeaver. I learned something new and hopefully it can help you too.


Hennie

Geen opmerkingen:

Een reactie posten