Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upLive data migrations #1086
Comments
This comment has been minimized.
|
This seems like a good idea, but I'm not sure how actionable that is for Diesel? Your 3 steps can be implemented in application code, right? I guess we could in theory offer helpers for that, but those might also work as an external crate. Or, asked in another way: What needs to change to make this easier/possible? |
This comment has been minimized.
|
I think that's fine for it to be handled in application code, or via a library, but this was more around having a story for that: maybe that means implementing a demo application that shows how one might achieve that, and endorsing that particular technique. The reason for this is that when choosing a technology stack, it's important to have confidence that these kind of things are doable, even if it requires additional work. Here are some difficulties that I ran into when attempting to do the above:
In light of these difficulties, I changed my strategy:
You can see my experiments here: https://github.com/Diggsey/rust-crud-example |
This comment has been minimized.
|
I have not thought about it long enough to give a qualified answer, but… Quick thought: How about having a view for each table version? Like, CREATE VIEW baskets_v1 AS
SELECT *
FROM baskets
WHERE version = 1;and putting that in a mod schema {
mod v1 {
table! { baskets… }
}
}At least in postgres, simple views like this allow INSERT/UPDATE/…
Huh? We allow arbitrary SQL? With |
This comment has been minimized.
That's an interesting idea, but I'm not sure how it would work in practice. If my data migration is "add 10 to value", there's no way postgres could figure out that values inserted into the old view should be modified accordingly.
Each migration is run in a transaction, which is unsuitable for large data migrations. That said, I do like the simplicity of diesel's migrations system, which avoids certain problems that eg. alembic has, by being pure SQL. You could embed the migration process in your app, although I'm not sure how you would keep structural and data migrations in the same history. |
This comment has been minimized.
|
I think I should clarify what the intended role of Diesel's migrations are here. The term "structural" vs "data" migrations has been thrown around, which is fine. Diesel's migrations are really only meant for "structural" migrations. Things like However, that distinction has little to do with the issue that seems to be at hand here, which is zero downtime deploys. For backwards compatible changes (adding tables or columns), there's not much to do here. You run your migrations, then you deploy code. For destructive changes, the process with Diesel is the same as anything else:
However, it sounds like you're also asking about things like how to deploy migrations which would require a significant amount of down time. I think that is something which is out of scope for Diesel. There are existing tools (e.g. https://github.com/shopify/lhm) which handle this. Perhaps one will be written in Rust eventually, but I don't think the language that tools like that are written in is relevant here. |
Diggsey commentedAug 10, 2017
It would be useful to have a way to do live data migrations with diesel.
Here's how I would like to do these migrations:
This means the service code only needs to deal with the most recent two versions, with legacy versions only needing to be handled in the migration files themselves.
However, this doesn't work currently for two reasons:
For the data migration to be unobtrusive, it needs to update rows in relatively small batches, with one transaction per batch, so that it doesn't cause too many conflicts with other applications accessing the database.