simonw / datasette-socrata

Import data from Socrata into Datasette
Apache License 2.0
0 stars 1 forks source link

Only allow usage with databases in WAL mode #7

Closed simonw closed 2 years ago

simonw commented 2 years ago

From testing in #1 it looks like this plugin only works against databases running in WAL mode. Rather than switch the DB into WAL mode automatically, I'm going to show an error if the selected database is NOT in WAL mode.

Originally posted by @simonw in https://github.com/simonw/datasette-socrata/issues/5#issuecomment-1150588585

simonw commented 2 years ago

I'm going to check this just on the /-/import-socrata page itself.

simonw commented 2 years ago

Need to do this first:

simonw commented 2 years ago

This inspired me to file this issue:

simonw commented 2 years ago

Weirdly I was getting a sqlite3.OperationalError: unable to open database file error on this:

     supported_databases = [
          db
         for db in datasette.databases.values()
         if db.is_mutable
         and db.name != "_internal"
         and await db.execute_fn(
            lambda conn: sqlite_utils.Database(conn).journal_mode == "wal"
        )
    ]

But switching it to using await db.execute_write_fn fixed that error.

Maybe testing journal_mode on a database connection that was opened in read-only mode can cause errors.