Open2

golang-migrate/migrateを使うときはDSNのエスケープに気をつけるべし

ninomaeninomae

https://github.com/golang-migrate/migrate#database-urls

Database URLs
Database connection strings are specified via URLs. The URL format is driver dependent but generally has the form: dbdriver://username:password@host:port/dbname?param1=true&param2=false

Any reserved URL characters need to be escaped. Note, the % character also needs to be escaped
Explicitly, the following characters need to be escaped: !, #, $, %, &, ', (, ), *, +, ,, /, :, ;, =, ?, @, [, ]

重要なのはAny~のところ。URLで特殊文字として扱われる文字はエスケープする必要がある

ローカルの開発環境では、簡単のためにpasswordみたいなものを指定しているケースがあると思う。

いざクラウド上のRDBなどで払い出されたランダムなパスワードを入れてDSNを作ると、エスケープシーケンスのことを忘れていてマイグレーションに失敗するみたいなケースがあったのでメモとして残しておく