Skip to content

Commit 7ab8ab6

Browse files
committed
Extract crates_io_database_dump crate
1 parent d90ce45 commit 7ab8ab6

File tree

14 files changed

+392
-337
lines changed

14 files changed

+392
-337
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ bon = "=2.3.0"
5151
cargo-manifest = "=0.15.2"
5252
crates_io_cdn_logs = { path = "crates/crates_io_cdn_logs" }
5353
crates_io_database = { path = "crates/crates_io_database" }
54+
crates_io_database_dump = { path = "crates/crates_io_database_dump" }
5455
crates_io_env_vars = { path = "crates/crates_io_env_vars" }
5556
crates_io_github = { path = "crates/crates_io_github" }
5657
crates_io_index = { path = "crates/crates_io_index" }
@@ -116,7 +117,6 @@ tracing-subscriber = { version = "=0.3.18", features = ["env-filter", "json"] }
116117
typomania = { version = "=0.1.2", default-features = false }
117118
url = "=2.5.2"
118119
unicode-xid = "=0.2.6"
119-
zip = { version = "=2.2.0", default-features = false, features = ["deflate"] }
120120

121121
[dev-dependencies]
122122
bytes = "=1.8.0"
@@ -129,3 +129,4 @@ googletest = "=0.12.0"
129129
insta = { version = "=1.40.0", features = ["glob", "json", "redactions"] }
130130
regex = "=1.11.0"
131131
tokio = "=1.40.0"
132+
zip = { version = "=2.2.0", default-features = false, features = ["deflate"] }
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "crates_io_database_dump"
3+
version = "0.0.0"
4+
license = "MIT OR Apache-2.0"
5+
edition = "2021"
6+
7+
[lints]
8+
workspace = true
9+
10+
[dependencies]
11+
anyhow = "=1.0.90"
12+
chrono = { version = "=0.4.38", default-features = false, features = ["clock", "serde"] }
13+
flate2 = "=1.0.34"
14+
minijinja = "=2.3.1"
15+
serde = { version = "=1.0.210", features = ["derive"] }
16+
serde_json = "=1.0.132"
17+
tar = "=0.4.42"
18+
tempfile = "=3.13.0"
19+
toml = "=0.8.19"
20+
tracing = "=0.1.40"
21+
zip = { version = "=2.2.0", default-features = false, features = ["deflate"] }
22+
23+
[dev-dependencies]
24+
crates_io_test_db = { path = "../crates_io_test_db" }
25+
diesel = "=2.2.4"
26+
insta = { version = "=1.40.0", features = ["glob"] }

src/worker/jobs/dump_db/configuration.rs renamed to crates/crates_io_database_dump/src/configuration.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
use serde::Deserialize;
12
use std::collections::{BTreeMap, VecDeque};
23

34
/// An enum indicating whether a column is included in the database dumps.
45
/// Public columns are included, private are not.
56
#[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
67
#[serde(rename_all = "lowercase")]
7-
pub(super) enum ColumnVisibility {
8+
pub enum ColumnVisibility {
89
Private,
910
Public,
1011
}
@@ -16,7 +17,7 @@ pub(super) enum ColumnVisibility {
1617
/// used in a `WHERE` clause to filter the rows of the table. The `columns`
1718
/// field maps column names to their respective visibilities.
1819
#[derive(Clone, Debug, Default, Deserialize)]
19-
pub(super) struct TableConfig {
20+
pub struct TableConfig {
2021
#[serde(default)]
2122
pub dependencies: Vec<String>,
2223
pub filter: Option<String>,
@@ -28,17 +29,17 @@ pub(super) struct TableConfig {
2829
/// Maps table names to the respective configurations. Used to load `dump_db.toml`.
2930
#[derive(Clone, Debug, Default, Deserialize)]
3031
#[serde(transparent)]
31-
pub(super) struct VisibilityConfig(pub BTreeMap<String, TableConfig>);
32+
pub struct VisibilityConfig(pub BTreeMap<String, TableConfig>);
3233

3334
impl VisibilityConfig {
34-
pub(super) fn get() -> Self {
35+
pub fn get() -> Self {
3536
toml::from_str(include_str!("dump-db.toml")).unwrap()
3637
}
3738

3839
/// Sort the tables in a way that dependencies come before dependent tables.
3940
///
4041
/// Returns a vector of table names.
41-
pub(super) fn topological_sort(&self) -> Vec<&str> {
42+
pub fn topological_sort(&self) -> Vec<&str> {
4243
let mut num_deps = BTreeMap::new();
4344
let mut rev_deps: BTreeMap<_, Vec<_>> = BTreeMap::new();
4445
for (table, config) in self.0.iter() {

src/worker/jobs/dump_db/gen_scripts.rs renamed to crates/crates_io_database_dump/src/gen_scripts.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
use crate::configuration::{ColumnVisibility, TableConfig, VisibilityConfig};
12
use anyhow::Context;
3+
use serde::Serialize;
24
use std::{fs::File, path::Path};
3-
4-
use crate::worker::jobs::dump_db::configuration::{
5-
ColumnVisibility, TableConfig, VisibilityConfig,
6-
};
5+
use tracing::debug;
76

87
pub fn gen_scripts(export_script: &Path, import_script: &Path) -> anyhow::Result<()> {
98
let config = VisibilityConfig::get();
@@ -119,7 +118,7 @@ impl VisibilityConfig {
119118
#[cfg(test)]
120119
mod tests {
121120
use super::*;
122-
use crate::test_util::test_db_connection;
121+
use crates_io_test_db::TestDatabase;
123122
use diesel::prelude::*;
124123
use std::collections::HashSet;
125124
use std::iter::FromIterator;
@@ -128,8 +127,10 @@ mod tests {
128127
/// test database.
129128
#[test]
130129
fn check_visibility_config() {
131-
let (_test_db, conn) = &mut test_db_connection();
132-
let db_columns = HashSet::<Column>::from_iter(get_db_columns(conn));
130+
let test_db = TestDatabase::new();
131+
let mut conn = test_db.connect();
132+
133+
let db_columns = HashSet::<Column>::from_iter(get_db_columns(&mut conn));
133134
let vis_columns = VisibilityConfig::get()
134135
.0
135136
.iter()
@@ -167,6 +168,8 @@ mod tests {
167168
}
168169

169170
mod information_schema {
171+
use diesel::table;
172+
170173
table! {
171174
information_schema.columns (table_schema, table_name, column_name) {
172175
table_schema -> Text,

0 commit comments

Comments
 (0)