Migrate the scouting database to postgres
The existing database is sqlite3. That is not usable by Tableau which
is the visualization tool we use. Tableau also appears incapable of
scraping, say, JSON from our scouting app.
This patch migrates our application to use postgres instead of
sqlite3. That database will be accessible by Tableau.
I created a `testdb_server` application that sets up postgres in the
linux-sandbox in a bazel test. This is useful in the various tests
that we run on the scouting application.
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I9cd260f8998b9607e1e3229ab70f243cdded5ec5
diff --git a/scouting/testing/scouting_test_servers.py b/scouting/testing/scouting_test_servers.py
index 3447815..7a0d3c5 100644
--- a/scouting/testing/scouting_test_servers.py
+++ b/scouting/testing/scouting_test_servers.py
@@ -3,6 +3,7 @@
The servers are:
- The fake TBA server
- The actual web server
+ - The postgres database
"""
import argparse
@@ -29,6 +30,15 @@
connection.close()
time.sleep(0.01)
+def create_db_config(tmpdir: Path) -> Path:
+ config = tmpdir / "db_config.json"
+ config.write_text(json.dumps({
+ "username": "test",
+ "password": "password",
+ "port": 5432,
+ }))
+ return config
+
def create_tba_config(tmpdir: Path) -> Path:
# Configure the scouting webserver to scrape data from our fake TBA
# server.
@@ -54,13 +64,19 @@
self.tmpdir = Path(os.environ["TEST_TMPDIR"]) / "servers"
self.tmpdir.mkdir(exist_ok=True)
- db_path = self.tmpdir / "scouting.db"
+ db_config = create_db_config(self.tmpdir)
tba_config = create_tba_config(self.tmpdir)
+ # The database needs to be running and addressable before the scouting
+ # webserver can start.
+ self.testdb_server = subprocess.Popen(
+ ["scouting/db/testdb_server/testdb_server_/testdb_server"])
+ wait_for_server(5432)
+
self.webserver = subprocess.Popen([
"scouting/scouting",
f"--port={port}",
- f"--database={db_path}",
+ f"--db_config={db_config}",
f"--tba_config={tba_config}",
])
@@ -78,7 +94,7 @@
def stop(self):
"""Stops the services needed for testing the scouting app."""
- servers = (self.webserver, self.fake_tba_api)
+ servers = (self.webserver, self.testdb_server, self.fake_tba_api)
for server in servers:
server.terminate()
for server in servers: