Skip to content

Commit

Permalink
Made rowid a reserved column, closes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Nov 12, 2021
1 parent 55c95eb commit e553053
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion git_history/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
25 changes: 21 additions & 4 deletions tests/test_git_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand All @@ -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"
");"
)
Expand All @@ -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"},
]
Expand Down Expand Up @@ -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"
Expand All @@ -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"
");"
)
Expand Down

0 comments on commit e553053

Please sign in to comment.