<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">How do you feel about database triggers?</div></blockquote><div><br class=""></div>Mixed ;)<br class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Something like this should do what you're after, I think:</div><div class=""><br class=""></div><div class="">```</div><div class="">CREATE TRIGGER ensure_children_are_indexed_scoped_to_parent</div><div class="">  AFTER INSERT ON child_table</div><div class="">  UPDATE child_table SET index = MAX(index) + 1 WHERE id = LAST_INSERT_ID();</div><div class="">```</div><div class=""><div class=""><br class="webkit-block-placeholder"></div><div class="">No idea if it still works, but you could manage them using something like `hair_trigger`:</div><div class=""><br class=""></div><div class="">  <a href="https://github.com/jenseng/hair_trigger" class="">https://github.com/jenseng/hair_trigger</a></div></div></div></div></blockquote></div><br class=""><div class="">Thanks for the suggestion.  I hadn't considerd triggers at all...</div></body></html>