Skip to content

Commit 3b90189

Browse files
authored
Merge pull request #1823 from eth3lbert/fix-sqlite2pg
Fix schema issue in sqlite-to-postgres
2 parents 810e7ce + c052b29 commit 3b90189

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

database/src/bin/sqlite-to-postgres.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ struct Error;
218218

219219
#[derive(Serialize)]
220220
struct ErrorRow<'a> {
221-
benchmark: &'a str,
222221
aid: i32,
222+
benchmark: &'a str,
223223
error: Nullable<&'a str>,
224224
}
225225

@@ -229,7 +229,7 @@ impl Table for Error {
229229
}
230230

231231
fn sqlite_attributes() -> &'static str {
232-
"benchmark, aid, error"
232+
"aid, benchmark, error"
233233
}
234234

235235
fn postgres_generated_id_attribute() -> Option<&'static str> {
@@ -239,8 +239,8 @@ impl Table for Error {
239239
fn write_postgres_csv_row<W: Write>(writer: &mut csv::Writer<W>, row: &rusqlite::Row) {
240240
writer
241241
.serialize(ErrorRow {
242-
benchmark: row.get_ref(0).unwrap().as_str().unwrap(),
243-
aid: row.get(1).unwrap(),
242+
aid: row.get(0).unwrap(),
243+
benchmark: row.get_ref(1).unwrap().as_str().unwrap(),
244244
error: row.get_ref(2).unwrap().try_into().unwrap(),
245245
})
246246
.unwrap();
@@ -333,6 +333,7 @@ struct PullRequestBuildRow<'a> {
333333
include: Nullable<&'a str>,
334334
exclude: Nullable<&'a str>,
335335
runs: Nullable<i32>,
336+
commit_date: Nullable<DateTime<Utc>>,
336337
}
337338

338339
impl Table for PullRequestBuild {
@@ -341,7 +342,7 @@ impl Table for PullRequestBuild {
341342
}
342343

343344
fn sqlite_attributes() -> &'static str {
344-
"bors_sha, pr, parent_sha, complete, requested, include, exclude, runs"
345+
"bors_sha, pr, parent_sha, complete, requested, include, exclude, runs, commit_date"
345346
}
346347

347348
fn postgres_generated_id_attribute() -> Option<&'static str> {
@@ -350,6 +351,7 @@ impl Table for PullRequestBuild {
350351

351352
fn write_postgres_csv_row<W: Write>(writer: &mut csv::Writer<W>, row: &rusqlite::Row) {
352353
let requested: Option<i64> = row.get(4).unwrap();
354+
let commit_date: Option<i64> = row.get(8).unwrap();
353355

354356
writer
355357
.serialize(PullRequestBuildRow {
@@ -363,6 +365,9 @@ impl Table for PullRequestBuild {
363365
include: row.get_ref(5).unwrap().try_into().unwrap(),
364366
exclude: row.get_ref(6).unwrap().try_into().unwrap(),
365367
runs: row.get(7).unwrap(),
368+
commit_date: Nullable(
369+
commit_date.map(|seconds| Utc.timestamp_opt(seconds, 0).unwrap()),
370+
),
366371
})
367372
.unwrap();
368373
}

0 commit comments

Comments
 (0)