Fixed a major bug in basic migrate, causing the migration to raise an exception if a column is deleted.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 ---------------------------------------------------
|
||||
|
||||
2
setup.py
2
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",
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user