How to convert a postgres database to sqlite

前端 未结 6 709
感动是毒
感动是毒 2020-12-01 16:51

We\'re working on a website, and when we develop locally (one of us from Windows), we use sqlite3, but on the server (linux) we use postgres. We\'d like to be able to impor

6条回答
  •  误落风尘
    2020-12-01 17:14

    I found this blog entry which guides you to do these steps:

    1. Create a dump of the PostgreSQL database.

      ssh -C username@hostname.com pg_dump --data-only --inserts YOUR_DB_NAME > dump.sql
      
    2. Remove/modify the dump.

      1. Remove the lines starting with SET
      2. Remove the lines starting with SELECT pg_catalog.setval
      3. Replace true for ‘t
      4. Replace false for ‘f
    3. Add BEGIN; as first line and END; as last line

    4. Recreate an empty development database. bundle exec rake db:migrate

    5. Import the dump.

      sqlite3 db/development.sqlite3
      sqlite> delete from schema_migrations;
      sqlite> .read dump.sql
      

    Of course connecting via ssh and creating a new db using rake are optional

提交回复
热议问题