# Ruby activerecord problem

**URL:** <https://www.ruby-forum.com/t/ruby-activerecord-problem/87185>\
**Category:** Rails\
**Created:** [February 28, 2007, 6:24pm UTC](https://www.ruby-forum.com/t/ruby-activerecord-problem/87185 "2007-02-28T18:24:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![karry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f475e1/32.png) [@karry](https://www.ruby-forum.com/u/karry)\
**Post date:** [February 28, 2007, 6:24pm UTC](https://www.ruby-forum.com/t/ruby-activerecord-problem/87185/1 "2007-02-28T18:24:44Z")

</div>

Hello friends,  
I have written a ruby code which generates table in the database. I have  
given an option of overwriting the table if it already exists. Here is  
the code

domain\_object\_class “AuditTrailEntry” do  
attribute “process\_code”, :of\_type =\> :string  
attribute “process\_instance\_id”, :of\_type =\> :integer  
attribute “workflow\_model\_element”, :of\_type =\> :string  
attribute “event\_type”, :of\_type =\> :string  
attribute “timestamp”, :of\_type =\> :datetime  
attribute “originator”, :of\_type =\> :string  
attribute “data”, :of\_type =\> :binary, :optional  
=\> true

overwrite true  
end

session = Session.new()

trail\_entry = AuditTrailEntry.create(:session =\> session,  
:process\_code =\> “007”,  
:process\_instance\_id =\> 42,  
:workflow\_model\_element =\>  
“element1”,  
:event\_type =\> “on\_delete”,  
:timestamp =\> Time.now(),  
:originator =\> “orig”)  
session.persistChanges()  
session.end()  
puts(“Done!”)

same is for work\_list\_items table.

when I run the code for the first time it creates the table in database  
but when I try to overwrite it by running the code again it gives me an  
error.

/////This is the first try(generates tables properly)//////

C:\ruby\Crystallizer1\>ruby murrayTest.rb  
created table audit\_trail\_entries  
created Ruby class for AuditTrailEntry  
created table work\_list\_items  
created Ruby class for WorkListItem  
Changes stored persistently!  
Done!

//////Trying to overwrite the table in the database///////

C:\ruby\Crystallizer1\>ruby murrayTest.rb  
created table audit\_trail\_entries  
created Ruby class for AuditTrailEntry  
c:/Program Files/ruby/lib/ruby/1.8/mysql.rb:1032:in `sync=': closed stream (IOEr ror) from c:/Program Files/ruby/lib/ruby/1.8/mysql.rb:1032:in`write’  
from c:/Program Files/ruby/lib/ruby/1.8/mysql.rb:1092:in  
`finalizer' from ./nxw-persistency-0.2/nxw-persistency-0.2.rb:22:in`call’  
from ./nxw-persistency-0.2/nxw-persistency-0.2.rb:22  
from c:/Program  
Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.1/li  
b/active\_support/dependencies.rb:488:in `load' from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.1/li b/active_support/dependencies.rb:488:in`load’  
from c:/Program  
Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.1/li  
b/active\_support/dependencies.rb:342:in `new_constants_in' from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.1/li b/active_support/dependencies.rb:488:in`load’  
from ./persistencyDSL.rb:75:in `domain\_object\_class’  
from murrayTest.rb:32

I ll appreciate your help  
Thank you
