{"id":660,"date":"2015-01-31T10:36:44","date_gmt":"2015-01-31T16:36:44","guid":{"rendered":"http:\/\/www.crccheck.com\/blog\/?p=660"},"modified":"2015-10-11T22:21:52","modified_gmt":"2015-10-12T04:21:52","slug":"patterns-dont-mess-up-the-prod-db","status":"publish","type":"post","link":"https:\/\/www.crccheck.com\/blog\/patterns-dont-mess-up-the-prod-db\/","title":{"rendered":"Patterns: don&#8217;t mess up the prod db!"},"content":{"rendered":"<p>With <a href=\"http:\/\/12factor.net\/config\" target=\"_blank\">12factor style environment configs<\/a>, it&#8217;s a very easy to accidentally connect to your production database when you think you&#8217;re connecting to dev. Here&#8217;s a simple guard you can add to make sure your\u00c2\u00a0 <code>DATABASE_URL<\/code> isn&#8217;t somehow pointed to someplace it&#8217;s not supposed to (assuming you&#8217;re using Amazon AWS):<\/p>\n<h4>bash:<\/h4>\n<pre>if [[ ${DATABASE_URL} == *\"amazonaws\"* ]]; then exit -1; fi<\/pre>\n<h4>Python:<\/h4>\n<pre>if 'amazonaws' in os.environ['DATABASE_URL']:\r\n   exit('Cannot be run against a production database')\r\n<\/pre>\n<h4>Django:<\/h4>\n<pre>if 'amazonaws' in settings.DATABASES['default']['HOST']:\r\n    raise CommandError('Cannot be run against a production database')\r\n<\/pre>\n<p>(thanks to <a href=\"https:\/\/twitter.com\/x110dc\" target=\"_blank\">x110dc<\/a> for the bash syntax and 12factor link)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-672\" src=\"http:\/\/www.crccheck.com\/blog\/wp-content\/uploads\/2015\/01\/YouDidntSayTheMagicWord.gif\" alt=\"You didn't say the magic word\" width=\"320\" height=\"248\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With 12factor style environment configs, it&#8217;s a very easy to accidentally connect to your production database when you think you&#8217;re connecting to dev. Here&#8217;s a simple guard you can add to make sure your\u00c2\u00a0 DATABASE_URL isn&#8217;t somehow pointed to someplace it&#8217;s not supposed to (assuming you&#8217;re using Amazon AWS): bash: if [[ ${DATABASE_URL} == *&#8221;amazonaws&#8221;*&hellip;<\/p>\n <a href=\"https:\/\/www.crccheck.com\/blog\/patterns-dont-mess-up-the-prod-db\/\" title=\"Patterns: don&#8217;t mess up the prod db!\" class=\"entry-more-link\"><span>Read More<\/span> <span class=\"screen-reader-text\">Patterns: don&#8217;t mess up the prod db!<\/span><\/a>","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[50,78],"tags":[35,51,48],"class_list":["entry","author-showmewhatyougot","post-660","post","type-post","status-publish","format-standard","category-best-practices","category-patterns","tag-bash","tag-django","tag-python"],"_links":{"self":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts\/660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/comments?post=660"}],"version-history":[{"count":6,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts\/660\/revisions"}],"predecessor-version":[{"id":673,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/posts\/660\/revisions\/673"}],"wp:attachment":[{"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/media?parent=660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/categories?post=660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.crccheck.com\/blog\/wp-json\/wp\/v2\/tags?post=660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}