This example shows you how to seed your Postgres database with a SQL script.
- Our SQL Script downloads from a S3 bucket to avoid storing sensitive data in this repository. This is a good practice to follow.
- You can remove the S3 download part to put a SQL script in this repository. However, it's not recommended to store sensitive data in a public repository.
- Fork this repository
- Create a Lifecycle Job
- Select your forked repository with the appropriate branch (e.g.
main
) - Set the "Root application path" to the example you want to use (e.g.
examples/seed-postgres-database-with-sql-script
) - Set the "Dockerfile path" to the Dockerfile in the example you want to use (e.g.
Dockerfile
) - Select "Start" event and add the following CMD Arguments:
["seed.sh"]
- which indicates to the Lifecycle Job to run theseed.sh
script when the Lifecycle Job starts. - Create your Lifecycle Job but do not deploy it yet.
- Go to your Lifecycle Job variables and create:
DATABASE_URL
environment variable alias to provide toseed.sh
your database connection string where to restore your seed.SEED_URL
environment variable alias to provide toseed.sh
your seed SQL script URL. (can be a public S3 bucket URL or any other URL)RESTORE_METHOD
environment variable alias to provide toseed.sh
your restore method. (can bepsql
orpg_restore
)
- Deploy your Lifecycle Job.
Your database is now seeded with your SQL script.