My one-big website wiki/blog/cms application was based on SQLite. It worked well... until I upgraded my database version and the corresponding DBD::SQLite version, but my web host's version numbers lagged. Well, at this change, the db formats became incompatible and everything went up in smoke.
After I had cleaned up the debris, I decided to change things. In my quest for the "simplest thing that would work," and inspired by the database wars on http://radar.oreilly.com/ (too many links to mention here), I decided to convert my datastore to flat-files. Here is my experience in the hope that other monks will offer me suggestions and insights to make this better.
First item on the tackle-list was organization. Aware that too many files in a folder slow things down, and inspired by CPAN's apparent organization, I decided to implement an alphabetical hierarchy like so --
[datastore]/P/PE/PER/PerlMonks [datastore]/P/PE/PER/PerlTheLanguage [datastore]/F/FL/FLA/FlatFiles .. in other words .. my $FileName; my ($DIR, $DI, $D); if (length($FileName) >= 3) { $DIR = uc(substr($FileName, 0, 3)); $DI = substr($DIR, 0, 2); $D = substr($DI, 0, 1); } # in case the FileName is 2 characters long (less than 2 not possible) elsif (length($FileName) == 2) { $DIR = uc($FileName) . '0'; $DI = uc($FileName); $D = substr($DI, 0, 1); }
A'ite. That works. Now, on to metadata. A file allows only three possible metadata -- the FileName (the title of the web page), the contents of the File (basically, the contents of the web page), and its mtime. What about all manner of other items I had stored in my database table? After pondering a bit, I decided to create a shadow file prefixed with a period. On my Mac, that file is invisible (although it mucks up the landscape on my Windows box), so it is there but not there. I stored all the remaining metadata in this file in the same location as the main file in a key:value pattern
[datastore]/P/PE/PER/.PerlMonks [datastore]/P/PE/PER/PerlMonks [datastore]/P/PE/PER/.PerlTheLanguage [datastore]/P/PE/PER/PerlTheLanguage [datastore]/F/FL/FLA/.FlatFiles [datastore]/F/FL/FLA/FlatFiles .. # and inside a metadata file page_created_on: 2005-07-18 page_created_by: punkish page_modified_on: 2005-07-18 page_modified_by: punkish num_of_stars: 3 privacy_level: 1 prev_page: PrevPage next_page: NextPage firstname: Pun middlename: lastname: Kish company: title: address1: address2: city: state: zip: country: phone1: phone2: phone3: birthday: email: url: punkish.eidesis.org contact_created_on: 2005-08-21 00:20:00 contact_created_by: 1 lat: 43.065816 lon: -89.409005
Well, the above is working quite well. Some other things are not done yet but they will also get resolved with time and ingenuity. My question for now -- what insights can monks offer me with regards to the above?
Update: Fixed typo in a link above.In reply to Moving from SQL to flat-files by punkish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |