å®è·µImmutable Data Model
ã¯ããã«
ãã®è¨äºã§ã¯ãImmutable Data Modelã¨å¼ã°ããè¨è¨ææ³ããã¨ã«ããªã¬ã¼ã·ã§ãã«ã»ãã¼ã¿ãã¼ã¹ã«ãããããã¼ãã«è¨è¨ã®è©±ãæ¸ãã¦ãã¾ããã¾ããä»åã®å®è·µã§å©ç¨ãããå¥ã®èãæ¹ã®èæ¯ãç解ããããã«ãOut of the tar pitã¨ããå°è«æã®å 容ã«ãè¨åãã¾ãã
ãç¶æ ã¨ã¯ä½ãï¼ãã¨ããããããã話ãããããåºã¦ãã¾ããããã¼ã¿ãã¼ã¹ã®ãã¼ãã«è¨è¨ã«ã¤ãã¦ã®è©±ã§ãããã¨ãããããããã®SQLãåºã¦ãã¾ãããªã®ã§ããã¼ã¿ã¢ããªã³ã°ã¨ãç¶æ 管çã¨ããç¹ã«SQLã¨ãã«èå³ããªã人ã«ã¯é¢ç½ããªãã¨æãã¾ãã
ãã®ãããã«èå³ããæ¹ã¯ãèªãã§ã¿ã¦æ¬²ããã§ãã Immutable Data Modelããå®éã®ã¢ããªã±ã¼ã·ã§ã³ã§ä½¿ããã¼ã¿ãã¼ã¹ã«æ¡ç¨ããã«ããããã©ãããèãæ¹ã§ãã©ã®ããã«ãã¼ãã«ãæ§æããããèªåãªãã®çµé¨ãæ¸ãã¦ãã¾ãã
å½ããåã§ãããå®è·µãããã®ã§ããã¨ã¯ãããä¸ã¤ã®ã¢ã¤ãã¢ã§ããã®ã§ãå¥ã«ãã¹ããªææ³ã§ããã¨ä¸»å¼µããã¾ããããããã¯ããããã»ãããããããããªãã®ã§ã¯ãã¨ããã¦ãã§ã¯ãããã£ã¦ããã¿ãããªãã®ãããã°ããèªèº«ã®ããã°ã§æ¸ããªã©ãã¦ç¤ºãã¦ããã ããã°ãçºå±çãªè©±ã«ãªãããªãã¨æã£ã¦ãã¾ãã
Immutable Data Modelã¨ã¯
ããã°ã©ãã³ã°è¨èªã®ä¸çã«ã¯ãã¤ãã¥ã¼ã¿ãã«ãªãã¼ã¿ã®æ¹ãä¸å ·åãèµ·ããã«ããå®å ¨ã§ãããã¨ããèãæ¹ãå¤ããããããä¸é¨è¨èªã§ã¯ããããããã¼ã¿èªä½ãæ¹å¤ãããã¨ãã§ããªãï¼æ¹å¤ããæ°ãããã¼ã¿ãä½ããã¨ããã§ããªãï¼è¨èªãåå¨ãã¾ããClojureã¨ãã
ãã¼ã¿ãã¼ã¹ã®ãã¼ãã«è¨è¨ã«ããã¦ãããã¼ãã«ã®Create, Update, Deleteã®ãã¡ãç¹ã«Updateããã·ã¹ãã ãè¤éåããè¦å ã®ä¸ã¤ã ã¨ããèãæ¹ãããã¾ããUpdateããªãã¹ãçºçãããªãããã«ã¯ããã¼ã¿ãæ¹å¤ã§ããªãï¼ã¤ã¾ãCreateããã§ããªãï¼ã¢ãã«ã®æ¹ããé·æçã«å®å®ãããå®å ¨ãªã·ã¹ãã ãä½ããã¯ããã¨ããèãæ¹ã§ãã
Immutable Data Modelã¨å¼ã°ããããã§ãããç¥ãéãã§ã¯ãKawasimaãããåä»ã親ã®ã¯ãã
ã¤ãã¥ã¼ã¿ãã«ãã¼ã¿ã¢ãã«
Web+DB Pressã®ãã¼ã¿ã¢ãã«åã§ãçµæ§è©³ãã解説ããã¦ããã®ã§ããããã§ãã
èãæ¹ã§ããã解çã§ã¯ãªã
å¤ãã®è¨è¨è«ãããã§ããããã«ãImmutable Data Modelã¯ãèãæ¹ãã§ããããç´°ããæç¶ãã¨ã«ã¼ã«ããã£ã¦ããã®ã¨ããã«ããã°èªåçã«è¯ããªããããªæç§æ¸ãã§ã¯ããã¾ããããã¼ã¿ã¢ããªã³ã°ããã¨ãã«ãåå°ã¨ãã¦é¸æã§ãããä¸ã¤ã®æ¹æ³è«ã§ãããã®èãæ¹ããã¨ã«ãå®éã«ã©ã®ããã«ãã¼ãã«ãç¨æãããã¯ãèªåã§èããå¿ è¦ãããã¾ãã
åè¿°ã®Web+DB Pressã®è¨äºã«ããã¦ããæ¦ããããããã¨ãããããã®ã ãã¨ãã説æããææ¡ã¯åºã¦ãã¾ãããããããçããªã®ã§ä¸åä¸å¥ããã®éãããã°ãããã¨ããç©ã¯åºã¦ãã¾ããã
æã£åãæ©ãåçãç¥ããã人åãã§ã¯ãªãã®ã§ãã
ãªã®ã§ããã®è¨äºãããã®èãæ¹ããã¨ã«ãããããè¨è¨ãå®éã«ãã£ã¦ã¿ã¦ãããã©ã©ãã ãããï¼ã¨ããæå³åãã§èªãã§æ¬²ããã§ãã
åãèãæ¹ããã¼ã¹ã«ããã£ã¨ã¨ã¬ã¬ã³ããªæ¹æ³ããããªãã°ãã©ãã©ãæ¡ç¨ãã¦ããã°ããã®ã§ãã
Out of the tar pit
Out of the tar pitã¨ãããå²ã¨æåãªå°è«æããã£ã¦ãããããªè¨è¨çè«ã§å¼ç¨ããã¦ãã¾ããã·ã¹ãã ã«ãããç¶æ ï¼Stateï¼ã¨ãã¸ãã¯ã«ã©ã®ãããªåºå¥ãããã®ããæ¬å½ã«å¿ è¦ãªç¶æ ããã¸ãã¯ã¨ã¯ããããã¯ãããã§ãªããã®ã¯ï¼ã¨ãã£ããã¨ãè«ããåºåããããã¨ã§ãå®å®ããã·ã¹ãã ãä½ãã«ã¯ã©ããããããã®ãï¼ãè«ãã¦ãã¾ãã
Out of the tar pitã«ã¤ãã¦ã¯ãç§ãåã«ããã°ã§è©³ããç´¹ä»ããè¨äºãããã®ã§ããã¡ããèªãã§ã¿ã¦ãã ããã
ã·ã¹ãã ã®è¤éãã¯ã©ãããæ¥ãã®ã â Out of the tar pitãèªã
ãã¡ãã§ç´¹ä»ãã¦ããããã«ãOut of the tar pitã§ã¯ãã·ã¹ãã ã®ç¶æ ã¨ãã¸ãã¯ãã
- å¿ é ã®ç¶æ (Essential State)
- å¿ é ã®ãã¸ãã¯(Essential Logic)
ã¨ãã·ã¹ãã ã®é½åã«ããçã¾ãããä»éçãªãã®ã
- ä»éçãªç¶æ (Accidental State)
- ä»éçãªãã¸ãã¯(Accidental Logic)
ã¨ã«åããä½ãç¶æ ã§ãä½ããã¸ãã¯ãªã®ããä½ãå¿ é ã§ä½ãä»éçãªã®ãã説æãã¦ãã¾ãã
ãªããEssential/Accidentalã®è¨³èªã¨ãã¦ã¯ããæ¬è³ªçãªããå¶æçãªãã¨ããèªã使ããããã¨ãå¤ãã§ãï¼ããã°ã«æ¸ãã¦ããããã«ããã®è¨èã®å¤§å ã§ããã人æã®ç¥è©±ãã®ç¿»è¨³ã§ããã®è¨³èªã使ããã¦ããããã§ãï¼ããå¿ é ã®ããä»éçãªãã¨ããèªã¯ç§ãããã°ã«ããã¦ä½¿ã£ããã®ã§ãããããã§ã¯ãããå¼ãç¶ãã¾ãã
ç¶æ ã¨ãã¸ãã¯
Out of the tar pitã«æ¸ããã¦ããç¹å¾´çãªè©±ã«ãæã ãç¶æ ã¨æã£ã¦ãããã®ã¯ãå®éã«ã¯ç¶æ ã§ã¯ãªãããã¸ãã¯ã§ãããã¨ãã話ãããã¾ãã
æ¶ç©ºã®è©±ã¨ãã¦ãè¨ç®æéã常ã«ã¼ãã®ãæ°å¦çä¸çã«ããã¨ä»®å®ããããã¨ãã²ã¼ã ã«ããããã¬ã¤ã¤ã¼ã®ç¾å¨ä½ç½®ã¯ãç¶æ ã§ã¯ãªããã¸ãã¯ã ã¨ãã話ããã¦ãã¾ãããªããªããè¨ç®æéãã¼ããªã®ã§ããã°ããã¹ã¿ã¼ãå°ç¹ãã¨ããç¶æ ã¨ãã移åæä½ã®å ¨å±¥æ´ãã¨ãã2ã¤ã®ç¶æ ããè¨ç®ããã°ãç¾å¨ä½ç½®ã¯è¨ç®ã§å°ãåºããããã§ããç¾å¨ä½ç½®ã¨ã¯ããã¹ã¿ã¼ãå°ç¹ãã¨ã移åæä½ã®å ¨å±¥æ´ãããã©ã¡ã¼ã¿ã¨ãããç¾å¨ä½ç½®ãé¢æ°ã ã¨ãããã¨ã§ãã
ã¤ã¾ããã¹ã¿ã¼ãå°ç¹ã¨ç§»åæä½ã®å ¨å±¥æ´ã®äºã¤ã¯ç¶æ ã ãããç¾å¨ä½ç½®ãã¯ãå®ã¯ç¶æ ã§ã¯ãªãã£ãã®ã ãã¨ãã話ã§ãã
ä¸æ¹ãå¿ é ã¨ä»éçã®åºå¥ã«ã¤ãã¦ã¯ãOut of the tar pitã«ããã¦ãä½ãå¿ é ã®(Essential)ç¶æ ãªã®ãã¯ã¯ã£ããããã¦ãã¦ããã¦ã¼ã¶ã¼ã®å ¥åãã ããå¿ é ã®ç¶æ ã§ãããã以å¤ã¯å ¨ã¦å¿ é ã®ç¶æ ã§ã¯ããã¾ãããã¦ã¼ã¶ã¼ã®å ¥åã ãã¯ãè¨ç®ã§å°ãåºããã¨ã¯ã§ããªãããå¾ããåãæ»ããã¨ãã§ããªãã®ã§ããã¦ã¼ã¶ã¼ã®å ¥åãè¨é²ãã以å¤ã«ãä»å¾ãã®ãã¼ã¿ãå¾ãæ¹æ³ããªãã®ã§ãã
ãªããã®Out of the tar pitã®è©±ããã¦ãããã¨ããã¨ãImmutable Data Modelãå®è·µããä¸ã§ãã»ãã¨ãã«ãã¼ã¿ãã¼ã¹ã«ä¿åãã¹ãæ å ±ã¯ãªããªã®ãï¼ãã¨ãããã¨ãèããä¸ã§éè¦ã ããã§ãã
ã¦ã¼ã¶ã¼ã®å ¥åã¯ãã¹ã¦ãå¿ é ã®ç¶æ ãã§ãã
ãªã®ã§ãã¦ã¼ã¶ã¼ã®å ¥åã¯ããããªãå ¨ã¦ä¿ç®¡ããããã§ããã以å¤ã¯å¿ é ã§ã¯ãªãã®ã§ãå¯è½ãªéãããã¸ãã¯ã§è¡¨ç¾ãããããããã¹ã¿ã¼ãå°ç¹ã¨ãã¾ãã
å¿ é ã®ãã¸ãã¯
ã§ã¯ããå¿ é ã®ãã¸ãã¯ãã¯Out of the tar pitã«ããã¦ã©ãæ±ããã¦ããããå¿ é ã®ãã¸ãã¯ã¯ãå¿ é ã®ç¶æ ããè¨ç®ã«ãã£ã¦ç´æ¥å°ãåºãããã®ã§ãã
ãªã«ããå¿ é ã®ç¶æ ãã§ããããªã«ãããã¸ãã¯ããªã®ããåºå¥ã§ããã°ããã¼ãã«ã¨ãã¦ç¨æãã¹ããã®ã¯ä½ãªã®ããã¯ã£ãããã¦ãã¾ããæ¬å½ã«ä¿åãå¿ è¦ãªã®ã¯ããå¿ é ã®ç¶æ ãã ãã§ãã
ãã¡ãããç¾å®ã®ä¸çã§ã¯ãè¨ç®æéã¯ã¼ãã§ã¯ãªãã®ã§ããªã«ãããã®æå½ã¦ãããªããã°ããã¾ãããã§ãããæåã®æ®µéã§ãããã¯å¿ é ã®ç¶æ ã§ãããããã¯å®ã¯ç¶æ ã§ã¯ãªããã¸ãã¯ã ãã¨åºåããã§ãã¦ãããã¨ã¯å¤§äºã§ãããå¿ é ã®ãã¸ãã¯ãã®é¨åã«ã¯ãæ¬æ¥ã¯ããã¼ã¿ãã¼ã¹ãã¼ãã«ã¯å¿ è¦ãªãã£ããã¨ããèªèãéè¦ãªã®ã§ãã
ã§ã¯ããªã¬ã¼ã·ã§ãã«ã»ãã¼ã¿ãã¼ã¹ã«ãããããå¿ é ã®ãã¸ãã¯ãã¯ã©ã®ããã«è¡¨ç¾ãããã¹ãã§ããããã
ç§ã¯ããã«ããã¥ã¼ãã使ããã¨ã«ãã¾ããã ãå¿ é ã®ç¶æ ãã®çµã¿åããã§è¡¨ç¾ã§ãããã®ã¯ããã¥ã¼ã§è¡¨ç¾ããã®ã§ãã
ä»éçãªç¶æ ã»ä»éçãªãã¸ãã¯
ã¨ã¯ããããªãã®æå½ã¦ããªãã¾ã¾ãã¥ã¼ã ãã§å ¨ã¦ã表ç¾ã§ãããã¨ããã¨ãã¤ã³ããã¯ã¹ãå ¨ãå¹ããªããã¥ã¼ãã§ãããããããããã¥ã¼ã¨ãã¦å®ç¾©ã§ããªããã®ãåºã¦ãã¾ããããã解決ããããã«ãå¹ççã«ãã¼ã¿ãåãããã®è£å®çãªãã¼ãã«ããã¥ã¼ãå¿ è¦ã«ãªããã¨ãããã§ãããã
ãããã¯ãã·ã¹ãã ã®é½åã§ãããã®ãããªãã·ã¹ãã ã®é½åä¸ç¨æãããã¼ãã«ããã¥ã¼ãããä»éçãªç¶æ ãï¼ãããã¯ãã¸ãã¯ï¼ã¨ã¿ãªããã¨ã«ãã¾ããããããããã¨ãããããããã®ãã¼ãã«ã¯ãå¿ é ã®ç¶æ ã§ã¯ãªããä»éçãªç¶æ ãªã®ã ãªããªã©ã¨ãããããã«ãè¦è¦çã«è¡¨ç¾ãããã¨ãç®æãã¾ãããã¼ãã«åããã¥ã¼åãè¦ãã ãã§ãããããã¯ã¦ã¼ã¶ã¼å ¥åã®ä¿åã¨ããããã¯ãã·ã¹ãã ãã¼ãã«ã®ä¸ç¨®ãªã®ã ãªãã¨ãããããã«ãããã®ã§ãã
ãããã®åæã®ãã¨ã§ãImmutable Data Modelçãªãã¼ãã«è¨è¨ãèãã¦ããã£ã¦ã¿ãçµæãç´¹ä»ããã®ããã®è¨äºã®ç®çã§ãã
ãã¼ãã«è¨è¨
ã¦ã¼ã¶ã¼å ¥åã¯ååã¨ãã¦ãå ¨ã¦ãã¼ãã«ã«ä¿åããã
ãå¿ é ã®ç¶æ ãã§ããã¦ã¼ã¶ã¼ããã®å ¥åã¯ããã¹ã¦ãã¼ãã«ã«ä¿åãã¾ãã
ãããã¼ã¿ãã¦ã¼ã¶ã¼ããã®å ¥åãã©ããã®èå¥ã¨ãªãæ å ±ã«ããã¼ã¿ãã¼ã¹ãã¼ãã«ã«ãããããcreated_atããcreated_byãã¨ãã®ååã§è¨é²ããããæä½è ã¨æä½æ¥æãè¨é²ããã«ã©ã ãããã¾ãã
ãããã®æ å ±ã¯ãããã«ã¦ã¼ã¶ã¼æä½ããããã¨ã示ãã¦ãã¾ãã
Immutable Data Modelã®å
è¨äºã«ããã¦ããæ¥ææ
å ±ã«ã©ã ã¯ãããåå¥ã®ãã¼ã¿ã§ãããã¨ã示ãã¦ãã¦ãä¸ã¤ã®ãã¼ãã«ã«è¤æ°ã®æ¥ææ
å ±ã«ã©ã ãããã®ã¯ãUPDATE
ã®å¿
è¦æ§ãå¢ãã®ã§è¯ããªããå¥ãã¼ãã«ã«ãã¹ããã¨ãã話ãåºã¦ãã¾ãã
ããã¦ãOut of the tar pitã®ãå¿ é ã®ç¶æ ãã®è¦³ç¹ããè¦ã¦ããæ¥ææ å ±ï¼ã¨æä½è æ å ±ï¼ãããã¨ãããã¨ã¯ãããã¯ã¦ã¼ã¶ã¼å ¥åã®è¨é²ãªã®ã§ãããã¡ããã¨ç¶æ ã¨ãã¦ç®¡çãã¹ãã ã¨èãããã¾ãã
ãªã®ã§ãæ¥ææ
å ±ãå¿
è¦ãªæ
å ±ãããã°ããããã¯å
¨ã¦ãåå¥ã®ãã¼ãã«ã«INSERT
ãããã¨ã«ãã¾ããååã¨ãã¦ãå¥ã®ãã¼ãã«ãç¨æãã¦ãå¥ã®ãç¶æ
ãã¨ãã¦ä¿åãã¾ãããããã¯ãããèªä½ãåå¥ã«è¨é²ãã¹ãã¦ã¼ã¶ã¼æä½ãªã®ã§ãã
ãã®ãããªã¦ã¼ã¶ã¼æä½ã®è¨é²ãããã¤ãã³ããã¨å¼ã¶ãã¨ã«ãã¾ãããã¼ã¿ãã¼ã¹ã«ã¯ãå ¥åãã¼ã¿ãã®ãã®ãæ ¼ç´ããããã¼ã¿ãã¼ãã«ãã¨ãã¦ã¼ã¶ã¼æä½ãè¨é²ãããã¤ãã³ããã¼ãã«ãããããã©ã¡ããã¦ã¼ã¶ã¼å ¥åããä½ãããã®ã§ãå¿ é ã®ç¶æ ã¨ãã¦æ±ãã¾ãã
æ´æ°ã¯ã¤ãã³ã
ããã¾ã§ãããã¾ããããæ¢åãã¼ã¿ã®æ´æ°ã¯ãæããã«ã¦ã¼ã¶ã¼å
¥åã§ããããæ´æ°ãã¨ããã¤ãã³ãã§ããImmutable Data Modelã§ã¯ããã¼ã¿ã¯ååã¨ãã¦UPDATE
ãããªãã®ã§ãæ´æ°æä½ãINSERT
ã¨ãã¦å®ç¾ãããã§ãã
ãªã®ã§ããã¼ã¿ã®æ´æ°ã¯ããã¼ã¿ãã¼ãã«ãã®ãã®ã¸ã®ãæ°ããã¬ã³ã¼ãã®INSERT
ã¨ãã¦è¡¨ç¾ãã¾ãã
ã¦ã¼ã¶ã¼ããã¼ã¿ã10åæ´æ°ãããããã®ãã¼ã¿ãä¿åãããã¼ã¿ãã¼ãã«ã«ã¯ãï¼æåã«ä½æãããã¼ã¿ãåããã¦ï¼åè¨11åã®ã¬ã³ã¼ããç»é²ããããã¨ã«ãªãã¾ãã11åã®ã¬ã³ã¼ãã®ãã¡ãææ°ã®ãã®ãããã®ãã¼ã¿ã®ãä»ã®ç¶æ ãã§ãã
ã¤ã¾ããã¦ã¼ã¶ã¼ãæ´æ°ã§ãããã¼ã¿ã®ãã¼ãã«ã¯ã大æµã¯ãå±¥æ´ç¶ã«ãªãã¨ãããã¨ã§ããå±¥æ´ã®ãã¡ãææ°ã®ãã®ãç¾å¨ã®ãã¼ã¿ã表ãã¦ãã¾ããã¾ããåããã¼ã¿ã®è¤æ°ã®å±¥æ´ãåå¨ããããããã¼ã¿ã®IDã¨ã¯å¥ã«ãï¼ããããã¯auto generatedãªï¼ãµãã²ã¼ããã¼ãåå¨ããã§ãããã
åç´ãªã¿ã¹ã¯ç®¡çã·ã¹ãã ãèãã¦ã¿ã¾ããããã¿ã¹ã¯ã表ãtaskãã¼ãã«ã¯
Task history_id (primary key) task_id title description created_at created_by
ãããªæãã«ãªãã§ãããã
ã¿ã¹ã¯ã®æ´æ°ããã£ãå ´åã¯ãåãtask_idã§ãæ°ãããã¼ã¿ãINSERT
ãã¾ããcreate_at
ããã£ã¨ãæ°ãããã®ãããã®ã¿ã¹ã¯ã®ãä»ãã®ç¶æ
ã§ãã
ä»éçãªç¶æ ã®å°å ¥
å±¥æ´ç¶ã®ãã¼ã¿ãã¼ãã«ã«ãããããä»ã®ãç¶æ ã¯ãï¼è¨ç®æéãç¡è¦ããã°ï¼è¨ç®ã§å°ãåºãããã®ãªã®ã§ããã¸ãã¯ã§ããã¾ããããã¦ã¼ã¶ã¼å ¥åãã¼ã¿ã®ä»ã®ç¶æ ã¨ããã®ã¯ãã¦ã¼ã¶ã¼å ¥åãè¨é²ãããã®ããã®ç´æ¥çæ´¾çãã¼ã¿ã§ãããã·ã¹ãã ã®é½åã§å é¨çã«å©ç¨ãããã¸ãã¯ã§ã¯ããã¾ããããããä»éçãªãã¸ãã¯ãã§ã¯ãªãããå¿ é ã®ãã¸ãã¯ãã§ãããã
ãã ãå±¥æ´ã®ææ°ã®ãã®ã ããéããã¨ãããã¸ãã¯ã¯ãç¾å®ã®ä¸çã§ã¯ãããªãéå¹çãªãã®ã«ãªãã¾ããæ¯åãtask_idåä½ã§ã½ã¼ããã¦ãå é ã®ã¬ã³ã¼ããåãåºãå¿ è¦ãããã¾ããããã¯ããªãè¤éãªã¯ã¨ãªãæ¸ãã°ããã¥ã¼ã¨ãã¦å®ç¾ã§ãã¾ãããç¾å®ä¸çã§ã¯ãããªãããã©ã¼ãã³ã¹ãæªããã§ãã
ã¯ã¨ãªã§ãä»ã®ã¿ã¹ã¯ããåå¾ããã¯ã¨ãªã®ä¾:
WITH RankedTasks AS ( SELECT *, ROW_NUMBER() OVER (PARTITION BY task_id ORDER BY created_at DESC) AS rn FROM task ) SELECT history_id, task_id, description, created_at FROM RankedTasks WHERE rn = 1;
è¦ãããã«ããã®ã¯ã¨ãªã§ãã¼ã¿ãåå¾ããã®ã¯ãããªãããã©ã¼ãã³ã¹ãæªããã§ãã è¤éãªSQLã¯ã¨ãªã¯ãããã©ã¼ãã³ã¹ã ãã§ã¯ãªããããã°ã©ã ã®ä¿å®æ§ãä¸ãã¾ãã®ã§ãé¿ããããã®ã§ãã ä¸è¨ã®ã¯ã¨ãªããããã¨ã¿ã¦ããç解ã§ãã人ã¯ãå¤ãã¯ãªãã§ãããã
ãªã®ã§ãä»éçãªç¶æ ãå°å ¥ãããã¨ã§ãã¯ã¨ãªãç°¡åã«ãã¤ã¤ãããã©ã¼ãã³ã¹ãæ¹åãã¾ãã
ã·ã³ãã«ã«ãææ°ãã¼ã¿ã表ãããã¤ã³ã¿ã¼ãã¼ãã«ããç¨æãã¾ããGitã®HEADã®ããã«ãã©ã®ãã¼ã¿ãææ°ãã¼ã¿ãªã®ãããã®IDãè¨é²ãã¾ãã
ã¿ã¹ã¯ã®ä¾ã§ç¤ºãã°
current_task_cache task_id (pk) history_id (Taskãã¼ãã«ã®history_idãæãï¼
ãããªãã·ã³ãã«ãªãã¼ãã«ã«ãªãã§ãããã ãã®ãã¼ãã«ã¯ãããã©ã¼ãã³ã¹åä¸ã®ããã«ãã·ã¹ãã ã®é½åã§ç¨æãããã¼ãã«ã§ãããã¦ã¼ã¶ã¼å ¥åã®è¨é²ã§ã¯ããã¾ãããã ããããã®ãã¼ãã«ã¯ãOut of the tar pitã§ããã¨ããã®ãä»éçãªç¶æ ãã§ãã
ä»éçãªç¶æ ã¯ãout of the tar pitã®èãæ¹ãå¾¹åºçã«æ¡ç¨ãããªãã°ãããã®ãã¼ãã«ãåé¤ãã¦ããããã©ã¼ãã³ã¹ã¯å£åãããã®ã®ãã·ã¹ãã ã¯ã¡ããã¨åããã¨ãããç®æããã°ãªãã¾ãããããã¯ã·ã¹ãã éçºã®ãã¬ã¼ããªãã§ãã©ãã¾ã§è¿½æ±ãããã¯ãåèªã§æ±ºããã°ãªãã¾ãããããã®ãã¼ãã«ããããªãã°å©ç¨ãããªããªãã°ãã¸ãã¯ã§å°ãåºããã®ããã«ãããã¨ããé å¼µãã°ã§ããã§ãããããç§ã¯ããã¾ã§ã¯ãããªã£ã¦ãã¾ãããä»éçãªãã¼ãã«ã ããããã°ã©ã çã«ã¯å¿ ãå¿ è¦ãªãã¼ãã«ï¼ãªãã¨åããªãï¼ãã¨ããæ±ãããã¦ãã¾ãã
ãããã«ããããã®ãã¼ãã«ã®å 容ã¯ãã¦ã¼ã¶ã¼å ¥åã®è¨é²ã§ã¯ãªããä»®ã«ãã¼ãã«ã失ããã¦ãããã¸ãã¯ã«ããåä½æå¯è½ã§ããã¨ããäºå®ã¯å¤ããã¾ããããªã®ã§ãä»éçãªãã®ã§ãããã¨ããè¦è¦çã«ãååã§è¡¨ç¾ãããã§ãã
ä»åã¯ãä»éçãªç¶æ ã表ããã¼ãã«ã«ã¯ãæ¥å°¾è¾ã_cacheããã¤ãããã¨ã«ãã¾ããã
ãã£ãã·ã¥ã¨ããã®ã¯ãæ¬æ¥ã¯ãªãã¦ãåããã¨ããæå³ãè¾¼ãã¦ãã¾ããä»åã¯ããªãã¦ãåãã¨ããã¾ã§ã¯ä½ãè¾¼ã¾ãªããã¨ã«ãããã®ã®ãä½ç½®ä»ãã¨ãã¦ã¯ãããããã¼ãã«ã§ãããã¨ãè¾¼ãã¦ãã¾ãã
ãã ãã®ãããã®ååã¥ãã¯ãç¹ã«ã«ã¼ã«ã¯ããã¾ããã®ã§ãèªç±ã«æ±ºããã°è¯ãã¨æãã¾ããããããã¦ã¼ã¶ã¼å ¥åãè¨é²ãããã¼ãã«ã§ã¯ãªããä»éçãªç¶æ ãè¨é²ãã¦ããã®ã ãã¨ãããã¨ãããããããªååä»ãããããã¨ããå§ããã¾ãã
ãã¤ã³ã¿ã¼ãã¼ãã«ãå°å ¥ããããã¨ã§ãææ°ã®ã¿ã¹ã¯ãéãããã¼ãã«ã¯ããã¸ãã¯ã«ããç°¡åã«æ±ãããã¨ãã§ãã¾ãã
SELECT task.* FROM task INNER JOIN current_task_cache c ON c.task_id = task.task_id AND c.history_id = task.history_id;
ãã®è¨ç®ãããã¥ã¼ã¨ãã¦å®ç¾©ãã¦ããã¾ãããå¿ é ã®ãã¸ãã¯ãã®å°å ¥ã§ãã
CREATE VIEW current_task AS SELECT task.* FROM task INNER JOIN current_task_cache c ON c.task_id = task.task_id;
ããã§ãcurrent_taskããSELECT
ããã°ããã¤ã§ããææ°ã®ã¿ã¹ã¯ãéãããã¼ãã«ã§ãããã®ããã«ããã¼ã¿ãåå¾ã§ãã¾ãã
ãã®ãããªå½¢ã§ããã¾ãã¯å¿ é ã®ç¶æ ãè¨é²ããããã®ãã¼ãã«ãä½ãããããããä½ã³ã¹ãã§è¨ç®å¯è½ãªæ´¾çãã¼ã¿ã¯ããã¥ã¼ã§å®ç¾©ããããä½ã³ã¹ãã§è¨ç®ã§ããªãå ´åã¯ãä½ã³ã¹ãã§è¨ç®ã§ããããã«ããããã®ä»éçãªç¶æ ãå°å ¥ããããã使ã£ã¦ãã¥ã¼ãä½ããã¨ããæ¹éã§ããã¾ãã
ãã®ãã¼ã¿æ§é ã§ã¯ããã¼ã¿ã®æ´æ°ä½æ¥ã«ããããã¼ã¿ãã¼ã¹ãã¼ãã«ã®æä½ã¯ã
- å¿
é ã®ç¶æ
ã®
INSERT
- ä»éçãªç¶æ
ã®
INSERT
ãããã¯UPDATE
ããåå¨ããªããã¨ã«ãªãã¾ããä¸è¨ã®ä¾ã§è¨ãã°ãTaskãã¼ã¿ã®æ´æ°ã¨ã¯ã
task
ãã¼ãã«ã¸ã®æ°ãã¼ã¿ã®INSERT
current_task_cache
ãã¼ãã«ã¸ã®ããã¤ã³ã¿ãã¼ã¿ã®INSERT
ãããã¯UPDATE
ã§è¡¨ç¾ããããã¨ã«ãªãã¾ããããããå¿
é ã®ç¶æ
ãã§ãããã¼ãã«ã«ãUPDATE
ãªã©ã®ãINSERT
以å¤ã®æä½ãè¡ããããããã°ãè¨è¨ãã¹ã®å¯è½æ§ãæ¤è¨ãã¾ãã
ãã¼ã¿ã®ç¶æ å¤æ´ã¯ã¤ãã³ãã§ãã
ãã¦ããã®ã¿ã¹ã¯ãå®äºãããã©ããã¹ãã§ããããã
å²ã¨ä¸è¬çãªãã¶ã¤ã³ã ã¨ããã¼ãã«ã«completed_at
ã®ãããªæ¥ä»ã«ã©ã ãããããã®ã«ã©ã ã«å¤ãããã°ããã®ã¿ã¹ã¯ã¯å®äºãã¦ããã¨ã¿ãªããã¨ãããã®ã§ãã
ãããImmutable Data Modelã§ã¯ããã¼ãã«ã®UPDATE
ãè¡ããªãï¼ä»åã®è¨è¨ã§ã¯ãå¿
é ã®ç¶æ
ãã®UPDATE
ã¯è¡ããªãï¼æ¹éã§ãã®ã§ããã®ããæ¹ã¯åãã¾ããã
ããã«è¨ãã°ãã¿ã¹ã¯ãå®äºãããã¨ããã®ã¯ã¦ã¼ã¶ã¼ã®å ¥åã§ãããã¦ã¼ã¶ã¼ã®å ¥åã¯å ¨ã¦ãå¿ é ã®ç¶æ ããªã®ã§ããã¼ãã«ã«åå¥ã®ãã¼ã¿ã¨ãã¦ä¿åãããã¹ãã§ãã
ãã®ãããªãæ¢åã®ãã¼ã¿ã®ç¶æ å¤æ´ããã¤ãã³ããã¨å¼ã³ã¾ããã¤ãã³ãã¯ã¤ãã³ãã¨ãã¦ããã®ã¤ãã³ããèµ·ããã¨ãããã¨ãè¨é²ããªãã¦ã¯ããã¾ããã
ãªã¬ã¼ã·ã§ãã«ã»ãã¼ã¿ãã¼ã¹(RDB)ã®ãã¼ã¿ã¢ããªã³ã°ã«è©³ããæ¹ã§ããã°ããã¼ã¿ã ãã§ã¯ãªããã¤ãã³ããããã¡ãã¨è¦æ¥µãã¦ãã¼ãã«ã¨ãã¦åé¢ãã¦è¨é²ãã¹ããã¨ããèãæ¹ã¯ãããªãåããæå±ããã¦ããèãæ¹ã ã¨ãããã¨ã¯ãåç¥ã ã¨æãã¾ããä¾ãã°ãç§ããã¼ã¿ãã¼ã¹ã»ã¢ããªã³ã°ãå¦ã¶ä¸ã§ä»ã§ããå§ããã¦ããæ¬ã®ä¸ã¤ã«ã楽ã ERDã¬ãã¹ã³ãã¨ããæ¬ãããã¾ãã
ãã¡ãã¯2006å¹´ã®æ¬ã§ããªãå¤ããã®ã§ããããã®é ã§ããã¤ãã³ããã¤ãã³ãã¨ãã¦èªèããã®ã大äºã§ãã¤ãã³ãããã¼ã¿ãã¼ãã«ã«ã«ã©ã ã¨ãã¦çµã¿è¾¼ãã®ã¯è¯ããªããã¡ããã¨ã¤ãã³ãã¨ãã¦è¨é²ãã¹ããã¨ããèãæ¹ãå¼·ã奨å±ããã¦ãã¾ãã
ã¤ã¾ãããã¼ã¿ãã¼ã¹ãã¼ãã«è¨è¨ã®èãæ¹ã§ã¯ãããªãåããåããã¨ã奨å±ããã¦ããã®ã§ãããä¸ã®ä¸ã§ã¯ãã¼ãã«ã«ãcompleted_atããªã©ã®ã«ã©ã ãç¨æãããã¨ããä½ãæ¹ã®æ¹ããã£ã¨ãã£ã¨å¤ãã¾ã¾ã ã£ãã®ã§ãããä»ãImmutable Data Modelã¨ããè¨è¨ææ³ãä»ãã¦ãç§ãã¡ã¯åã³åãã¨ããã«æ»ã£ã¦ããã®ã§ãã
ãªã¬ã¼ã·ã§ãã«ã»ãã¼ã¿ãã¼ã¹ã®ã¢ããªã³ã°ã§å¥¨å±ããã¦ããèãæ¹ã¨ãImmutable Data Modelã¨ã"Out of the tar pit"ã«ãããç¶æ 管çã®èãæ¹ã¨ããä»ããã§ç¶ºéºã«ç¹ãã£ãã¨ãè¨ããããããã¾ããã
ã¤ãã³ãããã¼ãã«ã¨ãã¦è¨é²ãã
ããã§ã¯ãããã¿ã¹ã¯ãå®äºãããã¨ããã¦ã¼ã¶ã¼æä½ã§ããã¨æãããå¿
é ã®ç¶æ
ãã®ä¸ã¤ã¨ãã¦è¨é²ãã¾ããtask_completed
ãã¼ãã«ã¯ä»¥ä¸ã®ãããªæ§æã«ãªãã§ãããã
task_completed task_id (PK) completed_at completed_by
ã·ã³ãã«ã«ãçµäºããã¿ã¹ã¯ã¸ã®ãªã³ã¯ã¨ãªãtask_id
ã¨ãå®äºããæ¥æã¨å®äºè
ãè¨é²ãã¾ãããäºå®ãè¨é²ãããã¨ãã観ç¹ã§æãã·ã³ãã«ãªãã¼ãã«å®ç¾©ã§ãããããªã¬ã¼ã·ã§ãã«ã»ãã¼ã¿ãã¼ã¹ã§ã¯å¶ç´ã使ãã¾ããããtask_id
ã¯å¤é¨ãã¼ã¨ãã¦è¨å®ããã®ãè¯ãã§ãããããã®å ´åãtask
ã«ç´æ¥FOREIGN KEYã§çµã³ã¤ãããã¨ãã§ããªãç¹ã«æ³¨æãã¦ãã ãããtask
ã¯å±¥æ´ç¶ã«ãªã£ã¦ãããããtask_id
ã¯ãã©ã¤ããªãã¼ã§ã¯ããã¾ãããå¤é¨ãã¼ãè²¼ãå ´åã¯ãcurrent_task_cache
ãã¼ãã«ã«å¼µããã¨ã«ãªãã§ãããã
ãã¦ãããã§ãã¦ã¼ã¶ã¼ãã¿ã¹ã¯ãå®äºããã¨ããç¶æ
ãã®è¨é²ã¯ã§ãã¾ããããå®éã«ã¢ããªã±ã¼ã·ã§ã³ã§å¿
è¦ã¨ãªãã®ã¯ãå®äºããã¿ã¹ã¯ãã®ä¸è¦§ã§ãã£ã¦ãã¿ã¹ã¯ãå®äºããã¤ãã³ãã®ãã¼ã¿ãã§ã¯ãªãã§ããããtask
ã¨task_completed
ããããå®äºããã¿ã¹ã¯ãä¸è¦§ãè¨ç®ããã®ãããã¸ãã¯ã®å½¹å²ã§ãããã¸ãã¯ã¯ä»¥ä¸ã®ããã«ãã¥ã¼ã§è¡¨ç¾ã§ãã¾ãã
CREATE VIEW completed_task AS SELECT task.*, comp.completed_at, comp.completed_by FROM current_task task -- current_taskã¯ãåè¿°ãããææ°ã®ã¿ã¹ã¯ã ããåå¾ã§ãããã¥ã¼ã§ã INNER JOIN task_completed comp ON comp.task_id = task.task_id;
è¯ãããã§ãããtask_completed
ãã¼ãã«ã«ãã¼ã¿ããªãã¿ã¹ã¯ã¯ããããå®äºãã¦ããªãã®ã§ããããINNER JOIN
ã§ããªãã¿ã¹ã¯ã¯å
¨ã¦æé¤ãã¦è¯ãããã§ãã·ã³ãã«ã«INNER JOIN
ã ãã§è¡¨ç¾ã§ãã¾ãã
ã¾ããããã§ã¯ãã¥ã¼ã®å®ç¾©ã®ããã«current_task
ãã¥ã¼ãå©ç¨ãã¦ãã¾ãã®ã§ãããã°ãæ¢åã®ãã¸ãã¯ã«æ°ãããã¸ãã¯ãç©ã¿ä¸ãã¦ãæ°ãããã¸ãã¯ãçã¿åºãã¦ããã¨ãè¨ãã¾ãã
ãã®ããã«ãã¤ãã³ããåå¥ã«è¨é²ãããã¸ãã¯ï¼ãã¥ã¼ï¼ã§çµã¿åãããã¨ããæ¹æ³ã§ããã°ã表ç¾ãããç¶æ ãå¢ããã¨ãã¦ããã·ã³ãã«ã«è§£æ±ºã§ãã¾ãã ä¾ãã°ãã¿ã¹ã¯ã¯ä¿çã§ããã¨ããå ´åããã®ãä¿çãããã¨ããã¤ãã³ãããã·ã³ãã«ã«ããä¿çãããã¨ããäºå®ãè¨é²ãããã¼ãã«ãç¨æããã ãã§äºè¶³ãããã§ãã
task_delayed task_id (PK) delayed_until delayed_at delayed_by
ããã¤ã¾ã§ä¿çãããããè¨é²ããããã«delayed_until
ã¨ããã«ã©ã ãå¢ãã¦ãã¾ãããåºæ¬çãªæ§é ã¯task_completed
ã¨åãã§ãããä¿çãããã¿ã¹ã¯ããããå®äºããã¿ã¹ã¯ãã¨åãããã«ãã·ã³ãã«ãªãã¥ã¼ã§è¡¨ç¾ã§ãã¾ãã
CREATE VIEW delayed_task AS SELECT task.*, delayed.delayed_until, delayed.delayed_at, delayed.delayed_by FROM current_task task INNER JOIN task_delayed delayed ON delayed.task_id = task.task_id;
ãã®ããã«ãã¿ã¹ã¯ã«å¯¾ããæ°ããç¶æ
ãå¢ããã¨ãã¦ãããã®ç¶æ
å¤åãè¨é²ããã¤ãã³ããã¼ãã«ãç¨æããã ãã§ãããå
ã®task
ãã¼ãã«ã«æãå ãããã¨ãªããæ°ããªç¶æ
ãã©ãã©ã追å ã§ãã¾ããç¶æ
ãè¨é²ãããããã°ã欲ãããã¼ã¿ã¯ããã¸ãã¯ï¼ãã¥ã¼ï¼ã§å°ãåºããã¨ãã§ãã¾ãã
åé¤ãã¤ãã³ã
ã¿ã¹ã¯ãåé¤ãããå ´åã®ãã¨ãèãã¦ã¿ã¾ãããã
ãããããã¿ã¹ã¯ãåé¤ããããã¨ããã®ã¯ãªãã§ãããããããã®ã¿ã¹ã¯ã¯ãããããªããã¨ã«ãããã¨ããã¦ã¼ã¶ã¼ã®ææ決å®ã§ããããã®æä½ã¯è¨é²ãããã¹ãã§ããçµå±ãåè¿°ã®ãã¿ã¹ã¯ãå®äºãããã¨ããã¿ã¹ã¯ãä¿çãããã¨ãã¨åããªã®ã§ãã
ãªã®ã§ãããã¨ãåãã§ãã
ã¾ããä¸è¨ã®ãããªãã¤ãã³ããè¨é²ãããã¼ãã«ãä½ãã
task_abandoned task_id (PK) abandoned_at abandoned_by
æ¾æ£ãããã¿ã¹ã¯ãè¨ç®ãããã¥ã¼ãä½ãã°OKããã§ãã
CREATE VIEW abandoned_task AS SELECT task.*, ab.abandoned_at, ab.abandoned_by FROM current_task task INNER JOIN task_abandoned ab ON ab.task_id = task.task_id;
ããã§è¯ãããã§ãã
ä»ã¢ã¯ãã£ããªã¿ã¹ã¯ãåå¾ãã
æ¾æ£ãããã¿ã¹ã¯ã¯ããã¯ãã¢ã¯ãã£ããªã¿ã¹ã¯ã§ã¯ããã¾ãããæ®éã®ãã¼ã¿ãã¼ã¹è¨è¨ã§ããã°ãDELETEããããã¼ã¿ã«è¿ããã®ãªã®ã§ããã¯ããã®ã¿ã¹ã¯ã¯åå¨ããªããã¨ããæ±ãããããã§ããã
å ãã¦ãããèãã¦ã¿ãã°ãå®äºããã¿ã¹ã¯ããæ¶ãã¦ã¯ããªããã®ã®ããã¯ããå¦ç対象ã¨ãªããããªãçãããã¿ã¹ã¯ã§ã¯ããã¾ããã
ã¢ããªã±ã¼ã·ã§ã³ã«è¡¨ç¤ºããã¨ããããã¾ã å¦çãã¦ããªãã¿ã¹ã¯ä¸è¦§ã«ã¯è¡¨ç¤ºããããªããã¼ã¿ã§ãããã
ã¤ã¾ãã¯ãææ°ã¿ã¹ã¯ãã¼ã¿current_task
ããããå®äºããã¿ã¹ã¯ããæ¾æ£ããã¿ã¹ã¯ããå
¨ã¦çãããã®ããä»ã¢ã¯ãã£ããªã¿ã¹ã¯ã¨ãããã¨ã«ãªãããã§ãã
ããã¯ãä»ã¾ã§ã«è¨é²ããã¦ã¼ã¶ã¼æä½ã®è¨é²ããããã¸ãã¯ã§åå¾ã§ãããã§ãããä¾ãã°ã以ä¸ã®ãããªãã¥ã¼ãä½ãã°ã©ãã§ããããã
CREATE VIEW active_task AS SELECT task.* FROM current_task task LEFT JOIN task_completed comp ON comp.task_id = task.task_id LEFT JOIN task_abandoned ab ON ab.task_id = task.task_id WHERE comp.completed_at IS NULL AND ab.abandoned_at IS NULL;
task_completed
ã¨ãtask_abandoned
ã¨ãããããã¨ãJOINã§ããªãã¿ã¹ã¯ãæ¢ããã¨ããè¨ç®ãè¡ãããã§ãã
ããã§ä»ã¢ã¯ãã£ããªã¿ã¹ã¯ãåããããã«ãªã£ãâ¦ã¨è¨ãããã¨ãããªã®ã§ãããæ£ç´ããã®ã¯ã¨ãªã¯ã¨ã¦ãé ãã§ãããã
ãã¼ã¿ãå°ãªããã¡ã¯ããã§ãããããå¤ããªã£ã¦ããã¨ãIS NULL
ã¯ã¨ãªã®ããã§ãã¼ã¿ãã¼ã¹INDEXã®å¹æã¯æå¾
ã§ããªãã§ãããããã¥ã¼ã§è¡¨ç¾ã¯ã§ãã¦ããå®ç¨ã¨ãã¦ã¯é
ããããã¸ãã¯ã¨ãããã¨ã«ãªãããã§ãã
ããã¯ãcurrent_task_cache
ãå°å
¥ããæã¨åãã±ã¼ã¹ã§ããtask
ãã¼ãã«ã«ã¯å
¨æ´æ°å±¥æ´ãå
¥ã£ã¦ããããããä»ã®ãã¼ã¿ããå¾ãããã«ã¯ãæ¯åã½ã¼ããã¦ææ°å¤ãåå¾ããå¿
è¦ãããã¾ããããã®ããã«ã¯ãããªãè¤éãªSQLãæ¸ãå¿
è¦ããã£ããããSQLãã·ã³ãã«ã«ããããã©ã¼ãã³ã¹ãæ¹åããããã«ãcurrent_task_cache
ãã¼ãã«ããä»éçãªç¶æ
ãã¨ãã¦å°å
¥ããã®ã§ããã
ä»åãåãã¼ãã«ã¨LEFT JOIN
ãããã®ã¯ããç¶æ
ãè¨é²ãããã¼ãã«ã«ãã¼ã¿ããªããã¨ãã調ã¹ãããã§ããããªã¬ã¼ã·ã§ãã«ã»ãã¼ã¿ãã¼ã¹ã¯ãããããã¼ã¿ããããã¨ãã調ã¹ãã®ã¯é«éã§è¡ãã¾ãããããªããã¨ãã調ã¹ãã®ã¯é
ããã®ã§ãï¼ããããå
¨ãã¼ã¿ãèµ°æ»ããªãã¨ããªããã¨ãã確å®ã§ããªãã§ãããï¼ã
ã§ããã°ãåç´ã«ãä»ã®ç¶æ ããè¨é²ãã¦ããã°ããã§ãããã
task_status_cache task_id (PK) status
status
ã«ã¯ãactive
ãcompleted
ãabandoned
ã®ããããã®å¤ãå
¥ãã¾ããENUM
ãã¼ã¿åãåå¨ãããã¼ã¿ãã¼ã¹ã§ããã°ãENUM
ã¨ãã¦å®ç¾©ãã¦ãããã§ãããã
ãã®ãã¼ãã«ã«ã¯ãããã¿ã¹ã¯ã®ãç¾å¨ã®ç¶æ ããè¨é²ãã¾ãã
ãã¼ã¿ä½æç´å¾ã§ããã°active
ã«ãªããå®äºããã¨completed
ãæ¾æ£ããã¨abandoned
ã«ãªãã¨ããããã§ãã
ãã®ãã¼ãã«ã使ãæã¯ãstatus
ã§æ¤ç´¢ãããã¨ãå¤ãã§ããããããtask_id
ã¨status
ã§INDEXãä½ã£ã¦ãããæ¹ããããã©ã¼ãã³ã¹çã«æå©ã§ãããã
ãã®ãã¼ãã«ã«ãã¼ã¿ãå
¥ããã¿ã¤ãã³ã°ã«ã¯ãè²ã
èãæ¹ãããã§ããããä¸çªåç´ãªæ¹æ³ã¯ãä½æããæãå®äºããæãæ¾æ£ããæã«ãã¤ãã§ã«ãã®ãã¼ãã«ã®INSERT
ãããã¯UPDATE
ãè¡ããã¨ã§ãã
ã¤ã¾ãããã¿ã¹ã¯ã®å®äºããä¾ã«ã¨ãã°ããå®äºãã¨ããæä½ã¯ã
task_completed
ã¸ã®ãã¼ã¿ã®INSERT
task_status_cache
ã®ã対象ãã¼ã¿è¡ã®status
ãcompleted
ã«UPDATE
ãã
ã¨ããï¼ã¤ã®æä½ã«ãªãããã§ãã
å®éã®ããã°ã©ã ã§ã¯ãããããããã¿ã¹ã¯ãå®äºãããã¨ããé¢æ°ãã¡ã½ãããããã¯ãã§ããã®é¢æ°å ã§ãã®æä½ãè¡ãããããã¿ã¹ã¯ãå®äºãããå ´åã¯å¿ ããã®é¢æ°ãå¼ã¶ãã¨ããããã°ã©ã æ§é ãä½ãã°ãé¢æ°ãå¼ã¶å´ããã¯ä¸è¨ã®ï¼æä½ã¯é è½ãããã§ãããã
ãããã¯ããã¿ã¹ã¯ã®ææ°ç¶æ
ãåè¨ç®ããé¢æ°ããããã°ã©ã å
ã«ç¨æãã¦ãããtask_completed
ãtask_abandoned
ãªã©ãç¶æ
ãå¤ãããã¼ãã«ã¸ã®INSERT
å¾ã«ãã®é¢æ°ãå¼ã³åºããã¨ããæ¹æ³ãããã§ããããããããã¼ã¿ã®ç»é²ãå³åº§ã«åæ ãããªãã§ãè¯ãã±ã¼ã¹ï¼æ´æ°ãã¦ã¼ã¶ã¼ã«è¦ããã®ã¯å°ãå¾ã«ãªã£ã¦ãè¯ãã±ã¼ã¹ï¼ã§ããã°ããã®é¢æ°ãéåæã«å®è¡ãã¦ãããã§ãããã
å¾è¿°ãããå®äºç¶æ
ãã復å
ããªã©ã®æä½ãããéã«ãtask
ã®ãä»ãã®statusãåè¨å®ãããå ´åã¯ããã¡ãã®æ¹æ³ã®æ¹ããå®è£
ãç°¡åã«ãªãã§ãããï¼å®äºããã¿ã¹ã¯ã復å
ããå ´åãactive
ã¹ãã¼ã¿ã¹ã«ããã®ãæ£ãããã©ããã¯ãã¢ããªã±ã¼ã·ã§ã³ã®ä»æ§ã«ããã¾ããä¾ãã°ããä¿ç(delayed)ããã¹ãã¼ã¿ã¹ã®ä¸ã¤ã¨ãã¦æ±ããã¦ããã¢ããªã±ã¼ã·ã§ã³ã®å ´åãå®äºããã¿ã¹ã¯ã復å
ããã¨ãã«ãactive
ã«ãªãã¹ããdelayed
ã«ãªãã¹ããã¯ãã¢ããªã±ã¼ã·ã§ã³ã®ä»æ§ã«ããã§ããããã¢ããªã±ã¼ã·ã§ã³ã§å
±éã®ã¿ã¹ã¯ç¶æ
ã®åè¨ç®é¢æ°ãããã°ãåã«ãããå¼ã³åºãã ãã§æ£ããã¹ãã¼ã¿ã¹ã«ãªãã¯ãã§ãï¼
ãããã¯ãå®æçã«åè¨ç®é¢æ°ãéåæã«èµ·åããtask_completed
ãtask_abandoned
ã¸ã®ãã¼ã¿ã®INSERT
ããå¾ãæ¾ç½®ãã¦ããã°ãã©ããã®ã¿ã¤ãã³ã°ã§åæã«å®äºç¶æ
ãæ¾æ£ç¶æ
ã«ãªãã ãããã¨ããä½ãã§ãããããããã¾ããã
ãªãã«ããããã®ä»éçãªç¶æ
ãã¼ãã«ã§ããtask_status_cache
ãå°å
¥ããã°ãã¢ã¯ãã£ããªã¿ã¹ã¯ãåå¾ãããã¸ãã¯ï¼ã¯ã¨ãªï¼ã¯ä¸æ°ã«åç´ï¼ãã¤é«éï¼ã«ãªãã¾ãã
CREATE VIEW active_task AS SELECT task.* FROM current_task task INNER JOIN task_status_cache sts ON sts.task_id = task.task_id WHERE sts.status = 'active';
ããã§ããç¾å¨ã¢ã¯ãã£ããªã¿ã¹ã¯ããåå¾ããããã®ãã¸ãã¯(ãã¥ã¼)ãå®æãã¾ããã
ã¤ãã§ã«ããå®äºããã¿ã¹ã¯ããæ¾æ£ããã¿ã¹ã¯ããè¨ç®ããããã®ãã¥ã¼ãã以ä¸ã®ããã«æ¸ãç´ãã¦ãããã§ãããã
ç¹ã«ãtask_status_cache
ã®æ´æ°ãé
延ããã¦ããå ´åã¯ããã¡ãã®æ¹ããtask_status_cache
ã®å
容ã«ãã£ã¦ã¹ãã¼ã¿ã¹ã確å®ãã¦ããã®ã§ãé½åãè¯ãããããã¾ããã
CREATE VIEW completed_task AS SELECT task.*, comp.completed_at, comp.completed_by FROM current_task task INNER JOIN task_status_cache sts ON sts.task_id = task.task_id INNER JOIN task_completed comp ON comp.task_id = task.task_id WHERE sts.status = 'completed'; CREATE VIEW abandoned_task AS SELECT task.*, ab.abandoned_at, ab.abandoned_by FROM current_task task INNER JOIN task_status_cache sts ON sts.task_id = task.task_id INNER JOIN task_abandoned ab ON ab.stask_id = task.task_id WHERE sts.status = 'abandoned';
ä¿çããã¿ã¹ã¯(delayed_task
ï¼ã«ã¤ãã¦ãã対象ã¿ã¹ã¯ãããã¯ãã¢ã¯ãã£ãã§ãªãï¼å®äºãããæ¾æ£ããããããï¼ã¿ã¹ã¯ã ã£ãå ´åã«ã¯ãä¿çããã¿ã¹ã¯ã¨ãã¦ãä¸è¦ã¨ãªãã®ã§ããã¥ã¼ãå°ãå¤æ´ããactive_task
ãã¥ã¼ã«ä¾åããããã«å¤æ´ããæ¹ãè¯ãããã§ãã
CREATE VIEW delayed_task AS SELECT task.*, delayed.delayed_until, delayed.delayed_at, delayed.delayed_by FROM active_task task INNER JOIN task_delayed delayed ON delayed.task_id = task.task_id;
è¦æ¯ã¹ã¦ã¿ãã¨ãããã¾ãããFROM
å¥ããcurrent_task
ããactive_task
ã«å¤ãã£ãã ãã§ãããã®ããã«ããã¥ã¼ã¨ãããã¸ãã¯ãå°å
¥ãããã¨ã§ããã¥ã¼å士ãçµã¿åãããæ°ãããã¸ãã¯ãå°å
¥ãããã¨ãã§ããããã§ãã
ããã¾ã§ã®éç¨ã§ããå¿ é ã®ç¶æ ããè¨é²ãããã¼ãã«ã«ã¯ä¸åæãå ãããä»éçãªç¶æ ã®å°å ¥ã¨ããã¥ã¼ã®å®ç¾©å¤æ´ã ãã§å¯¾å¿ãã¾ããããã¸ãã¯ï¼ãã¥ã¼ï¼ã§ãç¶æ ã¨ã¤ãã³ããçµã¿åããã¦ã欲ãããã¼ã¿ãä½ãåºãææ³ãªã®ã§ãä¸çªå¤§åãªãå¿ é ã®ç¶æ ããè¨é²ãããã¼ãã«ã«ã¯æãå ãããã¨ãªãããã¸ãã¯ãåæ§æããã ãã§ã欲ãããã¼ã¿ãå¾ããã¨ãã§ãã¦ããããã§ãã
è¦ç´ ãã·ã³ãã«ãªã¾ã¾ã«ããçµã¿åããããã¨ã§ã欲ãããã¼ã¿ãä½ãåºã
Immutable Data Modelã§ã¯ããã¼ã¿ã®UPDATE
ãè¡ããªããã¨ãçæ³çã§ãããå®éã®ãã¼ã¿ãã¼ã¹è¨è¨ã§ã¯ãæ¬å½ã«INSERT
ã ãã§æ§æããã¨ãããã©ã¼ãã³ã¹ãªã©ã®å¤ãã®åé¡ãçºçãããã¨ãããã¾ãã
ãªã®ã§ã"Out of the tar pit"ã®èãæ¹ããã¼ã¹ã«ããã¦ã¼ã¶ã¼å
¥åããè¨é²ãããå¿
é ã®ç¶æ
ãã§ãããã¼ãã«ã¨ãããã§ãªãã·ã¹ãã é½åã®ãã¼ãã«ã¨ãåé¢ãããå¿
é ã®ç¶æ
ãã§ãããã¼ãã«ã«ã¯Immutable Data Modelã®èãæ¹ãå¾¹åºãã¦INSERT
ããè¡ãããããã«ããããã©ã¼ãã³ã¹ãã¯ã¨ãªã®è¤éåãªã®ã©ã®åé¡ã¯ããä»éçãªç¶æ
ãã¨ãã¦å°å
¥ããã·ã¹ãã ãã¼ãã«ã«ãã£ã¦è£ããã¨ããæ¦è¡ãåãã¾ããã
ã©ããã¦ã¼ã¶ã¼å ¥åã表ããå¿ é ã®ç¶æ ãã§ãããã©ããã·ã¹ãã é½åã®ãä»éçãªç¶æ ããªã®ããæ確ã«ããããã«ãä»éçãªç¶æ ãè¨é²ãããã¼ãã«åã«ã¯ãæå³çã«ã_cacheãæ¥å°¾è¾ãã¤ãããã¨ã§è¦è¦åãè¡ãªã£ã¦ãã¾ãã
ã¾ããå®éã«ã¢ããªã±ã¼ã·ã§ã³ã§å¦çããããã¼ã¿ã¯ãã¦ã¼ã¶ã¼å ¥åã®çµã¿åããã«ãã£ã¦å¾ããããè¨ç®çµæãã®æ¹ã§ãããã¨ãå¤ãã®ã§ããããã®ãã¸ãã¯ããã¥ã¼ã§è¡¨ç¾ãã¦ãã¾ãã
ãã®ä½ãã§ã¯ãã¢ããªã±ã¼ã·ã§ã³ã®ãã¼ã¿ã¢ã¯ã»ã¹ï¼å¤æ´ã¨åå¾ï¼ã¯ã
- ã¢ããªã±ã¼ã·ã§ã³ããã¼ã¿ãå¤æ´ããæã«ã¯ããå¿ é ã®ç¶æ ãã¨ãä»éçãªç¶æ ããæ´æ°ãã
- ãã¼ã¿ãä¿åããããã«ã¯ãå°ç¨ã®é¢æ°ãã¡ã½ãããç¨æããããã°ã©ã ããã¯å¿ ããã®é¢æ°çµç±ã§ä¿åãããããªã·ã¹ãã æ§æãä½ããã¨ã§ããå¿ é ã®ç¶æ ãã¨ãä»éçãªç¶æ ãã確å®ã«æ´æ°ãããããã«ãã
- ã¢ããªã±ã¼ã·ã§ã³ããã¼ã¿ãåå¾ããæã«ã¯ããå¿ é ã®ãã¸ãã¯ãã§ãããã¥ã¼ãããã¼ã¿ãåå¾ãã
ã¨ããã®ãåºæ¬çãªæ§æã«ãªãã¾ãã
å¿ é ã®ç¶æ ãä»éçãªç¶æ ãåé¢ããå¿ é ã®ç¶æ ã®ä¸ã§ããã¤ãã³ããè¦æ¥µãã¦ç´°ããå°ããªãã¼ãã«ã«åå²ãã¾ãããããã«ãããè¦ç´ ã¯å¢ãã¾ããããä¸ã¤ä¸ã¤ã®ãã¼ãã«ã¯ãä¸ç¨®é¡ã®ãã¼ã¿ãã管çãã¦ããªãããã«ã§ãã¾ããããã®ãããªåç´ãªãã®ãããã¥ã¼ã¨ããããã¸ãã¯ãã使ã£ã¦çµã¿åããããã¨ã§ãå®éã«æ¬²ãããã¼ã¿ãä½ãåºãã¦ãã¾ãã
ãã®ãããªèãæ¹ã¯ãClojureéçºè ã®Rich Hickeyãçºè¡¨ãããSimple Made Easyãã¨ãããã¬ã¼ã³ãã¼ã·ã§ã³ã§èª¬æãããã·ã³ãã«ããã¨åæ§ãªãã®ã§ããRich Hickeyã¯ããã·ã³ãã«ãããããç°¡åã§ãããã¨ã¯åºå¥ãã¦èª¬æãã¾ãããã·ã³ãã«ã§ããã¨ã¯ãããããä¸ã¤ã®äºæããæ±ã£ã¦ããªããã¨ãããã¨ã§ãããã®éããä¸ã¤ã®ãã®ã§ããããã®ãã®ãæ±ã£ã¦ããç¶æ ã§ããããã®ãããªç¶æ ããComplectãã¨ãã£ã¦ãããããã®ç´ã絡ã¾ãåã£ã¦ãããããªç¶æ ã ã¨èª¬æãã¦ãã¾ãã
ãã·ã³ãã«ãªãã·ã¹ãã ã¨ã¯ããããããä¸ã¤ã®å½¹å²ããæã£ã¦ããªããã®ããçµã¿åããããã¨ã§ä½ãããã·ã¹ãã ã§ããããã®ããã«ä½ãããã·ã¹ãã ã¯ãçµã¿åããæ¹ãå¤ãããã¨ã§ãèªç±ã«åæ§æã§ããã®ã§ãã
ã¾ããRich Hickeyã¯ãç©äºãã·ã³ãã«ã«ãããã¨ããã¨ãè¦ç´ ã®æ°ã¯å¢ãããã¨ãè¨ã£ã¦ãã¾ããå®éãä»åã®è¨è¨ã§ã¯ãæ¥ä»ã«ã©ã ãåèã«ããã¼ã¿ã®è¨é²ã¨ã¤ãã³ãã®è¨é²ãåé¢ããçµæãä¸ã¤ã®ãã¼ãã«ã«ããããã®æ¥ä»ã«ã©ã ããããããªãã¼ãã«ãããããã¼ãã«æ°ãå¢ãã¦ãã¾ããããã«ã表ç¾ãããã¤ãã³ããå¢ãããã³ã«ããã¼ãã«æ°ã¯å¢ãã¦ãããã¨ã§ãããã
ä¸æ¹ã§ãä¸ã¤ä¸ã¤ãã·ã³ãã«ã«ãã¦åå²ããããããããã¸ãã¯ã«ãã£ã¦ãçµã¿åããã«ãã£ã¦æ¬²ãããã¼ã¿ãä½ãåºããã¨ãã§ãã¦ãã¾ããä»åã®è¨è¨ã§ã¯ãOut of the tar pitã®ãç¶æ ã¨ãã¸ãã¯ã®åé¢ããå¿ é ã¨ä»éçã®åé¢ããåãå ¥ãããã¨ã§ããã¼ã¿ãã¼ã¹ã«ä¿åãããã¼ã¿ããå¿ é ã®ç¶æ ãä»éçãªç¶æ ãããããçµã¿åãããããã®ãã¸ãã¯ï¼ãã¥ã¼ï¼ã¨ããå½¢ã«å解ããããã¼ãã«ã¨ããå½¢ã§è¡¨ç¾ãããç¶æ ãããã¥ã¼ã¨ããå½¢ã§è¡¨ç¾ããããã¸ãã¯ã«ãã£ã¦çµã¿åããããã¨ããæ¹æ³ãæ¡ç¨ãã¾ããã
ãã®æ¹æ³ã§ããã°ãåã ã®ãã¼ãã«ãã·ã³ãã«ã«ç¶æãã¤ã¤ããã大ããªã·ã¹ãã ãæ§æãããã¨ãã§ããã®ã§ã¯ãªãã§ããããã
çºå±çã«æ§æãå¤åããã
ããã§èª¬æããä½ãæ¹ã¯ãåãªãã¢ã¤ãã¢ã¨ããããã§ã¯ãªããå®éã®ã¢ããªã±ã¼ã·ã§ã³ã§ãå©ç¨ãã¦ãã¦ãå®ç¨æ§ããããã®ã§ãããå®éã®ã¢ããªã±ã¼ã·ã§ã³ã§ã¯ããã£ã¨è¾¼ã¿å ¥ã£ãç¶æ å¤åã管çããªããã°ãããªãã±ã¼ã¹ãããã¾ãã
ä¾ãã°ããééã£ã¦å®äºããã¿ã¹ã¯ã¯ã復å ãããã¨ãã§ãããã¨ããä»æ§ãããã¨ããããã©ãã§ããããã
- 誤ã£ãæä½ãªã®ã ãããåã«èª¤ã£ã¦æ¿å
¥ããã
task_completed
ãåé¤ï¼DELETEï¼ãã¦ãã¿ã¹ã¯ã®statusãåè¨ç®ããã°ãã - å®äºããã¿ã¹ã¯ã復å ããã®ã¯ã¦ã¼ã¶ã¼æä½ãªã®ã ããããããè¨é²ãããªããã°ãããªã
ã©ã¡ãã®æãããã§ããããã1ãåããã2ãåããã¯ãã¢ããªã±ã¼ã·ã§ã³ã®ä»æ§ã¨ããã¬ã¼ããªãã絡ãã§ããã®ã§ãä¸æ¦ã«ããã¨ãããã¨ã¯ã§ãã¾ãããåãªãã¢ã³ãã¥å¦çã§ããã¨èããã°ã1ã®é¸æè¢ãããã§ããããã¦ã¼ã¶ã¼å
¥åãè¨é²ããå¿
é ã®ç¶æ
ã§ããtask_completed
ã«DELETE
ãå®è¡ãããã¨ã«ãªãã¾ãããã¢ã³ãã¥ã ã¨èããã°ãã·ã¹ãã çã«å
ã®ç¶æ
ã«å¾©å¸°ããã¨ããæå³ã§ãé¸æçã«ã¯ããã§ãããããã¡ããã1ã®é¸æè¢ã¯ããå¿
é ã®ç¶æ
ãã§ããã¯ãã®task_completed
ãã¼ãã«ã«å¯¾ãã¦DELETE
ãå®è¡ãããã¨ããç¦å¿ãç¯ãã¦ããï¼ã¨èãããã¨ãã§ããã§ãããã
2ãé¸æããå ´åã¯ãtask_completion_reverted
ã®ãããªããå®äºããã¿ã¹ã¯ã復å
ããããã¨ãè¨é²ãããã¼ãã«ãå¿
è¦ã«ãªãããã§ãã
åãã¿ã¹ã¯ã«å¯¾ãã¦ããå®äºãæä½ãè¤æ°åçºçãããã¨ã«ãªããããtask_completed
ã¯ãtask_id
ããã¼ã¨ãããã¼ãã«ã§ã¯ãã¡ã«ãªãã¾ããhistory_id
ã®ãããªãè¡ãç¹å®ãããã¼ãå¿
è¦ã«ãªãã§ãããã
è¤æ°ã®task_completed
ã®ã©ããã¢ã¯ãã£ããªã®ããç¹å®ããããã«ãtask
ãã¼ãã«ã®ããã«ããã¤ã³ã¿ã¼ãã¼ãã«ãç¨æãã¦ææ°ã®ã¬ã³ã¼ããç¹å®ããæ¹æ³ãããã§ããããããã¡ãã¯å±¥æ´æ
å ±ã¨ããããã¯ãrevertãããtask_completed
ã¨ãactiveãªtask_completed
ããããã¨ãããã¨ãªã®ã§ãåè¿°ã®task_status_cache
ã®ããã«ãtask_completed
ã«å¯¾ãã¦ç¾å¨ã®ã¹ãã¼ã¿ã¹ã表ãã·ã¹ãã ãã¼ãã«ãç¨æããã¨ããæãããã§ãããã
ãããã¼ãã«ã®é¢é£ãã¼ãã«ã¨ãã¦ãç¶æ
ã表ããã¼ãã«ãå°å
¥ããï¼ä¾ãã°ãtask
ã«å¯¾ãã¦task_delayed
ã¨ããé¢é£ãã¼ãã«ãç¨æããï¼å ´åã®å¯¾å¿æ¹æ³ãä¸å®ã«ä¿ã¤ã¨ããã¼ãã«æ§æå
¨ä½ã®ç解ãç°¡åã«ãªãã¾ãã®ã§ãããã¯ãã¹ãã¼ã¿ã¹ãã¼ãã«ãå°å
¥ããæ¹æ³ã§ããã¾ãããã
task_completed_status_cache
ãã¼ãã«ãå°å
¥ãã¾ãã
task_completed history_id (PK) task_id completed_at completed_by
task_completed_status_cache task_completed_history_id (PK) status
status
ã«ã©ã ã¯ãactive
ãããã¯reverted
ã§ãtask_completed
ä½ææã«ã¯active
ã¨ãã¦INSERT
ãã¦ãããå®äºããã¿ã¹ã¯ã®å¾©å
ãè¡ãããã¿ã¤ãã³ã°ã§ã
task_completion_reverted
ãã¼ãã«ã«INSERT
ãã¾ãï¼å¾©å ã®äºå®ãè¨é²ããï¼task_completed_status_cache
ã®status
ãreverted
ã«UPDATE
ããtask
ã®ã¹ãã¼ã¿ã¹ãæ´æ°ããé¢æ°ãå¼ã³åºã
ä¸è¨æä½ããããã¨ã§ã復å ããã¾ãã
ä»ã¾ã§ã®task_completed
ã¨åããã¼ã¿ãåãããã®ãã¥ã¼ãç¨æãããã¨ã§ãä»ã®é¨åã¯ãã¥ã¼ãåç
§ããã°ãä»ã¾ã§ã¨åãç¶æ
ãç¶æã§ãã¾ãã
CREATE VIEW active_task_completed AS SELECT comp.* FROM task_completed comp INNER JOIN task_completed_status_cache sts ON sts.task_completed_history_id = comp.history_id WHERE sts.status = 'active';
ãã®ãã¥ã¼ã¯ãå
ã
ã®task_completed
ã¨åããã¼ã¿ãè¿ãã¯ãã§ãã
ã¤ã¾ããtask
ãã¼ãã«ã§è¡ãªã£ãã®ã¨åããã¨ãæ·¡ã
ã¨å®æ½ãã¦ããã°ãå¿
è¦ãªæ
å ±ã¯æ¼ããªãè¨é²ã§ãããããã¥ã¼ãä»ãã¦ãå
ã®ãã¼ãã«ã¨åããã¼ã¿ã簡便ã«åããããã«ä½ããã¨ãã§ããããã§ããã©ã®ãã¼ãã«ã§ãèãæ¹ã¯ä¸è²«ãã¦ããããã¼ã¿å©ç¨å´ããè¦ãã¨ãä»ã¾ã§task_completed
ãç´æ¥è¦ãã°è¯ãã£ãã¨ããããactive_task_completed
ãã¥ã¼ãåç
§ããããã«å¤ããã ãã§ãããã
å³ï¼ã¯ãä»è¡ããã¨ãã¦ããæ¡å¼µãè¡ãåã®ç¶æ ã表ãã¦ãã¾ãã
task_completed
ããtask
ã¨åããããªå±¥æ´ç¶ã®ãã¼ãã«ã«å¤ããã¨ãããããã以ä¸ã®ãããªæ§æã«ãªãã§ãããã
task
ã§è¡ã£ãã®ã¨åãææ³ããtask_completed
ã§ãè¡ããactive_task_completed
ã¨ãããã¸ãã¯ï¼ãã¥ã¼ï¼ã«ãã£ã¦ãå
ã®task_completed
ã¨åãç¶æ
ãä½ãåºãã¦ãã¾ããããããã¢ããªã±ã¼ã·ã§ã³ããã¼ã¿ãèªã¿åãã¨ãã«ã¯ãcompleted_task
ãªã©ã®ï¼å³ã®ä¸çªä¸ã«ããï¼ãã¥ã¼ã使ã£ã¦åå¾ãã¦ããã¯ããªã®ã§ãã¢ããªã±ã¼ã·ã§ã³ã³ã¼ãããã¼ã¿ãå©ç¨ãã¦ããé¨åã«å½±é¿ãä¸ãããã¨ã¯ããã¾ããï¼ãã¡ãããä¿åé¨åã«ã¯ä¿®æ£ãå¿
è¦ã§ããï¼ã
ãã®ããã«ããã®ã¢ããªã³ã°ã®å©ç¹ã¯ãç¶æ³ãè¤éåãã¦ããããã¼ãã«ã追å ããããå¿ è¦ãªãã°ä»éçãªç¶æ ã¨ãªãcacheãã¼ãã«ã追å ããããããããçµã¿åããã¦æ¬²ãããã¼ã¿ãè¨ç®ãããã¥ã¼ãä½ããã¨ããä½æ¥ãç¹°ãè¿ãã¦ãããã¨ã§ãã¤ã¾ããåãããæ¹ãç¹°ãè¿ãé©ç¨ãã¦ããã ãã§ãã¢ãã«ãçºå±ããã¦ãããã¨ãã§ããã¨ããã«ããã¾ããææ³ã®ä¸è²«æ§ã¯ãå ¨ä½ãææ¡ãããã¨ãç°¡åã«ãã¦ããã¾ãã
å ¨ä½ãè¤éã«è¦ãã¦ãããã®ãã¼ãã«ããåºæ¬ã¨ãªãå¿ é ã®ç¶æ ã表ããã¼ãã«ãªã®ã ãªããããã¦ãã¡ãã¯ãã·ã¹ãã é½åã®ä»éçç¶æ ãã¼ãã«ãªãã ãªããå¤ãåãã¨ãã¯ããã¡ãã®ãã¥ã¼ãåç §ããã°åãããã¨ããã大æ ãåããããã«ãååã¥ããªã©ã§å·¥å¤«ããã°ãèªã¿è§£ããã¨ãã§ããã®ã§ãã
éã®å¼¾ä¸¸ãããªã
Immutable Data Modelãæ¡ç¨ããã¨ãINSERT
ã ãã§ãã¼ã¿ãæ§æãã¦ããé¢ä¿ä¸ãå¿
ããå±¥æ´ç¶ã®ãã¼ã¿ãç¾ãã¾ããå±¥æ´ä¸ã®ãã¼ã¿ã¯ããã段éã§ã®ãã¼ã¿ãã©ãã ã£ãã®ããè¨ç®ããã°ç¹å®ã§ããã¨ããç¹ã§å©ç¹ãå¤ãã§ãããå
¨ã¦ã®ã·ã¹ãã ã§å¿
è¦ã¨ããããã§ãããã¾ããã
å¤ãã®ãã¸ãã¹ããã»ã¹ã§ã¯ããå ¨ã¦ã®ã¦ã¼ã¶ã¼æä½ãè¨é²ãã¹ãããã¨ãã質åã¸ã®åçã¯ãå®ã¯ãYesãã«ãªããã¨ã®æ¹ãå¤ãã§ããç´ã®ä¼ç¥¨ç®¡çã ã£ãæ代ã§ããä¼ç¥¨ã¯ãã¨ã§æ¸ãæãããã¨ã¯ã§ãããã赤ä¼ç¥¨ï¼èµ¤ä¼ï¼ãã§ãã£ã³ã»ã«ãè¨é²ãããé»ä¼ç¥¨ï¼é»ä¼ï¼ãã§ä¿®æ£ãã¼ã¿ãè¨é²ããããªã©ãæç³»åã«å¤æ´å¦çãå ¨ã¦ãããããã«ãªã£ã¦ãããããã§ããã¸ãã¹ããã»ã¹ã§ã¯ãã³ã³ãã¥ã¼ã¿å¦çããããåãããå±¥æ´ãè¨é²ããã®ã¯å½ããåã ã£ãã®ã§ããããããæ¥ã«å¿ è¦ãªããªããã¨ã¯ããã¾ãããç¾ä»£ã§ããçºæ³¨ããã£ã³ã»ã«ãããããã¨ãã£ã¦ãçºæ³¨ãã¼ã¿ãæ¶ãã¦ããããã§ã¯ãªãã®ã§ããããããå±¥æ´ã¯è¨é²ãããã¹ãã ãã¨èããæ¹ãç¾å®ã®ãã¸ãã¹å®æ ã«åã£ã¦ããã¯ãã§ãããããã®ç°å¢ã«ãImmutable Data Modelã¨ãããã§æ¸ããææ³ã¯å½¹ç«ã¤ã§ãããã
ã§ããä¸ã®ä¸ã«ã¯ããã¸ãã¹ããã»ã¹ã表ç¾ãã¦ããããããªãã¢ããªã±ã¼ã·ã§ã³ãããããããããã§ããããã§Immutable Data Modelãæ¡ç¨ããã¨ãä»ã¾ã§UPDATE/DELETEããã°è¯ãã£ãã¨ããã«ãæ¥ã«å±¥æ´ç®¡çãææ°ãã¼ã¿ç¹å®ãªã©ã®å¦çãå ¥ãè¾¼ãã§ãããã¨ã«ãªãã¾ãã
ãªã®ã§ãããã¹ã¦ãImmutable Data Modelã«ãªãã¹ããã¨èããå¿ è¦ã¯ãªãã§ãããã
ä¸æ¹ã§ããImmutable Data Modelããã®ãããæ´»ãããé åã¨ããã®ãééããªãããã®ã§ï¼åè¿°ã®ãã¸ãã¹ããã»ã¹ãªã©ï¼ãä»ä½ããã¨ãã¦ããã¢ããªã±ã¼ã·ã§ã³ããªããªã®ãã«ãã£ã¦ãæ¡ç¨ãã¹ããã©ãããã£ã¡ãå¤æãããã¨ã大äºã§ãããã
Immutable Data Modelã¯ãèãæ¹ã ããå è¡ãã¦åºã¾ã£ã¦ããç¶æ ãªã®ã§ãã©ãå®ç¾ãããã¯ãåå¥ã«æ¤è¨ããå¿ è¦ãããã¾ããããã®å®éã®å®ç¾ææ³ã¨ãã¦ãã²ã¨ã¤ã®ãããããæ¹æ³ã§ã¯ã¨ãªããã©ã¼ãã³ã¹ãç¶æããªããå®ç¾ã§ããããã¨ããæ¡ã¨ãã¦åèã«ãã¦ããããã°ã¨æãã¾ãã
çµãã