On 2016/02/15 11:01 AM, Luca Ferrari wrote:
> Hi all,
> this could sound trivial but I've got a few hundreds SQLite 3 database
> files, all with the same schema, that I need to alter adding a few
> columns here and there.
> While I'm pretty sure a simple sheel script that will execute, file
> per file, the alter table (within a transaction) will do the job I'm
> wondering if there's a better approach or a more automated one.
>
> Any suggestion is welcome.

If all the files are in the same folder and use the same extension, then 
a simple bash/batch script iterating the files feeding it into sqlite3 
cli along with the column-altering script - is by far the easiest.

If the file distribution is more complex, or table names differ, perhaps 
a custom little C program or something that allows you to pick files in 
bulk and then iterates the list pushing the SQL alterations to each one. 
I have in fact done this recently, but only on Windows in a small gui. 
If you are doing this on Windows, you are welcome to have the tool.

As an aside, may I ask why the hundreds of similar db files?
if they are in the same place, and the design doesn't absolutely require 
this fragmentation, it would be far more efficient to have one DB, in 
the table add an identifying column (perhaps the old DB name, but more 
efficient would be an Integer) to show where the row belongs to. This 
amalgamation would be easy to do too, for bulk files.

Cheers,
Ryan

Reply via email to