ãã¤ã³ãã¯2ç¹
Rails 㧠PostgreSQL ãç¨ããéã®è¨å®ã§ã®ãã¤ã³ãã¯ä»¥ä¸ã®2ç¹ã§ãã
1. pg ã® gem ãå ¥ãã
PostgreSQL ãæ±ãããã® gem ã§ãã pg ãã¤ã³ã¹ãã¼ã«ããå¿
è¦ãããã¾ããGemfile
ã« gem 'pg'
ã¨æ¸ã㦠bundle install
ãã¾ãã
MySQL ã®å ´å㯠mysql2
ã¨ãã gem ãã¤ã³ã¹ãã¼ã«ãã¦ããã¨ããã§ãã
2. ãã¼ã¿ãã¼ã¹è¨å®ãã¡ã¤ã«ã® adapter ã« postgresql ãæå®ãã
config/database.yml
ã« adapter
ã¨ã㦠postgresql
ãæå®ãã¾ãã
MySQL ã®å ´å㯠adapter: mysql2
ã¨æå®ãã¦ããå ´æã§ãã
development: adapter: postgresql ï¼ä»¥ä¸ç¥ï¼
ï¼åèï¼ä»»æã®ã¹ãã¼ãã使ç¨ããããã«è¨å®ããæ¹æ³
PostgreSQL ã®å ´åã¯ãã¼ã¿ãã¼ã¹ã®æ§é ãããã¼ã¿ãã¼ã¹âã¹ãã¼ãâãã¼ãã«ç¾¤ãã¨ãªã£ã¦ãã¾ããMySQL ã§ã¯ããã¼ã¿ãã¼ã¹âãã¼ãã«ç¾¤ãã¨ãªã£ã¦ããé¨åã§ãã
PostgreSQL ã§ã¯ MySQL ã¨æ¯è¼ãã¦ãã¹ãã¼ããã®é¨åã追å ããã¦ãã¾ããã©ã®ã¹ãã¼ãã使ãããæ示çã«æå®ããã«ã¯ããã¼ã¿ãã¼ã¹è¨å®ãã¡ã¤ã«ã®ä¸ã«ä»¥ä¸ã®ããã«è¨è¿°ãã¾ãã
development: database: foobar schema_search_path: hogefuga ï¼ä»¥ä¸ç¥ï¼
ããã§ãfoobar ã¨ãããã¼ã¿ãã¼ã¹ã® hogefuga ã¨ããã¹ãã¼ããæä½å¯¾è±¡ã«ãªãã¾ãããã¼ãã«ãåé¤ããã追å ãããããéã«ã¯ãã®ã¹ãã¼ãã®é ä¸ã§è¡ããã¾ãã
ããããªãã public
ã§ã¯ãªãã¹ãã¼ããç¨ãã¦ããã¨ãdb:reset
ã db:migrate:reset
ãªã©ãå®è¡ããéã«ã¨ã©ã¼ãåºã¾ããåã³ãã³ããã¹ãã¼ãã¾ã§ã¯èªåä½æãã¦ãããªãï¼ã¯ãï¼ã ããã§ãã
$ rails db:migrate:reset ï¼çç¥ï¼ rails aborted! ActiveRecord::StatementInvalid: PG::InvalidSchemaName: ERROR: ä½æå ã®ã¹ãã¼ããé¸æããã¦ãã¾ãã LINE 1: CREATE TABLE "schema_migrations" ("version" character varyin...
ãããã£ã¦åã³ãã³ããå®è¡ããå ´åã¯æåã§ã¹ãã¼ããä½ãç´ãå¿ è¦ãããã¾ããããã㯠Rake ã¿ã¹ã¯ã追å ããã¨ãã§ãããã*1ã
ããããèããã¨ãè¦ç´ããå¤ãããããªä½ãã«ãããããã¯ãç´ ç´ã« public
ã¹ãã¼ãã使ãã¹ãã ã¨æãã¾ãã
*1:試ãã¦ããªãã®ã§æå®ã§ãã¾ãããâ¦â¦