From 6d4efd294971bb7528a2fc45990f90dcebe11ceb Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 27 Aug 2022 16:00:54 -0700 Subject: [PATCH] transform=True for differing column types, refs #467 --- sqlite_utils/db.py | 2 +- tests/test_create.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index 549b39a..b653cc4 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -912,7 +912,7 @@ class Database: if missing_columns: for col_name, col_type in missing_columns.items(): table.add_column(col_name, col_type) - if missing_columns or columns_to_drop: + if missing_columns or columns_to_drop or columns != existing_columns: should_transform = True # Do we need to change the column order? if ( diff --git a/tests/test_create.py b/tests/test_create.py index 03e5781..7252e48 100644 --- a/tests/test_create.py +++ b/tests/test_create.py @@ -1176,6 +1176,13 @@ def test_create_if_no_columns(fresh_db): 'CREATE TABLE "demo" (\n [id] INTEGER PRIMARY KEY,\n [name] TEXT,\n [age] INTEGER\n)', True, ), + # Change a column type + ( + {"id": int, "name": bytes}, + {"pk": "id"}, + 'CREATE TABLE "demo" (\n [id] INTEGER PRIMARY KEY,\n [name] BLOB\n)', + True, + ), # Change the primary key ( {"id": int, "name": str},