Skip to content

Commit b747663

Browse files
committed
Archive > Mesa Migration: migrate non-nullable zkapp state as well
1 parent 3964e50 commit b747663

File tree

2 files changed

+105
-6
lines changed

2 files changed

+105
-6
lines changed

src/app/archive/downgrade-to-berkeley.sql

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-- ============================================================================
22
-- Mina rollback: from mesa to berkeley
3+
-- + remove zkapp_states.element31..element8 (int)
34
-- + remove zkapp_states_nullable.element31..element8 (int)
45
-- + record status in migration_history
56
-- ============================================================================
@@ -17,7 +18,7 @@ SET archive.current_protocol_version = '4.0.0';
1718
-- Post-HF protocol version. This one corresponds to Mesa, specifically
1819
SET archive.target_protocol_version = '3.0.0';
1920
-- The version of this script. If you modify the script, please bump the version
20-
SET archive.migration_version = '0.0.2';
21+
SET archive.migration_version = '0.0.3';
2122

2223
-- TODO: put below in a common script
2324

@@ -106,6 +107,56 @@ BEGIN
106107
END IF;
107108
END$$;
108109

110+
-- 2. `zkapp_states`: Remove columns element31..element8
111+
112+
CREATE OR REPLACE FUNCTION try_remove_zkapp_states_element(p_element_num INT)
113+
RETURNS VOID AS $$
114+
DECLARE
115+
col_name TEXT := 'element' || p_element_num;
116+
BEGIN
117+
118+
RAISE DEBUG 'Trying to removing column % for zkapp_states', col_name;
119+
120+
EXECUTE format(
121+
'ALTER TABLE zkapp_states DROP COLUMN IF EXISTS %I',
122+
col_name
123+
);
124+
125+
RAISE DEBUG 'Ensured column % for zkapp_states not existent', col_name;
126+
EXCEPTION
127+
WHEN OTHERS THEN
128+
PERFORM set_migration_status('failed'::migration_status);
129+
RAISE EXCEPTION 'An error occurred: %', SQLERRM;
130+
END
131+
$$ LANGUAGE plpgsql;
132+
133+
SELECT try_remove_zkapp_states_element(31);
134+
SELECT try_remove_zkapp_states_element(30);
135+
SELECT try_remove_zkapp_states_element(29);
136+
SELECT try_remove_zkapp_states_element(28);
137+
SELECT try_remove_zkapp_states_element(27);
138+
SELECT try_remove_zkapp_states_element(26);
139+
SELECT try_remove_zkapp_states_element(25);
140+
SELECT try_remove_zkapp_states_element(24);
141+
SELECT try_remove_zkapp_states_element(23);
142+
SELECT try_remove_zkapp_states_element(22);
143+
SELECT try_remove_zkapp_states_element(21);
144+
SELECT try_remove_zkapp_states_element(20);
145+
SELECT try_remove_zkapp_states_element(19);
146+
SELECT try_remove_zkapp_states_element(18);
147+
SELECT try_remove_zkapp_states_element(17);
148+
SELECT try_remove_zkapp_states_element(16);
149+
SELECT try_remove_zkapp_states_element(15);
150+
SELECT try_remove_zkapp_states_element(14);
151+
SELECT try_remove_zkapp_states_element(13);
152+
SELECT try_remove_zkapp_states_element(12);
153+
SELECT try_remove_zkapp_states_element(11);
154+
SELECT try_remove_zkapp_states_element(10);
155+
SELECT try_remove_zkapp_states_element(9);
156+
SELECT try_remove_zkapp_states_element(8);
157+
158+
-- 3. `zkapp_states_nullable`: Remove nullable columns element31..element8
159+
109160
CREATE OR REPLACE FUNCTION try_remove_zkapp_states_nullable_element(p_element_num INT)
110161
RETURNS VOID AS $$
111162
DECLARE
@@ -127,8 +178,6 @@ EXCEPTION
127178
END
128179
$$ LANGUAGE plpgsql;
129180

