4 ms·
> This would require storing removed columns or tables somewhere... Simpler, you have an underlying set of base tables, and each "migration" is simply creating
by ben509 8y ago
> This would require storing removed columns or tables somewhere...
Simpler, you have an underlying set of base tables, and each "migration" is simply creating a new schema with a set of views / stored procedures over the base tables.
Then your migrations will be forward only for the base tables, and constructing a new schema of views over them for the new version. Older versions of the app continue reading their original views.
And once you've decided a version has been deprecated long enough and any legacy data or indices can be safely removed, you'd move the earliest valid version forward.
That approach, of course, means you have to be able to come up with a view of the data consistent with the existing base tables, of course, and the base table migrations have to be compatible with the oldest valid schema version.
And you run into other sticky questions like adding constraints: if v1 doesn't have a constraint, but v2 does, do we:
1. apply the constraint to both and v1 is now going to have to deal with errors
2. apply the constraint only to v2, and it's sometimes going to see invalid data from v1
3. apply the constraint only to v2, and invalid data will be hidden
But it's still doable.
- ams6110 8y agoIt's great in theory, but in most databases I've used, if you get too crazy with views your performance goes to crap. The optimizer just can't handle it. Views are great for specific use cases, but if your interaction with the underlying tables is entirely through views I've never had that work really well.
- garmaine 8y agoChicken and egg problem. It's inefficient because no one does it, not because of fundamental computer science problems. If Active Record et al adopted it, I guarantee you database vendors would make it efficient.
- ako 8y agoI used this approach, views on top of tables for all data access, quite often on oracle 7,8 & 9. Oracle query optimizer can handle it perfectly fine.