Foreign Keys
What Are Foreign Keys?
The master_2019.2 version of SimpleInvoices, introduce major changes including full, foreign key support.
Foreign Keys (FKs) define a parent/child relationship between database tables.
For instance, an invoice is associated with one customer. But a customer can be associated with many invoices. This means a parent record in the customer table can have one or more child records in the invoices table.
By defining the FK relationship in the database, protection is put in place to assure that spurious adds, updates and deletions do not create orphaned records.
For example, the Recurrence feature uses the cron and cron_log tables. The cron table is both a parent and a child to the cron_log and invoices tables respectively. When a new Recurrence record is added and a new cron table record is added, that record must be linked to a parent record in the invoices table via the cron invoice_id field.
Later when a crontab action (automated repeating task) is processed automatically creating a new invoice, a record is added to the cron_log table to record the event. This child record must contain a FK (cron_id) that points to its parent record in the cron table.
Further, if in phpMyAdmin, you attempt to delete a record from the cron table, without first deleting its child records in the cron_log table, an error is reported stopping your delete request.
By implementing the FK logic at the database level, utilities and programs that modify database information will not be allowed to do so without assuring that the FK rules have been met.
Should I Upgrade To master_2026?
As with any major update, unanticipated problems can occur. However, they will never be found and resolved unless people start using this update. That said, this version of the software has been running in a production environment for a number of months and several people have installed this software to help flesh out update issues not resolved.
The SimpleInvoices Group Forum accessed as the first menu item on the left, is the way to get help in resolving issues that you encounter. By signing up as a user on this group, you can submit issues, questions and comments to those developing SI and receive responses and solutions with reasonable turnaround; typically within 24 hours.
The database patches made by this version are extensive and rely on the database structure and data to conform to expectations established by the patch level of the version of SI being upgraded from. Typically, this works without issue. Sometimes however, unanticipated issues are encountered that cause the process to fail. These issues will be discovered as more users update to this new version. Support to resolve these issues will be provided as rapidly as possible when reported though the forum.
As with any update, make sure you back up your database and your SimpleInvoices folder (all programs and files) before loading the update. This way, push come to shove, you can restore to the previous version if an update solution is not provided in the necessary timeframe.