This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Altered a exchanges and exchane_route to handle NULL values fir recon…
…ciliations
- Loading branch information
1 parent
57180d6
commit 8ad9096
Showing
2 changed files
with
46 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
-- Alter the enums to cater for missing data. | ||
ALTER TYPE payment_net ADD VALUE 'unknown'; | ||
ALTER TYPE exchange_status ADD VALUE 'unknown'; | ||
|
||
-- Update the field status in the exchanges table from NULL to 'unknown' | ||
UPDATE exchanges SET status = 'unknown' WHERE status IS NULL; | ||
|
||
-- Alter the exchanges table to ensure that no more NULL values are entered | ||
ALTER TABLE exchanges ALTER COLUMN status SET NOT NULL; | ||
|
||
-- Insert records for ‘unknown’ (previously NULL in exchanges table | ||
-- network in exchange_route table | ||
INSERT INTO exchange_routes (participant, network, address, error) | ||
( | ||
SELECT DISTINCT participants.id, 'unknown'::payment_net, 'None', 'None' | ||
FROM exchanges, participants | ||
WHERE exchanges.participant = participants.username | ||
AND route IS NULL | ||
); | ||
|
||
-- Update exchanges records with exchange_route ids pointing to ‘unknown’ network records for that participants | ||
UPDATE exchanges | ||
SET route = exchange_routes.id | ||
FROM exchange_routes, participants | ||
WHERE exchange_routes.participant = participants.id | ||
AND participants.username = exchanges.participant; | ||
|
||
-- Alter exchanges table and set route to not null | ||
ALTER TABLE exchanges ALTER COLUMN route SET NOT NULL; |
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