Cloud9 + rails + Postgresql usage

前端 未结 1 679
闹比i
闹比i 2021-01-28 09:21

I can not set up a Rails app using Postgresql for development on Cloud9 (c9.io): the migration does not succeed.

Common error:

~/workspace (master) $ rak         


        
相关标签:
1条回答
  • 2021-01-28 09:55

    Cloud9 does not run PG by defalut. Below is the fast & easy way I use to use Postgresql on C9:

    1. Gemfile.rb:

    gem 'pg'
    

    2. Database.yml:

    default: &default
      adapter: postgresql
      encoding: unicode
      pool: 5
      username: my_name
      password: my_pass
      host:     <%= ENV['IP'] %>
    
    development:
      <<: *default
      database: my_db_development
    
    test:
      <<: *default
      database: my_db_test
    
    production:
      <<: *default
      database: my_db_production
    
    1. Paste the following code alltogether in the console:

    `

    sudo service postgresql start
    sudo sudo -u postgres psql
    CREATE USER my_name SUPERUSER PASSWORD 'my_pass';
    \q
    echo "export USERNAME=my_name"
    echo "export PASSWORD=my_pass"
    source
    bundle
    sudo sudo -u postgres psql
    UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
    DROP DATABASE template1;
    CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';
    UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
    \c template1
    VACUUM FREEZE;
    \q
    bundle exec rake db:create
    rake db:migrate
    

    Done! However after not using the app for some hours the db goes to sleep & you have to "switch" Postgres on manually by typing in the console: sudo service postgresql start

    0 讨论(0)
提交回复
热议问题