-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate legacy data (null columns)
- Loading branch information
Showing
45 changed files
with
620 additions
and
68 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
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
43 changes: 43 additions & 0 deletions
43
internal/storage/bucket/migrations/0-init-schema/tests_after.sql
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,43 @@ | ||
set search_path = '{{.Bucket}}'; | ||
|
||
create extension if not exists "uuid-ossp"; | ||
|
||
insert into logs(seq, ledger, id, type, date, data, hash) | ||
select | ||
seq, | ||
'ledger' || seq % 5, | ||
(seq/5) + (seq % 5), | ||
'NEW_TRANSACTION', | ||
now(), | ||
('{' | ||
'"transaction": {' | ||
'"id": ' || (seq/5) + (seq % 5) || ',' | ||
'"timestamp": "' || now() || '",' | ||
'"postings": [' | ||
'{' | ||
'"source": "world",' | ||
'"destination": "orders:' || seq || '",' | ||
'"asset": "USD",' | ||
'"amount": 100' | ||
'},' | ||
'{' | ||
'"destination": "fees",' | ||
'"source": "orders:' || seq || '",' | ||
'"asset": "USD",' | ||
'"amount": 1' | ||
'},' | ||
'{' | ||
'"destination": "sellers:' || (seq % 5) || '",' | ||
'"source": "orders:' || seq || '",' | ||
'"asset": "USD",' | ||
'"amount": 99' | ||
'}' | ||
'],' | ||
'"metadata": { "tax": "1%" }' | ||
'},' | ||
'"accountMetadata": {' | ||
'"orders:' || seq || '": { "tax": "1%" }' | ||
'}' | ||
'}')::jsonb, | ||
'invalid-hash' | ||
from generate_series(0, 100) as seq; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions
1
internal/storage/bucket/migrations/12-moves-fill-transaction-id/notes.yaml
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 @@ | ||
name: Fill transaction ids of table moves |
10 changes: 10 additions & 0 deletions
10
internal/storage/bucket/migrations/12-moves-fill-transaction-id/tests_after.sql
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,10 @@ | ||
set search_path = '{{.Bucket}}'; | ||
|
||
do $$ | ||
begin | ||
assert ( | ||
select count(*) | ||
from moves | ||
where transactions_id is null | ||
) = 0, 'Still some rows with null transactions_id'; | ||
end$$; |
10 changes: 10 additions & 0 deletions
10
internal/storage/bucket/migrations/12-moves-fill-transaction-id/tests_before.sql
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,10 @@ | ||
set search_path = '{{.Bucket}}'; | ||
|
||
do $$ | ||
begin | ||
assert ( | ||
select count(*) | ||
from moves | ||
where transactions_id is null | ||
) > 0, 'Should have some transactions with null transactions_id'; | ||
end$$; |
29 changes: 29 additions & 0 deletions
29
internal/storage/bucket/migrations/12-moves-fill-transaction-id/up.sql
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 @@ | ||
set search_path = '{{.Bucket}}'; | ||
|
||
do $$ | ||
declare | ||
_batch_size integer := 30; | ||
begin | ||
loop | ||
with _outdated_moves as ( | ||
select * | ||
from moves | ||
where transactions_id is null | ||
limit _batch_size | ||
) | ||
update moves | ||
set transactions_id = ( | ||
select id | ||
from transactions | ||
where seq = moves.transactions_seq | ||
) | ||
from _outdated_moves | ||
where moves.seq in (_outdated_moves.seq); | ||
|
||
exit when not found; | ||
end loop; | ||
end | ||
$$; | ||
|
||
alter table moves | ||
alter column transactions_id set not null; |
1 change: 1 addition & 0 deletions
1
internal/storage/bucket/migrations/13-transactions-fill-inserted-at/notes.yaml
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 @@ | ||
name: Fill inserted_at column of transactions table |
10 changes: 10 additions & 0 deletions
10
internal/storage/bucket/migrations/13-transactions-fill-inserted-at/tests_after.sql
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,10 @@ | ||
set search_path = '{{.Bucket}}'; | ||
|
||
do $$ | ||
begin | ||
assert ( | ||
select bool_and(log.date = transactions.inserted_at) | ||
from logs log | ||
join transactions on transactions.id = log.id | ||
), 'Insertion dates of logs and transactions should not match'; | ||
end$$; |
10 changes: 10 additions & 0 deletions
10
internal/storage/bucket/migrations/13-transactions-fill-inserted-at/tests_before.sql
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,10 @@ | ||
set search_path = '{{.Bucket}}'; | ||
|
||
do $$ | ||
begin | ||
assert ( | ||
select not bool_and(log.date = transactions.inserted_at) | ||
from logs log | ||
join transactions on transactions.id = log.id | ||
), 'Insertion dates of logs and transactions should match'; | ||
end$$; |
Oops, something went wrong.