text stringlengths 0 2.35k |
|---|
\[24:08\] So the next question I have for you is - talking about going to production... So we all deploy in different ways. For instance, Mike, you had talked about building this into your application, or some people like to build it in their application, so that when they deploy, it just kind of automatically does tha... |
**Mike Fridman:** Yeah, so I think there's three main ways. The first one is doing it ad-hoc, like running SQL against your database, creating tables and so forth... So we call that, let's say, the manual way. Then there's the semi-manual way, where you have a tool, let's say on your local host, like Goose or Golang Mi... |
**Jon Calhoun:** And I think you and I talked at one point - or maybe it was Vojtech and I, I'm not sure... But I know one of the things that sometimes comes up is that when we're running on one server, things feel simple, because you can deploy, you can wait for the migrations to run, and then you can deploy the new c... |
**Vojtech Vitek:** I think it may depend on the tool itself that you're using. As I mentioned previously, some of those migration tools use a locking mechanism, so even if you have hundreds of nodes running at the same time, and you're deploying them via some rolling update mechanism, they will eventually hang on and w... |
I would say the other approach is to really run a singleton process. So you just need to make sure that your CD pipeline has either a manual step or it has some dependency between your migration, and then deployment of the rest of the application. I saw people using Init Containers in Kubernetes to do this, that relies... |
**Jon Calhoun:** Another one I've seen people ask about is GitHub Actions. Have you seen people use something like that? Like, if they're using that for deployment and continuous integration stuff, have you seen people successfully use a step there that runs migrations before doing a deploy? Or are there some reasons w... |
**Vojtech Vitek:** I can't really think of a reason. It really depends on the infrastructure and the CI/CD pipeline of that specific organization. I mean, GitHub Actions is at the end a CI/CD pipeline anyway, and that's what most of the folks out there are using for deployments as well. So as long as you can depend on ... |
**Jon Calhoun:** That makes sense. I know it's one that people are more familiar with a lot of times, especially when they're getting started. I feel like GitHub Actions are a little bit more approachable. Obviously, when you get to larger-scale corporations there's usually some process involved. And I know these quest... |
**Mike Fridman:** \[28:22\] I think GitHub Actions are perfectly fine, because in GitHub Actions you have workfiles and you have jobs, and then within jobs you have steps... And as long as one of those steps -- and steps are run sequentially, if I remember correctly, within a single job. So as long as one of those step... |
**Jon Calhoun:** Awesome. So the next thing I have is about testing. People always wanna know "How do you test different parts of your code?" and when it comes to touching data, obviously that's a very important thing to make sure you don't mess up. We've all heard horror stories about people accidentally dropping data... |
**Mike Fridman:** Yeah, so testing migrations can usually be done in your continuous (CI) environment. The best way I've found doing that is you kind of apply your migration, add some data, apply a migration, add some data, apply a migration, add some data, and keep doing that going all the way up. Then once you're all... |
**Jon Calhoun:** So when you talk about testing this, what does the test actually look like? Is it like a Go test file, is it something else you're doing? How would you typically do that? |
**Mike Fridman:** Right. For example, now I work at Buf, and the way we do it is for every migration that we apply, we also do a few insert and update statements. And then the next person that comes in, they write a few insert or update statements, and you're kind of just constantly checking to make sure that the thing... |
And then once at the end of the test, it'll run all the down migrations and make sure that you have nothing left in your database. So literally doing that inside something like testing.t, and just a big test file, with some helpers around that. |
**Vojtech Vitek:** What I also like to do on top of that is to check the final schema of the database. So both Postgres, MySQL and modern databases let you explore the schema, drop the schema from the database. And what I've found really useful is to check out the desired schema into your GitHub repository, and then ch... |
**Jon Calhoun:** Is that something that people are checking into their tooling? Or sorry, is that something they're checking into Git, the schema that they're gonna be like "Okay, everybody should compare to this"? Or how does that check process work in your mind? |
**Vojtech Vitek:** Right. So you can check the final schema after you run all the migrations into your Git repository... And then this is also applicable to your local host. So even when you're developing your own new migrations, you see the changes against the file, and you can compare if this is exactly what you mean... |
**Jon Calhoun:** \[32:12\] Okay. |
**Mike Fridman:** Yeah, so maybe I can expand on that one. I also found that useful, where you kind of apply all of your migrations, and at the end of that, let's say in CI, you ask CI to drop the current schema. So you're running, let's say, a Postgres database in a container, you're applying all your migrations and y... |
And when you go to auditing, you can then ask, let's say once a quarter or once a month, or maybe even automated in some way, a DBA to say "Give me the current schema in production", and then compare that against the schema that you have checked in on your main branch. And you'll oftentimes find that -- let's say you g... |
**Jon Calhoun:** So when that type of thing happens, does it make sense to try to go through the effort of somehow getting a migration file -- like, basically, you want a migration that's not actually gonna run when it goes to production, because it's already been run in production. So is it worth the effort of trying ... |
**Vojtech Vitek:** I think this type of changes that let's say some performance engineers or DBAs would do is adding the indexes, as Mike mentioned. And just to make sure that, for example the CPU of the database server goes down immediately when there's a high traffic spike, or whatever... And for those SQL queries, y... |
But yes, I believe that it's worth it to keep the schema the same everywhere... For example, I'm working with one of my customers who has production in five different regions around the globe, and I would be very surprised if there was a different database schema just in Europe, compared to North America, and then some... |
So I like to be in charge of our database schema, because schemas is our state, the most important thing of our application. |
**Jon Calhoun:** That makes sense. And it also makes sense what you were saying earlier, Mike, about developers can sometimes make changes locally when they're sort of tinkering with things and it's easy to forget, especially if you have a long weekend or anything; you can forget that you even tried some different chan... |
**Break:** \[35:19\] |
**Jon Calhoun:** So I guess we're getting close to the end, so we're gonna start talking about unpopular opinions soon... But before that, are there any big takeaways, or words of wisdom, or anything like that that you'd like to share with people before we move on? |
**Vojtech Vitek:** Write documentation. Disaster recovery documentation. Be ready. Be ready to have backups and be able to actually apply them if you need to... Because if you are in panic mode, if the company is down just because of some production issue, you will not think straight. So be ready, that's my advice. |
**Jon Calhoun:** Vojtech, is that something you suggest people actually go through the process of trying it once before they get into actual panic mode? |
**Vojtech Vitek:** Yeah, that's definitely useful. When you're writing this disaster recovery document, you should be also trying it by hand. That's kind of the point. |
**Jon Calhoun:** Okay. So basically have a playbook to go by, so that you aren't making it up as you go and you're also freaking out at the same time. |
**Vojtech Vitek:** Yeah, that's right. And same goes for rollbacks if there's a problem, same goes to potentially think about if it's worth it to do the rollback or if you should go and release a hotfix instead. It's all about trade-offs, but you've gotta be ready. |
**Jon Calhoun:** Mike? |
**Mike Fridman:** Yeah, I was just gonna piggyback on that and say please, please, please have backups. You don't realize it until you need it, and if it's not there when you need it, you're screwed. So make sure you have backups and make sure you understand how to actually apply those backups and do disaster recovery.... |
**Jon Calhoun:** I think I've also heard stories of people where they thought they had backups, and then when it came time to actually use them, they realized that the backup process wasn't working the way they thought it was... So all of a sudden, they don't have the backups they thought they did. Like, yes, you wanna... |
**Vojtech Vitek:** Yeah, that's for sure. And if you're using a database from one of those big providers, then use their own backups. There's no need to write your own tooling for that. |
**Jon Calhoun:** It's one of those things where -- I do a lot of smaller projects myself, or myself and one or two other developers, and sometimes it can feel like you're getting cut by a thousand papercuts when you have all these different bills stacking up... And you aren't a big company, so you're paying for all the... |
**Jingle:** \[39:38\] to \[39:54\] |
**Jon Calhoun:** Okay, Vojtech, I think you said you have an unpopular opinion for us. Would you like to share? |
**Vojtech Vitek:** Yeah. I mean, generics - I'm not against it, I'm very excited about the feature; I can't wait for it, and I'm already playing with it... But I'm also scared for the Go community, like what's gonna happen in the next two years. I'm sure that people will use it and abuse it to the levels that we will e... |
\[40:24\] I think this kind of happened with the Go channels back in the day... People were very excited about the channels, and they used it everywhere, prematurely; they didn't really make sense. And it settled, and now people only use it for specific use cases. And I think the same applies to Go generics. So people,... |
**Jon Calhoun:** I think my one hope around that is that anybody coming to Go from a language that already has generics isn't gonna be like "Oh, I need to use these generics", because they've already had enough experience with it... Whereas the concurrency stuff, if you're coming from a language that doesn't have great... |
An example of this is when I first learned about meta programming in Ruby, I used it way, way too much, because it was just so cool. And then you start debugging code that's using meta programming and you're like "Oh. I don't wanna use this ever again if I can avoid it." |
**Vojtech Vitek:** Yeah, I think the reason why we all love Go - it's simplicity. So I'm just hoping that we will not lose it any time soon. |
**Jon Calhoun:** Mike, do you have an unpopular opinion you'd like to share? |
**Mike Fridman:** Yeah, I do. Hindsight is always 20/20, but I think one of the biggest mistakes in Go is the logger struct. It should have been a logging interface. And because there's no unified interface to marry all of these third-party packages, you have everyone reinventing what a logger interface is... Which cre... |
**Jon Calhoun:** That's one that in my mind I think would have been hard to predict upfront. It's almost like the standard library - it's hard for them to enforce "This is what a logger should look like all the time", because like you're saying, everybody has different wants and needs... I don't disagree with you fully... |
But you might also be right, in the sense that had there been an interface, maybe all those third-party tools would have been more likely to adapt, and make their tool work for it... Because I think about HTTP handlers, and stuff like that, and almost every router out there tries to make it work well with the standard ... |
**Vojtech Vitek:** Maybe a good start would be to have this interface implementing the methods that are currently available in the standard logger struct. That's a good start. |
**Jon Calhoun:** I'm trying to even think about which ones are there, because I don't think I ever used the standard logging struct... \[laughs\] I'm sure I've used it, but it's not common, is how I'd put it. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.