spotifyovercastrssapple-podcasts

Evergreen Migrations with Mario Rogic

Mario walks us through how Evergreen gives you type-safety between versions of your application, and some improvements in Lamdera 1.1.0.
July 31, 2023
#87

Transcript

[00:00:00]
Hello Jeroen.
[00:00:02]
Hello Dillon.
[00:00:04]
Well Jeroen, there are some topics that are hot off the presses and you gotta hit them while they're hot.
[00:00:09]
And some topics never get old.
[00:00:11]
You might even call them evergreen.
[00:00:13]
And I'd like to think that our topic today is a bit of an evergreen topic.
[00:00:17]
So, Mario Rojic, welcome back to the show.
[00:00:20]
Hey guys, thanks for having me.
[00:00:22]
And what are we talking about today?
[00:00:25]
So yeah, I guess we're talking about the idea of evergreen elm.
[00:00:30]
So, type safety between versions of your application.
[00:00:35]
Or at least that's my interest in evergreen elm.
[00:00:38]
Maybe there's other kinds of evergreen elm that people are interested in.
[00:00:41]
That's a nice tagline for it.
[00:00:43]
So, evergreen elm.
[00:00:45]
And we were talking before the recording here about different species, different variants of elm tree.
[00:00:53]
And apparently there are some variants that are deciduous elm trees and some that are evergreen.
[00:00:59]
So, perhaps lamdara is an evergreen variant of an elm tree.
[00:01:04]
Yeah, I'm down for that.
[00:01:07]
I'm really keen to dig into the philosophical implications and ideas behind evergreen migrations.
[00:01:16]
And what makes it such a core part of lamdara and the guarantees that it provides.
[00:01:22]
So, I'm kind of curious, Mario, could you tell us about the motivations and contrast it to deciduous migrations in other contexts?
[00:01:34]
Maybe non-elm contexts.
[00:01:36]
What was the pain point and problem you were trying to solve and the guarantees you were trying to provide?
[00:01:41]
Yeah, sure.
[00:01:42]
I think the driver for evergreen was a practical one and the name came afterwards as I kind of expanded that practical problem to the front end.
[00:01:55]
So, where the concept arose from and kind of what led to my original presentation called Evergreen Elm at Elm Europe in 2019.
[00:02:08]
I had started working on the ideas behind early versions of lamdara.
[00:02:14]
So, this idea of full stack elm and what that would look like if the elm architecture was on the back end as well.
[00:02:21]
As opposed to previous incarnations of back end elm and some current incarnations of back end elm.
[00:02:28]
I kind of like, well, what if we just use elm as a language instead of JavaScript as a language, but otherwise have all the same concepts.
[00:02:36]
Back ends obviously have a server with HTTP endpoints.
[00:02:41]
And so, one of the approaches was like, okay, let's model all of that in elm and see what that looks like.
[00:02:47]
Whereas, the projects that I'd been working on and the thing that I was kind of reaching for was,
[00:02:52]
I wanted an experience on the back end that was the same as the experience on the front end.
[00:02:58]
And so, part of that crazy idea initially was, well, what if the database wasn't like a separate thing?
[00:03:06]
Like, I like the elm model. It's nice that it just, you know, while you're operating in the front end as a front end developer,
[00:03:12]
you don't think about the persistence of the front end model.
[00:03:16]
As long as the user's browser is open, it's quote unquote persistent, right? You're not thinking about it.
[00:03:22]
And if the user closes their tab, well, then it's gone.
[00:03:26]
And so, for the back end, I was like, okay, that's great. But, you know, if the server crashes
[00:03:32]
and all your state disappears, like that sucks.
[00:03:36]
And so, step one was like, okay, can we solve that problem?
[00:03:40]
But then step two was several of them being like, okay, well, you know, now there's a new thing that we don't really have.
[00:03:46]
Or at least I hadn't heard talked about a lot in elm or just in front end in general,
[00:03:51]
which is what happens when we have a new version of our app and the types have changed.
[00:03:57]
Now, I think the general approach on the front end is like, I don't know.
[00:04:03]
Cross your fingers and yeah.
[00:04:07]
Maybe they'll click a link and the page will refresh. We'll be lucky.
[00:04:13]
Or, you know, like, I suppose if you're, I suppose most companies would be like, I don't know.
[00:04:18]
We'll just, hopefully it doesn't happen that much. And if something goes wrong and they contact support,
[00:04:23]
we'll tell them, hey, have you tried refreshing the page? Oh, the issues have gone away. That's cool.
[00:04:27]
Great. Glad we solved your problem. And no one thinks about it again.
[00:04:30]
I guess the problem happens more with single page applications rather than.
[00:04:35]
Yeah, definitely.
[00:04:36]
More traditional way.
[00:04:38]
And I had heard, I can't remember who I heard this from, but I had heard anecdotally that like someone was,
[00:04:43]
told me, I was like, oh, they once received like their company used like versioning or something.
[00:04:48]
Right. So for the front end comes. So they're like, oh, you know, I don't think we have this problem because we use versioning.
[00:04:53]
And I was like, okay, cool. What's the oldest event version that you've gotten?
[00:04:58]
They're like, oh yeah, we got like, someone must have kept a tab open for like a year or something because we got events from like a year ago.
[00:05:04]
I was like, right. And what do you do with those? And they're like, I don't know if you drop them on the floor.
[00:05:08]
What can you do? You can't do anything right. In the normal thinking.
[00:05:12]
So I was like, what would be a really elm way to solve this?
[00:05:16]
And yeah, the only thing I could think of was, well, it should just upgrade.
[00:05:20]
Like it should just work. It should just continue.
[00:05:24]
And even more so than that, it's like, I want it to type check. That's what I want.
[00:05:27]
Like I want to go from one version of app to a new version of an app.
[00:05:31]
And I want the compiler to be like, yeah, you, this is good.
[00:05:35]
Like however you're going between these two, that type checks, that makes sense.
[00:05:40]
So that was the first motivation. It was like that, that thought of like, okay, well, if we have data that's alive in one app and we're releasing new app with new types, how do we get from one app to the second app?
[00:05:53]
And the reason name came about.
[00:05:55]
I feel like you're intuitively going to the more like subtle edge case of it, but there's also like the core meat of what most people would think of as a migration that people wouldn't gloss over how to handle these edge cases in their application and just be like, Matt, I hope it works, which is migrating your backend, migrating your database.
[00:06:20]
Right. And so of course that's a less subtle case, but evergreen migrations also provide a type safe way to migrate from one version of your backend model to a new version of your backend model.
[00:06:35]
Yeah, absolutely. So that was the practical driver.
[00:06:38]
It was like, yeah, obviously the concept of migrations of your backend is already a thing and it's important.
[00:06:43]
So I wanted to facilitate that and for it to be type safe.
[00:06:46]
And then where the name came from is I realized like, oh, now that like if we have this, well, we could do this on the front end as well.
[00:06:53]
And so instead of the front end effectively like having to drop it state every time there was a new app or you hope the user clicks, which for me had that notion of like, you know, the leaves falling off the tree, kind of being deciduous.
[00:07:07]
Then I thought, oh, well, if the front end can always stay alive, then I was suddenly like, well, that's kind of like how browsers now, they call them like evergreen, right?
[00:07:16]
Like browsers that continually update themselves. And so, yeah, that's, you know, elm and trees and evergreen. I was like, oh, this is nice. This is, yeah, this is the way I'm going.
[00:07:25]
So, yeah, I'm not sure how well though that term translates. A lot of people get confused.
[00:07:31]
I had imagined evergreen would like perfectly like encapsulate and explain everything. I'd be like, yeah, it's evergreen, but it doesn't, I'm not sure that in practice that's translated.
[00:07:40]
So I've definitely found that, that, yeah, people, it feels to me like, or at least the way that I experienced it, I'd be curious how you guys have experienced it.
[00:07:50]
My experience is that people go, oh, that's some black magic. Like there's something crazy going on with evergreen. There's something magical happening.
[00:07:58]
When in reality, it's actually really dumb. Like it's, it's the dumbest possible thing. It's like, how do you migrate with a function?
[00:08:06]
Like it takes value A and it returns value B. But I think, yeah, the, the grokking, like the, the, the details of what that actually means has interestingly been, yeah, a stumbling point, which I found interesting.
[00:08:18]
Yeah, I was there. Well, we were both there actually with them. Churchalk in Europe, 2019. So yeah, we, we got the explanation right off the bat.
[00:08:28]
So you've been biased. Yeah, very biased. So for me, it's clear. It's, it's a function. And I've also played with them there a little bit. So yeah, for me, it's pretty simple, but I can understand why people would be confused or scared of this because yeah.
[00:08:46]
Like imagine doing this in any other system than Elm or Lamdara and like, yeah, no, like that has to be magic.
[00:08:54]
Yeah, yeah, yeah. So maybe, and I think it was also funny because like at, I was devising this idea for Lamdara, which didn't quite exist yet. And so I kind of wanted to do a talk on evergreen Elm, but I couldn't really mention the backend.
[00:09:06]
So I had to reframe my whole Elm Europe talk as, well, yeah, like this concept on the front end. And I think for some people, maybe it was like, well, why would you go to all that effort in just refresh?
[00:09:18]
So it was kind of like this idea was there and I was like, this idea is so cool, but then I couldn't talk about it in the context where I thought it was super cool.
[00:09:26]
So yeah, I think I kind of demonstrated it backwards, but yeah, maybe, maybe if we just went very briefly for those listening to understand or people who may not have a concept or maybe aren't tracking,
[00:09:36]
we could go through like a couple of types of state and what a migration would look like verbally. I think that might give an indicator. What do you reckon?
[00:09:44]
I just want to correct something because, which is my fault because I induced you into giving an error, saying something wrong. Evergreen Elm was from 2018.
[00:09:54]
Oh, I see.
[00:09:56]
Lamdera.
[00:09:58]
Lamdera was 2019.
[00:10:00]
That's the one I was in the audience for. But I really enjoyed watching the Evergreen one on YouTube.
[00:10:08]
Yeah. Okay. So let's take a model. So let's say you have a, I think explaining it on the front end is probably the easiest. So let's say on your front end, we have the counter app. Right.
[00:10:20]
And I think I did this in my talk in France. So say the counter app starts with like counter of, it's a record with one field, field name counter, and the field type is int. Right.
[00:10:33]
And let's say for some silly reason, we say, okay, well, we now want to release a new version of the app, but we've changed the counter field to type float.
[00:10:44]
And the question would be like, how do we migrate from one to the other? And so, yeah, when we say it's just a function, what we're saying is like, yeah, we want a function that takes a record with a field counter type int and returns a record with a field counter type float.
[00:10:59]
So returning the new record, you basically just construct the record. But for the value of counter, right, you've got an integer and now you need a float.
[00:11:08]
So you kind of go off and you find a function, you know, what does like what function takes an integer and returns a float. And that's the function that you would use. So I can't remember off the top of my head. Is that from int or to float?
[00:11:20]
One of those two. Probably have to look that up.
[00:11:23]
To float, I'm pretty sure. Is what I would try. And then if I get a compiler error.
[00:11:31]
This is a guess driven development is how we operate. Yeah, so to float, to float, right from basics. So it's in the call.
[00:11:40]
So yeah, that is in an essence it, like that's the end of Evergreen migrations at like a simplified level.
[00:11:50]
So basically any model that you have in your back end or front end in Lambda, it's both. But if you're just thinking of Elm, like in the Elm architecture, whatever your model type is, if you change that type, the question is, well, what is a sensible transition?
[00:12:07]
What is a sensible transformation between whatever it used to be and whatever the new value is?
[00:12:12]
And on the front end, there is some interesting stuff, like some of the problems I posed in my talk was like, you know, do you need to tell a user that things are upgrading?
[00:12:21]
Like sometimes for a minor change or maybe for new features, additive stuff, you don't need to.
[00:12:26]
But, you know, maybe it would be kind of weird if the user was halfway filling out a form and then suddenly a form field like disappears.
[00:12:33]
But maybe it's not, you know, maybe it's not a big deal. Like is it any more or less confusing than the page breaking and them having to refresh?
[00:12:40]
But yeah, the cool thing is that like once you have this idea and then that evergreen setup is possible, it becomes a bit magical.
[00:12:50]
And it's something I love about Lambda and I really love it.
[00:12:53]
You know, occasionally people will come and tell me, so someone at Elm camp came and told me like, oh yeah, you know, I was making a game and some friends were testing and they were like, oh, this thing doesn't work.
[00:13:02]
And he was like, hold on, I'll fix that. And they're like, all right, that's deployed.
[00:13:06]
And like all of their apps like updated, you know, without them doing anything. And he's like, cool, that's done.
[00:13:11]
And they were like, wow. And yeah, that's that. I'm like, yeah, that that feels right to me.
[00:13:16]
I feel like that's how it should be. That feels awesome. So yeah, I think that's the joy of it.
[00:13:20]
That is very unique. So you're doing a hot reload on the client and applying the new code changes with that safe migration that migrates the front end model and then migrates any incoming front end messages.
[00:13:39]
So it hot swaps that in. Is that correct?
[00:13:42]
Yeah, that's right. So basically we take the concept of it. So the theoretical concept of evergreen is really just a function, right?
[00:13:48]
It's saying we've got this old type with an actual value of that old type that's live.
[00:13:53]
And then, you know, we want to go to this new type in the new app.
[00:13:56]
So we write a function that helps us migrate that live value from one to the other.
[00:14:01]
And then once you have that tool, it's like, what do you do with it?
[00:14:05]
And so in Lambdaera, what we do with it is we apply it to every value primitive that you have in Lambdaera.
[00:14:10]
And there's six of them. There's the front end model, there's the back end model, there's a front end message, the back end message.
[00:14:16]
And then the two messages that connect the two, two back end and two front end.
[00:14:20]
And so we apply this in Lambdaera, this idea that any time you change a type in any of those six core types, we go, cool, we can see you've changed this type.
[00:14:30]
You know, please write this migration. You know, here's the harness for it.
[00:14:33]
And, you know, if you do and it type checks, then we go, great.
[00:14:37]
If you deploy this, then, yeah, we can do exactly what you've said.
[00:14:40]
On both the front end and the back end, load the new version, take the model from the old app, migrate it into the new app.
[00:14:47]
And now you've got the new app running and it was all kind of smooth and hot and live and delightful.
[00:14:53]
So, yeah, that's the deal.
[00:14:55]
Yeah, that's amazing.
[00:14:57]
And I mean, if you wanted to, like, so you have, you know, as you said, it's a function from one version of a model to another.
[00:15:07]
And we should probably just to paint a picture here more explicitly, you have your types module in a Lambdaera app,
[00:15:18]
which defines, as you described, those six core types, back end model, front end model, back end message, front end message,
[00:15:27]
and then the two back end and two front end custom types, which define sending data back and forth.
[00:15:34]
But then those essentially get versioned under these namespaces V1, V2, V3, as you change your types.
[00:15:44]
So you have that module with all those six core types defined and any supporting types that you might have that are used in your back end model, in your front end model.
[00:15:56]
Yeah, the subsumed types.
[00:15:58]
Right. And that all, so those are all versioned.
[00:16:02]
So now instead of just types, being some fuzzy thing that you're like, Oh, yeah, I think it was different in a different version.
[00:16:09]
You actually have every version of your types for your Lambdaera application that you've ever deployed.
[00:16:16]
Yeah, absolutely. So the, it's funny, it's like the fundamental idea is really, really simple.
[00:16:23]
But then like the practicality of the tooling to implement that simple idea ended up being quite complicated.
[00:16:31]
And I think this is kind of where, and I talked about this as well in the talk, like part of the pitch for Lambdaera was that this idea behind this kind of live reload migrations.
[00:16:47]
I think it was, it seems to me that it is most compelling when your entire system has this philosophy behind it.
[00:16:54]
Because if you can, like if you're tracking your entire system, your front end and your back end and everything between, it's then that the tooling is really nice.
[00:17:03]
Right. Without that setup, you would have kind of what you've just described, which is like, you know, there's no good way to know what the authority is on these types.
[00:17:13]
So you can't, like, it's not very easy for you to, you'd have to use discipline to be like, okay, you know, I've changed the type, therefore let's go and copy paste our types and let's try and name space.
[00:17:24]
You know, you'd have to do this. Whereas with Lambdaera, because everything's integrated, like the local tooling, you know, when you run a check, like a pre-check for a deploy,
[00:17:33]
it knows to talk to your production instances and go, okay, well that's what's deployed currently.
[00:17:39]
That's what the type hashes are. Do we have a change? Okay, we do. Let's automate the snapshotting.
[00:17:44]
Let's automate, you know, giving you some feedback about what's happening, what types have changed so that, you know, the developer experience that, you know, I've been chasing in Lambdaera is that you don't have to think about it. Right.
[00:17:55]
So in the early versions of Lambdaera, you had to think about it, you had to track it.
[00:18:00]
And yeah, as of the latest release, we are now trying to make that as seamless and kind of carefree as possible so that you can, with confidence, be like, you know what, I'm going to re-architect my whole backend.
[00:18:14]
I'm going to change the whole backend model. I'm going to move things around. I'm going to change dictionaries to sets and nest things into custom. I'll do whatever I want.
[00:18:23]
And the idea is that you can kind of do that and then Lambdaera will be like, cool, that's cool. Here's what changed. All right. Like this is now you need to tell me how to get from where you were to where you are.
[00:18:34]
And if you can figure that out, if you can make it compile, then cool. Like probably this is going to, well, from a type perspective, it's going to migrate.
[00:18:42]
But obviously we can't guarantee that you haven't put dic.empty or set.empty where you shouldn't have and that you'll lose some data. So you can still write the wrong migration in the business sense, but you can't forget to migrate a column.
[00:19:00]
You can't delete a column and still have code that's referring to it. Right. So in that sense, I think it's a step up from the traditional transactional database migrations that I think most of us are used to.
[00:19:12]
Have you heard of people writing unit tests for their migrations or is it usually straightforward enough where people are?
[00:19:20]
Yeah, no, that's a good question. I think the question's been expressed before. I don't think there's any reason you couldn't. There's a slightly awkward technical reason in Lambdaera why it would be a bit weird.
[00:19:33]
It's because Lambdaera, yes, actually it's not specific to Lambdaera. There's a question of, you know, we've got these type snapshots, right? So we snapshot our types every time things change.
[00:19:44]
But we want to snapshot anything that's changed and we deploy. We want to snapshot that. However, because of the way that Elm's namespacing works, we want in production for our migrations to result in values of the type of our current types file, not of values of the type of the last snapshot file, if that makes sense.
[00:20:10]
So maybe to put this another way, if I define a custom type called ice cream with the variants chocolate, vanilla and strawberry, and I put that in my types.elm, and then in Lambdaera I go to deploy, Lambdaera will go, ooh, let's say it's our first deploy.
[00:20:26]
Lambdaera goes, ooh, it's your first deploy. I'm going to snapshot those types into evergreen slash v1 slash types.elm. So now in this v1 types.elm, there's an evergreen.v1.icecream type that has the exact same variants.
[00:20:42]
That is what's going to be deployed, the ones with v1.
[00:20:48]
Yeah, so both actually get deployed, but the v1s there, the v1s on the first deploy only exist to be referenced in future deploys when the types change.
[00:21:00]
But in the current version, we still want ice cream values of the types.elm, right? Because that's what our whole application uses.
[00:21:08]
But in the future, when we now deploy version two, and let's say for ice cream, we had chocolate, vanilla, strawberry, and let's say we add mango, right? So now we're going, okay, this type is now different.
[00:21:19]
It has an additional variant. The migration that gets generated is a migration from version one to version two, right? And so we decide what we do with those values.
[00:21:28]
Probably we do nothing, or maybe we say, hey, you know, actually, everybody that told us that they put strawberry in the first version, they all emailed us and they said, you know, we hate strawberry, we actually want mango.
[00:21:39]
So can you please add a mango option, but also migrate any of our strawberry choices to mango, right? So that would be an example where that function when you migrate the value, you might case the old type, you know, on chocolate, vanilla, strawberry, and chocolate and vanilla, you would map to chocolate and vanilla in the new type.
[00:21:55]
But maybe strawberry variants, we would map to mango in the new type, right? So that's how you could do data changes or data transformations in your migrations.
[00:22:04]
But yeah, we're getting a bit into the weeds here. But the trick is that that new type will become a snapshot version two, right? And your migration has to type check between version one and version two.
[00:22:15]
But actually, when we deploy, we get sneaky. And we don't map it to version two, we actually map it to types dot elm, because that's what you need in your application. So we do this little we do this little swapsy, so that you're always getting the types that your application actually uses.
[00:22:31]
But at the same time, we're preparing that snapshot, that's that snapshot in time to go, okay, when we deployed version two, this is what the types were. So that's ready and committed and in your repository, such that if you change it in the future, we don't have to try to go back and remember what they were, we already snapshotted what they were when you deployed.
[00:22:50]
Is that making any sense? I realize that's a bit that's a bit squirrelly.
[00:22:54]
It makes sense to me.
[00:22:55]
Nice.
[00:22:56]
So you said that every time there's a change in the the types in those six core types, you need to write a migration. One, it's only when they change, right? If nothing has changed, and you don't need to write a to write a migration?
[00:23:10]
Yeah, that's correct. So that's a that's a little optimization that okay, yeah, lambda has, which is that even though in elm, those types aren't the same. If when we snapshot the types, the type tree that gets generated, generates identical encoders and decoders. So we can keep, you know, if, if you have a version two snapshot, right, and then you deploy version 34567, and nothing's changed, we can keep decoding straight into your types dot elm type.
[00:23:39]
Because we know that those encoders and decoders are identical from the binary format, right? So it's only when it's only when the types do change that we know, okay, that will mean that the encoders and decoders will become different, which means we need a function to get between the old value and the new value to keep everything sane.
[00:23:54]
And the second question is, could you write a migration, even if there's no type change, for instance, everyone hates strawberries. So let's write a migration that goes to to mango without having a type change.
[00:24:09]
Yeah, so you can't. But with an asterisk, you can't with an asterisk, you can. So you can't change nothing and ask, like evergreen and lambda to be like, please let me do a migration anyway. But you can just add a dummy field. And then evergreen will happily be like, Oh, you need a migration, right?
[00:24:26]
And so the trick is that when this is a technical, maybe a shortfall that we might tighten in the future. But right now, whenever you get asked to write a migration, you actually get placeholders for all six types.
[00:24:40]
But by default, it'll tag the migrations for the types that haven't changed as unchanged. So you could if you wanted to still apply a migration whenever there is a migration, if that makes sense. If there's a migration to any type, there's a migration to all six types.
[00:24:56]
That's just the way that it's implemented in lambda right now. So you could do data transformations like across the board. But yeah, yeah, it's you have to get lambda lambda is evergreen implementation to think that something's changed in order for it to be like, fine, okay, let's get let's get some migrations involved.
[00:25:13]
If the current version is v6, and I manually create a v7 folder, would that trick lambda into generating a migration?
[00:25:22]
No. So if you manually create a lambda right now, what would happen if you manually created a version seven, and then you try to deploy it in production, it would say, Hey, I wasn't expecting there to be a migration, but I see a v7 migration file, I don't know what's going on. Like something something's bad. So it'll it'll try bail out.
[00:25:40]
So let's say that you wanted to do the the strawberry to mango migration in a more polite opt in way. So the migrations files, they give you the opportunity to I mean, to arbitrarily change the model, the back end model, the front end model. So you could, you could make whatever changes, you know, as you're in is describing, you know, changing a model, when the data hasn't really changed.
[00:26:08]
And you need to sort of get lambda to create a migration file for you. But once you do that, you can make any data change, it doesn't necessarily have to be to get the types to fit together for the new format. That's correct. Yeah. And you also get a command for your for your back end and front end, you can trigger a command as part of that migration.
[00:26:30]
So so let's talk through that a little bit. If we wanted to do the polite version of the strawberry to mango, where we're saying, hey, unfortunately, strawberry is no longer an option. But so we are inviting you to opt into this. And now when you log in to the ice cream shop, you're going to see a, an announcement banner that says, we need you to choose a flavor. So how would you model that with a with an evergreen migration?
[00:26:56]
Yeah, absolutely. So I think 90% of the answer to that question has got nothing to do with evergreen. The question first is how would we model this in an L map? So kind of what if I reflect back at you, what I'm hearing is in terms of state. So there's something now on the user profile, right, which I would say a Boolean, which is something like requested, what would we call it? Like, please, revalidate ice cream preferences question, right?
[00:27:25]
Or show revalidate ice cream preference question, right? And that's a Boolean true or false. And so we add this to our front end model. Actually, we add it to our back end model. Let's see, because we've got accounts here. We've got user accounts, right? We have only saved preferences for users that have logged in, right? Otherwise, how will we know who they are when they come back? So we say, okay, every user profile has this new flag, right? And we add that to the back end model. And then we say, okay, in the front end model. Now, suddenly, we get type errors, right in the front end model, because in this case, it's lambda error, our types are shared.
[00:27:54]
You know, so when a user logs in on the front end, the session hydrates their account. And so that value will come into the front end. And we go into the view and we say, okay, cool. If user.showRevalidateIceCreamPreference is equal to true, then show them this little bit of UI that asks them for this question. Else, let's just show nothing. We'll just leave it, right?
[00:28:18]
And then maybe as part of that UI, we say, hey, like, it looks like you've chosen, you know, strawberry in the past. And, you know, you told us that you wanted to choose a different flavor when we had more available. That's now available. Like, click here to go to your profile page and edit your preferences. And I think, is that it from an app perspective? I think that's probably it.
[00:28:41]
Yeah. And I guess you could decide whether you want your custom type to include strawberry and have it be deprecated or remove strawberry and then set it as mango. But then you're going to need to have some application logic in the appropriate places so you don't accidentally ship them their monthly flavor of mango before they've chosen.
[00:29:09]
And maybe, you know, the monthly shipment process, instead of automatically sending it, is going to send an email and say, hey, you need to log in to change this because we no longer have this flavor. If you want your shipments to resume, then please log in and select something. So, you know, as you say, a lot of it is just modeling the problem in a sort of high-level way.
[00:29:35]
Yeah. So let's say you wanted to, so we're still, we're nowhere near evergreen yet, right? We're still in our application realm. So if you wanted to apply, like, make impossible states impossible, you know, if you wanted to be like, actually, you know what, like, what's the business rationale? Like, so let's invent some. Say the business rationale is enough people told us that they hate strawberry, that we're discontinuing strawberry. Right? So maybe we go, okay, well, we need to remove the strawberry variant, but we need somewhere to migrate these people to. Right?
[00:30:01]
So maybe we turn, you know, ice cream preference into a custom type itself. Well, maybe we turn it into a maybe, right? And nothing means they haven't selected. So we can't send them any shipments. Right? Because we don't know what flavor. Well, maybe we change it into a custom type where we say, you know, not selected or ice cream selected in this new type that only has the variants that we offer. And then a third state, which is like needs revalidation or, you know, ex, ex strawberry lover or something like that. Right?
[00:30:29]
Yeah. I thought there was no one who likes strawberries.
[00:30:33]
Yeah.
[00:30:35]
It's an impossible state.
[00:30:37]
Yeah, absolutely.
[00:30:39]
So yeah, we, we, we kind of do whatever modeling and I think this is the nice bit. And this is a nice bit that we go, we at this point, I think, unlike the way that you do it in, in kind of traditional full stack applications is like you're, you're simultaneously thinking about your data structure and the migration at the same time. Whereas in, in Elm, like via Lambda or specifically in that context, the idea is like, well, just forget about it. Just, just model what new state of affairs you would love to have in your app.
[00:31:07]
Like what is the actual value set up? That makes sense. And then we go great. Now that we've done, we've chosen whatever one of those it was. Now we go, okay, Lambda or deploy or Lambda or check like Lambda or deploy invokes Lambda or check first.
[00:31:21]
And Lambera goes, Ooh, I can see your types have changed. Okay. I'm going to go and attempt to make some migrations for you. I'm going to do my best. So that in the latest version, it goes, not only am I going to generate the scaffold, I'm going to do a best effort generation for you. I'm going to look at the tree of your types in the old version, the tree of your types in the new version.
[00:31:39]
I'm going to try diff them, like zip them together and you know where they don't look like they've changed. I'm going to try and just intelligently make all those, those choices for you to keep everything the same.
[00:31:51]
Mainly the concern is migrating custom types. Cause as we know in Elm, two equally semantically the same custom types in two different modules aren't actually equal. Right. So unlike two, two semantically identical record types in two different modules are equal. Right.
[00:32:05]
So evergreen goes, okay, I'm going to automate all of those kind of crud transformations for you. But in the bits where things have definitely changed and I can't, you know, I can't do anything reasonable.
[00:32:17]
I'm going to put placeholders for you and go, okay, here, I've gotten to ice cream preference. This has changed. You know, it used to be this custom type from version one. Now it's this different custom type from version two.
[00:32:28]
How do you want to do with this? You know, how do you want to get this value across? And so you write the code that says, great, I've done all my business logic. Everything makes sense. And you know, I'll, I guess we've, we've invented some sort of ice cream subscription store here in this, in this, in this analogy.
[00:32:44]
Sounds like a great business. Yeah. Except for the free frozen shipments. That could be. Yeah, that's tough. Tough. But yeah, I want, I definitely want ice cream now. But anyway, yeah.
[00:32:55]
So we've done it. We've done all the business logic. And then now it's kind of like, cool, how do we want to get from one value to the other? And the nice thing is once we've done all of this, you know, it type checks. So it goes, yeah, cool. Okay. That makes sense. You've, you've successfully done the transition.
[00:33:10]
And I suppose going back to the, to the unit test question, it's like, yeah, if, if that was a very complicated transition and you wanted to have certain invariants that hold, yeah, there's no reason why that function that you wrote in there for that particular part of the migration, you can put that function to the side.
[00:33:26]
You could put it elsewhere. You could include it from the tests and then you could do all your scenarios and tests. You know, I put in these old versions. I expect these new versions is my migration kind of making sense. And I think that's nice as well, because you get to stay in Elm, right? If you think of that in any other system, now you're mocking perhaps the database.
[00:33:43]
You have to, you have to, if you're not mocking the database, you actually have to boot a database in your test setup. You have to set the first versions. You have to do the migration of the schema. Then you have to load the value. You know, there'd be a lot to get that working.
[00:33:56]
Whereas in Elm, we get like a lot of confidence from the type checking and then you can cover the rest of the ground in tests if you need to.
[00:34:04]
Whenever there's a type change, you copy everything into like a V2. You copy all the types or do you copy all the code?
[00:34:15]
No, just the types. So what Lambda, so the implementation currently is Lambda kind of recursively trolls through your types from their known. So in Lambda you have to put the core types in a specific location, right?
[00:34:27]
So Lambda goes, okay, I know where they have to be. I start from there and I kind of recursively troll through the type definition and any type definitions it references.
[00:34:37]
And it kind of progressively sucks those out. And as it goes, it namespaces them and it writes them into the snapshots file. So you get, yeah, like an extracted copy of your types tree for every single core type.
[00:34:48]
Okay. Now there's a really good feature in Elm, which I don't know if you've ever heard us talk about, which is opaque types. How does it work for opaque types? Can you migrate them? Can you not?
[00:35:02]
Yeah, this is a great question. So sadly right now, there is a way around this. We could add compiler support and do some magic. But right now you sadly need to open up the constructors within your code base.
[00:35:17]
So there is a risk.
[00:35:19]
Do you mean only in migrations or always?
[00:35:21]
Always. So the reason for that is if you consider like, so let's go back to our ice cream flavors. Say you made that an opaque type, all right?
[00:35:32]
Obviously.
[00:35:33]
Yeah, obviously. Nobody is allowed to specifically say what flavor they like. They have to go through the flavor constructor function, right?
[00:35:43]
Okay, so maybe that's what you love. You're like, yes, this is the best way to do this. So in this maybe convoluted example, think about now how you express a migration for this, right?
[00:35:54]
So I'm asking you, I've written the function signature. So the function signature is from v1.icecream to v2.icecream, right? And into the value, into the migration, you get a value called old.
[00:36:09]
That's what I call it by default, right? Old is the name of the old ice cream flavor. So this is going to be a specific instance, like a specific value instance of that type, right?
[00:36:20]
The first thing you would normally do in migrations of a custom type is you would be case old of, and then you would pattern match on all the variants, right? And then you would return new variants.
[00:36:30]
But in your case, if you've made an opaque type, what do you do now?
[00:36:34]
Yeah, exactly. Yeah, that's why I was wondering, like, I think there's some problem with the opaque types. And I seem to remember that, yeah, opaque types didn't work well with Dundara or with the migration system.
[00:36:47]
If you really, really wanted to, you could write specific code to try. Yeah, so you would have to write like special functions that were like basically constructor functions for your new types.
[00:36:59]
And then maybe you would inside your actual normal elm code, like within that module that has access to the constructors, you might write like a deconstructing or put the migration file directly in there, right?
[00:37:11]
So you could try and keep all of your types opaque and hidden and put the actual migration function in the file somehow, right?
[00:37:18]
The thing that gets really weird and what I discourage with Lambda, although it is possible, is that obviously migrations are like a point in time thing.
[00:37:26]
And so part of the reason we do snapshots is as your app continues to evolve, your code is going to change, right?
[00:37:32]
So the weird thing is, if you put the migration function into the file that defines those constructors, in the next version, you're going to have to change the type that's in that file.
[00:37:41]
And suddenly those migration functions that are referring to the types that are in the same file are wrong.
[00:37:46]
So the question is like, okay, well, now where do I put them? You want to put them into the history, but the history can't access the constructors, right?
[00:37:54]
So the problem today is, okay, with those types, Lambda forces you to open it up. That's kind of the easy way.
[00:38:00]
Long-term, is there a way around it? Yes, the way around it would be at the compiler level for us to go when we're compiling,
[00:38:08]
when we see that we're compiling a module that is within the Evergreen namespace, magically the compiler unhinges its export restrictions and pretends like as if everything is exported.
[00:38:21]
So then only in the migrations context, you can reference a opaque type constructor and you won't get a type error saying, oh, this is, you know, unexposed or hidden.
[00:38:31]
But then in your main code base, any way you referenced one, you would get the type error as usual.
[00:38:37]
So that's the idea. I don't know how difficult that would be. I haven't delved into it yet.
[00:38:41]
But at least in theory, I think we could improve those ergonomics and, you know, get back the same kind of opaque type protections that we have today.
[00:38:51]
So yeah, to lovers of opaque types, I'm sorry, Jeroen, there's a little bit of a compromise there from, you know, ergonomics and language restrictions.
[00:39:01]
But yeah, I think for now it's probably not the end of the world, but we have a way to improve that in the future.
[00:39:09]
Not too many people have complained about it so far. And by not too many people, I mean zero people.
[00:39:15]
I'm complaining. Here's my official complaint, Mario.
[00:39:20]
Okay. So far we have officially had one person complaining. So there is one people demanding.
[00:39:26]
First the strawberry, now opaque types. What next?
[00:39:30]
Yeah, but also like with opaque types, what we tend to represent with the opaque types is invariance, right?
[00:39:39]
So there's the actual data and there's the invariance. So like, even if the types matched, if we have an opaque type that makes sure you have selected three types of ice cream,
[00:39:51]
and then in another version, well, it's only supposed to be two now. Like, yeah, there's, you have some kind of revalidation to do anyway, or which, yeah, not sure how you would do it.
[00:40:07]
Yeah. So there's one interesting part of this where this actually has come up. So there's some kind of, there's some a little bit undocumented auto-generation support for specific package types that are opaque and people kind of commonly use.
[00:40:26]
So for example, something like non-empty. Now, the thing I don't think we've spoken about yet is when I say that LambdaEra extracts the type hierarchy, we only do that to the extent of user-defined types.
[00:40:41]
Right? So if you're referencing like non-empty string, or like the string type from the non-empty package, we won't...
[00:40:49]
Which is an opaque type?
[00:40:51]
Yes. Yeah. So you have a constructor where you have to give it a string that has something in it, and it'll only return a non-empty string value if you give it a non-empty string.
[00:41:02]
So once you have a value of that type, you know that it's definitely non-empty. So yeah, in that case, LambdaEra isn't snapshotting the package type.
[00:41:11]
There's a few reasons for that, that I'm not sure entirely worth going into, but long story short, it focuses just on the user types now. Mainly, actually, the best reason for it is the opaque type discussion that we're having.
[00:41:24]
The best reason for it is we can't really do migrations on package types, because if it's something like non-empty, they don't offer us the internals of that package. Right?
[00:41:33]
So what I do is I generate some code that basically does what the sensible default would be if you knew you had a...
[00:41:43]
Well, the other thing is that package types don't change, at least if the package version hasn't changed. So if we already have a value of non-empty, we don't need to migrate it.
[00:41:52]
But there has been some cases where... Okay, so a better type than non-empty string, which is kind of monomorphic, or one that isn't, one that would be polymorphic, would be like, say, the anydict.
[00:42:04]
One of the anydict packages, right? Like, so packages that let you define a custom type as your key, and then it lets you do lookups and inserts on this dictionary that you can't do with the vanilla dictionary implementation, because it requires keys to be comparable.
[00:42:20]
So if you use one of these types, now you've got like a parametric type, right? You are putting your own user-defined custom type into this third-party package.
[00:42:30]
So if you've changed that type, when it comes to a migration, you may have anydict icecream version 1, and now you need to go to anydict icecream version 2.
[00:42:41]
So you need to extract all of the values from that first dictionary, and then do the migration, and then create a new dictionary. So for some of these types, it's kind of like, that's annoying, and it's mechanical.
[00:42:53]
And we know pretty much what people are going to do, especially if that custom type hasn't changed.
[00:42:59]
So lamdara in some cases will detect certain common library types, and it'll try and do the sensible migration for you if your custom type that's being used there hasn't changed.
[00:43:12]
Is that making sense? Am I tracking?
[00:43:14]
Yeah, does that mean that if I were to make a new package with a new data structure, like anydict, that it would be better if I contacted you to add support for that?
[00:43:29]
I definitely wouldn't want to encourage a perspective in the ARM community that everyone should be thinking of lamdara concerns in their packages.
[00:43:37]
I'd rather tackle it when it came up. But yeah, what would make it easier for a lamdara user to use your type if it's a type that doesn't contain user types, then I don't think it matters.
[00:43:48]
Because they can just put the old ones in the new one. But if you are publishing a package that does contain the ability for users to put in custom types, then putting in the ability to migrate.
[00:43:57]
If there was a map function that sensibly made sense, where they could give you a function of type A to B, and that let them migrate your type A to your type B in the package, then that would definitely make it easier for them to construct migrations.
[00:44:12]
But otherwise, yeah, an ability to somehow exhaustively deconstruct values in a meaningful way and exhaustively construct values in a meaningful way of your package type, I think would be the key primitives that people would need to be able to express this idea of going from an old type to a new type for any conceivable type change, if that makes sense.
[00:44:33]
Yeah, I could also imagine for some use cases, instead of directly having an opaque type, if you really wanted to model your application logic with an opaque type, especially in the front end, with the back end, there might be more performance concerns in some instances.
[00:44:52]
But you could have your raw type stored, let's say, in your front end model. And then you could have a wrapper that takes it from the raw type to your opaque types.
[00:45:12]
So you could have a function that transforms the raw types to opaque types. So immediately, as soon as you're actually working with those types, it's turning it into some opaque type that you can work with those guarantees.
[00:45:30]
But then, as you're modifying it, you also need a way to transform that too. So it's a challenging problem. But that idea you have of being able to reach into the opaque types in the context of a migration is very intriguing.
[00:45:46]
And it does, I mean, it's a, it's a, an interesting philosophical place to be. But overall, the feeling that I'm getting what I'm realizing with evergreen migrations is that so much of what happens with, you know, the traditional way that many people may have worked with migrating, you know, between a some sort of JavaScript front end and a Rails back end, or whatever it might be,
[00:46:12]
the traditional experience that I've had doing conceptually migrations, maybe there are some, you know, there are probably some back end migrations involved. And then you need to handle that with different versions of the front end is you, you very carefully queue up the changes you're going to make, you very carefully, you know, test your actual migrations on some test data.
[00:46:38]
And maybe you sort of hope that that in between state works out okay, and don't think too carefully about it. Or maybe you think very carefully about it. But even so, even if you're thinking very carefully about it, you're thinking very carefully about an implicit contract.
[00:46:53]
Whereas what I'm realizing is that what lambda gives you is an explicit contract for all of these pieces, and they're all living in the same ecosystem. And, you know, if you, you could make something implicit in a lambda app by depending on something in the outside world, but for the things that are self contained within a lambda back end and lambda front end code base, it's an explicit contract.
[00:47:18]
And it has the elm type system and all the guarantees that come with that of type safety and purity and no escape patches and immutability and all these things. So you put all those pieces together and what you get is an explicit contract for managing the entire migration, which is a really interesting feature to have. I mean, that's kind of a game changer.
[00:47:42]
Yeah, absolutely. So for people thinking about like their traditional migration setup, I think it's kind of the pitch of evergreen is similar to the elm pitch against JavaScript. It comes up in a lot of different areas, but let's take like JavaScript, you know, decoders, right? So the idea is that you go, okay, well, there's like a whole, you know, we know, that first name is always going to be there. Like we know this, in quotes, know this, right?
[00:48:11]
Then at some point in the future, someone changes it and now our code's broken. Right? So like an elm, it's like, yeah, yeah, I know, you know, this, but no, like, you've got to, you got to tell me how does this decode? I'm going to, I'm going to validate it. Okay. We validate it with the decoder. Now we know, now we know for sure. Right? Like, it's not just a, like you said, we've turned that implicit thing into the explicit.
[00:48:33]
And so I think there's a lot of stuff with migrations. And part of why I was really excited about this is like, there's all this, there's all this cognitive overhead that you have to keep. Right? Because there's nothing snapshotting, nothing keeping your types for you. You have to remember when you're building this new thing, like exactly what you've changed, exactly what you've added, exactly what you've removed to the point where, like, I think it's, it's kind of nuts that the industry response seems to me, the industry standard response is like, oh, well, obviously the sensible solution is the one that's going to be the most effective.
[00:49:02]
The sensible solution is to never remove anything ever again. And that's like, I get it. Like, that's, that's probably the only way that we can cut that, at least that part of the problem out. Right. In like the traditional kind of stack, or if you're working at scale, right, you go, okay, we never remove everything, never deprecate it. That's why you have stuff like, you know, protobufs. So it's like, yeah, you've allocated a field. Well, that's there forever in your payloads, every future payload, even if you never use it, that byte range is now allocated. Right?
[00:49:31]
You'd have to do a major version deprecation or shift your, your schema to a new endpoint to change that or to optimize it. And so the other nice thing that we get there is that all of that stuff becomes explicit. But also, on the other hand, something I think we haven't talked about is that gap problem. Right?
[00:49:48]
So I talk about in my talk, which is what if you have, if you don't have a system where everything's integrated together, and especially if you work at a company where potentially different teams can deploy different things at different times, right, you merge this change in for your backend, maybe if you're lucky, I mean, not if you're lucky, that's the wrong word. Let's say your company has chosen chosen to have a mono repo, maybe you've got one pull request, right? So the thing you merge is the front end and the backend changes at the same time.
[00:50:14]
So at least that step is synchronized. But worst case, you have two different repositories, right? So those things could merge at different times. In both cases, regardless of whether you merge at the same time, or whether you merged at two different times, the deploy could still happen at two different times, right? And in most systems, they're not necessarily synchronized from a user perspective.
[00:50:36]
So it is very possible that you have a situation where you have version one front end and version one backend in production. And you get a version two front end, that's trying to talk to a version one backend for a moment in time, or you could have the version two backend launches faster. So you have version one front end that's trying to talk to a future version two backend. And that inverses as well, right?
[00:51:03]
So you could have a version two backend that's trying to respond to a version one front end or a version two front end that's trying to respond back to a version one backend. So there's four variations there, right? There's the outbound payloads, and there's the inbound payloads, and you could have failures on both sides.
[00:51:19]
And I think generally, the thing that like, we kind of think about, okay, what tools or techniques can we apply to solve that? And I think generally, the answer is none. Right? Like there isn't really anything we can do to get explicit guarantees. One thing we can do is say we never remove fields, right? But we can still get the wrong semantics, right?
[00:51:39]
Like it may be compatible, that a version two front end message gets ingested by the version one backend, but it may process the wrong business logic, you know, stuff that we've said, or should now change, right? It should be version two. Version two should be handling, you know, strawberry responses coming in and becoming mango, but we've actually gotten, you know, a mango response in the future, or we've gotten a strawberry response in the future, and a version one backend has created yet another subscription to strawberry, which shouldn't be possible anymore.
[00:52:08]
So yeah, one thing. This is why I mentioned this before about, I think evergreen works really well in a system where you have full and total control of both the front end and the backend migration synchronicity, synchronicity, I'm not sure the correct pronunciation of that word. So that, you know, we apply this evergreen concepts to everything in lockstep. Right? So we know that you only there's never going to be a scenario where we're getting events from the future to older versions.
[00:52:36]
Everything's always being pushed forward. And so yeah, lambda has like, like a migration, kind of like a staging thing where it basically hot loads everything and everything's prepped and ready, all the new versions are ready, everything's live. And then there's like a sudden lockstep where everything in the same instant as much as possible, kind of all slides into the future. But if we've missed anything, you know, if there's any old front end that comes online later, or there's a backend that lags for some reason, or whatever, I mean, that's technically not possible.
[00:53:05]
Let's say in the future, we had, you know, distributed setup, and it was possible, it was a backend that was lagging, because that all those new versions have this migration thing set up, the first thing they do be like, Oh, I'm receiving a version one, but I'm actually on version two, let's run that through the migration first. And so now you always have consistent, like that's consistently being executed in the latest version, regardless of kind of what's at play in that synchronicity.
[00:53:28]
So I think that that is a really difficult problem to solve outside of the context of a type safe, pure, immutable and exhaustive language. And I think that's what makes this thing so nice. And I'm like evergreen in Elm, I think is super delightful. It just sheds all these delightful properties. And so yeah, we leverage that as much as possible as we can.
[00:53:52]
I don't think you would need the type safe parts, but it definitely helps.
[00:53:57]
Yeah, it definitely you could with discipline get the same effect. But yeah, you could.
[00:54:04]
And it makes the contract more explicit. I find that like thinking about migrations in this paradigm, like it, it's making me think of the data modeling in a different way, as you said, like more, more focused on the ideal data modeling, which often just a vanilla LMAP makes us do this too, I think, right? Just think about the data modeling in a, I don't know, less hacky way, like just what would be the ideal way to model this?
[00:54:33]
And then you just kind of do that and, and let everything flow from there. And like, for the, you know, strawberry ice cream deprecation, like I was talking about that strategy, you could use of, you know, leaving the users flavor, selected flavors as mango, and then having some separate data that tracks that it's actually, it's actually not mango, right?
[00:54:59]
And if you're doing, if you're doing a sort of migration in this more old school way, where you have these implicit contracts, then that that's not really any worse than modeling, modeling it explicitly.
[00:55:15]
But if you, if you have the ability to have all these pieces, connects together very explicitly, I would tend to think of it differently, I would tend to think of it as I want my data to reflect exactly what it is. So I would tend to want to say, you know, maybe it's like a variant of flavors, or maybe it's like a wrapper around that.
[00:55:36]
So you have, you either have like a selected flavor, or you have a legacy selection, in which case, shipments can't proceed or whatever. But I would want to model that state very explicitly, because otherwise, you might end up with a code path where you aren't considering that case.
[00:55:56]
And what ends up happening all the time with sort of supporting these, these migrations, and these conceptual changes to the domain, in a code base is you don't consider how a change affects the entire system.
[00:56:13]
You end up with all these sort of conditionals scattered around where you could easily forget something. But as with any Elm custom type, you have, you know, when some when an Elm custom type changes, it forces you to consider the impact of that change everywhere, even if it's trivial, it forces you to explicitly, you know, recognize that it's changed.
[00:56:36]
And so instead of just scattering some conditionals around and saying, Oh, if it's this weird, extra Boolean that I need to check for that it's this weird case, like that ends up being really unpleasant to maintain and a huge source of bugs and also a huge source of like, you know, the more veteran programmers on that team who know this code base are like, Oh, like, talk to talk to this one programmer, you know, they know all the ins and outs of this code base,
[00:57:05]
they know all the conditionals you need to be sure to check for, they know all the strange Booleans in the system that you need to check for anytime you do something. But if you model it as a custom type where you're saying exactly what it is, like a user doesn't necessarily have a flavor, they may have some legacy thing. And why does that happen? And maybe, maybe you get to a point where you can drop that at a certain point, maybe you, you have, you are able to confirm that everybody has migrated off of that.
[00:57:33]
And then you can migrate off of that and, and reflect that. But it really allows you to think in terms of your ideal domain modeling instead of hacking something together and throwing some conditionals in there.
[00:57:46]
Yeah, absolutely. So this is this is slightly a tangent away from evergreen. And I kind of see this as more a benefit of Lambdaera itself, or at least a benefit of the idea of like, what if we didn't have this disconnection between the way that we choose to store our data and the way that we choose to model our data? Right. And so like, if you're already familiar with Elm, and you have experienced like the delight of Elm's type system in, in the large, right, I reckon in most,
[00:58:15]
cases, you can model, like your view of the world really nicely, right, especially like with custom types. And so there's this, I think, when you're in a more traditional code base, I think, at least the way that I'm thinking of more traditional code base is like, I might model those invariants with a new custom type on the front end.
[00:58:36]
But usually I start to, like, especially for something like this, right, where we go, okay, we're discontinuing this product, right? The marketing team has said, like, could we, you know, could we do this, like, it would make our lives easier. Could you do this stuff in the UI, but you know, like, if it's going to take more than a day, and it's going to impact our backlog, like, we just don't, like, just don't bother, we'll just manually send some emails, or we'll do something, right?
[00:59:00]
Like, because engineering time, I think, becomes scarce and precious in organizations, usually. So, you know, if you sit down, you're like, okay, well, yeah, you know, we could try and manage this for you. Okay, front end, easy, that's fine. We'll just put this new state and we'll do that. But, okay, so we're going to change the profile system in the backend, we're gonna have to add this new field, we're gonna have to do that migration.
[00:59:19]
But this other system uses that way to make sure, you know, like, and you're thinking about all these layers and the different systems that you're gonna have to coordinate. Whereas in Lambdaera, you can kind of go, okay, let's add this field to the thing. And bam, we forced all these failures across the, you know, we can see immediately what the impact is, like, we're driving, what is our to do list in terms of implementing this feature. And we can see straight away, like, oh, yeah, you know what, we forgot, this is used in this module, and it causes heaps of, you know what, guys, this isn't going to be worth it.
[00:59:47]
Or we can say, oh, I got two type errors, like, no, I reckon we can do this, you know, and you're not thinking about all these extra steps about how that change or set of changes is going to be translated into these kind of primitives, like into this primitive obsession that we talk about, or like, you know, Boolean blindness, or, you know, just this generally this idea where we have to dumb down to types, which we kind of, I mean, until we are graced with this much anticipated, you know,
[01:00:17]
anticipated future release of Evan's work and whatever's happening in the database side, right, but at the moment, there isn't a really great way to put custom types natively into Postgres, for example, right, so on the project, so I work on those elements, the front end, your custom types become something entirely different, there's a lot of glue around modeling that, and modeling those changes. And so I think a lot of the time, doing silly little things like that, it's kind of like, ah, too hard basket, let's not bother trying to, let's not mess with the stack.
[01:00:46]
Whereas I think in the Lambda situation, it's like, yeah, let's mess with the stack. Let's actively mess with it, because, you know, later on, the compiler is going to be like, all right, cool. I saw you messed with XYZ, can you please fix that? Tell me what you want to do with the migration. So I think that, yeah, that's a cool part. I'm excited for that on my own projects, because that's what I want. You know, when I'm dealing with my hobby projects, or I'm picking up a project I haven't touched for months. And I'm like, I want to add all this and change this and do that.
[01:01:14]
I want to have that joy of not now worrying like, oh, is my modeling correct? Do I need to fix how I've set my stuff up in Postgres? Am I going to have SQL queries somewhere that are now wrong? Yeah, I really like what that gives you from whatever green gives you, whatever green ideology kind of gives you in that kind of full stack Elm context. So yeah, and Lambdaera pitch rant at this point.
[01:01:38]
No, it's amazing. And Jeroen mentioned the idea of testing before, like that also strikes me as something that, you know, I mean, for a team that really, really wants to robustly manage their migrations and data integrity and all these sorts of things, just having evergreen migrations is huge. And, like, you know, makes the whole process so much more explicit.
[01:02:06]
And you could probably write some sort of tests manually for that. But I could imagine some sort of automated things around even like testing the UI after a migration with, you know, Lambdaera program tests or, you know, testing the hot swapping. There are so many things you could imagine conceptually when you just have these pieces fitting together in this way. So it's really intriguing, really exciting stuff.
[01:02:34]
Yeah, definitely. So that kind of thing, like being able to test migrations is not something that's easily done today in Lambdaera. Like if you're in Lambdaera live, like the live development environment locally, and you've changed all your types, like you'll be working on an app with the latest version. Right. But there's not a super easy way. You can with some effort do it manually. And I've helped people try and figure that out. Like the pieces are there, but it's not ergonomic.
[01:02:57]
But yeah, I think that would be really, really cool in future for you to be like, hey, I want to pull down my production model and run it through the migration. And then I want to play with that result locally and see what that looks like. So that would be one cool improvement.
[01:03:09]
Another one that, and so this is kind of like a full disclosure on a downside of this approach. So something that's kind of come up recently, there's been more, increasingly more teams using Lambdaera. And so when you have a team of people using or trying to develop an app together, we end up with this problem of, you know, it's kind of fairly common if you're working on a backlog and you have a few features and these teams are like kind of in an agency setting.
[01:03:35]
Right. So they're working on behalf of a customer. So they go, okay, well, you know, I've got a pull request for this particular feature. Can I deploy like a preview version of this app so we can kind of show the customer we can do some QA, right. Or some kind of review so they can take a look at this.
[01:03:49]
Now this has caused an interesting problem with Evergreen or some confusion, because if we think about the Evergreen assumption, right, the assumption is that you've got a straight linear change version one to two to three to four. And the idea is that when you're doing a check, what you're checking against is the production app.
[01:04:08]
The being the operative word there as in the singular the, because if you have multiple production apps, suddenly everything starts to not make sense. You know, if you've changed your types, you've changed it relative to which production app.
[01:04:23]
So we kind of had this issue where teams would go to create, they would just manually create another app. They would manually call it, you know, my app dash preview one, some feature. And then first things first, they would try to deploy their Lambda app that was only previously going to production.
[01:04:39]
Let's say it's at version seven. So they tried to deploy to this new app and the app goes, well, hold on, you're deploying version one, but I'm seeing like version seven snapshots, like what's going on? Right? So the compulsion there, I think the natural thing is to be like, oh, that's weird.
[01:04:53]
I don't know what to do about this. I'm just going to delete Evergreen folder. And now it goes, okay, great, cool. I can deploy version one for you. Right? So now you've got this code base that's deployed to version seven and to version one in two different apps.
[01:05:06]
Now, a Lambdaera doesn't have a preview app concept right now. So as far as Evergreen is concerned, there's two production apps. Right? So let's say throughout the course of your pull request, you change types.
[01:05:18]
And whenever you do, and you're checking against your preview deployment, Evergreen is going to be like, okay, well, this is your production app. Looks like your types have changed. You need to write a migration.
[01:05:26]
Right? There is a way in Lambdaera currently to be like, do you ignore the migration? Or like, I'm happy for you to just drop it on the floor and reset my backend model to init.
[01:05:38]
So they might do that because they're like, oh, this isn't important. You know, my state isn't important on this preview app. And so they do that a few times.
[01:05:45]
And then if they're unlucky, what's happened a couple of times was you get everything's good and they're like, okay, great. Let's merge. And now you merge that in and you've clobbered kind of your Evergreen history.
[01:05:58]
And now you're on your main app, the one that's already at version seven, you're trying to deploy and it's looking at maybe like an app version three.
[01:06:05]
And so in that context, it goes, okay, cool. You've got app version three, app version seven's improved. And it tries to figure out what's going on and it doesn't really make sense.
[01:06:15]
And then we end up in a really confusing position. So the way that I'm thinking to fix this, and maybe there's multiple ways to address it, but at least the Lambdaera way that I think we're going to do the first version is going to be,
[01:06:27]
okay, let's have the concept of preview apps. And in a preview app, like it's a first class concept, your main production application has this thing called preview apps.
[01:06:38]
So maybe somewhat similar to kind of like what people might be familiar with, like Netlify, or I think Vercel might do the same thing.
[01:06:46]
And so the idea is that when you deploy to a preview app, Lambdaera will be like, ah, okay, this is a preview app. We're going to completely ignore anything to do with migrations.
[01:06:57]
The assumption is that we're always deploying a version one, and we're always going to re-initialize.
[01:07:03]
And actually, we might be cheeky and be like, we'll try restore the existing state into the new version.
[01:07:11]
But if it happens that you've changed your types, we're just going to reset it. If the decoder fails, and it's a strict decoder, it's slightly variant from Elm's decoder.
[01:07:19]
So if all the bytes aren't consumed perfectly, then it will fail. So it has to be a perfect decoding from bytes into the value.
[01:07:29]
Then we've got this separate chain. So that would restore back to Lambdaera's assumptions, which is if you have an app, there is only one production, and there is only one evergreen story.
[01:07:39]
There is only one chain history of changes into production. And then we've got this separate mechanism, which is preview apps, no migrations, no nothing there.
[01:07:47]
So the idea is that you do your pull request, you go through all the changes, evergreen doesn't bother you at all.
[01:07:52]
And then once it's approved, you merge that into main. And now when you're trying to deploy main, now you've got that.
[01:08:00]
That's when that check comes in and goes, oh, okay, you're trying to deploy. Let's consistently look at what's in production now.
[01:08:06]
What have you been up to locally? And what's changed? Let's get you to do that migration.
[01:08:10]
So yeah, that's coming soon. TM, trademark.
[01:08:16]
Yeah, what I would have imagined to be maybe slightly easier, or well, the previous thing sounds awesome.
[01:08:24]
But like, if you had a v7 in production, and you're trying to deploy and it's a v10, because you tried to do some migrations in the meantime.
[01:08:34]
I feel like maybe accepting unseen versions would have been easier.
[01:08:41]
So there's another scenario that I can see, which could be problematic when your team grows, when you're working with teams,
[01:08:48]
is that, like, I'm adding a new feature, or I'm changing a feature and the requires to write a migration, maybe complex, maybe not.
[01:08:59]
And two other people on my team do the same thing. And then we all leave on vacation, and someone else tries to deploy and has to write those migrations,
[01:09:08]
because we didn't in the meantime, right? But I could imagine like, well, I'm done with my work, let me write a migration that will make a v8,
[01:09:19]
which we're never gonna ship. But we'll merge it anyway. And then someone else does the same thing v9 and v10. And we ship that.
[01:09:29]
I just say this, like, not just, I'm just throwing this out, but I'm sure that there's some problems that you have in mind.
[01:09:38]
Like, nope, that's not gonna work.
[01:09:40]
Yeah. So the first thing that would happen, remember that the snapshot only happens when you deploy. Right?
[01:09:45]
So let's say we have three pull requests, and every single pull, let's, so the worst case scenario is this.
[01:09:51]
Worst case scenario is you have three separate pull requests, all three team members have all changed the backend model.
[01:09:57]
All three team members independently on their branch have done a Lambda check against production, they've generated migrations, and they've implemented them.
[01:10:04]
Right? And then now they start merging. So first person merges, they get in first. Hunky-dory, no problems.
[01:10:11]
Second person now is probably gonna have GitHub conflicts on their pull request. Right?
[01:10:18]
Let's say even worst case version, let's say it's a clean merge for some reason. Right?
[01:10:23]
So they don't have any conflicts. Right?
[01:10:26]
You mean that both would have generated a v8 migration and that would...
[01:10:31]
But it would have been identical except for the differences. So let's say they changed very different parts of the model. Right?
[01:10:40]
All of the snapshots were almost identical except for these deep changes. Right?
[01:10:44]
So maybe the changes ended up in different snapshot files. Right?
[01:10:47]
So maybe Git's like clever and it's like, ah, yeah, you're merging the same thing except for this.
[01:10:51]
And I can figure out the merge. I'll merge it for you.
[01:10:55]
And let's say the third person does the same. Right?
[01:10:57]
What's gonna happen now is because there's only one deploy that's possible,
[01:11:02]
whoever gets to the deploy is gonna have to go through that Lambda check process.
[01:11:07]
And potentially, if Git has tried to be too clever, you're gonna get type errors. Right?
[01:11:12]
Because something as part of those mergers might not have fully carefully covered things.
[01:11:18]
So there, if you think of like, you know, like what kind of burden are they stuck with?
[01:11:23]
You know, all three of you have conveniently gone on holiday.
[01:11:26]
So it's the worst, worst, worst case. Like what's the absolute worst that happens?
[01:11:31]
The absolute worst that happens is, let's say it's me. I'm stuck with it.
[01:11:34]
I go, ah, you know, Dillon and Jeroen have left me with this.
[01:11:40]
So I go, you know what? I'm gonna delete the migration.
[01:11:43]
I'm gonna do a Lambda check again. Lambda always does the type snapshots. Right?
[01:11:49]
So say you did type snapshots, you didn't deploy, you committed them,
[01:11:53]
and then you changed more types and you did a check again.
[01:11:57]
Lambda is gonna replace those version snapshots. Right?
[01:12:00]
Because you haven't deployed yet. So if you haven't deployed version five, if that's the next version,
[01:12:04]
but you've been changing stuff, it's just gonna keep replacing the snapshots until you deployed.
[01:12:08]
Once you've deployed, it's gonna be like, okay, well fine. Next one's version six. Right?
[01:12:12]
So if I delete the migration file, I do a Lambda check.
[01:12:15]
I'm gonna get now consistent snapshots with everybody's changes together.
[01:12:18]
If their changes together, the mergers didn't type check, like if there was an Elm compiler error,
[01:12:23]
I wouldn't even be able to generate the snapshots. I would just get an Elm compiler error first.
[01:12:27]
So let's say it's like worst, worst, worst, worst case.
[01:12:30]
The code is broken. It's been merge broken. So A, I fix all the Elm types. Great.
[01:12:34]
Now Elm's compiling. B, I run Lambda check. It redoes the snapshots.
[01:12:39]
Cool. C, Lambda has now done the snapshots and it sees the migration's not there.
[01:12:43]
So it goes, cool, I'm gonna generate the whole migration file for you. Right?
[01:12:46]
With the placeholders for the bits that I can't migrate.
[01:12:49]
And so now my job is to go, okay, let me see if I can go to those individual pull requests
[01:12:54]
and slice out the individual specific migration implementations that everyone's already done.
[01:12:59]
If I can, and they fit in, and then it type checks, then I go, great.
[01:13:04]
I've gone through pretty much a mechanical process just following the types
[01:13:08]
and getting stuff done in.
[01:13:11]
If instead it was, hey, two people have actually changed stuff in the same thing,
[01:13:17]
like somebody's both added and removed variants on the same custom type
[01:13:21]
on two different PRs all at the same time, that's a really great stopping point
[01:13:26]
for me to look at this and be like, this is nuts.
[01:13:30]
We need them to come back from holiday and explain what should happen,
[01:13:33]
or I need to go to a product person, or I need to figure out what's actually going on here.
[01:13:37]
And I think that's cool because if that happened without this setup,
[01:13:41]
there wouldn't necessarily be an indicator there that something's gone wrong.
[01:13:45]
You might merge these migrations together, or actually even worse,
[01:13:50]
if I think of Rails, I have a lot of experience with Rails as a counterpoint.
[01:13:55]
In Rails, each developer does their own migrations as a separate file.
[01:13:59]
So you wouldn't necessarily even be aware that someone else was adding and removing stuff
[01:14:03]
to the same model because that would all be in different migrations.
[01:14:06]
There'd be no natural mechanism to see a conflict.
[01:14:09]
So you could end up in a situation where you deploy these non-commutative migrations
[01:14:14]
that end you up in a weird schema state, but that nothing catches.
[01:14:19]
Whereas at least in the Elm Lambdaera world, there'd be warning signs there.
[01:14:24]
There's things that in the worst case would make you be like, huh, what's going on?
[01:14:30]
So I think that's pretty cool. That's a decent outcome, I think,
[01:14:33]
even though there might be some pain.
[01:14:35]
So to summarize, your recommendation is for everyone to run Lambdaera check
[01:14:39]
and write a migration, and then those migrations get merged somehow by someone at some point?
[01:14:46]
No. So my recommendation would be that you do the migration part separately
[01:14:51]
on the main branch if you've got lots of people editing the same stuff.
[01:14:55]
Or that would be a point that you communicate together as a team.
[01:14:58]
It brings that kind of idea of continuous deployment back a step.
[01:15:06]
So it's not as freeform as some companies may practice,
[01:15:10]
like, oh, everybody can deploy and we deploy all the time,
[01:15:13]
we just don't think about it kind of thing.
[01:15:16]
So it makes that a little bit more centralized.
[01:15:19]
But I think what you get as a result is you get a much greater ability
[01:15:23]
to model your business logic directly.
[01:15:26]
And it means that you don't have to think as carefully about the consistency
[01:15:30]
or the invariance that you're holding in that migration.
[01:15:33]
So it trades off, I suppose, some of that kind of maybe,
[01:15:37]
I don't know if you'd call it decentralized deployment model
[01:15:40]
to something that's a bit more centralized, but that gives you back
[01:15:43]
a bunch of guarantees in return, if that makes sense.
[01:15:46]
So I remember that at one point, someone told me that Arm Review
[01:15:51]
was kind of slow with their projects.
[01:15:55]
If I recall correctly, that was James Carlson,
[01:15:58]
who's a fervent user of Landera.
[01:16:01]
And I checked it out and was like, yeah, this is a bit slow.
[01:16:06]
And I figured out why.
[01:16:10]
I think I know why.
[01:16:13]
There was an evergreen folder with over 600 versions,
[01:16:19]
meaning over six, you don't have a migration for every version,
[01:16:24]
but a few hundreds migrations and snapshots.
[01:16:30]
And there was code that remained in the project
[01:16:34]
and that Arm Review had to run to go through,
[01:16:38]
which is now a bit faster, so I'm not getting those issues anymore.
[01:16:43]
But yeah, I was wondering, when should you remove those migrations?
[01:16:49]
Should you? And can you remove v1?
[01:16:53]
Is there a way to tell, oh, well, no one is using v1 anymore
[01:16:57]
because Landera knows which client applications are running?
[01:17:03]
Do you have the knowledge or not at all?
[01:17:06]
Yeah, so the reason, maybe I'll answer your question backwards.
[01:17:11]
So here's why you wouldn't want to remove all the migrations.
[01:17:15]
You wouldn't want to remove all the migrations
[01:17:18]
if you wanted to preserve a full stack,
[01:17:22]
full time history, time traveling debugger.
[01:17:26]
And this is a feature that doesn't exist yet.
[01:17:30]
But if you wanted to use this feature when it does exist,
[01:17:34]
you can imagine a slider and if you can slide back like 17 versions
[01:17:38]
to a point in time backup
[01:17:42]
or like a log stream restoration in Landera, you could do that.
[01:17:46]
Because it could go through the migration chain
[01:17:49]
to get you to the right data source.
[01:17:52]
So that's why you wouldn't maybe want to remove those.
[01:17:55]
But saying that...
[01:17:57]
Can you migrate backwards?
[01:18:00]
No, but it would be being able to get to the exact state
[01:18:04]
that you were in for any given version
[01:18:07]
at any point in time in history.
[01:18:10]
So if you had the old migration chains,
[01:18:13]
you can make sure that if the last snapshot was in version 10
[01:18:16]
and you were trying to get to it, well, this wouldn't happen
[01:18:19]
because we take snapshots anyway. So it's a bit of a moot point.
[01:18:22]
But this idea that you could slide a piece of value through,
[01:18:25]
like the scenario that somebody told me
[01:18:28]
where they had a customer that came back like a year later
[01:18:31]
and they started seeing events from a year before.
[01:18:34]
That person could get a hot reload a year later.
[01:18:37]
Like their app could go from version 10,
[01:18:40]
in Jim's case, to version like 1500
[01:18:43]
and it could slide that value like all the way up all the versions
[01:18:47]
and if they were halfway through filling in a form, in theory,
[01:18:51]
the form would upgrade and all their stuff would still be there.
[01:18:54]
That's far-fetched.
[01:18:57]
In theory, that would be possible.
[01:19:00]
From a practical point of view, if you weren't concerned about that,
[01:19:03]
there's no really good reason to keep more than a few versions.
[01:19:06]
The only reason you want to keep a few versions is if you wanted to roll back your data.
[01:19:09]
To say you've done a migration
[01:19:12]
and you've done the wrong thing in the migration.
[01:19:15]
You set a dict.empty or a set.empty somewhere where you were being lazy
[01:19:18]
for the moment because you were like, I'll do the migration later
[01:19:21]
and you did it and suddenly you destroyed all your users.
[01:19:24]
If you wanted to go back in that case or if you had a customer
[01:19:27]
that had been like, oh my god, it's Wednesday but we just found out on Tuesday
[01:19:30]
that Mario went in and deleted 600 blog posts,
[01:19:34]
can you please roll back to our state on Sunday?
[01:19:37]
That happened to be four versions ago.
[01:19:40]
Keeping those migrations around lets us go, yeah, sure, we can load up that old version
[01:19:44]
and bam, it'll upgrade through the last four migration functions
[01:19:48]
into your current app.
[01:19:51]
We wouldn't have to roll your whole app back, you can have all the new features
[01:19:54]
we can just roll the data back in a safe way.
[01:19:57]
I guess you could use Git to restore those migrations again.
[01:20:00]
Yeah, so you've got it.
[01:20:03]
Which is a good feature of Git, right?
[01:20:06]
Yes, you've got it exactly. From a technical perspective, there's no reason
[01:20:09]
given that the snapshots would have always had to exist when you deploy,
[01:20:12]
there's no reason you couldn't clean that up or that Lambda Era
[01:20:15]
couldn't clean that up for you.
[01:20:18]
The actual reason that everything is there is I decided early on that I wanted
[01:20:21]
to keep everything really explicit and visible
[01:20:24]
because in my head that would demystify it.
[01:20:27]
People could go and actually look at the Elm code and be like,
[01:20:30]
there's no actual magic here, it's literally just the Elm code
[01:20:33]
and it's literally just there.
[01:20:36]
The fact that it's kind of there and you can see it,
[01:20:39]
yes, we're doing code generation but we're not hiding it away somewhere
[01:20:42]
and it's not going to break in really weird ways.
[01:20:45]
If it breaks, it should break with Elm type errors pointing to files
[01:20:48]
that you can go and look at and be like, oh yeah, that looks wrong or right
[01:20:51]
or whatever it is.
[01:20:54]
It doesn't seem to happen often to my absolute bewilderment
[01:20:57]
but I've always got this terror that I've implemented something wrong
[01:21:00]
and someone's going to do a migration
[01:21:03]
and it's just going to horrendously generate the wrong stuff.
[01:21:06]
So I kind of want that also to be visible so that the user can see
[01:21:09]
and if I've done the wrong thing, they could fix it.
[01:21:12]
You could fix the type snapshot yourself or you could modify stuff.
[01:21:15]
Thankfully, there's some gen issues in the latest migration generation
[01:21:18]
but so far there haven't been many or maybe only one or two a long time ago
[01:21:21]
issues with the type snapshotting.
[01:21:24]
So far the type snapshots extract correctly it seems.
[01:21:27]
Knock on wood, obviously.
[01:21:30]
So yeah, it's more a social reality thing.
[01:21:33]
I think it's a bit of a shame that Elm is not a big part of the Elm community
[01:21:36]
so yeah, it's more a social reason
[01:21:39]
for them being there than a technical necessity, so to speak.
[01:21:44]
So yeah, we might make that more magical in future
[01:21:47]
and then Elm review won't have problems, side effects as it were.
[01:21:52]
So the Evergreen migration auto generation
[01:21:56]
which we haven't really explicitly talked about
[01:21:59]
but I understand that was a big pain point
[01:22:02]
that was addressed by this latest release
[01:22:05]
which is v1.1.
[01:22:08]
Is there much to say about that
[01:22:11]
besides that it does most of the tedious work for you?
[01:22:16]
That's kind of the headline of it.
[01:22:18]
Yeah, that's the headline.
[01:22:19]
So the thing that people would run into that I think people would find confusing
[01:22:22]
is like, say you had a custom type.
[01:22:24]
Let's say we had the Ice Cream custom type
[01:22:26]
but with lots and lots and lots of flavors.
[01:22:28]
Let's say we had 200 flavors.
[01:22:30]
And say you've changed a field somewhere else
[01:22:33]
and you have to write migrations.
[01:22:34]
So like, not sadly, but as a trade-off
[01:22:38]
of Elm's current equality model, right?
[01:22:41]
You couldn't just take that old custom type
[01:22:43]
and cram it into the new one, right?
[01:22:45]
Like Elm would be like, well, these are different.
[01:22:46]
They're in different files, right?
[01:22:48]
They're different namespaces.
[01:22:49]
These are different values,
[01:22:51]
even though they're structurally the same.
[01:22:53]
So in prior to version 1.1,
[01:22:57]
the migration would only generate the placeholders.
[01:23:00]
Like, so the top level function types and names,
[01:23:03]
and it'd be like, okay,
[01:23:04]
here's the six migration functions I need,
[01:23:06]
but you have to go to all the work
[01:23:08]
of implementing what's inside them,
[01:23:10]
including writing a massive function,
[01:23:12]
migrate ice cream flavor,
[01:23:14]
case old of every single old variant
[01:23:18]
matches to every single new variant.
[01:23:21]
The only difference being they're in different namespaces,
[01:23:23]
but otherwise it's like the same text
[01:23:25]
over and over and over and over, right?
[01:23:26]
So I think this was frustrating as a user experience
[01:23:30]
because it was like, if I'd only changed one field,
[01:23:33]
now I'm writing migrations for all fields
[01:23:35]
and all custom types everywhere,
[01:23:37]
and I have to do this every time.
[01:23:39]
So it wasn't the end of the world.
[01:23:40]
Some people found like, okay, once I've done it once,
[01:23:43]
I can pretty much kind of copy paste
[01:23:45]
a lot of my migration implementation,
[01:23:47]
but I wasn't happy with it.
[01:23:48]
If you've done it 600 times.
[01:23:50]
Yeah, Jim got really, really, really good
[01:23:53]
at doing these migrations, clearly.
[01:23:55]
But for newcomers as well, it was really confusing, right?
[01:23:58]
Like it made them confused, extra confused.
[01:24:03]
Cause it's like, I'm like, oh yeah,
[01:24:04]
you generate migrations for your change types
[01:24:06]
and also for these types that haven't changed at all.
[01:24:08]
And it's like, once you get through it
[01:24:10]
and once you think about it, you're like, oh yeah, okay.
[01:24:12]
I can understand now if I understand Elm
[01:24:14]
why this is necessary, but yeah,
[01:24:16]
it was getting you to have to think about something else.
[01:24:19]
So yeah, long story short now, Evergreen,
[01:24:23]
where those types haven't changed,
[01:24:25]
it does a pretty good job at basically generating
[01:24:28]
a bunch of that for you.
[01:24:30]
And so it tries to, as deeply as possible,
[01:24:32]
I mentioned it zips effectively these two types.
[01:24:36]
It starts at the top and keeps going through them.
[01:24:38]
So if it's a record, it tries to pair the record fields
[01:24:40]
by name and so on and so forth.
[01:24:42]
And then yeah, anything that's been added,
[01:24:45]
it gives you like a little notice to be like,
[01:24:47]
hey, this variant has been added.
[01:24:49]
It's just a reminder in case you wanted some old variants
[01:24:51]
to map to this new variant that doesn't exist yet.
[01:24:53]
And also, hey, this variant has been removed, right?
[01:24:57]
Like what do you wanna do with this old value?
[01:25:00]
Cause it has nowhere to go.
[01:25:01]
So yeah, that now tries to be a lot more kind of automatic.
[01:25:06]
So yeah, the feedback so far is pretty good.
[01:25:08]
And Jim's happy at least.
[01:25:09]
He's my, I think he suffered the pain point the most
[01:25:13]
of anybody categorically.
[01:25:15]
So he's told me he's enjoying it.
[01:25:16]
And he says migrations only take him like,
[01:25:19]
you know, a minute or two now to sort out.
[01:25:21]
So yeah, that was the call.
[01:25:22]
Yeah.
[01:25:23]
That's great.
[01:25:24]
So one thing I've been curious about,
[01:25:26]
so this new release also ships with the Elm PKG's JS spec.
[01:25:32]
And I've been curious like how,
[01:25:35]
so from what I understand before this,
[01:25:39]
with a Lambda app, you couldn't just add a.js file
[01:25:43]
and ship that and arbitrarily add ports
[01:25:47]
and JavaScript behavior on the page, right?
[01:25:50]
So I was really curious to understand like,
[01:25:54]
how does that design decision and how does Elm PKG JS
[01:26:01]
fit into the concept of evergreen migrations
[01:26:04]
with the front end and the guarantees you're trying to give
[01:26:07]
in a front end Lambda application
[01:26:09]
or the front end part of a Lambda application?
[01:26:12]
Yeah, absolutely.
[01:26:13]
That's a great question.
[01:26:13]
So in short, there's a few features in Lambda
[01:26:16]
that have actually been there for a few versions.
[01:26:18]
And I've been kind of trialing it out with some customers
[01:26:21]
who've ran into certain kind of limitations
[01:26:23]
and they needed solutions for.
[01:26:25]
And so what I announced in the last version,
[01:26:27]
I think was this idea of labs.
[01:26:29]
So Lambda Labs is like a set of features
[01:26:32]
that are in Lambda that you can use in production,
[01:26:34]
but they're marked labs
[01:26:35]
because it's kind of like buyer beware, right?
[01:26:37]
It's like, there's a reason this isn't recommended yet
[01:26:41]
or isn't part of the mainline platform.
[01:26:43]
So Elm PKG JS, which kind of, yeah,
[01:26:45]
kind of started from the spec,
[01:26:47]
which I was hoping maybe it would take off,
[01:26:49]
but it hasn't yet, but maybe there's still time.
[01:26:52]
But the idea was to be like,
[01:26:53]
I'd noticed this problem where a lot of the JavaScript
[01:26:56]
that people wanted to use is this.
[01:26:58]
And I think as an Elm community,
[01:27:00]
we've talked about this problem a few times
[01:27:02]
where we've got like,
[01:27:02]
there's certain Elm packages that are like,
[01:27:04]
hey, this Elm package requires some ports
[01:27:07]
and some JavaScript set up.
[01:27:09]
Here's a bunch of long-winded instructions
[01:27:11]
of varying consistency between packages
[01:27:14]
of how to do that.
[01:27:16]
And it feels like,
[01:27:19]
I don't think it's a massive issue,
[01:27:20]
but it's kind of like, it's just a bit,
[01:27:23]
it's a bit painful.
[01:27:24]
I was always like, oh, how do I do this?
[01:27:25]
And you paste this and where do I paste it?
[01:27:27]
And should I put that on this file?
[01:27:28]
And what bundler do I use?
[01:27:29]
I was kind of thinking about that experience
[01:27:30]
with Lambda being like,
[01:27:31]
what would be a nicer way to do this?
[01:27:33]
And with Evergreen in mind, right?
[01:27:34]
And also this restriction where,
[01:27:36]
we don't want this on the backend at the moment.
[01:27:38]
So in the front end, it was like, okay,
[01:27:41]
a great example and a package that kind of got native,
[01:27:44]
quote unquote, a support for Lambda era
[01:27:46]
is Martin's Elm audio package, right?
[01:27:49]
So he added a specific,
[01:27:51]
like Lambda era front end with audio.
[01:27:53]
So it's a function where you put your Lambda era app
[01:27:55]
in that particular wrapper.
[01:27:57]
And then he has an app wrapper
[01:27:58]
that depends on certain ports
[01:28:00]
and add some extra functionality to support
[01:28:02]
like loading audio and playing audio
[01:28:05]
and managing like the various,
[01:28:07]
the state bits of that, right?
[01:28:08]
So as a user, you can kind of be like,
[01:28:10]
yeah, I have a normal app
[01:28:12]
and then I wrap it in this Lambda era front end with audio
[01:28:15]
and then I get like some extra bits, right?
[01:28:17]
So I can manage audio and that requires some JavaScript.
[01:28:21]
So the idea was to say, okay,
[01:28:22]
well, there should be some way,
[01:28:24]
like what effectively does this slimline JavaScript need?
[01:28:29]
Effectively, it needs a way to hook into init, right?
[01:28:31]
So when the Elm app is being initialized,
[01:28:34]
we want to get an instance of that Elm app
[01:28:36]
so that we can bind our subscriptions,
[01:28:39]
like our port, our inbound and our outbound ports.
[01:28:42]
So Elm package.js was being like, okay,
[01:28:44]
how could we, what would it look like
[01:28:46]
to have like a really delightful standard
[01:28:49]
for shipping a bit of extra JavaScript
[01:28:51]
and some ports with an Elm app
[01:28:54]
in a way where ideally it was type safe, right?
[01:28:59]
Like it was very clear what ports are there,
[01:29:01]
what things go in, what things go out,
[01:29:02]
how should they be used
[01:29:04]
and for it to be able to check this, right?
[01:29:06]
And there was some bigger grand ideas about like,
[01:29:09]
you know, should we do like community verification
[01:29:11]
that the JavaScript isn't gonna launch a blockchain client,
[01:29:15]
you know, or something like that, you know,
[01:29:16]
like maybe, you know, introduce like some safety stuff
[01:29:19]
to be like, you know, if you do like Elm package.js
[01:29:22]
install some package,
[01:29:23]
it's gonna do an Elm install of the package
[01:29:25]
and it's gonna pull the JavaScript down
[01:29:27]
and it's gonna set everything up in a consistent way.
[01:29:30]
And maybe that would make it really nice, you know,
[01:29:32]
for the use cases.
[01:29:35]
So there's, you know,
[01:29:36]
there's like a copy to clipboard example
[01:29:38]
in the Elm package.js spec
[01:29:40]
and a few other examples of like, you know,
[01:29:42]
what would it look like to have these little bits,
[01:29:44]
you know, little port bindings to web APIs
[01:29:48]
usually that aren't available natively in Elm.
[01:29:51]
So yeah, the second concern there was when I was,
[01:29:55]
so there's a proof of concept implementation of this spec.
[01:29:57]
The spec has got nothing to do with Lamdera,
[01:29:59]
but Lamdera implements that on package.js spec,
[01:30:02]
at least in its first version, as far as I'm aware,
[01:30:03]
it's the only consumer or implementer of the spec,
[01:30:07]
which was also written by me, so maybe that's why.
[01:30:10]
But I haven't pushed it too hard, I guess.
[01:30:12]
And so yeah, in the Lamdera implementation,
[01:30:14]
we only have this init,
[01:30:16]
but in the spec I was also considering like an upgrade,
[01:30:18]
right?
[01:30:19]
So what happens when a front end is upgrading,
[01:30:22]
maybe rather than init being re-invoked
[01:30:25]
and you having to carefully think about,
[01:30:27]
well, what happens if init gets invoked multiple times?
[01:30:30]
You know, yes, you want to rebind your ports to the new app,
[01:30:34]
but maybe you don't wanna re-initialize
[01:30:36]
like the audio context, right?
[01:30:38]
Because the user's browser hasn't reloaded.
[01:30:40]
So there was an idea of like,
[01:30:41]
well, could we just do all that in init
[01:30:43]
and say to people,
[01:30:44]
you have to think about init as being kind of like
[01:30:47]
item potent, I guess, you know,
[01:30:48]
like it can be run multiple times
[01:30:50]
and you have to do what's sensible when that happens,
[01:30:54]
or should we explicitly have,
[01:30:55]
okay, this is an init thing, and then here's an upgrade.
[01:30:58]
So that in upgrade, you could just be like,
[01:31:00]
okay, you know, I know I don't have to do any of the init
[01:31:02]
stuff, it's already there,
[01:31:03]
I can only do the code that needs to happen for upgrade,
[01:31:06]
which is probably rebinding ports.
[01:31:07]
So that's kind of an open question.
[01:31:09]
And that's why on package JS implementation,
[01:31:11]
Lambda is still in labs,
[01:31:12]
because that's not fully handled.
[01:31:14]
So there is a way,
[01:31:16]
currently the process is you contact me,
[01:31:18]
but there is a way to opt out of
[01:31:20]
the hot reload stuff in production.
[01:31:22]
And some people have chosen to do that on their apps
[01:31:25]
where they're like, you know,
[01:31:26]
I don't have that many users,
[01:31:27]
or I don't worry about that,
[01:31:29]
but I've got like some, you know,
[01:31:30]
complicated JavaScript setup
[01:31:32]
that I haven't figured out how to handle
[01:31:33]
this evergreen concept.
[01:31:34]
And so they might opt out of the live reload.
[01:31:37]
And then instead what happens is that
[01:31:38]
when the app deploys and then your front end version happens
[01:31:41]
it forces a hard refresh.
[01:31:43]
So it forces a full page reload and reinitialization,
[01:31:47]
you know, which will lose some front end state for people,
[01:31:49]
but gets back the, you know, things aren't,
[01:31:52]
you don't end up in that state where, you know,
[01:31:54]
things are broken or you're sending old versions
[01:31:55]
and you don't have the new app version.
[01:31:57]
So we still get the consistency at the loss
[01:31:59]
of some front end state.
[01:32:01]
Does that make sense?
[01:32:02]
Right, yeah, so how does that fit in with like the guarantee?
[01:32:07]
So like what would happen if it was just a free for all,
[01:32:12]
you can run JavaScript on the front end of a Lambda app,
[01:32:15]
like, or what do you gain by the design decision
[01:32:19]
to not allow that?
[01:32:21]
What's the motivation behind that?
[01:32:23]
Yeah, so there is no constraint actually,
[01:32:26]
like you can do anything in that JavaScript
[01:32:28]
on the front end.
[01:32:29]
What I suppose, like the guarantee that gets made
[01:32:32]
is that that JavaScript will only run
[01:32:35]
in the context of an app being initialized,
[01:32:37]
which isn't a huge guarantee,
[01:32:39]
but it means that you, your code doesn't have to worry
[01:32:43]
about the initialization setup
[01:32:44]
and Lambdaera can continue to control,
[01:32:47]
like there's a harness, right?
[01:32:49]
Like that does the evergreen magic and some other stuff
[01:32:52]
and does special bindings
[01:32:53]
to make the front end back end stuff work, right?
[01:32:54]
So Lambdaera platform has a bunch of harness things
[01:32:57]
that it does for you to make everything seamless
[01:32:59]
and everything work.
[01:33:02]
So yeah, the thing that we get from a Lambdaera perspective
[01:33:05]
is that we let the user kind of plug into that
[01:33:07]
into a sensible way, but yeah, 100%,
[01:33:09]
like a user can throw exceptions in that JavaScript code,
[01:33:12]
the user could crash the app,
[01:33:13]
like that all the normal JavaScript stuff
[01:33:15]
comes back into play.
[01:33:17]
So the user has to be careful, but yeah,
[01:33:21]
I suppose the only other guarantee they get
[01:33:22]
is that that in it will be called again
[01:33:25]
when the upgrade happens.
[01:33:27]
So it gives them a mechanism if they wanted to try
[01:33:30]
to make the evergreen philosophy work
[01:33:33]
with their JavaScript stuff.
[01:33:35]
If the JavaScript simple enough,
[01:33:37]
you don't really have to do anything,
[01:33:38]
but yeah, if you had something a bit more complex,
[01:33:40]
like an audio context, then yeah,
[01:33:42]
you could be like, okay, cool,
[01:33:43]
I know and it's gonna get called again.
[01:33:45]
I'll put in some guards to check
[01:33:48]
whether I'm doing the first initialization
[01:33:51]
or maybe I'm already on my second one.
[01:33:53]
Mm-hmm, got it, so conceptually,
[01:33:55]
like if you really wanted to model
[01:33:57]
what happens when you invoke a port,
[01:34:01]
I guess you could just say, if an exception happens,
[01:34:06]
we wanna model that explicitly and you could,
[01:34:08]
but I mean, since an outgoing port doesn't get anything back,
[01:34:13]
couldn't you just like let a port call happen
[01:34:18]
and then say, if it crashes,
[01:34:20]
we just catch the exception and log something,
[01:34:23]
something like that.
[01:34:24]
But I guess having the Elm package JS spec
[01:34:28]
gives you a box to make those,
[01:34:32]
to organize things and to make those safety guarantees
[01:34:35]
within a port, is that sort of the motivation?
[01:34:38]
Yeah, so the Elm package JS spec does kind of philosophize
[01:34:43]
about what would be a good overall mechanism there,
[01:34:46]
which could include those safety guards,
[01:34:48]
but the Lambda implementation currently,
[01:34:50]
it just goes to the, at least,
[01:34:52]
it just kind of goes to the concept of being like,
[01:34:54]
okay, you put your JavaScript for your individual port
[01:34:57]
use cases in this folder in this way,
[01:35:00]
and then anything that's in that folder,
[01:35:01]
I'm looking for an init in each file
[01:35:03]
and I'm gonna run it for you, and that's as far as it goes.
[01:35:05]
So none of the spec stuff about like the types
[01:35:08]
and the safety of that,
[01:35:08]
like you still have to implement that yourself.
[01:35:11]
So it's not like a full automatic implementation
[01:35:13]
of the spec, but I would like to have that eventually,
[01:35:16]
like it would be nice if there,
[01:35:19]
like if that was a feature where you,
[01:35:20]
if you did like a Lambda install of a package
[01:35:23]
that did have JavaScript,
[01:35:24]
that Lambda would be like,
[01:35:25]
hey, this package is JavaScript,
[01:35:27]
would you like me to set this up
[01:35:29]
and create the packageports.elm file
[01:35:32]
and put all the types in there for you?
[01:35:35]
And I'm like, then it's just ready to go.
[01:35:36]
I think that would be really nice.
[01:35:38]
And then it's just a question of,
[01:35:40]
would people find that interesting as a standalone tool?
[01:35:43]
And would the community find that interesting
[01:35:44]
as a way to be like, hey, this is how we bundle
[01:35:47]
small bits of JavaScript,
[01:35:49]
utility JavaScript with our packages.
[01:35:52]
It's definitely an anti-goal for it to be like,
[01:35:56]
this is how you drag in 17 NPM dependencies into your project
[01:36:01]
like it's absolutely not for that use case.
[01:36:04]
There's an, I mean, there's an example
[01:36:06]
of how you would use Elm package.js,
[01:36:08]
but at this stage, you'd have to bundle
[01:36:10]
some of that stuff yourself, right?
[01:36:12]
Like you'd have to pre-package things.
[01:36:13]
Like it's not really for that.
[01:36:14]
The idea was how do we like in a nice way
[01:36:17]
get like this ancillary JavaScript for Elm packages.
[01:36:21]
Yeah.
[01:36:22]
Well, amazing stuff, Mario.
[01:36:24]
If people wanna learn more about the latest release,
[01:36:28]
more about Evergreen, more about Lemdira,
[01:36:31]
what should they look at?
[01:36:32]
Yeah, absolutely.
[01:36:33]
So lemdira.com, probably the easiest starting point
[01:36:36]
and easiest to remember.
[01:36:38]
With a B, right?
[01:36:39]
Oh, you're just ruining all of my naming.
[01:36:45]
It's definitely not with a B, lemdira.com.
[01:36:50]
But yeah, that'll get you through some of the pitch
[01:36:53]
and pretty much straight through to the documentation.
[01:36:55]
So you can take a look at that.
[01:36:57]
Yeah, there's some example apps there
[01:36:59]
that are really quite small and contained.
[01:37:01]
So I'd recommend people take a look at those.
[01:37:03]
Evergreen, I wouldn't, I mean, I would say
[01:37:06]
it probably makes more sense to look at Evergreen
[01:37:08]
when you need to look at Evergreen.
[01:37:11]
If people are interested, you can read the Evergreen docs,
[01:37:13]
but I think it probably makes more sense in practice
[01:37:16]
when you're actually trying to get from one model to another
[01:37:18]
in a specific use case for your specific app,
[01:37:21]
but then going through that process,
[01:37:22]
I think you can be like, oh yeah, that makes sense.
[01:37:24]
I've done these changes and this migration
[01:37:27]
that I want out of that.
[01:37:28]
Reading it as a high level, I'm not sure how well
[01:37:31]
that lands.
[01:37:35]
But yeah, anyway, all the docs are there.
[01:37:36]
And yeah, as always, we've got a Discord
[01:37:39]
full of lots of lovely and helpful people.
[01:37:41]
So if you want to ask any questions or ponder anything,
[01:37:45]
you're always very welcome in there.
[01:37:47]
Yeah, that's pretty much it.
[01:37:48]
Wonderful, thanks so much for coming on, Mario.
[01:37:51]
Yeah, thank you.
[01:37:52]
No, it's been my absolute pleasure.
[01:37:53]
Thanks for having me as always.
[01:37:55]
And you're in, until next time.
[01:37:57]
Until next time.
[01:37:58]
Music