Introducing Squeak, an open source SQLite schema editor

To just view or download the code, click here.

I love SQLite, I really do. For any quick and dirty development, there is no other relational database like it: it's fast, lightweight, ultra portable, DB-API 2.0 compliant, and baked right into any distro of Python 2.5 or higher.

Using it is generally a very positive experience right up until the point where you need to make any changes to a table's schema. I distinctly remember that when learning Django it was particularly annoying to have to do a little SQLite dance every time I would need to edit or remove a model field.

It is to scratch that itch that I've created Squeak, which is a python module that can be used as a script from the command line or as a library that lets you:

  • Drop a table column
  • Rename a table column
  • Change the definition of a table column (for example foreign key relationships or constraints)

Here is a test scenario where a column gets dropped from a table schema:

$ sqlite3 db
SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> CREATE TABLE "my_table" (
   ...>     "id" integer NOT NULL PRIMARY KEY,
   ...>     "name" varchar (20) NOT NULL DEFAULT ""
   ...> )
   ...> ;
sqlite> .quit

$ ./squeak.py db my_table drop_column name
Column 'name' dropped

$ sqlite3 db .schema
CREATE TABLE "my_table" (
    "id" integer NOT NULL PRIMARY KEY
);

For more examples and further details, please visit the project's GitHub page at http://github.com/teebes/squeak

Disclaimer:

Squeak should be used for development purposes only. It is not meant to be used on production systems and is nowhere near fool proof.

blog comments powered by Disqus

Twitter

Jan 25 - Registered for PyCon 2012. Woot! #fb

Jan 09 - @bsirach I identified myself to Siri as "Teebow Morel Lorset", it's what gets my name butchered the least

Jan 07 - @justincbeck @bsirach @andrewroycarter One more intern joke for Andrew! In a couple years you can have a stand-up routine for every new hire