schemalexã®ç¥æ©è½
ãã®è¨äºã¯OSSç´¹ä» Advent Calendar 2017 ã® 5æ¥ç®ã®è¨äºã§ãã
schemalexã¨ã¯
Generate the difference of two mysql schema
ã¨æ¸ãã¦ããéããï¼ã¤ã®MySQLã®ã¹ãã¼ãã®å·®å(ALTER)ã表示ãããããã¯ãã§ã@soh335ãä¸å¿ã¨ãªã£ã¦éçºããã¦ããã åãæ¥åã§ã使ã£ã¦ããã®ã§ãã¾ã«patchãéã£ã¦ãã¾ãã
perlã ã¨SQL::Translator::Diffã«ãããã
ãã®schemalexã¯MySQLã«ãã対å¿ãã¦ããªãã®ã§ãããGo製ã®ãããã¯ãã®ãããã¤ããªãæä¾ããã¦ãããããã³ãã³ãã©ã¤ã³ãã¼ã«ã¨ãã¦ç°¡åã«ä½¿ããã¨ãããSQL::Translator::Diff
ãã使ããããã¨æã£ã¦æ°ã«å
¥ã£ã¦ãã¾ãã
ç´¹ä»ããããã¨
@lestrratã«ãã#34 ã®PullRequestãå人çã«ã©ã¤ããã§ã³ã¸ã³ã°ã ã£ãã®ã§æ¯éç´¹ä»ããã¦ãã ããã
ãã®æ©è½ã§ã§ããããã«ãªã£ããã¨ã¯ã¹ãã¼ãã®æ¯è¼æ¹æ³ã®æ¡å¼µã§ãã
ããã¾ã§ã¯ä»¥ä¸ã®ç¨ã«before/afterã®sqlãç¨æãã¦æ¯è¼ãã¦ãã¾ããã
$ schemalex /path/to/before.sql /path/to/after.sql
ãã®PRã§ä»¥ä¸ã®3ãã¿ã¼ã³ã®å ¥åã«å¯¾å¿ããã¾ããã
1. mysqlãã¼ã¿ã½ã¼ã¹
$ schemalex /path/to/file mysql://user:password@tcp(host:port)/dbname
2. gitã®ã³ãããããã·ã¥
$ schemalex local-git:///path/to/repo?file=foo.sql&commitish=deadbeaf /path/to/file
3. æ¨æºå ¥å
.... | schemalex - /path/to/file
ä½ãå¬ããã®
ä¾ãã°ãæ®æ®µæ¥åã«ããã¦DBã®migrationã§gitã®ã³ãããããã·ã¥ã¨æ¯è¼ããgit-schemalexãGitDDLã使ã£ã¦ããã®ã§ããã æ®å¿µãªãããã£ããç´æ¥ALTERããã¦ãã¾ã£ãããALTERã®éä¸ã§FKå¶ç´ã«å¼ã£ããã£ãããã¦ãã¾ããããã¹ãç¶æ ã«ãªãã¨ãæ»ããããªã£ãããããã¨ãããã¾ãã ã¾ããgitlogã®ä»»æã®ãã¼ã¸ã§ã³ã«æ»ãããå ´åãããã¾ãã
ãããã£ãæã«ä¸è¨ã®ç¨ã«ã³ãã³ãä¸çºã§alteråãåºåã§ããã®ã§ãã
schemalex mysql://user:password@tcp(host:port)/dbname /path/to/file > revert.sql
æå¾ã«
ããã¾ãå¿ è¦æ§ã«ãã³ã¨æ¥ãªãããããã¾ããããæå ã®ç°å¢ãã¼ã¼ã¼ï¼ãã¹ããã¼ã¿ã®å ¥ãç´ãã¯ããããªã¼ã¼ã¼ã¼ãï¼ã¨ãªã£ãã¨ãã«ãå©ãã¦ããããã¼ã«ã ã¨æãã¾ãã®ã§ã ãæ´»ç¨ããã ãã¾ãã¨å¹¸ãã§ãã
ãã³ãã¼æ¸ãããï¼