Forum: Ruby on Rails Extracting SQL and Rebuilding from SQL?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E51c6ae07e72cf04ef869868cb8eca6e?d=identicon&s=25 Jake Janovetz (Guest)
on 2005-12-29 17:37
Hello-

With a database filled with several customers' datasets, I thought it
would be a nice feature of my app's backend interface to be able to
extract (and optionally delete) the data from a single customer.  It
would then also be nice to rebuild that data from the stored info.

What's a good way to do this efficiently?

If all the ":dependent => true" are setup properly on associations
within models, a single ".destroy()" called on the customer will yank
all the data.  Is there a way to do something else with those rows?
i.e. sqldump of some sort?

I thought of adding a "before_destroy" hook, checking a global
"archive_on_destroy" or something and dumping those rows out.  Is this a
good way?

Anyway, I'm just shooting in the dark now to brainstorm ways of
performing this archival and retrieval.  Any ideas would be greatly
appreciated!
E51c6ae07e72cf04ef869868cb8eca6e?d=identicon&s=25 Jake Janovetz (Guest)
on 2005-12-30 00:12
Jake Janovetz wrote:
> Hello-
>
> With a database filled with several customers' datasets, I thought it
> would be a nice feature of my app's backend interface to be able to
> extract (and optionally delete) the data from a single customer.  It
> would then also be nice to rebuild that data from the stored info.
>
> What's a good way to do this efficiently?
>
> If all the ":dependent => true" are setup properly on associations
> within models, a single ".destroy()" called on the customer will yank
> all the data.  Is there a way to do something else with those rows?
> i.e. sqldump of some sort?
>
> I thought of adding a "before_destroy" hook, checking a global
> "archive_on_destroy" or something and dumping those rows out.  Is this a
> good way?
>
> Anyway, I'm just shooting in the dark now to brainstorm ways of
> performing this archival and retrieval.  Any ideas would be greatly
> appreciated!



Is this possibly supported using some obscure application of schemas or
migrations?

   Jake
8217faf2bfdfa7daf10135d41ddd421e?d=identicon&s=25 Jeff Cohen (jeff)
on 2005-12-30 00:25
Jake Janovetz wrote:
> Hello-
>
> With a database filled with several customers' datasets, I thought it
> would be a nice feature of my app's backend interface to be able to
> extract (and optionally delete) the data from a single customer.  It
> would then also be nice to rebuild that data from the stored info.
>
> What's a good way to do this efficiently?

Not sure if this is exactly what you need, but take a look at topfunky's
plugin at
http://nubyonrails.com/articles/2005/12/27/dump-or....

You'll want the dump_to_file and load_from_file helpers.

Hope this helps,
Jeff
www.softiesonrails.com
132a94ca65959bda6c74fae54bff2425?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2005-12-30 01:14
(Received via mailing list)
On Dec 29, 2005, at 3:12 PM, Jake Janovetz wrote:

>> If all the ":dependent => true" are setup properly on associations
>> performing this archival and retrieval.  Any ideas would be greatly
>> appreciated!
>
>
>
> Is this possibly supported using some obscure application of
> schemas or
> migrations?
>
>    Jake


Jake-

	You might want to look at acts_as_versioned or acts_as_paranoid to
get some ideas about how to do what you want. Google for both of
these terms to get more info,

Cheers-
-Ezra Zygmuntowicz
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
ezra@yakima-herald.com
E51c6ae07e72cf04ef869868cb8eca6e?d=identicon&s=25 Jake Janovetz (Guest)
on 2005-12-30 03:23
> Not sure if this is exactly what you need, but take a look at topfunky's
> plugin at
> http://nubyonrails.com/articles/2005/12/27/dump-or....
>
> You'll want the dump_to_file and load_from_file helpers.
>
> Hope this helps,
> Jeff
> www.softiesonrails.com

Thanks.  It's close.  In fact, it asks my question differently.  I
originally thought that an SQL dump would be better.  This seems to
indicate that perhaps a YAML dump would be more appropriate.  Afterall,
the tables already exist, so I'm not trying to reconstruct the form of
the db, just the content of some of it.

This solution would likely be more immune to version differences, too, I
suspect.

I'll need to write something more appropriate to my usage, but it's a
good reference.  Thanks!

   Jake
E51c6ae07e72cf04ef869868cb8eca6e?d=identicon&s=25 Jake Janovetz (Guest)
on 2005-12-30 03:41
Jake Janovetz wrote:
>> Not sure if this is exactly what you need, but take a look at topfunky's
>> plugin at
>> http://nubyonrails.com/articles/2005/12/27/dump-or....

One question that doesn't seem to be addressed in this case is how to
rebuild an associated database where the new records may have different
rows.

The new database will need to be reconstructed in a hierarchical manner
so that the association IDs can be replaced as the new items are added
(with presumably new IDs!).

Being somewhat new to Rails, I'm wondering if there are any shortcuts
available to me to do this.

   Jake
This topic is locked and can not be replied to.