# My own custimized db:bootstrap

**URL:** <https://www.ruby-forum.com/t/my-own-custimized-db-bootstrap/105608>\
**Category:** Radiant CMS\
**Created:** [May 31, 2007, 6:00pm UTC](https://www.ruby-forum.com/t/my-own-custimized-db-bootstrap/105608 "2007-05-31T18:00:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathan2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/fbc32d/32.png) [@jonathan2000](https://www.ruby-forum.com/u/jonathan2000)\
**Post date:** [May 31, 2007, 6:00pm UTC](https://www.ruby-forum.com/t/my-own-custimized-db-bootstrap/105608/1 "2007-05-31T18:00:38Z")

</div>

Hi,

I have created a reference radiant website, where I get exactly what I  
need for any other website I added YUI stylesheets, XML Sitemap,  
contact form, etc…

Now I would like to “take a snapshot” of it and be able to apply it to  
any new radiant website I create.

What would be the better way to do that?

I though of simply dumping the database, but then it would be broken  
with future Radiant versions.

So I think the solution is in the migrations?

When doing rake db:bootstrap, you are presented with a choice of 3  
websites templates: empty, blog and fully styled blog. How can I add  
my own template here?

Thanks!

J.

---

<div class="post-metadata">

**Author:** ![jonathan2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/fbc32d/32.png) [@jonathan2000](https://www.ruby-forum.com/u/jonathan2000)\
**Post date:** [May 31, 2007, 6:06pm UTC](https://www.ruby-forum.com/t/my-own-custimized-db-bootstrap/105608/2 "2007-05-31T18:06:39Z")

</div>

Check out the bleeding-edge import\_export extension. In creating it, I  
leveraged a lot of existing code in the db:bootstrap task, so it  
essentially creates a template similar to the predefined ones.  
_However_, it also loads users from the template, unlike the  
pre-packaged ones. The extension essentially works but may have  
undiscovered bugs. Caveat emptor.

Sean

---

<div class="post-metadata">

**Author:** ![jonathan2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/fbc32d/32.png) [@jonathan2000](https://www.ruby-forum.com/u/jonathan2000)\
**Post date:** [May 31, 2007, 6:31pm UTC](https://www.ruby-forum.com/t/my-own-custimized-db-bootstrap/105608/3 "2007-05-31T18:31:40Z")

</div>

I tried to use the import\_export extension recently and ran into  
errors on the import. I was a bad boy and didn’t report it though.  
I figured it was just me. I ended up just dumping the db and  
importing into production. I think it was during railsconf and the  
list was slow, so I just didn’t take the time. sorry.

dm

---

<div class="post-metadata">

**Author:** ![jonathan2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/fbc32d/32.png) [@jonathan2000](https://www.ruby-forum.com/u/jonathan2000)\
**Post date:** [June 1, 2007, 3:08pm UTC](https://www.ruby-forum.com/t/my-own-custimized-db-bootstrap/105608/4 "2007-06-01T15:08:05Z")

</div>

Jonathan MÃ©tillon wrote:

> I exported very easily to YAML using /admin/export  
> And I created a new Radiant app with empty template, then:  
> rake db:import TEMPLATE=export.yml  
> The migration starts and fails at:
> 
> == AddOptimisticLocking: migrated (0.4705s) =============
> 
> rake aborted!  
> You have a nil object when you didn’t expect it!  
> You might have expected an instance of Array.  
> The error occurred while evaluating nil.delete
> 
> You can review the full rake task log with trace here:  
> [http://paste.ubuntu-nl.org/23550/](http://paste.ubuntu-nl.org/23550/)

The error you get should be related to the instruction

users\_only = {‘records’ =\> {‘Users’ =\> data[‘records’].delete(‘Users’)}}

Maybe in the yaml file you have created with the ‘export’ task there are  
no entries for the ‘Users’ key.

I too have used the import\_export extensions with some problems.  
I had to tweak the treatment of user data: e.g. in the yaml file I had  
to change the value for ‘Created by’ and ‘Updated by’ to “1” (admin  
user) or nil otherwise the User object to be saved could not be  
instantiated correctly before saving the user record.

I had also to change the create\_records method in radiant/setup.rb in  
order to maintain the original id’s (otherwise associations between  
pages and page\_parts would be lost):

def create\_records(template)  
records = template[‘records’]  
if records  
records.keys.each do |key|  
feedback “Creating #{key.to\_s.underscore.humanize}” do  
model = model(key)  
puts "Created model instance for " + key  
model.reset\_column\_information  
record\_pairs = order\_by\_id(records[key])

```
          step do
            record_pairs.each do |id, record|
              newrec = model.new(record)
                              #added by Luca to maintain the 

```

imported id  
newrec.id = id  
newrec.save  
end  
end  
end  
end  
end  
end

Hope this helps.

Luca Erzegovesi
