<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -95,7 +95,7 @@ class Site &lt; ActiveRecord::Base
   end
   
   def add_pages
-    if connection.select_value(&quot;SELECT count(*) from pages where site_id=#{id}&quot;).to_i == 0
+    if Page.table_exists?
       require Rails.root + &quot;/db/migrate/20080722143227_move_system_content_to_pages&quot;
       MoveSystemContentToPages.up
     end</diff>
      <filename>app/models/site.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,9 @@ class MoveSystemContentToPages &lt; ActiveRecord::Migration
         html = File.read(filename)
         path, filename = filename.split('pages/').last.split('/')
         pub = nav = path != 'system'
-        Page.create!(:slug =&gt; path, :title =&gt; path.titleize, :body =&gt; html, :system =&gt; true, :navigation =&gt; nav, :published =&gt; pub)
+        unless Page.find_by_path(path)
+          Page.create!(:slug =&gt; path, :title =&gt; path.titleize, :body =&gt; html, :system =&gt; true, :navigation =&gt; nav, :published =&gt; pub)
+        end
       end
       Dir[File.dirname(__FILE__) + &quot;/20080722143227_move_system_content_to_pages/**/*.html&quot;].each do |filename|
         next if filename =~ /index\.html$/
@@ -13,7 +15,10 @@ class MoveSystemContentToPages &lt; ActiveRecord::Migration
         path, filename = filename.split('pages/').last.split('/')
         slug = filename.split('.').first
         nav = path != 'system'
-        Page.find_by_path(path).children.create!(:slug =&gt; slug, :title =&gt; slug.titleize, :body =&gt; html, :system =&gt; true, :navigation =&gt; nav, :published =&gt; true)
+        parent = Page.find_by_path(path)
+        unless parent.children.find_by_slug(slug)
+          parent.children.create!(:slug =&gt; slug, :title =&gt; slug.titleize, :body =&gt; html, :system =&gt; true, :navigation =&gt; nav, :published =&gt; true)
+        end
       end
       unless Page.find_by_path('home')
         Page.create!(:slug =&gt; 'home', :title =&gt; 'Home', :body =&gt; 'Congratulations! OneBody is up and running.', :system =&gt; true)</diff>
      <filename>db/migrate/20080722143227_move_system_content_to_pages.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>75034c80e44a35a8d47de01128e67db22c01f0c7</id>
    </parent>
  </parents>
  <author>
    <name>Tim Morgan</name>
    <email>tim@timmorgan.org</email>
  </author>
  <url>http://github.com/seven1m/onebody/commit/e14a3a39fdaece81684f1df6ceab5ec67f3117c1</url>
  <id>e14a3a39fdaece81684f1df6ceab5ec67f3117c1</id>
  <committed-date>2008-08-17T19:16:07-07:00</committed-date>
  <authored-date>2008-08-17T19:16:07-07:00</authored-date>
  <message>Fix broken pages migration (again).
Don't duplicate page when creating a new site.</message>
  <tree>d58e29b9e5c991f11a34fd8fda757e9d96275309</tree>
  <committer>
    <name>Tim Morgan</name>
    <email>tim@timmorgan.org</email>
  </committer>
</commit>
