Run custom script on postgres docker container after database initialization

Hello all, I am using a Docker Hub (alpine-based Postgres container) for database setup. I have a shell script that basically checks the version of the software by running a psql query and compares it with the latest version, if there is a difference in the version then pull the latest sql files from GitHub and update the database. I want this shell script to run whenever the container starts. I tried to keep this script in /docker-entrypoint-initdb.d but later found that the scripts inside /docker-entrypoint-initdb.d do not run if the database is already initialized, so it does not solve my problem. I also tried using entrypoint: /custom-entrypoint-override.sh in my docker-compose file but then this script executes before the Postgres is started and so the psql command in my shell script failed, so it also did not solve my problem.
If anyone has any solution for this, please let me know. Thanks in advance.