Hi all! I need to migrate from my Sqlite3 DB to Po...
# support
b
Hi all! I need to migrate from my Sqlite3 DB to Postgresql DB. Do you know any good guide to do this? Thanks in advance.
1
k
You could try with the simplest:
Copy code
pgloader sqlite:///path/to/file.db <pgsql://pguser@pghost/dbname>
after creating your empty postgres database
b
Thanks @kennyadsl. But in my
db/
folder I have not the extension .db, I have .sqlite3 extension.
k
I think it might work anyway
b
thanks.
It worked!! 😀 Thanks!
k
Nice!
b
Now, I have the data converted to Postgresql. But I need to remove the sqlite3 gem from my Gemfile and add the Postgres gem to it;
gem "pg"
. And I need to modify the `config/database.yml`file. Do you know where can I find a database.yml template with the correct postgres configuration? I've found some of them but they are diferent and I dont know wich is the correct. Thanks in advance.
May be useful to someone. My resume about migrate from Sqlite3 db to Postgresql (PG) db in Rails. • Install PG. My recommendation is to install also Pgadmin (a GUI for PG). • Add the PG gem to `Gemfile`;
gem "pg"
. • Comment or remove the Sqlite3 gem in the
Gemfile
. • Fix the application gem's dependencies;
bundle install
. • Configure the
config/database.yml
file to connect the PG db with the Rails app...
...I need to refactor with "default" and "environment variables" (don't use it!). See below.
• Create the application database;
rails db:create
. • Execute the migrations to generate all the tables and relations;
rails db:migrate
. • Verify with the server;
rails server
. •
To pass all the data from one Sqlite3 db to another PG db I recommend Pgloader and Pgadmin. Sorry for my ignorance. May be there are mistakes.
Refactored database.yml.