Jump to content

PW Best Practices for normalized tables?


Stu Friedberg
 Share

Recommended Posts

I am in the process of converting a 14-year-old homebrew photo gallery CMS into ProcessWire as my first PW project.  The original was based on nicely normalized SQL tables, with a photo id being used as a foreign key across auxiliary tables like "description", "notes", "keywords", etc.  I've completed the first phase of the conversion by treating original SQL tables as PW page tree nodes, with original SQL records as PW child leaf pages under the corresponding table parent page.  The leaf pages are named for the original key value.  Where the original schema used non-unique keys, I am using Repeaters on a single page.

This went pretty smoothly.  My existing "database access" layer in hand-written PHP becomes a much lighter wrapper in PW, and could disappear entirely if I feel motivated to rewrite all the other PHP client code which uses it.

Before I proceed to the second phase (capturing all the directly managed photo files as PW PageImages and converting the original keyword records into PW file tags), I'd like to ask about PW best practices and my first phase conversion.  None of the auxiliary data is especially large, perhaps 40 to 200 characters when present.  However, it can be quite sparse; most photos have no notes, for example.  Is it "better" to fold all the possible data fields into a single page template (denormalization), or are there still DB advantages to retaining the separation based on a raw SQL table schema?  I suppose I am interested in both technical and cultural answers to that question.

Link to comment
Share on other sites

In ProcessWire each page is defined in a single db table, while each field you create does have a own table, where data is linked to a page. So "denormalization" to having each image be a single page with image/description/notes/…  will still be stored kinda like in your old setup. The page-tree / templates don't actually represent any db based normalization as they're basically the pages, pages_parents, templates tables in the db. They've no influence at all about how actual data is stored.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...