Skip to content

Commit

Permalink
Make owner_kind an enum, change migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrubias authored and syphar committed Jun 21, 2024
1 parent 23b6124 commit 3ce9c61
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 183 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

2 changes: 2 additions & 0 deletions migrations/20240227040753_add_owner_kind.down.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
ALTER TABLE owners
DROP COLUMN IF EXISTS kind;

DROP TYPE IF EXISTS owner_kind;
16 changes: 13 additions & 3 deletions migrations/20240227040753_add_owner_kind.up.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
CREATE TYPE owner_kind AS ENUM (
'user',
'team'
);

ALTER TABLE owners
ADD COLUMN IF NOT EXISTS kind TEXT NOT NULL CHECK (
kind IN ('user', 'team')
) DEFAULT 'user';
ADD COLUMN IF NOT EXISTS kind owner_kind NOT NULL DEFAULT 'user';

UPDATE owners
SET
kind = CASE
WHEN login LIKE 'github:%' THEN 'team'::owner_kind
ELSE 'user'::owner_kind
END;
35 changes: 0 additions & 35 deletions src/bin/cratesfyi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use humantime::Duration;
use once_cell::sync::OnceCell;
use sentry::TransactionContext;
use tokio::runtime::{Builder, Runtime};
use tracing::info;
use tracing_log::LogTracer;
use tracing_subscriber::{filter::Directive, prelude::*, EnvFilter};

Expand Down Expand Up @@ -516,9 +515,6 @@ enum DatabaseSubcommand {
/// Backfill GitHub/Gitlab stats for crates.
BackfillRepositoryStats,

/// Backfill crate owner kind from crates.io API
BackfillCrateOwnerKind,

/// Updates info for a crate from the registry's API
UpdateCrateRegistryFields {
#[arg(name = "CRATE")]
Expand Down Expand Up @@ -605,37 +601,6 @@ impl DatabaseSubcommand {
.block_on(ctx.repository_stats_updater()?.backfill_repositories())?;
}

Self::BackfillCrateOwnerKind => {
let pool = ctx.pool()?;
ctx.runtime()?
.block_on(async {
let mut list_crates_conn = pool.get_async().await?;
let mut update_crates_conn = pool.get_async().await?;

let mut result_stream =
sqlx::query!("SELECT id, name FROM crates ORDER BY name")
.fetch(&mut *list_crates_conn);

while let Some(row) = result_stream.next().await {
let row = row?;
let registry_data =
ctx.registry_api()?.get_crate_data(&row.name).await?;

info!("Updating crate {}", row.name);

db::update_crate_data_in_db_by_id(
&mut update_crates_conn,
row.id,
&registry_data,
)
.await?;
}

Ok::<(), anyhow::Error>(())
})
.context("Failed to backfill crate owner kind")?
}

Self::UpdateCrateRegistryFields { name } => ctx.runtime()?.block_on(async move {
let mut conn = ctx.pool()?.get_async().await?;
let registry_data = ctx.registry_api()?.get_crate_data(&name).await?;
Expand Down
Loading

0 comments on commit 3ce9c61

Please sign in to comment.