Skip to content

Commit

Permalink
Drop old schema scheme (#1223)
Browse files Browse the repository at this point in the history
Completes the change initiated in #1221:

 - Delete `db/schema.sql`
 - Stop bundling `db/schema.sql` into container images
 - remove `janus_cli write-schema` subcommand
 - Stop publishing `db/schema.sql` to artifact store
 - Stop publishing migration scripts to per-minor version directory

Part of #30
  • Loading branch information
tgeoghegan authored Apr 27, 2023
1 parent 41fee02 commit 848240e
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 276 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/publish-sql-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ jobs:
id: get_version
run: |
VERSION=${GITHUB_REF/refs\/tags\//}
echo VERSION=${VERSION} >> $GITHUB_OUTPUT
echo "MINOR_VERSION=$(echo ${VERSION} | awk -F'.' '{if (NF != 3) {exit 1}; printf "%s.%s", $1, $2}')" >> $GITHUB_OUTPUT
- name: "Upload schema file(s)"
run: |-
gcloud alpha storage cp --recursive \
db \
gs://janus-artifacts-sql-schemas/${{ steps.get_version.outputs.VERSION }}/
gcloud alpha storage cp --recursive \
db \
gs://janus-artifacts-sql-schemas/${{ steps.get_version.outputs.MINOR_VERSION }}/
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry --mount=type=cache,targe

FROM alpine:3.17.3
ARG BINARY=aggregator
COPY --from=builder /src/db/schema.sql /db/schema.sql
COPY --from=builder /$BINARY /$BINARY
# Store the build argument in an environment variable so we can reference it
# from the ENTRYPOINT at runtime.
Expand Down
51 changes: 1 addition & 50 deletions aggregator/src/bin/janus_cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::{anyhow, Context, Result};
use base64::{engine::general_purpose::STANDARD_NO_PAD, Engine};
use clap::Parser;
use deadpool_postgres::Pool;
use janus_aggregator::{
binary_utils::{database_pool, datastore, read_config, CommonBinaryOptions},
config::{BinaryConfig, CommonConfig},
Expand All @@ -24,8 +23,6 @@ use std::{
use tokio::fs;
use tracing::{debug, info};

static SCHEMA: &str = include_str!("../../../db/schema.sql");

#[tokio::main]
async fn main() -> Result<()> {
// Parse options, then read & parse config.
Expand All @@ -38,12 +35,6 @@ async fn main() -> Result<()> {

#[derive(Debug, Parser)]
enum Command {
/// Write the Janus database schema to the database.
WriteSchema {
#[clap(flatten)]
common_options: CommonBinaryOptions,
},

/// Write a set of tasks identified in a file to the datastore.
ProvisionTasks {
#[clap(flatten)]
Expand Down Expand Up @@ -81,17 +72,6 @@ impl Command {
// generally create the command's dependencies based on options/config, then call another
// function with the main command logic.
match self {
Command::WriteSchema { common_options } => {
let config: Config = read_config(common_options)?;
install_tracing_and_metrics_handlers(config.common_config())?;
let pool = database_pool(
&config.common_config.database,
common_options.database_password.as_deref(),
)
.await?;
write_schema(&pool).await
}

Command::ProvisionTasks {
common_options,
kubernetes_secret_options,
Expand Down Expand Up @@ -164,16 +144,6 @@ fn install_tracing_and_metrics_handlers(config: &CommonConfig) -> Result<()> {
Ok(())
}

async fn write_schema(pool: &Pool) -> Result<()> {
info!("Writing database schema");
let db_client = pool.get().await.context("couldn't get database client")?;
db_client
.batch_execute(SCHEMA)
.await
.context("couldn't write database schema")?;
Ok(())
}

async fn provision_tasks<C: Clock>(
datastore: &Datastore<C>,
tasks_file: &Path,
Expand Down Expand Up @@ -398,7 +368,7 @@ mod tests {
generate_db_config, generate_metrics_config, generate_trace_config, roundtrip_encoding,
},
config::CommonConfig,
datastore::test_util::{ephemeral_datastore, ephemeral_db_handle},
datastore::test_util::ephemeral_datastore,
task::{test_util::TaskBuilder, QueryType, Task},
};
use janus_core::{task::VdafInstance, test_util::kubernetes, time::RealClock};
Expand Down Expand Up @@ -480,25 +450,6 @@ mod tests {
.unwrap_err();
}

#[tokio::test]
async fn write_schema() {
let db_handle = ephemeral_db_handle();
let ds = db_handle.datastore(RealClock::default());

// Verify that the query we will run later returns an error if there is no database schema written.
ds.run_tx(|tx| Box::pin(async move { tx.get_tasks().await }))
.await
.unwrap_err();

// Run the program logic.
super::write_schema(&db_handle.pool()).await.unwrap();

// Verify that the schema was written (by running a query that would fail if it weren't).
ds.run_tx(|tx| Box::pin(async move { tx.get_tasks().await }))
.await
.unwrap();
}

fn task_hashmap_from_slice(tasks: Vec<Task>) -> HashMap<TaskId, Task> {
tasks.into_iter().map(|task| (*task.id(), task)).collect()
}
Expand Down
Loading

0 comments on commit 848240e

Please sign in to comment.