diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c3d640d..16d8c21 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -261,11 +261,14 @@ jobs: # test ungathered_v2 default name upgrade-db .github/workflows/log_ungathered_v2.sqlite + # utilize nogather flag to ensure schema is from modification + # instead of gathering, which builds schema v3 runalyzer .github/workflows/log_ungathered_v2_upgrade.sqlite -c 'db.print_cursor(db.q("select * from warnings"))' --nogather runalyzer .github/workflows/log_ungathered_v2_upgrade.sqlite -c 'print([l[0] for l in q("select * from warnings").description])' --nogather runalyzer .github/workflows/log_ungathered_v2_upgrade.sqlite -c 'print([l[0] for l in q("select * from logging").description])' --nogather runalyzer .github/workflows/log_ungathered_v2_upgrade.sqlite -c 'assert "unixtime" in [l[0] for l in q("select * from warnings").description]' --nogather runalyzer .github/workflows/log_ungathered_v2_upgrade.sqlite -c 'assert "rank" in [l[0] for l in q("select * from warnings").description]' --nogather + runalyzer .github/workflows/log_ungathered_v2_upgrade.sqlite -c 'assert [l[0] for l in q("select schema_version")][0] == 3' # test gathered_v2 default name @@ -276,6 +279,7 @@ jobs: runalyzer .github/workflows/log_gathered_v2_upgrade.sqlite -c 'print([l[0] for l in q("select * from logging").description])' --nogather runalyzer .github/workflows/log_gathered_v2_upgrade.sqlite -c 'assert "unixtime" in [l[0] for l in q("select * from warnings").description]' --nogather runalyzer .github/workflows/log_gathered_v2_upgrade.sqlite -c 'assert "rank" in [l[0] for l in q("select * from warnings").description]' --nogather + runalyzer .github/workflows/log_gathered_v2_upgrade.sqlite -c 'assert [l[0] for l in q("select schema_version")][0] == 3' # test gathered custom name @@ -286,6 +290,7 @@ jobs: runalyzer .github/workflows/log_gathered_v2_new.sqlite -c 'print([l[0] for l in q("select * from logging").description])' --nogather runalyzer .github/workflows/log_gathered_v2_new.sqlite -c 'assert "unixtime" in [l[0] for l in q("select * from warnings").description]' --nogather runalyzer .github/workflows/log_gathered_v2_new.sqlite -c 'assert "rank" in [l[0] for l in q("select * from warnings").description]' --nogather + runalyzer .github/workflows/log_gathered_v2_new.sqlite -c 'assert [l[0] for l in q("select schema_version")][0] == 3' - name: Upgrade V3 to V3 # Tests upgrades on current version for stability and allows users @@ -296,11 +301,14 @@ jobs: # test ungathered_v3 default name upgrade-db .github/workflows/log_ungathered_v3.sqlite + # utilize nogather flag to ensure schema is from modification + # instead of gathering, which builds schema v3 runalyzer .github/workflows/log_ungathered_v3_upgrade.sqlite -c 'db.print_cursor(db.q("select * from warnings"))' --nogather runalyzer .github/workflows/log_ungathered_v3_upgrade.sqlite -c 'print([l[0] for l in q("select * from warnings").description])' --nogather runalyzer .github/workflows/log_ungathered_v3_upgrade.sqlite -c 'print([l[0] for l in q("select * from logging").description])' --nogather runalyzer .github/workflows/log_ungathered_v3_upgrade.sqlite -c 'assert "unixtime" in [l[0] for l in q("select * from warnings").description]' --nogather runalyzer .github/workflows/log_ungathered_v3_upgrade.sqlite -c 'assert "rank" in [l[0] for l in q("select * from warnings").description]' --nogather + runalyzer .github/workflows/log_ungathered_v3_upgrade.sqlite -c 'assert [l[0] for l in q("select schema_version")][0] == 3' # test gathered_v3 default name upgrade-db .github/workflows/log_gathered_v3.sqlite @@ -310,6 +318,7 @@ jobs: runalyzer .github/workflows/log_gathered_v3_upgrade.sqlite -c 'print([l[0] for l in q("select * from logging").description])' --nogather runalyzer .github/workflows/log_gathered_v3_upgrade.sqlite -c 'assert "unixtime" in [l[0] for l in q("select * from warnings").description]' --nogather runalyzer .github/workflows/log_gathered_v3_upgrade.sqlite -c 'assert "rank" in [l[0] for l in q("select * from warnings").description]' --nogather + runalyzer .github/workflows/log_gathered_v3_upgrade.sqlite -c 'assert [l[0] for l in q("select schema_version")][0] == 3' # test gathered custom name upgrade-db .github/workflows/log_gathered_v3.sqlite --suffix '_new' @@ -319,3 +328,4 @@ jobs: runalyzer .github/workflows/log_gathered_v3_new.sqlite -c 'print([l[0] for l in q("select * from logging").description])' --nogather runalyzer .github/workflows/log_gathered_v3_new.sqlite -c 'assert "unixtime" in [l[0] for l in q("select * from warnings").description]' --nogather runalyzer .github/workflows/log_gathered_v3_new.sqlite -c 'assert "rank" in [l[0] for l in q("select * from warnings").description]' --nogather + runalyzer .github/workflows/log_gathered_v3_new.sqlite -c 'assert [l[0] for l in q("select schema_version")][0] == 3' diff --git a/bin/runalyzer b/bin/runalyzer index e21dc30..58849e3 100755 --- a/bin/runalyzer +++ b/bin/runalyzer @@ -17,7 +17,10 @@ def main() -> None: parser.add_argument("--script", type=str, help="script file to read") parser.add_argument("--nogather", action="store_true", - help="do not automatically gather files") + help=""" + Do not automatically gather files. Primarily + used internally to view database schema. + """) args = parser.parse_args() from logpyle.runalyzer import make_runalyzer_symbols, make_wrapped_db diff --git a/logpyle/runalyzer.py b/logpyle/runalyzer.py index 724dc36..00782f8 100644 --- a/logpyle/runalyzer.py +++ b/logpyle/runalyzer.py @@ -533,7 +533,7 @@ def make_wrapped_db( if gather: db = auto_gather(filenames) else: - assert len(filenames) == 1, "Enable autogather to support multiple infiles" + assert len(filenames) == 1, "Enable autogather to support multiple input files" db = sqlite3.connect(filenames[0]) db.create_aggregate("stddev", 1, StdDeviation) # type: ignore[arg-type] db.create_aggregate("var", 1, Variance) diff --git a/logpyle/upgrade_db.py b/logpyle/upgrade_db.py index 3ac2b54..31341e8 100644 --- a/logpyle/upgrade_db.py +++ b/logpyle/upgrade_db.py @@ -2,6 +2,9 @@ Database Upgrade Functions -------------------------------- .. autofunction:: upgrade_db +.. note:: + Currently, upgrades all schema versions to version 3. + Upgrading from version 1 is untested. .. list-table:: Overview of known changes between schema versions :widths: 25 25 50 @@ -71,6 +74,16 @@ def upgrade_conn(conn: sqlite3.Connection) -> sqlite3.Connection: ADD run_id integer; """) + from pickle import dumps + schema_version = 3 + value = bytes(dumps(schema_version)) + if gathered: + conn.execute("UPDATE runs SET schema_version=3") + # conn.execute("UPDATE runs SET schema_version = ?", (value,)) + else: + # conn.execute("UPDATE constants SET value=3 WHERE name='schema_version'") + conn.execute("UPDATE constants SET value = ? WHERE name='schema_version'", (value,)) + return conn