simonw / db-to-sqlite

CLI tool for exporting tables or queries from any SQL database to a SQLite file
Apache License 2.0
368 stars 28 forks source link

Support sqlite-utils with decimal fix. #22

Closed dvhthomas closed 4 years ago

dvhthomas commented 4 years ago

In order to upstream the fix in the sqlite-utils repo (https://github.com/simonw/sqlite-utils/issues/110) the version dependency needs to be bumped.

simonw commented 4 years ago

That test failure is from this: https://travis-ci.com/github/simonw/db-to-sqlite/jobs/341173396

    @all_databases
    def test_db_to_sqlite(connection, tmpdir, cli_runner):
        db_path = str(tmpdir / "test.db")
        cli_runner([connection, db_path, "--all"])
        db = sqlite_utils.Database(db_path)
        assert {"categories", "products", "vendors"} == set(db.table_names())
>       assert [
            # Slight oddity: vendor_id comes out as a string even though MySQL
            # defined it as an integer because sqlite-utils treats mixed
            # integer + null as a string type, not an integer type
            {"id": 1, "name": "Bobcat Statue", "cat_id": 1, "vendor_id": "1"},
            {"id": 2, "name": "Yoga Scarf", "cat_id": 1, "vendor_id": None},
        ] == list(db["products"].rows)
E       AssertionError: assert [{'cat_id': 1...or_id': None}] == [{'cat_id': 1,...or_id': None}]
E         At index 0 diff: {'id': 1, 'name': 'Bobcat Statue', 'cat_id': 1, 'vendor_id': '1'} != {'id': 1, 'name': 'Bobcat Statue', 'cat_id': 1, 'vendor_id': 1}
E         Use -v to get the full diff
simonw commented 4 years ago

Here's that comment in the code:

https://github.com/simonw/db-to-sqlite/blob/187f2a1e9b480f89c2203cd6733cc8f69d6591c3/tests/test_db_to_sqlite.py#L13-L19

It looks like I fixed that in https://github.com/simonw/sqlite-utils/issues/94 - which shipped in sqlite-utils 2.4.3: https://sqlite-utils.readthedocs.io/en/stable/changelog.html#v2-4-3

simonw commented 4 years ago

Thanks for this - I just released 1.2 with this fix: https://github.com/simonw/db-to-sqlite/releases/tag/1.2

dvhthomas commented 4 years ago

And now I can happily clone a Postgres database to SQLite with a one-liner. Thank you! We plan on using your sqlite tools and Datasette for an open data project around infrastructure stimulus spending for at least one U.S. state.

Fiddling with Geometry (PostGIS) data types next....