-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
42 lines (28 loc) · 1.33 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
ActiveRecordSqlExporter
=======================
This plugin takes a record in your database and converts it into SQL statements
that can be used to insert it.
This was written after I had to restore some specific data for a user (a number
of rows, across a number of tables.)
It might be useful as a simple backup utility - for example, store the restoration
sql after something gets removed.
This moves down through relations along has_many, has_one relations, but will
not move up along belongs_to relations.
However, this doesn't make you any less likely to screw up and shoot yourself
in the proverbial memory usage foot with a massive swath of data, so often
you'll want to use the second argument to to_sql, which is an array of classes
to ignore.
Example
=======
Obj.find( obj_id ).to_backup_sql
For a blog_post, that belongs to a user, that might have many posts:
Post.find( id ).to_backup_sql( {}, [User] )
Export an object to a file:
Post.find( id ).to_backup_sql( {:file => a_file_object} )
Copyright (c) 2010 Adam Palmblad ([email protected]), released under the MIT license
To Do
=====
* Watch dependent => nullify and write restoration query
* The generation the SQL that checks for the presence of a value is broken!
* Add ability to toggle sql options, such as the ON DUPLICATE KEY stuff
* Support for non MySQL databases