Working as developers, sometimes we need to migrate an existing app from one language to other, or even load data from Staging or Prod locally. So this guide shows how we can do that.
Creating dump files
If you don’t have any dump file for testing purposes you can generate one from an existing database
Of course you can create just one file that have the schemas and inserts,I prefer to have them in different files. You can learn more about all psql commands on https://www.postgresql.org/docs/current/app-pgdump.html
Create schema dump file
pg_dump --schema-only --file="schema_dump.sql" <database_name>
# or even shorter
pg_dump -s -f="schema_dump.sql" <database_name>
# --file=file
# Send output to the specified file.
# --schema-only
# Dump only the object definitions (schema), not data.
Create inserts dump file
pg_dump --data-only --file="insert_dump.sql" <database_name>
Applying data to our new databse
First of all you should create the database for you application:
mix ecto.create
If you already have the dump file, you can run the following command:
mix ecto.load -d <path_of_dumps>/schema_dump.sql
This will create the tables from the dump to our Phoenix app
If we have a data that we also want to add, we can use the same command in order to add the data to our app
mix ecto.load -d <path_of_dumps>/inserts_dump.sql
And we are ready to rock!
Now you should be able to generate migrations and run them on top of this!
Things we used:
Top comments (0)