Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Gay Marriage from a Database Engineering Perspective

Gay Marriage from a Database Engineering Perspective

This talk is adapted from qntm.org/gay - an essay about how not to write homophobic databases, and why politicians might be dragging their feet.

Liz Howard

March 15, 2013
Tweet

More Decks by Liz Howard

Other Decks in Programming

Transcript

  1. Gay Marriage! From a database engineering perspective @lizTheDeveloper Adapted from

    an essay by Sam Hughes @ qntm.org/gay Friday, March 15, 13
  2. A Relationship... • Recognized by the state • That affords

    certain legal rights Friday, March 15, 13
  3. A Relationship... • Recognized by the state • That affords

    certain legal rights • Defines common property Friday, March 15, 13
  4. A Relationship... • Recognized by the state • That affords

    certain legal rights • Defines common property • Automagically determines parentage of children created while in the relationship. Friday, March 15, 13
  5. Foreign Keys • Every entity has an ID • Other

    entities reference that ID Friday, March 15, 13
  6. “Good Enough for Government Work” `males` - `id` - `forename`

    - `surname` - `birthdate` - `wife_id` (foreign key references column `females`.`id`, may be NULL if male is unmarried) `females` - `id` - `forename` - `surname` - `birthdate` - `husband_id` (foreign key references column `males`.`id`, may be NULL if female is unmarried) Friday, March 15, 13
  7. Problem? • Bad Referential Integrity • Relationships can be one-way

    • Duplicates data • No metadata about relationship • Lots of other things Friday, March 15, 13
  8. Sexist Database Design `males` - `id` - `forename` - `surname`

    - `birthdate` - `wife_id` (unique foreign key references column `females`.`id`, may be NULL if male is unmarried) `females` - `id` - `forename` - `surname` - `birthdate` Friday, March 15, 13
  9. Serious problems • Mind-bogglingly sexist • But slightly better, from

    an engineering perspective (shockingly.) • Still have a lack of metadata Friday, March 15, 13
  10. Sexism with Metadata `males` - `id` - `forename` - `surname`

    - `birthdate` - `wife_id` (foreign key references column `females`.`id`, may be NULL if male is unmarried) - `marriage_date` (may be NULL if male is unmarried) - `divorce_date` (may be NULL if male is unmarried or married but not yet divorced) `females` - `id` - `forename` - `surname` - `birthdate` Friday, March 15, 13
  11. Problem? • Still sexist! • Also, men can only be

    married/divorced once. • “Flat” data presents these problems. Friday, March 15, 13
  12. Relationship Tables `males` - `id` - `forename` - `surname` -

    `birthdate` `females` - `id` - `forename` - `surname` - `birthdate` `marriages` - `id` - `husband_id` (foreign key references column `males`.`id`) - `wife_id` (foreign key references column `females`.`id`) - `marriage_date` - `divorce_date` (NULL if marriage not ended) Friday, March 15, 13
  13. But we still have problems • Still sexist • Separating

    genders doesn’t make sense. Friday, March 15, 13
  14. If two entities are equal (like men and women) then

    there is no reason to stratify them. Friday, March 15, 13
  15. We are all humans. `humans` - `id` - `forename` -

    `surname` - `birthdate` - `sex` ("male" or "female") `marriages` - `id` - `partner_1_id` (foreign key references column `humans`.`id`) - `partner_2_id` (foreign key references column `humans`.`id`) - `marriage_date` - `divorce_date` (NULL if marriage not ended) Friday, March 15, 13
  16. Problems? • Unary marriages are now possible - you can

    marry yourself. • The “sex” column is more limiting than it seems. Friday, March 15, 13
  17. “There’s gonna be a lot more guys with makeup this

    millennium” - Eddie Izzard `humans` - `id` - `forename` - `surname` - `birthdate` - `sex_id` (foreign key references column `sexes`) `marriages` - `id` - `partner_1_id` (foreign key references column `humans`.`id`) - `partner_2_id` (foreign key references column `humans`.`id`) - `marriage_date` - `divorce_date` (NULL if marriage not ended) `sexes` - `id` - `string` Friday, March 15, 13
  18. `humans` - `id` - `forename` - `surname` - `birthdate` -

    `sex_id` (foreign key references column `sexes`) - `gender_id` (foreign key references column `genders`) `marriages` - `id` - `partner_1_id` (foreign key references column `humans`.`id`) - `partner_2_id` (foreign key references column `humans`.`id`) - `marriage_date` - `divorce_date` (NULL if marriage not ended) `sexes` - `id` - `string` `genders` - `id` - `string` Gender is a Spectrum Friday, March 15, 13
  19. Let’s just forget about it. `humans` - `id` - `forename`

    - `surname` - `birthdate` `marriages` - `id` - `partner_1_id` (foreign key references column `humans`.`id`) - `partner_2_id` (foreign key references column `humans`.`id`) - `marriage_date` - `divorce_date` (NULL if marriage not ended) Friday, March 15, 13
  20. Let’s take it slowly. `humans` - `id` - `forename` -

    `surname` - `birthdate` `marriages` - `id` - `marriage_date` - `divorce_date` (NULL if marriage not ended) `marriage_partners` - `id` - `human_id` (foreign key references column `humans`.`id`) - `marriage_id` (foreign key references column `marriages`.`id`) Friday, March 15, 13
  21. Problems? • What if a human joins the marriage after

    it begins? From a database engineering perspective. Friday, March 15, 13
  22. It’s all about metadata `humans` - `id` - `forename` -

    `surname` - `birthdate` `marriages` - `id` `marriage_partners` - `id` - `human_id` (foreign key references column `humans`.`id`) - `marriage_id` (foreign key references column `marriages`.`id`) - `marriage_date` - `divorce_date` (NULL if still in marriage) Friday, March 15, 13