Extracting SQL and Rebuilding from SQL?


#1

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!


#2

Jake J. 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


#3

Jake J. 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-slurp-yaml-reference-data.

You’ll want the dump_to_file and load_from_file helpers.

Hope this helps,
Jeff
www.softiesonrails.com


#4

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-slurp-yaml-reference-data.

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


#5

On Dec 29, 2005, at 3:12 PM, Jake J. 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 Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid


#6

Jake J. 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-slurp-yaml-reference-data.

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