sqltrack.commands.setup module

sqltrack.commands.setup.setup(client: Client, scripts: Iterable[str | Path | Tuple[str, str]] = ())[source]

Execute SQL scripts to setup (or update) the database. The included base.sql script is always executed first. User-defined scripts are run in the given order.

Scripts can be loaded from files, or defined directly as tuples (name, script), where script is the SQL code to execute.

A script is never run twice. Whether a script has already been run before is determined by its base filename without any directories. The rest of the path is ignored. Thus base.sql cannot be used as filename for user-defined scripts.

Example script with timestamps, loss and accuracies for training, validation, and test phases:

BEGIN;

ALTER TABLE metrics
    ADD COLUMN train_start TIMESTAMP WITH TIME ZONE,
    ADD COLUMN train_end TIMESTAMP WITH TIME ZONE,
    ADD COLUMN train_loss FLOAT,
    ADD COLUMN train_top1 FLOAT,
    ADD COLUMN train_top5 FLOAT,
    ADD COLUMN val_start TIMESTAMP WITH TIME ZONE,
    ADD COLUMN val_end TIMESTAMP WITH TIME ZONE,
    ADD COLUMN val_loss FLOAT,
    ADD COLUMN val_top1 FLOAT,
    ADD COLUMN val_top5 FLOAT,
    ADD COLUMN test_start TIMESTAMP WITH TIME ZONE,
    ADD COLUMN test_end TIMESTAMP WITH TIME ZONE,
    ADD COLUMN test_loss FLOAT,
    ADD COLUMN test_top1 FLOAT,
    ADD COLUMN test_top5 FLOAT;

END;
Parameters:
  • client – Client to connect to the database

  • scripts – Paths to SQL scripts or tuples (name, script); executed in the given order