Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql script executes each time on startup resulting in errors in docker logs #108

Open
Prachi481992 opened this issue Oct 15, 2018 · 2 comments

Comments

@Prachi481992
Copy link

Hi,
I am using a set of SQL files to populate my database with sample data on first time starting up the container.
but each time after that even if the container is stopped and I'm restarting it, it re-executes all the SQL files which result in errors during Inserts (due to unique constraints in DB tables).
Can we change the startup.sh so that we can check, if the data is already mounted, if yes, then skip SQL file execution.
I was trying something on the lines of
https://github.com/MaksymBilenko/docker-oracle-12c/blob/master/entrypoint.sh
but it is resulting in the abrupt exit of the container.

@asoltesz
Copy link

asoltesz commented Feb 5, 2019

Yes, it would be much better to have the scripts run only once, when the database is first initialized.

That way, it would also resemble more to the official PostgreSQL container (which is much more widely used and well known for Docker users) thus be more familiar.

As it is, I have to put a lot of extra efforts into ensuring that the init scripts all check that they have not yet been executed. It cannot be used very well in this form.

@Prachi481992
Copy link
Author

I've come up with a temporary fix to address this issue. I've replaced the entrypoint.sh in the image by a custom script which deletes the SQL insert scripts once the run is successful. Thus, the scripts are not re-run on restart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants