3 ms·
This doesn't seem fundamentally different from any schema/API mismatch issue. For example using the wrong header for a C library, or the wrong Protobuf schema.
by IshKebab 2y ago
This doesn't seem fundamentally different from any schema/API mismatch issue. For example using the wrong header for a C library, or the wrong Protobuf schema.
I guess it would be good if it verified it at runtime somehow though. E.g. when you first connect to the database it checks Postgresql is the minimum required version, and the tables match what was used at compile time.
- dietr1ch 2y agoIt could be verified at runtime, but I haven't seen anyone trying to version/hash schemas and include that in the request. The workaround in practice seems to be to keep the DB behind a server that always™ uses a compatible schema and exposes an API that's either properly versioned or at least safe for slightly older clients. To be fair it's hard to get rid of the middleman and serve straight from the DB, it's always deemed too scary for many reasons, so it's not that bad.
- Someone 2y agoIt shouldn’t be hard for a database to keep a hash around for each database, update it whenever a DDL (https://en.wikipedia.org/wiki/Data_definition_language https://en.wikipedia.org/wiki/Data_definition_language) command is run, and, optionally, verify that a query is run against the exact database structure. Could be as simple as secure hashing the old hash with the text of the DDL command appended. That would mean two databases can be identical, structure-wise, but have different hashes (for example if tables are created in a different order), but would that matter in practice? Alternatively, they can keep a hash for every table, index, constraint, etc. and XOR them to get the database hash.
- jeltz 2y agoSounds very hard to me. How do you handle online schema changes with this? Schema changes are trivial to do if you can be down for a long time.
- Someone 2y agoYou can only do those if schema changes are transactional. The transaction could update the checksum and return it for the caller to use in subsequent calls. And yes, that would shut off other clients that want to be sure to talk to the correct schema, but if you opt in to such a scheme, that’s what you want.