Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions databases/curriculum/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ CDB_PORT=13306
# Root SQL user: `openssl rand -hex 32`. Applies on an empty volume only.
CDB_ROOT_PASSWORD=
PLATFORM_NETWORK=platform
CDB_MIGRATOR_URL=mysql://root:$CDB_ROOT_PASSWORD@127.0.0.1:13306/curriculum
9 changes: 5 additions & 4 deletions databases/curriculum/config/server.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Dolt sql-server config. Mounted read-only; changes apply on restart.
# Info level: debug logs routine SQL and results, which include private answer keys.
# Info level: debug logs routine queries and results, which include private answer keys.
log_level: info
log_format: json
behavior:
Expand All @@ -14,14 +14,15 @@ listener:
max_connections: 50
read_timeout_millis: 300000
write_timeout_millis: 300000
# Explicit paths, all on the one volume, so a stopped-volume copy is a complete backup.
# Explicit paths, all on the one volume, so a copy of the volume is a complete backup.
data_dir: /var/lib/dolt/databases
cfg_dir: /var/lib/dolt/config
privilege_file: /var/lib/dolt/config/privileges.db
branch_control_file: /var/lib/dolt/config/branch_control.db
system_variables:
# Points at a directory that does not exist: no LOAD DATA / SELECT INTO OUTFILE.
secure_file_priv: /var/lib/dolt/disabled-file-import
# Points at a directory that does not exist, stopping LOAD DATA / SELECT INTO OUTFILE queries.
# We need to pass a directory because dolt does not pass NULL to MySQL.
secure_file_priv: /directory/that/does/not/exist
local_infile: false
dolt_allow_commit_conflicts: 0
dolt_force_transaction_commit: 0
49 changes: 12 additions & 37 deletions databases/curriculum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ pub(crate) mod testing {
.ok()
.filter(|v| !v.is_empty())
else {
eprintln!("CDB_MIGRATOR_URL not set: skipping Dolt test");
return Ok(None);
panic!(
"CDB_MIGRATOR_URL must be set for testing. Hint: copy the value from .env.example into .env"
);
};
let options = MySqlConnectOptions::from_str(&url)?;
let name = format!("cdb_test_{}", uuid::Uuid::new_v4().simple());
Expand Down Expand Up @@ -414,19 +415,9 @@ mod tests {
Ok(count > 0)
}

#[test]
fn migration_versions_are_unique() {
let mut versions = up_versions(&migrator());
let count = versions.len();
versions.dedup();
assert_eq!(versions.len(), count);
}

#[tokio::test]
async fn each_migration_is_one_dolt_commit_on_dev() -> Result<(), Error> {
let Some(db) = TestDb::new().await? else {
return Ok(());
};
let db = TestDb::new().await?.unwrap();
let expected = up_versions(&migrator());

assert_eq!(db.setup().await?, expected);
Expand Down Expand Up @@ -463,9 +454,7 @@ mod tests {

#[tokio::test]
async fn rerun_is_a_no_op() -> Result<(), Error> {
let Some(db) = TestDb::new().await? else {
return Ok(());
};
let db = TestDb::new().await?.unwrap();
db.setup().await?;
let before = db.hash_of(DEV).await?;

Expand All @@ -479,9 +468,7 @@ mod tests {
/// Two runs at once: the named lock serializes them.
#[tokio::test]
async fn concurrent_runs_apply_each_migration_once() -> Result<(), Error> {
let Some(db) = TestDb::new().await? else {
return Ok(());
};
let db = TestDb::new().await?.unwrap();
let migrator = migrator();

let (a, b) = tokio::join!(db.migrate_with(&migrator), db.migrate_with(&migrator));
Expand All @@ -496,9 +483,7 @@ mod tests {

#[tokio::test]
async fn older_bundle_runs_against_newer_migrations() -> Result<(), Error> {
let Some(db) = TestDb::new().await? else {
return Ok(());
};
let db = TestDb::new().await?.unwrap();
db.setup().await?;
apply_newer_migration(&db).await?;

Expand All @@ -509,9 +494,7 @@ mod tests {

#[tokio::test]
async fn strict_migrator_rejects_newer_migrations() -> Result<(), Error> {
let Some(db) = TestDb::new().await? else {
return Ok(());
};
let db = TestDb::new().await?.unwrap();
db.setup().await?;
apply_newer_migration(&db).await?;
let mut migrator = migrator();
Expand All @@ -531,9 +514,7 @@ mod tests {

#[tokio::test]
async fn rejects_changed_migration() -> Result<(), Error> {
let Some(db) = TestDb::new().await? else {
return Ok(());
};
let db = TestDb::new().await?.unwrap();
db.setup().await?;
db.commit_on_dev("UPDATE _sqlx_migrations SET checksum = X'00' WHERE version = 1")
.await?;
Expand All @@ -553,9 +534,7 @@ mod tests {
/// The failed migration stays on the scratch branch, half applied; the next run starts over.
#[tokio::test]
async fn failed_migration_leaves_dev_untouched() -> Result<(), Error> {
let Some(db) = TestDb::new().await? else {
return Ok(());
};
let db = TestDb::new().await?.unwrap();
db.setup().await?;
let before = db.hash_of(DEV).await?;

Expand All @@ -578,9 +557,7 @@ mod tests {
/// eDd commits content to `dev` while migrations apply: the run ends in a merge commit with both.
#[tokio::test]
async fn merges_when_dev_moved() -> Result<(), Error> {
let Some(db) = TestDb::new().await? else {
return Ok(());
};
let db = TestDb::new().await?.unwrap();
let migrator = migrator();
let mut conn = db.connect().await?;

Expand Down Expand Up @@ -616,9 +593,7 @@ mod tests {

#[tokio::test]
async fn never_touches_other_branches() -> Result<(), Error> {
let Some(db) = TestDb::new().await? else {
return Ok(());
};
let db = TestDb::new().await?.unwrap();
let mut conn = db.connect().await?;
sqlx::query("CALL DOLT_BRANCH('prd', ?)")
.bind(DEV)
Expand Down