ydd 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +9 -21
- data/VERSION +1 -1
- data/lib/ydd/serialization_helper.rb +16 -23
- data/ydd.gemspec +2 -2
- metadata +4 -4
data/README.markdown
CHANGED
@@ -8,34 +8,22 @@ This plugin can now be installed as a gem via
|
|
8
8
|
|
9
9
|
gem install ydd
|
10
10
|
|
11
|
-
Note that when doing this, the rake tasks won't automatically be available to your app. You'll have to explicitly include them via the approaches followed: [here](http://ggr.com/how-to-include-a-gems-rake-tasks-in-your-rails-app.html), [here](https://rails.lighthouseapp.com/projects/8994/tickets/510-rake-tasks-not-included-for-gems), [and here](https://rails.lighthouseapp.com/projects/8994/tickets/59)
|
12
11
|
|
13
12
|
## Usage
|
14
13
|
|
15
|
-
|
16
|
-
|
14
|
+
ydd dump where-to-dump rails-app-root
|
15
|
+
ydd dump where-to-dump # Default to pwd for rails app
|
16
|
+
ydd dump where-to-dump rails-app-root --force # override the dump folder check
|
17
|
+
ydd dump where-to-dump rails-app-root --env=staging # change env to dump
|
18
|
+
|
19
|
+
All are applicable with dump and load above as the command.
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
rake db:data:dump_dir -> Dump contents of database to curr_dir_name/tablename.extension (defaults to yaml)
|
21
|
-
rake db:data:load_dir -> Load contents of db/data_dir into database
|
22
|
-
|
23
|
-
In addition, we have plugins whereby you can export your database to/from various formats. We only deal with yaml and csv right now, but you can easily write tools for your own formats (such as Excel or XML). To use another format, just load setting the "class" parameter to the class you are using. This defaults to "YamlDb::Helper" which is a refactoring of the old yaml_db code. We'll shorten this to use class nicknames in a little bit.
|
24
|
-
|
25
|
-
## Examples
|
26
|
-
|
27
|
-
One common use would be to switch your data from one database backend to another. For example, let's say you wanted to switch from SQLite to MySQL. You might execute the following steps:
|
28
|
-
|
29
|
-
1. rake db:dump
|
30
|
-
|
31
|
-
2. Edit config/database.yml and change your adapter to mysql, set up database params
|
32
|
-
|
33
|
-
3. mysqladmin create [database name]
|
34
|
-
|
35
|
-
4. rake db:load
|
21
|
+
Note that this creates a `schema.rb` and a `data.yml` in the data dump directory.
|
36
22
|
|
37
23
|
## Credits
|
38
24
|
|
25
|
+
This gem is maintained by Darcy Laycock.
|
26
|
+
|
39
27
|
Created by Orion Henry and Adam Wiggins. Major updates by Ricardo Chimal, Jr.
|
40
28
|
|
41
29
|
Patches contributed by Michael Irwin, Tom Locke, and Tim Galeckas.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -49,18 +49,14 @@ module YDD
|
|
49
49
|
|
50
50
|
def self.load_table(table, data, truncate = true)
|
51
51
|
column_names = data['columns']
|
52
|
-
if truncate
|
53
|
-
truncate_table(table)
|
54
|
-
end
|
52
|
+
truncate_table(table) if truncate
|
55
53
|
load_records(table, column_names, data['records'])
|
56
54
|
reset_pk_sequence!(table)
|
57
55
|
end
|
58
56
|
|
59
57
|
def self.load_records(table, column_names, records)
|
60
|
-
if column_names.nil?
|
61
|
-
|
62
|
-
end
|
63
|
-
columns = column_names.map{|cn| YDD.connection.columns(table).detect{|c| c.name == cn}}
|
58
|
+
return if column_names.nil?
|
59
|
+
columns = column_names.map{ |cn| YDD.connection.columns(table).detect{ |c| c.name == cn } }
|
64
60
|
quoted_column_names = column_names.map { |column| YDD.connection.quote_column_name(column) }.join(',')
|
65
61
|
quoted_table_name = SerializationHelper::Utils.quote_table(table)
|
66
62
|
records.each do |record|
|
@@ -75,7 +71,6 @@ module YDD
|
|
75
71
|
end
|
76
72
|
end
|
77
73
|
|
78
|
-
|
79
74
|
end
|
80
75
|
|
81
76
|
module Utils
|
@@ -95,8 +90,7 @@ module YDD
|
|
95
90
|
def self.convert_booleans(records, columns)
|
96
91
|
records.each do |record|
|
97
92
|
columns.each do |column|
|
98
|
-
|
99
|
-
record[column] = (record[column] == 't' or record[column] == '1')
|
93
|
+
record[column] = ['t', '1', true].include? record[column]
|
100
94
|
end
|
101
95
|
end
|
102
96
|
records
|
@@ -107,8 +101,8 @@ module YDD
|
|
107
101
|
columns.map { |c| c.name }
|
108
102
|
end
|
109
103
|
|
110
|
-
def self.
|
111
|
-
|
104
|
+
def self.boolean?(value)
|
105
|
+
[true, false].include? value
|
112
106
|
end
|
113
107
|
|
114
108
|
def self.quote_table(table)
|
@@ -150,17 +144,16 @@ module YDD
|
|
150
144
|
end
|
151
145
|
|
152
146
|
|
153
|
-
def self.each_table_page(table, records_per_page=1000)
|
154
|
-
total_count
|
155
|
-
pages
|
156
|
-
id
|
157
|
-
boolean_columns
|
158
|
-
quoted_table_name = SerializationHelper::Utils.quote_table(table)
|
159
|
-
|
160
|
-
(
|
161
|
-
sql = YDD.connection.add_limit_offset!
|
162
|
-
|
163
|
-
)
|
147
|
+
def self.each_table_page(table, records_per_page = 1000)
|
148
|
+
total_count = table_record_count(table)
|
149
|
+
pages = (total_count.to_f / records_per_page).ceil - 1
|
150
|
+
id = table_column_names(table).first
|
151
|
+
boolean_columns = SerializationHelper::Utils.boolean_columns(table)
|
152
|
+
quoted_table_name = SerializationHelper::Utils.quote_table(table)
|
153
|
+
base_query = "SELECT * FROM #{quoted_table_name} ORDER BY #{id}"
|
154
|
+
0.upto(pages) do |page|
|
155
|
+
sql = YDD.connection.add_limit_offset! base_query.dup,
|
156
|
+
:limit => records_per_page, :offset => records_per_page * page
|
164
157
|
records = YDD.connection.select_all(sql)
|
165
158
|
records = SerializationHelper::Utils.convert_booleans(records, boolean_columns)
|
166
159
|
yield records
|
data/ydd.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ydd}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Adam Wiggins", "Orion Henry", "Darcy Laycock"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-19}
|
13
13
|
s.default_executable = %q{ydd}
|
14
14
|
s.description = %q{
|
15
15
|
YDD is a tool (a fork of yaml_db really) to make it generally easy
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ydd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adam Wiggins
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-09-
|
20
|
+
date: 2010-09-19 00:00:00 +08:00
|
21
21
|
default_executable: ydd
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|