Program with better backward compatibility lazarus / 16-Databases ---------------------------------------------------------------------- Handoko · 2017-05-30 15:25 Sorry if sounds off topic. I remember something interesting when I used WordPress. Although it is different but we can learn about how it manages  backward compatibility. I use WordPress, but because I am a web designer not web programmer I do not read the code inside. I think WordPress has awesome backward compatibility. WordPress main code and plugins' codes are usually developed by different developers. So far, although I often get warnings that the database need to upgrade but it never fails to start if ignore it. For example, if I download a newer version of WordPress and run the update. Wait several minutes until it say finished, reload the page and login. It tells me that my database is old and need an upgrade. I'm not sure but I think what it actually means is to restructure the database, maybe adding or removing some fields. To make it clearer lets say current version is 3.2 and I update it to 3.3. After that process, it said the database need to upgrade. Which means the running code now is version 3.3 but the database version is 3.2. If I choose to ignore it, the website will still able to run. I only get a red warning at the top on the backend admin page. To make it more complicated, similar things also happen on plugins' update sometimes. After a plugin update, it may ask me to upgrade the database too. But I can ignore it without causing the website fails to run. Of course, I always upgrade the database immediately when it asks me to do so. So, how do you think it can be achieved? The code of never version able to run on older version of database. ---------------------------------------------------------------------- sky_khan · 2017-05-30 15:38 I dont know how wordpress does it but it can be done if your queries are not hardcoded but you construct them at runtime. You can add a version info column in one table and compare it on program startup and show a warning. ---------------------------------------------------------------------- Handoko · 2017-05-30 15:59 I am more interested to know how the code can tolerate different version of the database. If I remember correctly. I ever upgraded the software version but for some reasons I manually deleted the software (not the database) and reinstall the lower version. It worked, the lower version of code can use the higher version of database. It seems they separate the code and database nicely and they can be 'plugged' together even their versions are not the same. The previous discussion started me to think: http://forum.lazarus.freepascal.org/index.php/topic,37053.msg247815.ht ml#msg247815 WP used Lazarus 1.8.0 to write a demo, which I can't open because I'm using Lazarus 1.6.4. Similar to this case, WordPress handles it nicely. Also if I'm not wrong, it happens on Drupal too. When something not working correctly after Drupal update, you can easily remove the code and install a lower version, nothing bad will happen on the database. ---------------------------------------------------------------------- taazz · 2017-05-30 16:10 Quote from: Handoko on May 30, 2017, 05:59:16 pmI am more interested to know how the code can tolerate different version of the database. If I remember correctly. I ever upgraded the software version but for some reasons I manually deleted the software (not the database) and reinstall the lower version. It worked, the lower version of code can use the higher version of database. It seems they separate the code and database nicely and they can be 'plugged' together even their versions are not the same. The previous discussion started me to think: http://forum.lazarus.freepascal.org/index.php/topic,37053.msg247815.ht ml#msg247815 WP used Lazarus 1.8.0 to write a demo, which I can't open because I'm using Lazarus 1.6.4. Similar to this case, WordPress handles it nicely. Also if I'm not wrong, it happens on Drupal too. When something not working correctly after Drupal update, you can easily remove the code and install a lower version, nothing bad will happen on the database. You are comparing apples and oranges. Do you have a database application that you want to apply this feature to? In any case for a database application you can accomplish the same by restricting your self to use views and stored procedures avoiding direct access to the tables and data behind changing the database to newer/older version will have no effect to you application as long as the views are constant and you use dynamic commands from the application eg (Select * from customerView instead of select name,address,.... from CustomerView). ---------------------------------------------------------------------- sky_khan · 2017-05-30 16:11 If you dont ever remove a column it is easier to run a lower version code against upper database. All columns you need would be there. Running a new code on old database which requires new columns are more tricky but it still can be done in some extent, as I said, if you construct all queries on runtime. Besides their(wp,drupal) database schemas are not that complex and self-contained. On the other hand, if you are developing a software which needs to adapt external entity/regulations, like if you need printing an invoice that requires new information to be legally accepted  it is impossible. ---------------------------------------------------------------------- Thaddy · 2017-05-30 16:22 Handoko, I used to work with wordpress myself, but the backwards compatibility would exist of  a very long list of highly critical security issues that even caused companies to go bankrupt. AFAIK nobody got bankrupt because of a critical error in FPC.... but that is always possible.... Backwards compatibility is a dream, like a nightmare... don't believe it your whole life. ---------------------------------------------------------------------- Handoko · 2017-05-30 16:42 Okay, I will remember your advice. I'm just curious with the tricks they use. Anyway, thank for the explanations. Although I don't fully understand but I think I know what that means and that gives me the basic idea: runtime constructing, add and compare the version info column, use views and store procedures, use dynamic commands. Some new lessons learned, I am sure to use it someday in the future. Thank you all.