ã¿ãªããããã«ã¡ãã ã¡ããã¢ã§ã¨ã³ã¸ãã¢ããã£ã¦ããå ç°ã¨ç³ãã¾ãã
ç¾å¨ã¡ããã¢ã§ã¯PHPã§ä½ãããã¬ã¬ã·ã¼ãªç¬èªãã¬ã¼ã ã¯ã¼ã¯ (以ä¸FW) ããRailsã¸ã¨ç§»è¡ããããã¸ã§ã¯ããé²ãã§ãã¾ãã ä»åã¯ç§»è¡ã«åãã¦è¡ã£ããã¨ã«ã¤ãã¦å ±æãããã¨æãã¾ãã
移è¡ã®è¨ç»
ã¡ããã¢æ ªå¼ä¼ç¤¾ã§ã¯ãå»å¸«éå®ã®ã³ãã¥ããã£ãµã¤ããMedPeer ããéå¶ãã¦ãã¾ãã ãMedPeer ããµã¼ãã¹å ã§ã¯ãè¬å¤è©ä¾¡æ²ç¤ºçãçä¾ç¸è«ãForumããã¥ã¼ã¹ãªã©ãå»å¸«å士ãæ å ±äº¤æãããããã®ãæ©è½ã®ç°ãªãè¤æ°ã®ãµã¼ãã¹ãæä¾ãã¦ãã¾ãã
ããããµã¼ãã¹ã®å é¨ã§ã¯7å¹´åã«ä½ãããPHPã®ç¬èªFWãæ¡ç¨ããã¦ãããã³ã¼ããè¥å¤§åãããã¨ã§æ©è½ã®å¤æ´ã追å ãã¨ã¦ãå°é£ã«ãªã£ã¦ãããã¨ã課é¡ã§ããã
ãããã課é¡ã解決ããããã«ãã¢ã¼ããã¯ãã£ã®è¦ç´ããå«ãããªãã¬ã¼ã¹ãã¨ã³ã¸ãã¢ã®ä¸»å°ã§è¨ç»ããã¾ããã æ§ã ãªè¨èªãæ¯è¼ããä¸ã§ãçç£æ§ã®é«ããã³ãã¥ããã£ãæ´»çºãªã¨ããã«é åãæãã¦è¨èªã¯Rubyã¸ã¨æ±ºããFWã¯ç¬èªã§ä½ããããOSSã®æ¹ãããå¤ãã®éçºè ã«ãã£ã¦éçºãè¡ããã¦ãããããæ°ããæ©è½ã使ãããå®å®æ§ãé«ãã¨ãã£ãã¡ãªãããããã ããã¨èããRailsã¸ã¨ç§»è¡ãããã¨ã«æ±ºãã¾ããã
ãããã移è¡ããã«ãã¦ããMedPeerãã¯ã¨ã¦ãã¢ããªã·ãã¯ãªä¸ã«ãæ©è½ã«ãã£ã¦ã¯ãã¯ã誰ãç¥ããªãã³ã¼ããªã©ãåå¨ãã¦ãããä¸çç¸ã§ã¯ããã¾ããã ä¸åº¦ã«å ¨ã¦ã移è¡ããã¨ããæ¹éã ã¨æ°å¹´ã¯ãããããã§ãããã®éãã¸ãã¹ãæ¢ããããã«ã¯ãããªãã®ã§ã移è¡ã®éãæ°ãµã¼ãã¹ã®éçºã ã£ããæ©è½ã®è¿½å ã常ã«è¡ã£ã¦ããå¿ è¦ãããã¾ãã
ããã§ãæ¢åã®æ©è½è¿½å ã¯ä»ã¾ã§éãã¬ã¬ã·ã¼ãªæ§ç°å¢ã§éçºãã¤ã¤ãæ°ãµã¼ãã¹ããµã¼ãã¹ãã¨ç§»è¡ããããã®ã«é¢ãã¦ã¯Railsã®æ°ç°å¢ã§éçºãã¦ãããã¨ããæ¹éãåããã¨ã«ãã¦ã両ç°å¢ãéç¨ããªããå¾ã ã«ç§»è¡ãããã¨ã«ãã¾ããããã®ããã«ã¾ãã¯æ§ç°å¢ã¨æ°ç°å¢2ã¤ãé£æºãã¦ä¸¦å稼åãããä»çµã¿ãå¿ è¦ã§ããã
ãã£ããã¨
å ·ä½çã«ãã£ããã¨ã¯ä»¥ä¸ã®3ã¤ã§ã
urlãã¨ã®æ¯ãåã
å ±éå¦çã®åãåºã
ãã¼ã¿ã®åæ
urlãã¨ã®æ¯ãåã
urlã®æ¯ãåãã¯ãnginxã使ã£ããªãã¼ã¹ãããã·ã¼å ã®æ¯ãåãã§ãããã¡ã¤ã³ã¯ä¸¡ç°å¢ã§åãã«ãã¦ãã¨ãã°ã/aaaã¨ããurlã¯æ§ç°å¢ã«ã/bbbã¨ããurlã¯æ°ç°å¢ã«ã¨æ¯ãåããããã«ãã¾ããã 幸ãMedPeerã¯åè¿°ã®éãè¤æ°ã®ãµã¼ãã¹ã§æãç«ã£ã¦ãããµã¼ãã¹ãã¨ã«urlãç°ãªãä¾å度ãå°ãªããããã®æ¹æ³ã¯åã£ã¦ãã¾ããã 注æç¹ã¨ãã¦ã¯ä¸¡ç°å¢ã§urlããããã£ã³ã°ããªãããã«è¨è¨ããå¿ è¦ããã£ãããåä¸ãã¡ã¤ã³ã§ããããcookieã®æ±ãã«æ°ãã¤ããå¿ è¦ããããã¨ã§ãã
å ±éå¦çã®åãåºã
両ç°å¢ã«ã¦å ±éã«å¦çããå¿ è¦ã®ããæ©è½ãåå¨ãã¾ãããã¨ãã°èªè¨¼ã§ããèªè¨¼ãããç°å¢ãã¾ããã§ãã»ãã·ã§ã³ãã»ãã¥ã¢ã«ç¶æã§ããä»çµã¿ãå¿ è¦ã§ãã ããã«å¯¾ãã¦ã¯æ¢ã«APIã²ã¼ãã¦ã§ã¤ã¨ãã¦èªè¨¼é¨åãå¥ã®ã¢ããªã±ã¼ã·ã§ã³ã¨ãã¦åãåºãã¦ãããããããæ°ç°å¢ã§ãå©ç¨ããããã«ãã¾ããããããã£ãå ±éå¦çãåãåºãã¦ããã¨ä»ãµã¼ãã¹ã§ãé£æºããããã¨ãã£ãã¡ãªãããããã¾ããå®éã«ã¡ããã¢ã®ä»ãµã¼ãã¹ï¼ãã£ãªã¢ãã¤ã·ã³ã¡ï¼ã§ãèªè¨¼é¨åã¯APIã²ã¼ãã¦ã§ã¤ãå©ç¨ãã¦ããããµã¼ãã¹ã®ã¹ã±ã¼ã«ã«å¯ä¸ãã¦ãã¾ããAPIã²ã¼ãã¦ã§ã¤ãéçºããéã®è©±ã«ã¤ãã¦ãèå³ããæ¹ã¯ãã¡ãããåç §ãã ããã
Golang(Go言語)を採用して、たった二人で基盤となるAPIゲートウェイを開発した話 - メドピア開発者ブログ
ãã¼ã¿ã®åæ
両ç°å¢ã§ã¯ã¦ã¼ã¶ã¼ãã¼ãã«ãªã©å ±éã®ãã¼ã¿ãå©ç¨ããå¿ è¦ãããã¾ãã å½åã¯ç¾è¡ã®DBãå ±ç¨ãããã¨ãèãã¾ããã以ä¸ã®çç±ã§ããã¾ããã
ãã¼ãã«ã®è¨è¨ãRailsã«æé©åããã¦ããªã
移è¡ãæ©ã«DBæ§é ãè¦ç´ããã
Railsã¯DBã«å¯¾ãã¦ããä¸å®ã®è¦ç´ãããã¾ããä¾ãã°ä¸»ãã¼ã¯idãæã¾ããã¨ãã£ããã¨ã§ãã æ§ç°å¢ã®DBã§ã¯ä¸»ãã¼ãid以å¤ã«è¨å®ããã¦ãããããã¼ãã«åãè¤æ°å½¢ã«ãªã£ã¦ããªããªã©Railsãå©ç¨ãã ã«ããã£ã¦æé©åããã¦ããªãã¨ããåé¡ãããã¾ãããã¾ããé·å¹´DBãéç¨ãã¦ãã¦è¨è¨ä¸è¦ç´ãããé¨åãå¤ã ããã¾ãããä¾ã㰠以ä¸ã®å 容ã§ãã
ä¸è¦ãªãã¼ãã«ãã«ã©ã ãåå¨ãã¦ãã
ã«ã©ã åãé©åã§ãªãããç解ãã«ãã
æ£è¦åãé©åã«ããã¦ããªã
indexãuniqueå¶ç´ãé©åã«è²¼ããã¦ããªã
移è¡ãããæ©ä¼ã¨ãã¦ããããè¦ç´ãã¦åè¨è¨ããããã¨ããããDBã¯æ°ããä½ãã¨ããæ¹éãç«ã¦ã¾ããã ãã®ããã«ï¼ã¤ã®DBã®ãã¼ã¿ãåæããå¿ è¦ããã£ãããã両ç°å¢ã®DBãæ©æ¸¡ãããå½¹å²ã®ã¢ããªã±ã¼ã·ã§ã³ãä½ãã¾ããã ãããDB-SYNCã§ãã
DB-SYNCã¯æ§ç°å¢ã®ãã¼ã¿ãæ°ç°å¢ã§ã使ãããå ´åã«ãã¼ã¿ãä»»æã®å½¢ã«ã³ã³ãã¼ããã¾ããä¾ãã°æ§ç°å¢ã§ããã¦ã¼ã¶ã¼ã®Emailãæ´æ°ãããã¨ãã¾ãã ãã®éã«æ´æ°ããã£ããã¨ãéç¥ãããã¼ãã«ã«ç»é²ããã¾ããDB-SYNCã¯cronï¼ãã¥ã¼ã®å¦çã¨ãã¦ãã®ãã¼ãã«ãreadãã¦æ´æ°ã®ãã£ã対象ã®ãã¼ãã« ã¨ãã¼ã¿ãå¤å¥ãã¾ãããã®å¾ãæ§ç°å¢ã®DBãã対象ã®ãã¼ã¿ãFetchãã¦ãæ°ç°å¢ã®DBã«æ°ããè¨è¨ããããã¼ãã«ã®ã©ã®ã«ã©ã ã«å¯¾å¿ããã®ã ãå¤æã«ã¼ã«ãå®ç¾©ããããã¡ã¤ã«ãåç §ããªããUPSERTãè¡ãã¾ããå¤æã«ã¼ã«ãå®ç¾©ããããã¡ã¤ã«ã¯ä¾ãã°ä»¥ä¸ã®ãããªå 容ãè¨è¼ããã¾ãã
user: old_table: portal.users column_name_mappings: id: old_user_id last_login_time: last_logged_in_at account_id: email state_cd: registration_status profession_id: profession_type physical_deletable: true unsync_columns: - id
DB-SYNCã§ã¯å½åã®å¤æ´ã ãã§ãªããï¼ã¤ã®ãã¼ãã« ãçµ±åãã¦åè¨è¨ããä¸ã¤ã®ãã¼ãã«ã«ãã¼ã¿ãç»é²ãã¦ããã¨ãã£ããã¨ãå¯è½ã«ãªã£ã¦ãã¾ãããã®ä»ã®ãã¤ã³ãã¨ãã¦ã¯ãã¼ã¿ã®æµã㯠æ§ç°å¢ããæ°ç°å¢ã¸ã®ä¸æ¹åã®ã¿ã¨ãã¦ãã¾ããçç±ã¨ãã¦ã¯ã両ç°å¢ã§ãã¼ã¿ãè¡ãæ¥ããã¨ç ©éã«ãªãé害çºçæã«åå ã®ç©¶æã«æéããã ãã®ã§ã¯ã¨èããã®ã¨ãéæ¹åã¸ã®ãã¼ã¿åæã«ããããã使ãæ©è½ãéçºããè¦ä»¶ããããªãã°ãããã¯æ°ç°å¢ã§ã®éçºãä¿ãã¹ãã ã¨ããããªã· ã¼ã®ãã¨ã§ããã®ããã«ã«ã¼ã«åãã¾ããã
ã¾ã¨ã
以ä¸ã®ãããªæ½çãè¡ã2016å¹´ã®å¤ã«Railsã§ä½ãããæ°ã·ã¹ãã ããªãªã¼ã¹ããã¦ãããç¾å¨ã¯ï¼ã¤ã®ç°å¢ãå®å®ãã¦åãã¦ãã¾ãã å¾ã ã«ç§»è¡ãããã¨ã§æ¯è¼çå°ãããªãªã¼ã¹ã¨ãªãã®ã§å¤§ããªé害ãèµ·ãã«ããã¨ãã£ãå®å¿æãããã®ã¨ãRailsã§ã®éçºãã§ããããã«ãªã£ãã®ã§æ¥½ããã§éçºãã¦ããã¨ã³ã¸ãã¢ãè¦ãããããã«ãªã£ãã®ã¯ãã¸ãã£ããªè¦ç´ ã ã¨æãã¦ãã¾ãã
ã¾ããRailsã¢ããªã±ã¼ã·ã§ã³ã®ç«ã¡ä¸ãã«ã¤ãã¦ã¯ãã¼ãã§ã¯ãRuby on Railså ±èã®å島ãããå§ããæ ªå¼ä¼ç¤¾ ä¸èã®ã¨ã³ã¸ãã¢ãããªã©Rails ã«ç¥è¦ãããã¡ã³ãã¼ã«æ¨é²ãã¦ãããã¾ãããä»å¾è¦æ¨¡ã大ãããªãã¨äºæ³ãããã¢ããªã±ã¼ã·ã§ã³ã§æ°ããè¨èªãFWãæ¡ç¨ããã« ããã£ã¦çµé¨è±å¯ãªã¨ã³ã¸ãã¢ã«ãã£ããã¨ããåå°ãä½ã£ã¦ãããããã®ä¸ã§éçºãã¦ãããã¨ãé·ãéç¨ãã¦ããããã§å¤§äºã ã¨èãã¦ãã¾ãã
è¿é ã大è¦æ¨¡ã¢ããªã±ã¼ã·ã§ã³ãRailsåãã¦ããã¨ããæ¡ä»¶ãèããã¨ãå¤ããªã£ãæ°ããã¾ãããããã£ãè¨ç»ãèãã¦ããæ¹ã«å¼ç¤¾ ã®äºä¾ãä¸ã¤ã§ãåèã«ãªãã°å¹¸ãã§ãã