Question

I have "db_dump.sql" file. Which consist of some data for testing. I need to import this into the PG DB before starting the test run.

I checked http://franz-see.github.io/Robotframework-Database-Library/api/0.5/DatabaseLibrary.html, but did not find any keyword to import DB dump.

Do we have an existing keyword to import DB dump?

Was it helpful?

Solution

If what you have is an SQL file, then you don't need a keyword that specifically import a database but you need a keyword that can execute a SQL file (the statements in the file are going to create the schema, tables, FK etc.). In the library you mention you should be able to yse "Execute Sql Script" keyword for that.

OTHER TIPS

This is how I solved the above issue:

Create a file with command to import the Postgres dump.

Create File importdump.sh content=psql -d dbName -h hostName -p 5432 -U username -f ${DUMP_FILE_LOCATION} encoding=ASCII

Run the script

Run sh importdump.sh

Here, ${DUMP_FILE_LOCATION} = /path/to/the/file/db_dump.sql

The keyword 'Execute Sql Script' is useful to run the commands once connected to the DB. In this scenario, the dump file was on my local machine and the PG is an ec2 instance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top