Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature idea: --always columns #61

Open
simonw opened this issue Nov 20, 2022 · 1 comment
Open

Feature idea: --always columns #61

simonw opened this issue Nov 20, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Nov 20, 2022

Sometimes you might find that you want to record a value every time for a column even while using the mechanism which uses null for values that have not changed - for this project for example: https://github.com/simonw/scrape-instances-social

Idea: a --always colname option which turns this on (and can be applied multiple times).

@simonw simonw added the enhancement New feature or request label Nov 20, 2022
@simonw
Copy link
Owner Author

simonw commented Nov 20, 2022

Quick prototype of this feature - not fully tested, may not cover all the edge-cases:

diff --git a/git_history/cli.py b/git_history/cli.py
index f3a4c40..975da28 100644
--- a/git_history/cli.py
+++ b/git_history/cli.py
@@ -79,6 +79,13 @@ def cli():
     is_flag=True,
     help="Record full copies in the item_version table, not just the columns that changed since the previous version",
 )
+@click.option(
+    "always_columns",
+    "-a",
+    "--always",
+    multiple=True,
+    help="Record this column in the item_version table even if it has not changed",
+)
 @click.option("ignore", "--ignore", multiple=True, help="Columns to ignore")
 @click.option(
     "csv_",
@@ -130,11 +137,12 @@ def file(
     namespace,
     branch,
     ids,
-    ignore,
     start_at,
     start_after,
     skip_hashes,
     full_versions,
+    always_columns,
+    ignore,
     csv_,
     dialect,
     convert,
@@ -306,7 +316,7 @@ def file(
                     updated_values = {}
                     updated_columns = set()
 
-                    if item_is_new or item_full_hash_has_changed:
+                    if item_is_new or item_full_hash_has_changed or always_columns:
                         # TODO: delete-me
                         previous_item_hash = item_id_to_last_full_hash.get(item_id)
 
@@ -349,7 +359,9 @@ def file(
                                     if column in RESERVED_SET:
                                         continue
                                     value = item_flattened.get(column)
-                                    if value != previous_item.get(column):
+                                    if column in always_columns or str(value) != str(
+                                        previous_item.get(column)
+                                    ):
                                         updated_values[column] = value
                                         updated_columns.add(column)
                             else:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant