From 9800bf989c5f3610872ce56504ad48866856e9ac Mon Sep 17 00:00:00 2001 From: Hank Szeto <szeto@thinkingcap.com.au> Date: Mon, 16 Dec 2024 10:31:21 +1000 Subject: [PATCH] fix: when there is no data in the table, the primary key is not copied --- db_to_sqlite/cli.py | 2 +- tests/test_db_to_sqlite.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db_to_sqlite/cli.py b/db_to_sqlite/cli.py index bfd4dcf..a80c258 100644 --- a/db_to_sqlite/cli.py +++ b/db_to_sqlite/cli.py @@ -125,7 +125,7 @@ def cli( except NotImplementedError: column_type = str create_columns[column["name"]] = column_type - db[table].create(create_columns) + db[table].create(create_columns, pks) else: rows = itertools.chain([first], rows) if progress: diff --git a/tests/test_db_to_sqlite.py b/tests/test_db_to_sqlite.py index e12b98a..ba82ee4 100644 --- a/tests/test_db_to_sqlite.py +++ b/tests/test_db_to_sqlite.py @@ -27,7 +27,7 @@ def test_db_to_sqlite(connection, tmpdir, cli_runner): assert [{"id": 1, "name": "Lila"}] == list(db["user"].rows) assert ( db["empty_table"].schema - == "CREATE TABLE [empty_table] (\n [id] INTEGER,\n [name] TEXT,\n [ip] TEXT\n)" + == "CREATE TABLE [empty_table] (\n [id] INTEGER PRIMARY KEY,\n [name] TEXT,\n [ip] TEXT\n)" ) # Check foreign keys assert [