On Mon, Sep 29, 2008 at 2:41 PM, Errol Siegel <[EMAIL PROTECTED]> wrote:
> I have built a radiant-based site and will soon be ready to deploy it.
>
> I'm looking for advice on best practices.  I was not able to find much
> about this in the documentation.
>
> Most of the issue is the database.  I want to be able update content in
> a copy of the site running on my development machine.  Then, when I'm
> satisfied everything looks right, dump the database and import it into
> the production database running on the server.

Here's the code from the model of my little publisher extension.  It's
not quite ready for releasing yet, but it should give you an idea.
This assumes your dev database is on the same host as the production
database.  And that you're using postgres.  :D

Note: I have some tables (the event ones) that you won't have, so you
can remove those.

# Puts data from the development database into the production one
# (by deleting the production tables and recreating them and filling
# them with production data.
# Note: Obviously won't work with enforced database foreign keys,
# so don't make them.
# TODO: Also copy over user-provided photos from the dev env to the
production one
class Publisher
  TABLES = %w( events event_options users page_parts pages layouts snippets )
  def self.publish!
    table_string = TABLES.map { |t| "-t #{t} " }
    data = `pg_dump #{current_dev} -a #{table_string}`
    pg = IO::popen("psql #{current_prod}", "w+")

    pg << "begin;"
      TABLES.each do |table|
        pg << "delete from #{table};"
      end
      pg << data
    pg << "commit;"
  end

  private

  def self.current_dev
    config = Rails::Configuration.new
    config.database_configuration["development"]["database"]
  end

  def self.current_prod
    config = Rails::Configuration.new
    config.database_configuration["production"]["database"]
  end

end
_______________________________________________
Radiant mailing list
Post:   [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to