130-
-- 2. `zkapp_states_nullable`: Remove nullable columns element31..element8
131-
132181
SELECT try_remove_zkapp_states_nullable_element(31);
133182
SELECT try_remove_zkapp_states_nullable_element(30);
134183
SELECT try_remove_zkapp_states_nullable_element(29);
@@ -154,7 +203,7 @@ SELECT try_remove_zkapp_states_nullable_element(10);
154203
SELECT try_remove_zkapp_states_nullable_element(9);
155204
SELECT try_remove_zkapp_states_nullable_element(8);
156205

157-
-- 3. Update schema_history
206+
-- 4. Update schema_history
158207

159208
DO $$
160209
BEGIN

src/app/archive/upgrade-to-mesa.sql

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-- =============================================================================
22
-- Mina migration: from berkeley to mesa
33
-- + extend zkapp_states_nullable with element8..element31 (int)
4+
-- + extend zkapp_states with element8..element31 (int)
45
-- + record status in migration_history
56
-- =============================================================================
67

@@ -17,7 +18,7 @@ SET archive.current_protocol_version = '3.0.0';
1718
-- Post-HF protocol version. This one corresponds to Mesa, specifically
1819
SET archive.target_protocol_version = '4.0.0';
1920
-- The version of this script. If you modify the script, please bump the version
20-
SET archive.migration_version = '0.0.2';
21+
SET archive.migration_version = '0.0.3';
2122

2223
-- TODO: put below in a common script
2324

@@ -160,7 +161,56 @@ SELECT add_zkapp_states_nullable_element(29);
160161
SELECT add_zkapp_states_nullable_element(30);
161162
SELECT add_zkapp_states_nullable_element(31);
162163

163-
-- 3. Update schema_history
164+
-- 3. `zkapp_states`: Add columns element8..element31
165+
166+
CREATE OR REPLACE FUNCTION add_zkapp_states_element(p_element_num INT)
167+
RETURNS VOID AS $$
168+
DECLARE
169+
col_name TEXT := 'element' || p_element_num;
170+
BEGIN
171+
172+
RAISE DEBUG 'Adding column % for zkapp_states', col_name;
173+
174+
EXECUTE format(
175+
'ALTER TABLE zkapp_states ADD COLUMN IF NOT EXISTS %I INT DEFAULT 0 NOT NULL REFERENCES zkapp_field(id)',
176+
col_name
177+
);
178+
179+
RAISE DEBUG 'Added column % for zkapp_states', col_name;
180+
181+
EXCEPTION
182+
WHEN OTHERS THEN
183+
PERFORM set_migration_status('failed'::migration_status);
184+
RAISE EXCEPTION 'An error occurred while adding column % to zkapp_states: %', col_name, SQLERRM;
185+
END
186+
$$ LANGUAGE plpgsql;
187+
188+
SELECT add_zkapp_states_element(8);
189+
SELECT add_zkapp_states_element(9);
190+
SELECT add_zkapp_states_element(10);
191+
SELECT add_zkapp_states_element(11);
192+
SELECT add_zkapp_states_element(12);
193+
SELECT add_zkapp_states_element(13);
194+
SELECT add_zkapp_states_element(14);
195+
SELECT add_zkapp_states_element(15);
196+
SELECT add_zkapp_states_element(16);
197+
SELECT add_zkapp_states_element(17);
198+
SELECT add_zkapp_states_element(18);
199+
SELECT add_zkapp_states_element(19);
200+
SELECT add_zkapp_states_element(20);
201+
SELECT add_zkapp_states_element(21);
202+
SELECT add_zkapp_states_element(22);
203+
SELECT add_zkapp_states_element(23);
204+
SELECT add_zkapp_states_element(24);
205+
SELECT add_zkapp_states_element(25);
206+
SELECT add_zkapp_states_element(26);
207+
SELECT add_zkapp_states_element(27);
208+
SELECT add_zkapp_states_element(28);
209+
SELECT add_zkapp_states_element(29);
210+
SELECT add_zkapp_states_element(30);
211+
SELECT add_zkapp_states_element(31);
212+
213+
-- 4. Update schema_history
164214

165215
DO $$
166216
BEGIN

0 commit comments

Comments
 (0)