Skip to content

Commit d3fc68b

Browse files
committed
Add database migration for linecount statistics
This commit adds a new `JSONB` column called `linecounts` to the versions table to store Source Lines of Code statistics for each crate version. The column stores language breakdown and totals as structured `JSON` data, enabling flexible schema evolution without requiring additional migrations. The database schema and test snapshots are updated accordingly to reflect this new column structure.
1 parent 0f6c8f9 commit d3fc68b

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

crates/crates_io_database/src/schema.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,8 @@ diesel::table! {
10771077
keywords -> Array<Nullable<Text>>,
10781078
/// JSONB representation of the version number for sorting purposes.
10791079
semver_ord -> Nullable<Jsonb>,
1080+
/// Source Lines of Code statistics for this version, stored as JSON with language breakdown and totals.
1081+
linecounts -> Nullable<Jsonb>,
10801082
}
10811083
}
10821084

crates/crates_io_database_dump/src/dump-db.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ documentation = "public"
280280
repository = "public"
281281
categories = "public"
282282
keywords = "public"
283+
# The following column is private for now, until we can guarantee a stable data schema.
284+
linecounts = "private"
283285

284286
[versions_published_by.columns]
285287
version_id = "private"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- Remove line count statistics column from versions table
2+
ALTER TABLE versions
3+
DROP COLUMN linecounts;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Add line count statistics column to versions table
2+
ALTER TABLE versions
3+
ADD COLUMN linecounts JSONB DEFAULT NULL;
4+
5+
-- Add comment explaining the column
6+
COMMENT ON COLUMN versions.linecounts IS 'Source Lines of Code statistics for this version, stored as JSON with language breakdown and totals.';

0 commit comments

Comments
 (0)