Repository navigation
Conversation
The comment said that Cli reads its URL, user and password from Db so that the settings have one source. That is a design decision, and the code shows it: each override returns the Db value of the same name. The comment also said that the chapters that demonstrate raw JDBC get their connection from Db.withConnection. That is no longer true. No code in the repository calls Db.withConnection or Db.connect; the Tour opens its own connection to its container.
A test source has no public API, so it carries no scaladoc. The scaladoc on the object said how to run the Tour and why the switch is the TOUR_NOPAUSE environment variable and not an argument or a -D property. The example block in build.sbt gives the command, and ADR 0005 records why it is an environment variable. The rest described what the chapters print, and the chapters print it. The scaladoc on the container said that the Tour lives in src/test for testcontainers and that it asserts nothing. The example block in build.sbt says the same. The scaladoc on databaseSchema said that naming the schema makes each pooled connection create it and set search_path to it. DbAppSuite pins that: "databaseSchema alone puts the tables in that schema, creating it, and status agrees".
The scaladoc said that the Tour works in a Postgres schema of its own, so that it disturbs nothing else. The name TourSchema now says whose schema it is, and the Tour prints the reason when it starts: "Working in schema eezo_tour ..., so nothing else is touched."
The comment justified "if not exists" on the create that follows the drop in prepare. The pool of DbApp fills in the background while boot runs, and each new connection creates the schema that databaseSchema names when it is missing. So the pool can create eezo_tour between the drop and the create, and a plain create would fail. The function name createTourSchemaRacingThePool now states that constraint. This is a workaround, and the comment hid it. The Tour starts a new container on each run, so the drop can only remove a schema the pool made. The behaviour stays as it is in this change.
Three markers cut Tour.scala into chapters, plumbing and output. The markers go. They show that the file holds three things: the eleven chapters of the program, the database steps the chapters share (connect, prepare, finish, dropAll, attempt, exec), and the console output helpers (header, chapter, note, sql, ok, warn, rejected, blank, pause). A later change can move the output helpers to a file of their own.
… is formatted The gate checks the prose of each changed file, and it read the two sbt commands in the scaladoc of Cli as prose with a double hyphen. The commands are now a code block, one command on each line, which is what the old line meant. scalafmt also formats the rest of Cli.scala, which was not formatted on dev; the example project is not in the root aggregate, so the format step of the gate does not see it.
…e them, not their history Public scaladoc tells a user how to use the member. The history of Cli, the reason Db is not part of the db module, and the reason AccessProbe exists are not usage, so they go. Db.scala is formatted with scalafmt.
A name says what the function does. It creates the schema of the Tour.
… is TourDatabaseSchema
…t the database that Db names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The maintainer decided that a comment is allowed in one place only: scaladoc on a member of the public API, in main code, and that scaladoc tells a user how to use the member, not its history or the reason for a design. Every other comment is refused, and every comment in a test source too. The reason a comment carried moves to a test or an ADR, or it is deleted, so that the code speaks for itself and no comment can hide a workaround.
This pull request applies the decision to
modules/example, one module at a time.What
Findings of the rule, counted with a syntactic lint rule that is not in the build yet:
src/main)src/test)The lint rule cannot see history or rationale in public scaladoc. The public scaladoc of
CliandDbheld some, so it now says only how to use each object.No behaviour changes. The changes are deletions, one rename (
Schema0is nowTourDatabaseSchema), the deletion ofAccessProbe, a scaladoc code block for the run commands ofCli, atourcommand alias, one new suite inmodules/db, and scalafmt onCli.scalaandDb.scala, which were not formatted ondev.This pull request is wider than
modules/example:modules/db/src/test/scala/outside/OneImportFromOutsideEezoSuite.scalais new. It is the home of the guard thatAccessProbeclaimed to be (see below).build.sbtgets one line,addCommandAlias("tour", "example/Test/runMain example.Tour"), beside theexampleblock. No comment ofbuild.sbtchanges.modules/examplehas no test framework, and this pull request does not add one. So no reason in it could become a test of the module; each reason that needed one has a home elsewhere or is listed under Candidate issues.Where each reason went
Cli.scala:18Dbalready reads these, andDb.withConnectionis still how the chapters that demonstrate raw JDBC get a connection."Dbvalue of the same name. The second half was false: nothing callsDb.withConnection.Cli.scala:5, public scaladocdesign/cli.md§3 named it the specification ... That port happened."dbcommands against the database thatDbnames, and how.Db.scala:5, public scaladocdbmodule: every entry point there takes aConnection..."DbInit.databasenow builds the pool fromdatabaseUrl. The scaladoc now names the three environment variables and the defaults.AccessProbe.scala:6, public scaladocio.eezo.db.Exportsand the inline entry points from outsideio.eezo"outside.OneImportFromOutsideEezoSuiteinmodules/db, andAccessProbeis deleted. See "TheAccessProbeguard".Tour.scala:18-Dproperty"TOUR_NOPAUSEinstead of--no-pause". The run command: the aliassbt tourinbuild.sbt, which is code. The rest restated what the chapters print.Tour.scala:32src/testfor the container rather than because it is a test"src/testsurvives only in the comment of theexampleblock inbuild.sbt, which is not a home; see Candidate issues 4.Tour.scala:51search_pathto it"dbmoduleDbAppSuitetest "databaseSchema alone puts the tables in that schema, creating it, and status agrees", anddocs/how-to/configure-the-database.md.Tour.scala:84Tour.scala:374Tour.scala:376TourDatabaseSchemasays which value it is: the one thatdatabaseSchemareturns.Tour.scala:398if not exists: the pool fills in the background while this runs, and each new connection creates the schema ... maybe between the drop and here."Tour.scala:450The lint rule counts each line of a comment, so the two line comments at
Cli.scala:18and the two atTour.scala:398give four findings for two rows.The
AccessProbeguardThe deleted scaladoc said that
AccessProbewas "the only thing that exercisesio.eezo.db.Exportsand the inline entry points from outsideio.eezo". An earlier version of this body repeated that claim. It was partly stale:transactandreadare already used from packages outsideio.eezobyexamples/shop,examples/blogandexamples/reminders, and the gate compiles the examples build. So for them the claim was false.TxandDB: no source outsideio.eezowroteusing Txorusing DBexceptAccessProbe.CapabilitySuitewritesusing Tx, but inpackage io.eezo.db, where the alias is in scope without the export.modules/example(not in the root aggregate, no step inbin/gateor CI). So this guard never ran in CI.The guard now lives in
modules/db/src/test/scala/outside/OneImportFromOutsideEezoSuite.scala, inpackage outside. It importsio.eezo.db.*andio.eezo.db.Scopes.*, declares one method that takesusing Txand one that takesusing DB, and calls them insidetransactandreadagainst the suite Postgres, as the otherDbSuitesuites do. The gate compiles and runs it.It is a guard: with
Exports.scalachanged by hand toexport io.eezo.db.capability.DBplusprivate[eezo] type Tx = io.eezo.db.capability.Tx,bin/fast 'db/testOnly outside.OneImportFromOutsideEezoSuite'fails withNot found: type TxatOneImportFromOutsideEezoSuite.scala:9:30, and with no other error. WithExports.scalarestored, it passes, 2 tests.AccessProbeis deleted: no source, build file or doc names it (grep of*.scala,*.sbtand*.md).Workarounds found
Tour.preparedropseezo_tour, then runscreate schema if not exists, thenset search_path, all on the Tour's own connection fromDriverManager.DbApppool starts empty and fills in the background, so whenprepareruns no pool connection has to exist yet, and the schema can be missing.if not existsdoes not settle the race with the pool. When a pool connection and the Tour both find the schema missing, the loser fails on the catalog's unique index.DbInit.enterSchemasays so in its scaladoc and catchesunique_violation(23505) andduplicate_schema(42P06) for that reason. The Tour's create has no such catch, so the Tour can still fail inprepare.The behaviour of the Tour is not changed here. See Candidate issues 3.
Files to split
None. The three markers of
Tour.scaladivided helpers of one program: the eleven chapters, the database steps they share, and the console output helpers (header,chapter,note,sql,ok,warn,rejected,blank,pause). An earlier version of this body listed the file to split. The independent evaluation of this pull request disagrees, and this body now follows it: the output helpers are about 30 lines, only the Tour uses them, andpausereads the Tour'svar paused, so a split must move that state or pass it. They are one program and its private vocabulary, not two different things, and a split adds a file and a package private surface for no reader. If the owner reads the rule as written ("When the marker divided two different things, the file is split"), the split is a follow up that moves statements.Candidate issues
Each one can be pasted as an issue. None is opened by this pull request.
1.
Db.connectandDb.withConnectioninmodules/examplehave no callermodules/example/src/main/scala/example/Db.scala,connectandwithConnection.git grep -n "Db\.connect\|withConnection"showswithConnectiononly at its definition, and no caller ofDb.connect;connect()is called only insidewithConnection(the Tour has its own privateconnect).Db.url,Db.userandDb.passhave callers inCli.scalaandTour.scala.2. The Tour prints a database URL that it does not connect to
Tour.prepareprintsDb.url, but the Tour connects to its own testcontainers Postgres, whose URL isdatabaseUrl. The fix is${databaseUrl}in place of${Db.url}.modules/example/src/test/scala/example/Tour.scala,prepare, the linenote(s"Working in schema ... on ${Db.url}, so nothing else is touched.").TOUR_NOPAUSE=1 sbt tour. The output saysWorking in schemaeezo_touron jdbc:postgresql://localhost:5442/eezo, while the container listens on a random port that testcontainers gives it.3.
Tour.prepareraces theDbApppool when it creates its schemapreparedropseezo_tourand runscreate schema if not existson its own connection while the pool fills in the background and each new pool connection creates the same schema.if not existsdoes not settle that race: the loser fails on the catalog's unique index, and the Tour does not catch it. The drop has no use, because the container is new on each run. One fix: delete the drop and let the pool create the schema beforeprepare(for example oneread { ... }that borrows a pool connection), and keep onlyset search_pathon the Tour's connection. Another: catch the SQL states thatDbInitcatches (23505,42P06).modules/example/src/test/scala/example/Tour.scala,prepare; compareDbInit.enterSchemaandCreatedMeanwhileinmodules/db/src/main/scala/io/eezo/db/DbInit.scala.preparenext to the scaladoc ofDbInit.enterSchema. The race is timing dependent, so a run does not show it on demand; its symptom is a Tour run that fails inpreparewith a duplicate key error onpg_namespace_nspname_index.4. The Tour could move to
src/main, which removes the need for the reason it lives insrc/testsrc/testonly becausetestcontainersPgis a test scoped dependency. That reason now survives only in a comment of theexampleblock inbuild.sbt, which the rule does not accept as a home.modules/exampleis not published and not inunidoc, so it can taketestcontainersPgwithout theTestscope, and the Tour can move tosrc/main. Then no reason is left to carry, and the Tour's usage could be public scaladoc. Thetouralias and ADR 0005's pointer to theexampleblock change with it.modules/example/src/test/scala/example/Tour.scala; theexampleblock ofbuild.sbt;testcontainersPginproject/Dependencies.scala; ADR 0005, section "The Tour readsTOUR_NOPAUSEinstead of--no-pause".exampleblock inbuild.sbt: "The Tour lives insrc/testbecause it starts its own Postgres through testcontainers, and that is a test scoped dependency."The other deleted texts need no issue: the
Clihistory and theDbrationale were history or stale, andClireading its settings fromDbis shown by the code.How to review
Cli,DbandAccessProbe, the namecreateTourSchema, and a format fix. The last five apply an independent evaluation: the newdbsuite, the deletion ofAccessProbe,createTourSchemainline again and the nameTourDatabaseSchema, theCliscaladoc, and thetouralias.OneImportFromOutsideEezoSuitenext tomodules/db/src/main/scala/io/eezo/db/Exports.scala.Tour.scala:51row, read theDbAppSuitetest inmodules/db/src/test/scala/io/eezo/db/DbAppSuite.scalaanddocs/how-to/configure-the-database.md.TOUR_NOPAUSErow, read ADR 0005. Its pointer, "theexampleblock inbuild.sbtdocuments the spelling", is still true: that comment is not changed.Tour.scalachanges no statement: only the rename.createTourSchemawas extracted in an earlier commit to carry a name that a later commit removed; it is inline again, because the three statements ofprepareread better side by side.How it was tested
local.trusthooksnocomment0.1.0-ab947017159c) onexample/Compile,example/Testand the newdbsuite: 0 findings each. Before this pull request,examplehad 2 and 9.bin/fast 'example/Test/compile': success. The root build does not aggregateexample, so the gate does not compile it; this is the compile check for the module.TOUR_NOPAUSE=1 bin/fast 'example/Test/runMain example.Tour'andTOUR_NOPAUSE=1 bin/fast tour: exit 0 each, against a new container. 11 checks passed, 6 rejections as expected, 0 warnings, the same as before the change.bin/fast 'db/testOnly outside.OneImportFromOutsideEezoSuite': 2 passed; red withTxmadeprivate[eezo]by hand, as above.bin/fast 'example/scalafmtCheckAll': success. The gate's format step does not coverexample.bin/prose-check: exit 0.bin/gate: GATE GREEN on JDK 25, at commit cd29799. The root suites passed 562 and 118 tests, the examples 17 and 25, the site 52, with 0 failures.🤖 Generated with Claude Code