Skip to content

Commit 3ce9c61

Browse files
Tyrubiassyphar
authored andcommitted
Make owner_kind an enum, change migration
1 parent 23b6124 commit 3ce9c61

16 files changed

+201
-183
lines changed

.sqlx/query-16dfb0d87266568fb8a84585614387c8bfa4790b9e8d317159b37397e42b7ceb.json

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-1e48486ba272a4e2ea8793114e412c14ed13f652419b1467c21e1829f31cd573.json

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-24c697ed817d33dbdfb0e5126feaf3f5addfba6ed45f46afdc523b324da2cbab.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

.sqlx/query-87952bd450ed2c13b99bd502a73a84edd7d17e6171523ebbd57f1d9dd7c9b46c.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-b6273727360630c958b856427cb9dacc3289dcadf82061774866fec3a62669c5.json

Lines changed: 0 additions & 32 deletions
This file was deleted.

.sqlx/query-d87220d3f4503e99fa17815db0058ab7883bf28f216d5b5fd720c56fd8889eed.json

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-ee9dddd0c37c0e89eab1feaddd27e5e9c7016a1b8b35b031cb05b4d0802b6be1.json

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
ALTER TABLE owners
22
DROP COLUMN IF EXISTS kind;
3+
4+
DROP TYPE IF EXISTS owner_kind;
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
CREATE TYPE owner_kind AS ENUM (
2+
'user',
3+
'team'
4+
);
5+
16
ALTER TABLE owners
2-
ADD COLUMN IF NOT EXISTS kind TEXT NOT NULL CHECK (
3-
kind IN ('user', 'team')
4-
) DEFAULT 'user';
7+
ADD COLUMN IF NOT EXISTS kind owner_kind NOT NULL DEFAULT 'user';
8+
9+
UPDATE owners
10+
SET
11+
kind = CASE
12+
WHEN login LIKE 'github:%' THEN 'team'::owner_kind
13+
ELSE 'user'::owner_kind
14+
END;

src/bin/cratesfyi.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use humantime::Duration;
2525
use once_cell::sync::OnceCell;
2626
use sentry::TransactionContext;
2727
use tokio::runtime::{Builder, Runtime};
28-
use tracing::info;
2928
use tracing_log::LogTracer;
3029
use tracing_subscriber::{filter::Directive, prelude::*, EnvFilter};
3130

@@ -516,9 +515,6 @@ enum DatabaseSubcommand {
516515
/// Backfill GitHub/Gitlab stats for crates.
517516
BackfillRepositoryStats,
518517

519-
/// Backfill crate owner kind from crates.io API
520-
BackfillCrateOwnerKind,
521-
522518
/// Updates info for a crate from the registry's API
523519
UpdateCrateRegistryFields {
524520
#[arg(name = "CRATE")]
@@ -605,37 +601,6 @@ impl DatabaseSubcommand {
605601
.block_on(ctx.repository_stats_updater()?.backfill_repositories())?;
606602
}
607603

608-
Self::BackfillCrateOwnerKind => {
609-
let pool = ctx.pool()?;
610-
ctx.runtime()?
611-
.block_on(async {
612-
let mut list_crates_conn = pool.get_async().await?;
613-
let mut update_crates_conn = pool.get_async().await?;
614-
615-
let mut result_stream =
616-
sqlx::query!("SELECT id, name FROM crates ORDER BY name")
617-
.fetch(&mut *list_crates_conn);
618-
619-
while let Some(row) = result_stream.next().await {
620-
let row = row?;
621-
let registry_data =
622-
ctx.registry_api()?.get_crate_data(&row.name).await?;
623-
624-
info!("Updating crate {}", row.name);
625-
626-
db::update_crate_data_in_db_by_id(
627-
&mut update_crates_conn,
628-
row.id,
629-
&registry_data,
630-
)
631-
.await?;
632-
}
633-
634-
Ok::<(), anyhow::Error>(())
635-
})
636-
.context("Failed to backfill crate owner kind")?
637-
}
638-
639604
Self::UpdateCrateRegistryFields { name } => ctx.runtime()?.block_on(async move {
640605
let mut conn = ctx.pool()?.get_async().await?;
641606
let registry_data = ctx.registry_api()?.get_crate_data(&name).await?;

0 commit comments

Comments
 (0)