Garry,

Although this doesn't answer your principle question, the smarter
design really would be to just have a revision column in the content
table.  Esp. if this is to be an open source projects as most
developers would expect such and understand the code much better than
a whole bunch dynamically constructed tables.

Such design would also make it far easier to evolve your CMS over time
(perhaps adding a new column to the content table and writing specs
for such).  With your design, you're also facing solving your various
issues like below when writing migrate scripts and doing system
upgrades where you can potentially touch on a large number of revision
tables.

A potential headache you probably really would like to avoid.

Michael

On Tue, Dec 20, 2011 at 10:00 AM, Garry Hill <[email protected]> wrote:
>
> Hi all,
>
> I'm developing a CMS system based on Sequel that uses the concept of
> 'revisions' to manage the publish workflow and need some advice about
> the best way to implement this in Sequel.
>
> Let me explain a bit more. The editable content of the CMS is held in
> a table called simply "content". When a user decides to make some
> changes live the system duplicates the "content" table into another
> table named after the next revision number, e.g. "revision_023". This
> "revision_023" table is then used by the Content model in place of
> "content" on the public site, thus sand-boxing the published content
> from the edited content.
>
> As a system it works really, really well but my current method for
> dynamically changing the table name within a certain context is very
> fragile and very hacky. Basically I have this monkey patch:
>
> (This is the new version that I had to fix for the 3.30 release.
> Having to make this fix has prompted me to (finally) ask for some
> advice on how to do it properly.)
>
> module Sequel
>  class Dataset
>
> alias_method :sequel_quote_identifier_append, :quote_identifier_append
>
>    def quote_identifier_append(sql, name)
>      if name == :content or name == "content"
>        name = Content.current_revision_table
>      end
>      sequel_quote_identifier_append(sql, name)
>    end
>  end
> end
>
> Nasty huh?
>
> What I need to achieve is the following:
>
> Content.dataset #=> #<Sequel::Mysql2::Dataset: "SELECT * FROM
> `content`">
>
> Content.with_revision(23) do
>  Content.dataset #=> #<Sequel::Mysql2::Dataset: "SELECT * FROM
> `revision_023`">
>
>  Content.with_revision(24) do
>    Content.dataset #=> #<Sequel::Mysql2::Dataset: "SELECT * FROM
> `revision_024`">
>
>    Content.with_editable do
>      Content.dataset #=> #<Sequel::Mysql2::Dataset: "SELECT * FROM
> `content`">
>    end
>  end
> end
>
> Does anyone know the right way to code this into a self-contained
> Sequel plugin? Any ideas greatly appreciated...
>
> Thanks,
>
> Garry
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sequel-talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sequel-talk?hl=en.
>



-- 
http://codeconnoisseur.org

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to