Skip to content

Conversation

@parkan
Copy link
Collaborator

@parkan parkan commented Dec 17, 2025

No description provided.

  --delete-car: delete physical CAR file from storage (default: true)
  --force: delete even if deals reference this piece
@parkan
Copy link
Collaborator Author

parkan commented Dec 17, 2025

NOTE: right now this will not know what to do with unlabeled pieces (dag vs data) and I am reluctant to shoehorn the heuristics into the handler logic

labeling the pieces is simple, though may take some time for large databases:

-- Infer piece_type for cars that predate the piece_type column
-- A piece is Data if any of its blocks reference files (contain file content)
-- A piece is DAG if none of its blocks reference files (contain only directory metadata)

-- Preview what would be updated
SELECT
    c.id,
    c.piece_cid,
    c.piece_size,
    c.piece_type as current_type,
    CASE
        WHEN EXISTS (
            SELECT 1 FROM car_blocks cb
            WHERE cb.car_id = c.id AND cb.file_id IS NOT NULL
        ) THEN 'data'
        ELSE 'dag'
    END as inferred_type
FROM cars c
WHERE c.piece_type IS NULL OR c.piece_type = '';

-- Uncomment to actually update:
-- UPDATE cars c
-- SET piece_type = CASE
--     WHEN EXISTS (
--         SELECT 1 FROM car_blocks cb
--         WHERE cb.car_id = c.id AND cb.file_id IS NOT NULL
--     ) THEN 'data'
--     ELSE 'dag'
-- END
-- WHERE c.piece_type IS NULL OR c.piece_type = '';

needs to be put somewhere before proper major release; I remain convinced that gormigrate is not the right solution, so I may bundle this with a couple of other QoL improvements in semi-manual admin init migrate

@parkan
Copy link
Collaborator Author

parkan commented Dec 17, 2025

I will merge this unless there are concerns in the next 24 hrs

@parkan parkan merged commit 7db174f into main Dec 18, 2025
3 checks passed
@parkan parkan deleted the feat/delete-piece branch December 18, 2025 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants