From 564f5a5f38e67853f805748cdcb436b536f805de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20Emir=20=C3=96zkan?= Date: Sun, 16 Aug 2020 22:12:00 +0300 Subject: [PATCH] Fixed a major bug in basic migrate, causing the migration to raise an exception if a column is deleted. --- datalite/migrations.py | 5 ++++- docs/conf.py | 2 +- setup.py | 2 +- test/main_tests.py | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/datalite/migrations.py b/datalite/migrations.py index 1a27574..2814389 100644 --- a/datalite/migrations.py +++ b/datalite/migrations.py @@ -102,6 +102,8 @@ def _modify_records(data, col_to_del: Tuple[str], col_to_add: Tuple[str], for key in record.keys(): if key in col_to_del and key in flow: record_mod[flow[key]] = record[key] + elif key in col_to_del: + pass else: record_mod[key] = record[key] for key_to_add in col_to_add: @@ -144,7 +146,8 @@ def basic_migrate(class_: type, column_transfer: dict = None) -> None: delete the fields that no longer exist, create new columns for new fields. If the column_flow parameter is given, migrate elements - from previous column to the new ones. + from previous column to the new ones. It should be + noted that, the obj_ids do not persist. :param class_: Datalite class to migrate. :param column_transfer: A dictionary showing which diff --git a/docs/conf.py b/docs/conf.py index 3f5cdcf..7e5ac4d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -23,7 +23,7 @@ copyright = '2020, Ege Ozkan' author = 'Ege Ozkan' # The full version, including alpha/beta/rc tags -release = 'v0.5.5' +release = 'v0.5.6' # -- General configuration --------------------------------------------------- diff --git a/setup.py b/setup.py index 8eeb405..5adec55 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setuptools.setup( name="datalite", # Replace with your own username - version="0.5.5", + version="0.5.6", author="Ege Ozkan", author_email="egeemirozkan24@gmail.com", description="A small package that binds dataclasses to an sqlite database", diff --git a/test/main_tests.py b/test/main_tests.py index 836177c..54c3123 100644 --- a/test/main_tests.py +++ b/test/main_tests.py @@ -34,6 +34,7 @@ class FetchClass: @dataclass class Migrate1: ordinal: int + conventional: str @datalite(db_path='test.db') @@ -144,7 +145,7 @@ class DatabaseFetchPaginationCalls(unittest.TestCase): class DatabaseMigration(unittest.TestCase): def setUp(self) -> None: - self.objs = [Migrate1(i) for i in range(10)] + self.objs = [Migrate1(i, "a") for i in range(10)] [obj.create_entry() for obj in self.objs] def testBasicMigrate(self):