From 2c32c6190c391b165000584b9d15c668000d1dcc Mon Sep 17 00:00:00 2001 From: Andrew Dickinson Date: Sun, 26 Apr 2020 08:20:24 -0400 Subject: [PATCH 1/3] Direct Alembic to ignore the sqlite_sequence table (#586) * Direct Alembic to ignore the sqlite_sequence table * Direct Alembic to ignore the sqlite_sequence table * Fix "Skipping unsupported ALTER" warning on database migration --- ihatemoney/migrations/env.py | 9 ++++- .../versions/2dcb0c0048dc_autologger.py | 38 ++++++++++++++----- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/ihatemoney/migrations/env.py b/ihatemoney/migrations/env.py index 4d4729c5..0bd0031e 100755 --- a/ihatemoney/migrations/env.py +++ b/ihatemoney/migrations/env.py @@ -41,7 +41,7 @@ def run_migrations_offline(): """ url = config.get_main_option("sqlalchemy.url") - context.configure(url=url) + context.configure(url=url, include_object=include_object) with context.begin_transaction(): context.run_migrations() @@ -75,6 +75,7 @@ def run_migrations_online(): context.configure( connection=connection, target_metadata=target_metadata, + include_object=include_object, process_revision_directives=process_revision_directives, **current_app.extensions["migrate"].configure_args ) @@ -86,6 +87,12 @@ def run_migrations_online(): connection.close() +def include_object(object, name, type_, reflected, compare_to): + if name == "sqlite_sequence": + return False + return True + + if context.is_offline_mode(): run_migrations_offline() else: diff --git a/ihatemoney/migrations/versions/2dcb0c0048dc_autologger.py b/ihatemoney/migrations/versions/2dcb0c0048dc_autologger.py index 08008355..b0b4f44c 100644 --- a/ihatemoney/migrations/versions/2dcb0c0048dc_autologger.py +++ b/ihatemoney/migrations/versions/2dcb0c0048dc_autologger.py @@ -165,21 +165,39 @@ def upgrade(): sa.Column("remote_addr", sa.String(length=50), nullable=True), sa.PrimaryKeyConstraint("id"), ) - op.add_column( - "project", - sa.Column( - "logging_preference", - sa.Enum("DISABLED", "ENABLED", "RECORD_IP", name="loggingmode"), - server_default="ENABLED", - nullable=False, - ), - ) + bind = op.get_bind() + if bind.engine.name == "sqlite": + with op.batch_alter_table("project", recreate="always") as batch_op: + batch_op.add_column( + sa.Column( + "logging_preference", + sa.Enum("DISABLED", "ENABLED", "RECORD_IP", name="loggingmode"), + server_default="ENABLED", + nullable=False, + ), + ) + else: + op.add_column( + "project", + sa.Column( + "logging_preference", + sa.Enum("DISABLED", "ENABLED", "RECORD_IP", name="loggingmode"), + server_default="ENABLED", + nullable=False, + ), + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_column("project", "logging_preference") + + bind = op.get_bind() + if bind.engine.name == "sqlite": + with op.batch_alter_table("project", recreate="always") as batch_op: + batch_op.drop_column("logging_preference") + else: + op.drop_column("project", "logging_preference") op.drop_table("transaction") op.drop_index( op.f("ix_project_version_transaction_id"), table_name="project_version" From 55419ab94ba7fee1f3f80d864f86016a9642da31 Mon Sep 17 00:00:00 2001 From: Andrew Dickinson Date: Sun, 26 Apr 2020 08:22:21 -0400 Subject: [PATCH 2/3] Add .idea/ folder to gitignore (#585) --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 927a8d64..d8d18940 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ build .env .pytest_cache ihatemoney/budget.db +.idea/ From d9dc38947c88f211f7deef2454f3a15251ed23d3 Mon Sep 17 00:00:00 2001 From: zorun Date: Sun, 26 Apr 2020 14:22:54 +0200 Subject: [PATCH 3/3] Fix string representation of bills (#584) Currently the string representation of a Bill is: " for " It is used in the History Page to describe changes that were applied to Bills, for instance: Bill "42.0 for Test" renamed to "Another Test" This is inconsistent, not easy to read, and the "for" in the middle is not translatable. To solve this issue, simply switch the string representation of a bill to its description. Co-authored-by: Baptiste Jonglez --- ihatemoney/models.py | 2 +- ihatemoney/tests/tests.py | 36 +++++++++++++----------------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/ihatemoney/models.py b/ihatemoney/models.py index dca86110..742bc8ca 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -460,7 +460,7 @@ class Bill(db.Model): return 0 def __str__(self): - return f"{self.amount} for {self.what}" + return self.what def __repr__(self): return ( diff --git a/ihatemoney/tests/tests.py b/ihatemoney/tests/tests.py index b50fae6c..62cb0485 100644 --- a/ihatemoney/tests/tests.py +++ b/ihatemoney/tests/tests.py @@ -2598,7 +2598,7 @@ class HistoryTestCase(IhatemoneyTestCase): resp = self.client.get("/demo/history") self.assertEqual(resp.status_code, 200) self.assertIn( - f"Bill {em_surround('25.0 for fromage à raclette')} added", + f"Bill {em_surround('fromage à raclette')} added", resp.data.decode("utf-8"), ) @@ -2619,26 +2619,26 @@ class HistoryTestCase(IhatemoneyTestCase): resp = self.client.get("/demo/history") self.assertEqual(resp.status_code, 200) self.assertIn( - f"Bill {em_surround('25.0 for fromage à raclette')} added", + f"Bill {em_surround('fromage à raclette')} added", resp.data.decode("utf-8"), ) self.assertRegex( resp.data.decode("utf-8"), r"Bill %s:\s* Amount changed\s* from %s\s* to %s" % ( - em_surround("25.0 for fromage à raclette", regex_escape=True), + em_surround("fromage à raclette", regex_escape=True), em_surround("25.0", regex_escape=True), em_surround("10.0", regex_escape=True), ), ) self.assertIn( "Bill %s renamed to %s" - % (em_surround("25.0 for fromage à raclette"), em_surround("new thing"),), + % (em_surround("fromage à raclette"), em_surround("new thing"),), resp.data.decode("utf-8"), ) self.assertLess( resp.data.decode("utf-8").index( - f"Bill {em_surround('25.0 for fromage à raclette')} renamed to" + f"Bill {em_surround('fromage à raclette')} renamed to" ), resp.data.decode("utf-8").index("Amount changed"), ) @@ -2650,8 +2650,7 @@ class HistoryTestCase(IhatemoneyTestCase): resp = self.client.get("/demo/history") self.assertEqual(resp.status_code, 200) self.assertIn( - f"Bill {em_surround('10.0 for new thing')} removed", - resp.data.decode("utf-8"), + f"Bill {em_surround('new thing')} removed", resp.data.decode("utf-8"), ) # edit user @@ -2746,7 +2745,7 @@ class HistoryTestCase(IhatemoneyTestCase): self.assertRegex( resp.data.decode("utf-8"), r"Bill {}:\s* Amount changed\s* from {}\s* to {}".format( - em_surround("25.0 for Bill 1", regex_escape=True), + em_surround("Bill 1", regex_escape=True), em_surround("25.0", regex_escape=True), em_surround("88.0", regex_escape=True), ), @@ -2789,11 +2788,9 @@ class HistoryTestCase(IhatemoneyTestCase): self.assertEqual(resp.status_code, 200) self.assertEqual(resp.data.decode("utf-8").count(" -- "), 5) self.assertNotIn("127.0.0.1", resp.data.decode("utf-8")) + self.assertIn(f"Bill {em_surround('Bill 1')} added", resp.data.decode("utf-8")) self.assertIn( - f"Bill {em_surround('25.0 for Bill 1')} added", resp.data.decode("utf-8") - ) - self.assertIn( - f"Bill {em_surround('25.0 for Bill 1')} removed", resp.data.decode("utf-8"), + f"Bill {em_surround('Bill 1')} removed", resp.data.decode("utf-8"), ) # Add a new bill @@ -2812,20 +2809,13 @@ class HistoryTestCase(IhatemoneyTestCase): self.assertEqual(resp.status_code, 200) self.assertEqual(resp.data.decode("utf-8").count(" -- "), 6) self.assertNotIn("127.0.0.1", resp.data.decode("utf-8")) - self.assertIn( - f"Bill {em_surround('25.0 for Bill 1')} added", resp.data.decode("utf-8") - ) + self.assertIn(f"Bill {em_surround('Bill 1')} added", resp.data.decode("utf-8")) self.assertEqual( - resp.data.decode("utf-8").count( - f"Bill {em_surround('25.0 for Bill 1')} added" - ), - 1, + resp.data.decode("utf-8").count(f"Bill {em_surround('Bill 1')} added"), 1, ) + self.assertIn(f"Bill {em_surround('Bill 2')} added", resp.data.decode("utf-8")) self.assertIn( - f"Bill {em_surround('20.0 for Bill 2')} added", resp.data.decode("utf-8") - ) - self.assertIn( - f"Bill {em_surround('25.0 for Bill 1')} removed", resp.data.decode("utf-8"), + f"Bill {em_surround('Bill 1')} removed", resp.data.decode("utf-8"), ) def test_double_bill_double_person_edit_second_no_web(self):