Skip to content

Commit

Permalink
Add migration for the DB columns
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc committed Sep 5, 2024
1 parent c3a3e17 commit 42db941
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 112 deletions.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
UPDATE protocol_patches SET recursion_scheduler_level_vk_hash = snark_wrapper_vk_hash WHERE recursion_scheduler_level_vk_hash = ''::bytea;
ALTER TABLE protocol_patches DROP COLUMN snark_wrapper_vk_hash;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE protocol_patches ADD COLUMN snark_wrapper_vk_hash BYTEA NOT NULL;
ALTER TABLE protocol_patches ALTER COLUMN recursion_scheduler_level_vk_hash SET DEFAULT ''::bytea;
UPDATE protocol_patches SET snark_wrapper_vk_hash = recursion_scheduler_level_vk_hash;

-- Old column should be removed once the migration is on the mainnet.
COMMENT ON COLUMN protocol_patches.recursion_scheduler_level_vk_hash IS 'This column is deprecated and will be removed in the future. Use snark_wrapper_vk_hash instead.';
10 changes: 4 additions & 6 deletions core/lib/dal/src/protocol_versions_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl ProtocolVersionsDal<'_, '_> {
sqlx::query!(
r#"
INSERT INTO
protocol_patches (minor, patch, recursion_scheduler_level_vk_hash, created_at)
protocol_patches (minor, patch, snark_wrapper_vk_hash, created_at)
VALUES
($1, $2, $3, NOW())
ON CONFLICT DO NOTHING
Expand Down Expand Up @@ -233,7 +233,7 @@ impl ProtocolVersionsDal<'_, '_> {
protocol_versions.bootloader_code_hash,
protocol_versions.default_account_code_hash,
protocol_patches.patch,
protocol_patches.recursion_scheduler_level_vk_hash AS snark_wrapper_vk_hash
protocol_patches.snark_wrapper_vk_hash
FROM
protocol_versions
JOIN protocol_patches ON protocol_patches.minor = protocol_versions.id
Expand Down Expand Up @@ -263,11 +263,10 @@ impl ProtocolVersionsDal<'_, '_> {
&mut self,
version: ProtocolSemanticVersion,
) -> Option<L1VerifierConfig> {
// `recursion_scheduler_level_vk_hash` actually stores `snark_wrapper_vk_hash`
let row = sqlx::query!(
r#"
SELECT
recursion_scheduler_level_vk_hash AS snark_wrapper_vk_hash
snark_wrapper_vk_hash
FROM
protocol_patches
WHERE
Expand All @@ -290,7 +289,6 @@ impl ProtocolVersionsDal<'_, '_> {
minor_version: ProtocolVersionId,
snark_wrapper_vk_hash: H256,
) -> DalResult<Vec<VersionPatch>> {
// `recursion_scheduler_level_vk_hash` actually stores `snark_wrapper_vk_hash`
let rows = sqlx::query!(
r#"
SELECT
Expand All @@ -299,7 +297,7 @@ impl ProtocolVersionsDal<'_, '_> {
protocol_patches
WHERE
minor = $1
AND recursion_scheduler_level_vk_hash = $2
AND snark_wrapper_vk_hash = $2
ORDER BY
patch DESC
"#,
Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
UPDATE prover_fri_protocol_versions SET recursion_scheduler_level_vk_hash = snark_wrapper_vk_hash WHERE recursion_scheduler_level_vk_hash = ''::bytea;
ALTER TABLE prover_fri_protocol_versions DROP COLUMN snark_wrapper_vk_hash;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE prover_fri_protocol_versions ADD COLUMN snark_wrapper_vk_hash BYTEA NOT NULL;
ALTER TABLE prover_fri_protocol_versions ALTER COLUMN recursion_scheduler_level_vk_hash SET DEFAULT ''::bytea;
UPDATE prover_fri_protocol_versions SET snark_wrapper_vk_hash = recursion_scheduler_level_vk_hash;

-- Old column should be removed once the migration is on the mainnet.
COMMENT ON COLUMN prover_fri_protocol_versions.recursion_scheduler_level_vk_hash IS 'This column is deprecated and will be removed in the future. Use snark_wrapper_vk_hash instead.';
7 changes: 3 additions & 4 deletions prover/crates/lib/prover_dal/src/fri_protocol_versions_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ impl FriProtocolVersionsDal<'_, '_> {
id: ProtocolSemanticVersion,
l1_verifier_config: L1VerifierConfig,
) {
// `recursion_scheduler_level_vk_hash` column actually stores `snark_wrapper_vk_hash`
sqlx::query!(
r#"
INSERT INTO
prover_fri_protocol_versions (id, recursion_scheduler_level_vk_hash, created_at, protocol_version_patch)
prover_fri_protocol_versions (id, snark_wrapper_vk_hash, created_at, protocol_version_patch)
VALUES
($1, $2, NOW(), $3)
ON CONFLICT (id, protocol_version_patch) DO NOTHING
Expand All @@ -44,7 +43,7 @@ impl FriProtocolVersionsDal<'_, '_> {
sqlx::query!(
r#"
SELECT
recursion_scheduler_level_vk_hash AS snark_wrapper_vk_hash
snark_wrapper_vk_hash
FROM
prover_fri_protocol_versions
WHERE
Expand All @@ -66,7 +65,7 @@ impl FriProtocolVersionsDal<'_, '_> {
let result = sqlx::query!(
r#"
SELECT
recursion_scheduler_level_vk_hash AS snark_wrapper_vk_hash
snark_wrapper_vk_hash
FROM
prover_fri_protocol_versions
ORDER BY
Expand Down

0 comments on commit 42db941

Please sign in to comment.