From e553053df969f9bc19c84df0c78a1c02789fc7ba Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 11 Nov 2021 23:28:37 -0800 Subject: [PATCH] Made rowid a reserved column, closes #10 --- README.md | 2 +- git_history/cli.py | 2 +- tests/test_git_history.py | 25 +++++++++++++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5099bf3..bd781b7 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Additional options: - `--ignore-duplicate-ids` - if a single version of a file has the same ID in it more than once, the tool will exit with an error. Use this option to ignore this and instead pick just the first of the two duplicates. - `--silent` - don't show the progress bar. -Note that `id`, `item`, `version` and `commit` are reserved column names that are used by this tool. If your data contains any of these they will be renamed to `id_`, `item_`, `version_` or `commit_` to avoid clashing with the reserved columns. +Note that `id`, `item`, `version`, `commit` and `rowid` are reserved column names that are used by this tool. If your data contains any of these they will be renamed to `id_`, `item_`, `version_`, `commit_` or `rowid_` to avoid clashing with the reserved columns. There is one exception: if you have an `id` column and use `--id id` without specifying more than one ID column, your ìd` column will be used as the item ID but will not be renamed. diff --git a/git_history/cli.py b/git_history/cli.py index 920ef91..5574022 100644 --- a/git_history/cli.py +++ b/git_history/cli.py @@ -286,7 +286,7 @@ def _hash(record): def fix_reserved_columns(item, allow_id=False, allow_banned=False): - reserved = {"item", "version", "commit"} + reserved = {"item", "version", "commit", "rowid"} banned = {"id_", "item_", "version_", "commit_"} if not allow_id: reserved.add("id") diff --git a/tests/test_git_history.py b/tests/test_git_history.py index 227d0c8..d0183d7 100644 --- a/tests/test_git_history.py +++ b/tests/test_git_history.py @@ -28,8 +28,20 @@ def repo(tmpdir): (repo_dir / "items-with-reserved-columns.json").write_text( json.dumps( [ - {"id": 1, "item": "Gin", "version": "v1", "commit": "commit1"}, - {"id": 2, "item": "Tonic", "version": "v1", "commit": "commit1"}, + { + "id": 1, + "item": "Gin", + "version": "v1", + "commit": "commit1", + "rowid": 5, + }, + { + "id": 2, + "item": "Tonic", + "version": "v1", + "commit": "commit1", + "rowid": 6, + }, ] ), "utf-8", @@ -218,7 +230,8 @@ def test_file_with_reserved_columns(repo, tmpdir): " [id] TEXT PRIMARY KEY,\n" " [item_] TEXT,\n" " [version_] TEXT,\n" - " [commit_] TEXT\n" + " [commit_] TEXT,\n" + " [rowid_] INTEGER\n" ");\n" "CREATE TABLE [item_versions] (\n" " [item] TEXT REFERENCES [items]([id]),\n" @@ -228,6 +241,7 @@ def test_file_with_reserved_columns(repo, tmpdir): " [item_] TEXT,\n" " [version_] TEXT,\n" " [commit_] TEXT,\n" + " [rowid_] INTEGER,\n" " PRIMARY KEY ([item], [version])\n" ");" ) @@ -237,6 +251,7 @@ def test_file_with_reserved_columns(repo, tmpdir): assert item_versions == [ {"id": 1, "item_": "Gin", "version_": "v1", "commit_": "commit1"}, {"id": 2, "item_": "Tonic", "version_": "v1", "commit_": "commit1"}, + {"id": 1, "item_": "Gin", "version_": "v1", "commit_": "commit1"}, {"id": 2, "item_": "Tonic 2", "version_": "v1", "commit_": "commit1"}, {"id": 3, "item_": "Rum", "version_": "v1", "commit_": "commit1"}, ] @@ -275,7 +290,8 @@ def test_more_than_one_id_makes_id_reserved(repo, tmpdir): " [id_] INTEGER,\n" " [item_] TEXT,\n" " [version_] TEXT,\n" - " [commit_] TEXT\n" + " [commit_] TEXT,\n" + " [rowid_] INTEGER\n" ");\n" "CREATE TABLE [item_versions] (\n" " [item] TEXT REFERENCES [items]([id]),\n" @@ -285,6 +301,7 @@ def test_more_than_one_id_makes_id_reserved(repo, tmpdir): " [item_] TEXT,\n" " [version_] TEXT,\n" " [commit_] TEXT,\n" + " [rowid_] INTEGER,\n" " PRIMARY KEY ([item], [version])\n" ");" )