Amazing Tool For Handling Database Migrations In Golang

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what is up guys I hope you are all doing fine I just want to make this quick video because I am building a new service for laue which is the company I found it three years ago we need to make a new go service and um I needed to have some interaction with my database which also means I need to have some migration tools and I've been using go migrate for basically everything um the past couple of years but somebody from my community say hey Anthony why aren't you using goose and uh hey I checked and I'm using it right now and I think it's pretty amazing so let's actually dive a little bit deeper into that so if you're wondering what I'm building I'm building this actually live it's uh a real service that we're going to use for the laue company and I am building this basically live on total coder right so if you want to completely see how I built these things that actually going to be used in prodution for the company uh you can basically go to the total coder Link in the description and uh you can learn from that if you want all right so let's take a look at Goose so goose is very simple um let me show you basically how to install this thing so this is the GitHub I will also provide that in the description so the only thing you need to do is basically install this thing right you just copy this stuff and goog will install that as a binary and then you can actually do something like uh Goose like this let me close this and you're going to have a complete CLI right so there it's basically supports a lot of drivers for example red shift post Quest MySQL uh click house it's I don't know it's supporting a ton of stuff which is amazing right um so basically how I use this um so you see these commands which you can do right you could do goose up and all that stuff the problem is that you need to specify some environment variables telling Goose which driver you are using what is basically the uh credentials of your database and all that stuff so I have this of course uh a make file wrapper uh it's it's not the best wrapper but it works for me it's basically where I set my uh database environment variables that I'm using post my connection string my migration pad and all that stuff um that's what I'm doing and then I can just do something like this right let me clear the screen make a reset which basically resets my database make up to uh do all my migrations uh and for example make seat but that's actually something that I created myself internally so that's basically how I'm using this if you want to create a new migration it's very simple you can do goose uh create for example at users uh table right just something like this and then you need to specify U and that's something new in go migrate in goang migrate you don't have the option to you could basically do that programmatically with go functions but it's not that straightforward I think Goose lets you uh have a very very ideoma way to create your migrations with plain goang syntax which is amazing I'm a little bit old school I love to use SQL uh for that so I'm going to say here Goose create at user table SQL press enter so what we didn't do here is specify our migrations there so what go is going to do it's going to dump this thing into your root folder here but I'm going to copy that to my migrations you can actually specify um an environment variable that will uh Target your migration pad if you want right so you can see we have this stuff and let me show you something that I already did you can see here for example the file uploads you do a goose up create a table goose down drop table and uh all this cool stuff I really like go much more than go migrate um that's actually basically it guys so again I'm a big fan of that uh let me know what kind of migration tools you are using is it going and migrate something else or you do it manually could be U or also maybe you're using Goose let me know in the comments what you think about that and again if you really want to see how I'm building these stuff for uh the laue company hey feel free to uh go to the total codish and I'll see you there right thanks for watching this video and I'm looking forward to see you in the next one or in one of my live streams peace out
Info
Channel: Anthony GG
Views: 10,490
Rating: undefined out of 5
Keywords: golang, golang programming, golang migrations, golang goose, golang database migration, learn golang, golang tutorial, golang course, golang tutorial for beginners, golang applications, golang tricks, best resources to learn golang, golang for beginners, vscode, computer science, go programming language, software
Id: tyDan_pFUHE
Channel Id: undefined
Length: 4min 8sec (248 seconds)
Published: Fri May 03 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.