Skip to content

Conversation

@Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Oct 27, 2024

This shall be filled by the following SQL script:

update versions
    set num_no_build = split_part(num, '+', 1);

with duplicates as (
    -- find all versions that have the same `crate_id` and `unique_num`
    select crate_id, num_no_build, array_agg(num ORDER BY id) as nums
    from versions
    group by crate_id, num_no_build
    having count(*) > 1
),
duplicates_to_update as (
    -- for each group of duplicates, update all versions except the one that
    -- doesn't have "build metadata", or the first one that was published if
    -- all versions have "build metadata"
    select crate_id, num_no_build, unnest(case when array_position(nums, num_no_build) IS NOT NULL then array_remove(nums, num_no_build) else nums[2:] end) as num
    from duplicates
)
update versions
    set num_no_build = duplicates_to_update.num
    from duplicates_to_update
    where versions.crate_id = duplicates_to_update.crate_id
    and versions.num = duplicates_to_update.num;

The script takes a few seconds to complete, so this should not be added to the database schema migration script, since it would block the API server from booting.


This PR was extracted from #9756, because it needs to be deploy separately from the other migrations in that PR.

This shall be filled by the following SQL script:

```sql
update versions
    set num_no_build = split_part(num, '+', 1);

with duplicates as (
    -- find all versions that have the same `crate_id` and `unique_num`
    select crate_id, num_no_build, array_agg(num ORDER BY id) as nums
    from versions
    group by crate_id, num_no_build
    having count(*) > 1
),
duplicates_to_update as (
    -- for each group of duplicates, update all versions except the one that
    -- doesn't have "build metadata", or the first one that was published if
    -- all versions have "build metadata"
    select crate_id, num_no_build, unnest(case when array_position(nums, num_no_build) IS NOT NULL then array_remove(nums, num_no_build) else nums[2:] end) as num
    from duplicates
)
update versions
    set num_no_build = duplicates_to_update.num
    from duplicates_to_update
    where versions.crate_id = duplicates_to_update.crate_id
    and versions.num = duplicates_to_update.num;
```

The script takes a few seconds to complete, so this should not be added to the database schema migration script, since it would block the API server from booting.
@Turbo87 Turbo87 added C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear A-backend ⚙️ labels Oct 27, 2024
@Turbo87 Turbo87 enabled auto-merge October 27, 2024 14:27
@Turbo87 Turbo87 merged commit 101076a into rust-lang:main Oct 27, 2024
8 checks passed
@Turbo87 Turbo87 deleted the num_no_build1 branch October 27, 2024 14:33
@codecov
Copy link

codecov bot commented Oct 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@e8ef4e1). Learn more about missing BASE report.
Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9766   +/-   ##
=======================================
  Coverage        ?   88.81%           
=======================================
  Files           ?      289           
  Lines           ?    29810           
  Branches        ?        0           
=======================================
  Hits            ?    26475           
  Misses          ?     3335           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-backend ⚙️ C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant