Skip to content

Commit 3700da0

Browse files
authored
fix: auto enabled features on first ledger created on a bucket (#1149)
1 parent e6b4d02 commit 3700da0

File tree

1 file changed

+14
-7
lines changed
  • internal/storage/bucket/migrations/11-make-stateless

1 file changed

+14
-7
lines changed

internal/storage/bucket/migrations/11-make-stateless/up.sql

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -495,35 +495,42 @@ $do$
495495
vsql = 'select setval(''"log_id_' || ledger.id || '"'', coalesce((select max(id) + 1 from logs where ledger = ''' || ledger.name || '''), 1)::bigint, false)';
496496
execute vsql;
497497

498-
vsql = 'create trigger "set_effective_volumes_' || ledger.id || '" before insert on moves for each row when (new.ledger = ''' || ledger.name || ''') execute procedure set_effective_volumes()';
498+
vsql = 'create trigger "transaction_set_addresses_' || ledger.id || '" before insert on transactions for each row when (new.ledger = ''' || ledger.name || ''') execute procedure set_transaction_addresses()';
499499
execute vsql;
500500

501-
vsql = 'create trigger "update_effective_volumes_' || ledger.id || '" after insert on moves for each row when (new.ledger = ''' || ledger.name || ''') execute procedure update_effective_volumes()';
501+
vsql = 'create trigger "accounts_set_address_array_' || ledger.id || '" before insert on accounts for each row when (new.ledger = ''' || ledger.name || ''') execute procedure set_address_array_for_account()';
502502
execute vsql;
503503

504-
-- logs hash
505-
vsql = 'create trigger "set_log_hash_' || ledger.id || '" before insert on logs for each row when (new.ledger = ''' || ledger.name || ''') execute procedure set_log_hash()';
504+
vsql = 'create trigger "transaction_set_addresses_segments_' || ledger.id || '" before insert on "transactions" for each row when (new.ledger = ''' || ledger.name || ''') execute procedure set_transaction_addresses_segments()';
506505
execute vsql;
506+
end loop;
507507

508+
for ledger in select * from _system.ledgers where bucket = current_schema and features->>'ACCOUNT_METADATA_HISTORY' = 'SYNC' loop
508509
vsql = 'create trigger "update_account_metadata_history_' || ledger.id || '" after update on "accounts" for each row when (new.ledger = ''' || ledger.name || ''') execute procedure update_account_metadata_history()';
509510
execute vsql;
510511

511512
vsql = 'create trigger "insert_account_metadata_history_' || ledger.id || '" after insert on "accounts" for each row when (new.ledger = ''' || ledger.name || ''') execute procedure insert_account_metadata_history()';
512513
execute vsql;
514+
end loop;
513515

516+
for ledger in select * from _system.ledgers where bucket = current_schema and features->>'TRANSACTION_METADATA_HISTORY' = 'SYNC' loop
514517
vsql = 'create trigger "update_transaction_metadata_history_' || ledger.id || '" after update on "transactions" for each row when (new.ledger = ''' || ledger.name || ''') execute procedure update_transaction_metadata_history()';
515518
execute vsql;
516519

517520
vsql = 'create trigger "insert_transaction_metadata_history_' || ledger.id || '" after insert on "transactions" for each row when (new.ledger = ''' || ledger.name || ''') execute procedure insert_transaction_metadata_history()';
518521
execute vsql;
522+
end loop;
519523

520-
vsql = 'create trigger "transaction_set_addresses_' || ledger.id || '" before insert on transactions for each row when (new.ledger = ''' || ledger.name || ''') execute procedure set_transaction_addresses()';
524+
for ledger in select * from _system.ledgers where bucket = current_schema and features->>'MOVES_HISTORY_POST_COMMIT_EFFECTIVE_VOLUMES' = 'SYNC' loop
525+
vsql = 'create trigger "set_effective_volumes_' || ledger.id || '" before insert on moves for each row when (new.ledger = ''' || ledger.name || ''') execute procedure set_effective_volumes()';
521526
execute vsql;
522527

523-
vsql = 'create trigger "accounts_set_address_array_' || ledger.id || '" before insert on accounts for each row when (new.ledger = ''' || ledger.name || ''') execute procedure set_address_array_for_account()';
528+
vsql = 'create trigger "update_effective_volumes_' || ledger.id || '" after insert on moves for each row when (new.ledger = ''' || ledger.name || ''') execute procedure update_effective_volumes()';
524529
execute vsql;
530+
end loop;
525531

526-
vsql = 'create trigger "transaction_set_addresses_segments_' || ledger.id || '" before insert on "transactions" for each row when (new.ledger = ''' || ledger.name || ''') execute procedure set_transaction_addresses_segments()';
532+
for ledger in select * from _system.ledgers where bucket = current_schema and features->>'HASH_LOGS' = 'SYNC' loop
533+
vsql = 'create trigger "set_log_hash_' || ledger.id || '" before insert on logs for each row when (new.ledger = ''' || ledger.name || ''') execute procedure set_log_hash()';
527534
execute vsql;
528535
end loop;
529536
END

0 commit comments

Comments
 (0)