My application is in C. I have to add a functionality in my application so that it should be able to upgrade itself according to the latest version. More specifically it should recognize if any newer version is found and get updated with that newer version (according to
the new executable). There may be situations like schema of database may get changed in the newer version. So what provision can I give in my code so that it can recognize the new executable and upgrade itself according to that?
Platform: linux, gcc compiler
So you can update your binary as proposed by @Joachim and @awoodland above. While both are valid, I would err on the side of caution and simply get your package management tool to do the donkey work. Reasons being security and more critically to resolve dependencies. Unfortunately this requires you to maintain packages however given that you probably could get away with a deb file and an rpm file and cover the vast majority this is no biggy.
On the database upgrade side, create a SQL script that backup the db and one (or a series) to update it (adding the appropriate fields etc.)
Have your script create a database version table with the version number date and time of upgrade and the software revision number that performed the upgrade and whether it succeeded or not (anything you can think that is useful. Also make sure it inserts a row into your version table every time you upgrade.
When you start your binary program get it to check the maximum version number against the expected db version to ensure that the binary is compatible with the database version else upgrade.
Extending this further you can upgrade between vastly different versions by having it loop through a set of upgrade scripts. You should keep these as an embedded resource if you want to keep them safe(r) from prying eyes but this should resolve your problem.
Hope this helps, I haven’t had my coffee yet but it may point to a solution. Going a step further you could also create an upgrade log table to record how the upgrade went and if any problems were encoutered, to help in those situations that hopefully will never happen.