Re:Databases always have a schema (2018)
by _bxg1 on Monday February 25, 2019 @10:54AM
(#19246477)
Correction: you have a single authoritative view of the world, plus a secondary cached view of the world in a different language which probably doesn't perfectly map to the original one. Many people choose this approach, but it isn't without its own issues.
[ Parent
| on HN ]
Re:Databases always have a schema (2018)
by nathan_long on Monday February 25, 2019 @02:50PM
(#19248767)
> you have a single authoritative view of the world, plus a secondary cached view of the world in a different language
Yes. OTOH, with NoSQL you have no authoritative schema; your code may allow for multiple different schemas, and your records may have multiple different schemas, and they could agree or disagree to any extent.
You can still have an authoritative schema, it just doesn't live in the DB itself. It would have to be defined in the code, generally.
Re:Databases always have a schema (2018)
by nathan_long on Monday February 25, 2019 @04:02PM
(#19249433)
I would argue that it's not authoritative. Nothing guarantees that the records in the db match that schema; the closest you get to a guarantee is your diligence to 1) run a job mutating all records every time you change your in-code schema and 2) ensure that nothing but your latest application code can write to the db.
OTOH, `\d users` in PostgreSQL is authoritative; there cannot be a row that does not conform to the fields, types, and constraints listed there.
> I would argue that it's not authoritative.
I think the word you're looking for is "enforced". Where there are multiple schemas, one can certainly be the "authority", even if it's not enforced across all data.
Re:Databases always have a schema (2018)
by nathan_long on Tuesday February 26, 2019 @10:10AM
(#19254843)
Whatever terminology you use, every place you loop through records doing stuff with them, you'll either have to decide what to do with oddly-shaped records or implicitly decide to let exceptions occur at that point. Whereas if PostgreSQL tells you that `user` has a `email character varying(255) NOT NULL`, you can be sure that every `user` does. The only place you need a conditional related to that is when trying to insert an invalid record.