Fixed a major bug in basic migrate, causing the migration to raise an exception if a column is deleted.

This commit is contained in:
Ege Emir Özkan
2020-08-16 22:12:00 +03:00
parent 94eabb3e20
commit 564f5a5f38
4 changed files with 8 additions and 4 deletions

View File

@@ -102,6 +102,8 @@ def _modify_records(data, col_to_del: Tuple[str], col_to_add: Tuple[str],
for key in record.keys(): for key in record.keys():
if key in col_to_del and key in flow: if key in col_to_del and key in flow:
record_mod[flow[key]] = record[key] record_mod[flow[key]] = record[key]
elif key in col_to_del:
pass
else: else:
record_mod[key] = record[key] record_mod[key] = record[key]
for key_to_add in col_to_add: 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, delete the fields that no longer exist,
create new columns for new fields. If the create new columns for new fields. If the
column_flow parameter is given, migrate elements 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 class_: Datalite class to migrate.
:param column_transfer: A dictionary showing which :param column_transfer: A dictionary showing which

View File

@@ -23,7 +23,7 @@ copyright = '2020, Ege Ozkan'
author = 'Ege Ozkan' author = 'Ege Ozkan'
# The full version, including alpha/beta/rc tags # The full version, including alpha/beta/rc tags
release = 'v0.5.5' release = 'v0.5.6'
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------

View File

@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
setuptools.setup( setuptools.setup(
name="datalite", # Replace with your own username name="datalite", # Replace with your own username
version="0.5.5", version="0.5.6",
author="Ege Ozkan", author="Ege Ozkan",
author_email="egeemirozkan24@gmail.com", author_email="egeemirozkan24@gmail.com",
description="A small package that binds dataclasses to an sqlite database", description="A small package that binds dataclasses to an sqlite database",

View File

@@ -34,6 +34,7 @@ class FetchClass:
@dataclass @dataclass
class Migrate1: class Migrate1:
ordinal: int ordinal: int
conventional: str
@datalite(db_path='test.db') @datalite(db_path='test.db')
@@ -144,7 +145,7 @@ class DatabaseFetchPaginationCalls(unittest.TestCase):
class DatabaseMigration(unittest.TestCase): class DatabaseMigration(unittest.TestCase):
def setUp(self) -> None: 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] [obj.create_entry() for obj in self.objs]
def testBasicMigrate(self): def testBasicMigrate(self):