-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit creates administrative utilities for the database that are useful in correcting database issues. It includes the ability to repost every single transaction type as well as recalculate the entity maps.
- Loading branch information
Showing
4 changed files
with
111 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
DELIMITER $$ | ||
|
||
/* | ||
zRecomputeEntityMap | ||
Abolishes and recomputes the entity_map from the base tables in the system. This is | ||
useful in case of database corruption in which references get out of sync. | ||
*/ | ||
CREATE PROCEDURE zRecomputeEntityMap() | ||
BEGIN | ||
DELETE FROM entity_map; | ||
|
||
-- employee | ||
INSERT INTO entity_map | ||
SELECT employee.debtor_uuid, CONCAT_WS('.', 'EM', employee.id) FROM employee; | ||
|
||
-- patient | ||
INSERT INTO entity_map | ||
SELECT patient.uuid, CONCAT_WS('.', 'PA', project.abbr, patient.reference) | ||
FROM patient JOIN project ON patient.project_id = project.id; | ||
|
||
-- patient debtor | ||
INSERT INTO entity_map | ||
SELECT patient.debtor_uuid, CONCAT_WS('.', 'PA', project.abbr, patient.reference) | ||
FROM patient JOIN project ON patient.project_id = project.id; | ||
|
||
-- supplier | ||
INSERT INTO entity_map | ||
SELECT supplier.creditor_uuid, CONCAT_WS('.', 'FO', supplier.reference) FROM supplier; | ||
END $$ | ||
|
||
/* | ||
zRecomputDocumentMap | ||
Abolishes and recomputes the document_map entries from the base tables in the | ||
database. This is useful in case of data corruption. | ||
*/ | ||
CREATE PROCEDURE zRecomputeDocumentMap() | ||
BEGIN | ||
DELETE FROM document_map; | ||
|
||
-- cash payments | ||
INSERT INTO document_map | ||
SELECT cash.uuid, CONCAT_WS('.', 'CP', project.abbr, cash.reference) | ||
FROM cash JOIN project where project.id = cash.project_id; | ||
|
||
-- invoices | ||
INSERT INTO document_map | ||
SELECT invoice.uuid, CONCAT_WS('.', 'IV', project.abbr, invoice.reference) | ||
FROM invoice JOIN project where project.id = invoice.project_id; | ||
|
||
-- purchases | ||
INSERT INTO document_map | ||
SELECT purchase.uuid, CONCAT_WS('.', 'PO', project.abbr, purchase.reference) | ||
FROM purchase JOIN project where project.id = purchase.project_id; | ||
|
||
-- vouchers | ||
INSERT INTO document_map | ||
SELECT voucher.uuid, CONCAT_WS('.', 'VO', project.abbr, voucher.reference) | ||
FROM voucher JOIN project where project.id = voucher.project_id; | ||
END $$ | ||
|
||
/* | ||
zRepostVoucher | ||
Removes the voucher record from the posting_journal and calls the PostVoucher() method on | ||
the record in the voucher table to re-post it to the journal. | ||
*/ | ||
CREATE PROCEDURE zRepostVoucher( | ||
IN vUuid BINARY(16) | ||
) | ||
BEGIN | ||
DELETE FROM posting_journal WHERE posting_journal.record_uuid = vUuid; | ||
CALL PostVoucher(vUuid); | ||
END $$ | ||
|
||
/* | ||
zRepostInvoice | ||
Removes the invoice record from the posting_journal and calls the PostInvoice() method on | ||
the record in the invoice table to re-post it to the journal. | ||
*/ | ||
CREATE PROCEDURE zRepostInvoice( | ||
IN iUuid BINARY(16) | ||
) | ||
BEGIN | ||
DELETE FROM posting_journal WHERE posting_journal.record_uuid = iUuid; | ||
CALL PostInvoice(iUuid); | ||
END $$ | ||
|
||
/* | ||
zRepostCash | ||
Removes the cash record from the posting_journal and calls the PostCash() method on | ||
the record in the cash table to re-post it to the journal. | ||
*/ | ||
CREATE PROCEDURE zRepostCash( | ||
IN cUuid BINARY(16) | ||
) | ||
BEGIN | ||
DELETE FROM posting_journal WHERE posting_journal.record_uuid = cUuid; | ||
CALL PostCash(cUuid); | ||
END $$ | ||
|
||
DELIMITER ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters