Skip to content

Commit 436040e

Browse files
jhfclaude
andcommitted
fix: reset('getting-started') no longer deletes system import_definitions
Changed `DELETE FROM import_definition WHERE id > 0` to `WHERE custom` so only user-created definitions are removed. System definitions are preserved, preventing the spinner/error on /import/legal-units after reset. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bb63fcd commit 436040e

11 files changed

+992
-435
lines changed

migrations/20240531000000_create_reset.up.sql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ BEGIN
9292
ELSE END CASE;
9393

9494
CASE WHEN scope IN ('getting-started', 'all') THEN
95-
-- Apply pattern for 'import_definition'
96-
-- Must delete BEFORE data_source due to RESTRICT foreign key constraint.
97-
-- Deleting import_jobs first (above) removes the CASCADE dependency.
95+
-- Transient: delete custom definitions before data_source due to RESTRICT FK. See doc/data-model.md
9896
WITH deleted_import_definition AS (
99-
DELETE FROM public.import_definition WHERE id > 0 RETURNING *
97+
DELETE FROM public.import_definition WHERE custom RETURNING *
10098
)
10199
SELECT jsonb_build_object(
102100
'import_definition', jsonb_build_object(

migrations/20260311102131_fix_reset_fk_and_safeupdate.up.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ BEGIN
161161
-- ================================================================
162162

163163
CASE WHEN scope IN ('getting-started', 'all') THEN
164-
-- Transient: must delete BEFORE data_source due to RESTRICT FK. See doc/data-model.md
164+
-- Transient: delete custom definitions before data_source due to RESTRICT FK. See doc/data-model.md
165165
WITH deleted_import_definition AS (
166-
DELETE FROM public.import_definition WHERE id > 0 RETURNING *
166+
DELETE FROM public.import_definition WHERE custom RETURNING *
167167
)
168168
SELECT jsonb_build_object(
169169
'import_definition', jsonb_build_object(

migrations/20260312114521_tag_replace_type_enum_with_custom_boolean.up.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ BEGIN
159159
-- ================================================================
160160

161161
CASE WHEN scope IN ('getting-started', 'all') THEN
162-
-- Transient: must delete BEFORE data_source due to RESTRICT FK. See doc/data-model.md
162+
-- Transient: delete custom definitions before data_source due to RESTRICT FK. See doc/data-model.md
163163
WITH deleted_import_definition AS (
164-
DELETE FROM public.import_definition WHERE id > 0 RETURNING *
164+
DELETE FROM public.import_definition WHERE custom RETURNING *
165165
)
166166
SELECT jsonb_build_object(
167167
'import_definition', jsonb_build_object(

migrations/20260312114522_region_versioning_and_change_triggers.up.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,9 @@ BEGIN
420420
-- ================================================================
421421

422422
CASE WHEN scope IN ('getting-started', 'all') THEN
423+
-- Transient: delete custom definitions before data_source due to RESTRICT FK. See doc/data-model.md
423424
WITH deleted_import_definition AS (
424-
DELETE FROM public.import_definition WHERE id > 0 RETURNING *
425+
DELETE FROM public.import_definition WHERE custom RETURNING *
425426
)
426427
SELECT jsonb_build_object(
427428
'import_definition', jsonb_build_object(

migrations/20260312114524_person_to_external_ident.up.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,9 @@ BEGIN
435435
-- ================================================================
436436

437437
CASE WHEN scope IN ('getting-started', 'all') THEN
438+
-- Transient: delete custom definitions before data_source due to RESTRICT FK. See doc/data-model.md
438439
WITH deleted_import_definition AS (
439-
DELETE FROM public.import_definition WHERE id > 0 RETURNING *
440+
DELETE FROM public.import_definition WHERE custom RETURNING *
440441
)
441442
SELECT jsonb_build_object(
442443
'import_definition', jsonb_build_object(

test/expected/108_test_code_gen.out

Lines changed: 850 additions & 270 deletions
Large diffs are not rendered by default.

test/expected/305_load_norwegian_dataset_suitable_for_web_upload.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3437,7 +3437,7 @@ reset_getting_started
34373437
"changed_children_count": 73
34383438
},
34393439
"import_definition": {
3440-
"deleted_count": 10
3440+
"deleted_count": 0
34413441
},
34423442
"legal_relationship": {
34433443
"deleted_count": 1
@@ -3607,7 +3607,7 @@ reset_all
36073607
"changed_children_count": 73
36083608
},
36093609
"import_definition": {
3610-
"deleted_count": 10
3610+
"deleted_count": 0
36113611
},
36123612
"legal_relationship": {
36133613
"deleted_count": 1

test/expected/explain/303_import_jobs_for_norway_small_history-timeline_enterprise_def.txt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@
2727
-> GroupAggregate
2828
-> Sort
2929
Sort Key: timeline_legal_unit.legal_unit_id
30-
-> Bitmap Heap Scan on timeline_legal_unit
31-
Recheck Cond: ((valid_from < t_1.valid_until) AND (t_1.valid_from < valid_until))
30+
-> Index Scan using idx_timeline_legal_unit_valid_period on timeline_legal_unit
31+
Index Cond: ((valid_from < t_1.valid_until) AND (valid_until > t_1.valid_from))
3232
Filter: (enterprise_id = en_1.id)
33-
-> Bitmap Index Scan on idx_timeline_legal_unit_valid_period
34-
Index Cond: ((valid_from < t_1.valid_until) AND (valid_until > t_1.valid_from))
3533
-> GroupAggregate
3634
-> Sort
3735
Sort Key: timeline_establishment.establishment_id
@@ -46,13 +44,12 @@
4644
-> Hash
4745
-> Seq Scan on enterprise en
4846
-> Limit
49-
-> Sort
47+
-> Incremental Sort
5048
Sort Key: enplu_1.valid_from DESC, enplu_1.legal_unit_id DESC
51-
-> Bitmap Heap Scan on timeline_legal_unit enplu_1
52-
Recheck Cond: ((valid_from < t.valid_until) AND (t.valid_from < valid_until))
49+
Presorted Key: enplu_1.valid_from
50+
-> Index Scan Backward using idx_timeline_legal_unit_valid_period on timeline_legal_unit enplu_1
51+
Index Cond: ((valid_from < t.valid_until) AND (valid_until > t.valid_from))
5352
Filter: (primary_for_enterprise AND (enterprise_id = en.id))
54-
-> Bitmap Index Scan on idx_timeline_legal_unit_valid_period
55-
Index Cond: ((valid_from < t.valid_until) AND (valid_until > t.valid_from))
5653
-> Limit
5754
-> Sort
5855
Sort Key: enpes_1.valid_from DESC, enpes_1.establishment_id DESC
@@ -109,5 +106,5 @@
109106
-> Result
110107
-> ProjectSet
111108
-> Result
112-
(109 rows)
109+
(106 rows)
113110

test/expected/explain/303_import_jobs_for_norway_small_history-timeline_establishment_def.txt

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
-> Nested Loop Left Join
2525
Disabled: true
2626
-> Hash Left Join
27-
Hash Cond: (es.sector_id = s.id)
28-
-> Hash Left Join
29-
Hash Cond: (es.unit_size_id = us.id)
27+
Hash Cond: (sa.category_id = sac.id)
28+
-> Nested Loop Left Join
29+
Disabled: true
3030
-> Hash Left Join
31-
Hash Cond: (sa.category_id = sac.id)
32-
-> Nested Loop Left Join
33-
Disabled: true
34-
-> Hash Left Join
35-
Hash Cond: (pa.category_id = pac.id)
36-
-> Nested Loop Left Join
37-
Disabled: true
31+
Hash Cond: (pa.category_id = pac.id)
32+
-> Hash Left Join
33+
Hash Cond: (es.sector_id = s.id)
34+
-> Nested Loop Left Join
35+
Disabled: true
36+
-> Hash Left Join
37+
Hash Cond: (es.unit_size_id = us.id)
3838
-> Hash Left Join
3939
Hash Cond: (es.status_id = st.id)
4040
-> Nested Loop
@@ -70,32 +70,32 @@
7070
Filter: ((t.valid_from < valid_until) AND (valid_from < t.valid_until) AND (id = t.unit_id))
7171
-> Hash
7272
-> Seq Scan on status st
73-
-> Memoize
74-
Cache Key: es.id, t.valid_from, t.valid_until
75-
Cache Mode: binary
76-
-> Subquery Scan on pa
77-
-> Limit
78-
-> Sort
79-
Sort Key: a.id DESC
80-
-> Seq Scan on activity a
81-
Filter: ((t.valid_from < valid_until) AND (valid_from < t.valid_until) AND (establishment_id = es.id) AND (type = 'primary'::activity_type))
82-
-> Hash
83-
-> Seq Scan on activity_category pac
84-
-> Memoize
85-
Cache Key: es.id, t.valid_from, t.valid_until
86-
Cache Mode: binary
87-
-> Subquery Scan on sa
88-
-> Limit
89-
-> Sort
90-
Sort Key: a_1.id DESC
91-
-> Seq Scan on activity a_1
92-
Filter: ((t.valid_from < valid_until) AND (valid_from < t.valid_until) AND (establishment_id = es.id) AND (type = 'secondary'::activity_type))
73+
-> Hash
74+
-> Seq Scan on unit_size us
75+
-> Memoize
76+
Cache Key: es.id, t.valid_from, t.valid_until
77+
Cache Mode: binary
78+
-> Subquery Scan on pa
79+
-> Limit
80+
-> Sort
81+
Sort Key: a.id DESC
82+
-> Seq Scan on activity a
83+
Filter: ((t.valid_from < valid_until) AND (valid_from < t.valid_until) AND (establishment_id = es.id) AND (type = 'primary'::activity_type))
84+
-> Hash
85+
-> Seq Scan on sector s
9386
-> Hash
94-
-> Seq Scan on activity_category sac
95-
-> Hash
96-
-> Seq Scan on unit_size us
87+
-> Seq Scan on activity_category pac
88+
-> Memoize
89+
Cache Key: es.id, t.valid_from, t.valid_until
90+
Cache Mode: binary
91+
-> Subquery Scan on sa
92+
-> Limit
93+
-> Sort
94+
Sort Key: a_1.id DESC
95+
-> Seq Scan on activity a_1
96+
Filter: ((t.valid_from < valid_until) AND (valid_from < t.valid_until) AND (establishment_id = es.id) AND (type = 'secondary'::activity_type))
9797
-> Hash
98-
-> Seq Scan on sector s
98+
-> Seq Scan on activity_category sac
9999
-> Memoize
100100
Cache Key: es.id, t.valid_from, t.valid_until
101101
Cache Mode: binary

0 commit comments

Comments
 (0)