sqld4r 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,11 @@
1
+ == 0.0.2 2008-06-24
2
+
3
+ * generate migration file for your model's PKs and FKs.
4
+ * make a template of command list
5
+ * add --save option for save the SQLDesigner xml file
6
+ * add --command_list option for set command list path
7
+ * add --skip_command_list for skip to execute commands.
8
+
1
9
  == 0.0.1 2008-06-20
2
10
 
3
11
  * 1 major enhancement:
@@ -1,4 +1,3 @@
1
- .gitignore
2
1
  History.txt
3
2
  License.txt
4
3
  Manifest.txt
@@ -9,7 +8,6 @@ bin/sqld4r
9
8
  config/hoe.rb
10
9
  config/requirements.rb
11
10
  lib/sqld4r.rb
12
- lib/sqld4r/er2.xml
13
11
  lib/sqld4r/sqld4r_core.rb
14
12
  lib/sqld4r/sqld4r_options.rb
15
13
  lib/sqld4r/sqld4r_parser.rb
@@ -26,6 +24,7 @@ setup.rb
26
24
  spec/spec.opts
27
25
  spec/spec_helper.rb
28
26
  spec/sqld4r_spec.rb
27
+ spec/dbdesigner.xml
29
28
  tasks/deployment.rake
30
29
  tasks/environment.rake
31
30
  tasks/rspec.rake
@@ -1,4 +1,4 @@
1
- 1. Set environment valiable.
1
+ 1. Set environment valiable if you want to change a config file path.
2
2
 
3
3
  $ export SQLD4R_CONF=~/.sqld4r
4
4
 
@@ -8,9 +8,10 @@ $ export SQLD4R_CONF=~/.sqld4r
8
8
 
9
9
  $ sqld4r --init
10
10
 
11
- 3. Modify default values.
11
+ 3. Modify default values and command list.
12
12
 
13
13
  $ vi ~/.sqld4r
14
+ $ vi ~/sqld4r_execute_commands
14
15
 
15
16
  4. Test for setting
16
17
 
data/README.txt CHANGED
@@ -9,6 +9,10 @@ The sqld4r is model generator for SQLDesigner(http://ondras.zarovi.cz/sql/demo/)
9
9
  == FEATURES/PROBLEMS:
10
10
 
11
11
  * generate migration files and model files from SQLDesigner xml file.
12
+ * generate migration file for your model's PKs and FKs.
13
+ * execute command list before finish.
14
+ (exp., execute 'rake db:create:all' for migrate to your database).
15
+ * save the DBDesigner xml file.
12
16
 
13
17
  == SYNOPSIS:
14
18
 
@@ -19,6 +23,7 @@ Usage: sqld4r --check [options]
19
23
 
20
24
  == REQUIREMENTS:
21
25
 
26
+ * Readline library on your system
22
27
  * activesupport ver 2.1.0
23
28
  (I checked this version only)
24
29
 
@@ -26,6 +31,8 @@ Usage: sqld4r --check [options]
26
31
 
27
32
  * gem install sqld4r
28
33
 
34
+
35
+
29
36
  == LICENSE:
30
37
 
31
38
  (The MIT License)
@@ -18,8 +18,10 @@ class Sqld4r_core
18
18
  end
19
19
  @structure.each do |table|
20
20
  add_relationship_to(table) unless @options["skip-relation"]
21
- add_index_to(table) unless @options["skip-index"]
22
21
  end
22
+ add_index_for_all(@structure) unless @options["skip-index"]
23
+ copy_sqld_xml_file unless @options["copy_sqld_to"].nil?
24
+ execute_command_list unless @options["skip_command_list"]
23
25
  notice "sqld4r: Complete at " + Time.now.strftime("%Y/%m/%d %H:%M:%S")
24
26
  @logfile.close if @logfile
25
27
  end
@@ -146,7 +148,7 @@ relation_models = [
146
148
  end
147
149
 
148
150
  def modelname2modelpath(modelname)
149
- "app/models/" + modelname + ".rb"
151
+ "app/models/" + modelname.underscore + ".rb"
150
152
  end
151
153
 
152
154
  def text_insert_to(filename)
@@ -162,30 +164,77 @@ relation_models = [
162
164
  end
163
165
  =begin
164
166
 
165
- script/generate migration add_indexes_for_all_tables
167
+ % script/generate migration add_index_for_all
168
+ exists db/migrate
169
+ create db/migrate/20080622130506_add_index_for_all.rb
166
170
 
167
171
 
168
-
169
- class CreatePosts < ActiveRecord::Migration
172
+ % cat db/migrate/20080622130506_add_index_for_all.rb
173
+ class AddIndexForAll < ActiveRecord::Migration
170
174
  def self.up
171
- create_table :posts do |t|
172
- t.string :title
173
- t.text :body
174
- t.boolean :published
175
-
176
- t.timestamps
177
- end
178
175
  end
179
176
 
180
177
  def self.down
181
- drop_table :posts
182
178
  end
183
179
  end
184
180
  =end
185
- def add_index_to(table)
181
+ def add_index_for_all(structure)
182
+ notice "add index to a new migrate file"
183
+ index_list = []
184
+ structure.each do |table|
185
+ index_list << {"table" => table["tablename"], "column" => "id"}
186
+ table["colums"].each do |column|
187
+ index_list << {"table" => table["tablename"], "column" => column["name"]} unless column["relation"].nil?
188
+ end
189
+ end
190
+
191
+ if 0 == index_list.size
192
+ notice "--skip. because this database dose not have tables"
193
+ else
194
+ begin
195
+ result = exec_shell_command("script/generate migration add_index_for_all")
196
+ # result is " exists db/migrate\n create db/migrate/20080624022342_add_index_for_all.rb"
197
+ migratefile = result.scan(/create\s\s(db\/migrate\/.+_add_index_for_all.rb)$/).first.first
198
+ rescue
199
+ migratefile = nil
200
+ notice "--error. can not find migration file"
201
+ end
202
+ if migratefile
203
+ text_insert_to(migratefile) do |file, line|
204
+ file.puts line
205
+ if /def\sself\.up$/ =~ line
206
+ index_list.each do |target|
207
+ file.puts " add_index :" + target["table"] + ", :" + target["column"]
208
+ end
209
+ end
210
+ if /def\sself\.down$/ =~ line
211
+ index_list.each do |target|
212
+ file.puts " remove_index :" + target["table"] + ", :" + target["column"]
213
+ end
214
+ end
215
+ end
216
+ end
217
+ notice "--modifyed index on " + migratefile
218
+ end
186
219
 
187
220
  end
188
-
221
+
222
+ def copy_sqld_xml_file
223
+ notice "save this database xml file to " + @options["copy_sqld_to"]
224
+ exec_shell_command("cp " + @options["sqld_path"] + " " + @options["copy_sqld_to"])
225
+ end
226
+
227
+ def execute_command_list
228
+ notice "execute commands from " + @options["command_list_path"]
229
+
230
+ File::open(@options["command_list_path"], "r") do |file|
231
+ file.readlines.each { |command|
232
+ exec_shell_command(command) unless /^#.*/ =~ command or command.chomp.empty?
233
+ }
234
+ end
235
+
236
+ end
237
+
189
238
  def notice(message)
190
239
  puts "* " + message if @options["verbose"]
191
240
  @logfile.puts "* " + message if @options["logging"] and @logfile
@@ -200,7 +249,7 @@ end
200
249
  puts '-->' + result if @options["verbose"] and not result.nil? and not result.empty?
201
250
  @logfile.puts '-->' + result if @options["logging"] and not result.nil? and not result.empty?
202
251
  Sqld4r_options::error_with_show_usage "receive error from command." unless 0 == $?
203
- $?
252
+ result
204
253
  end
205
254
 
206
255
  end
@@ -49,6 +49,10 @@ class Sqld4r_options < Hash
49
49
  self["sqld4r_conf_path"] = p
50
50
  end
51
51
 
52
+ opts.on( '--save=/save/to/xmlfile', 'save xml file path(../docs/sqldesigner.xml < conf < command line params)' ) do |p|
53
+ self["copy_sqld_to"] = p
54
+ end
55
+
52
56
  opts.on( '--svn', 'Modify files with subversion. (Note: svn must be in path/for script/generate)') do
53
57
  @@command_line_params["svn"] = true
54
58
  end
@@ -80,7 +84,7 @@ class Sqld4r_options < Hash
80
84
  opts.on( '--skip-index', "Don't add index to migration files") do
81
85
  @@command_line_params["skip-index"] = true
82
86
  end
83
-
87
+
84
88
  opts.on( '--verbose', 'provide extra output while running') do
85
89
  @@command_line_params["verbose"] = true
86
90
  end
@@ -97,6 +101,14 @@ class Sqld4r_options < Hash
97
101
  @@command_line_params["log_file"] = p
98
102
  end
99
103
 
104
+ opts.on( '--command_list=/path/to/listfile', 'Set path to a command list for executing it before finish. default is $HOME/sqld4r_execute_commands' ) do |p|
105
+ @@command_line_params["command_list_path"] = p
106
+ end
107
+
108
+ opts.on( '--skip_command_list', "Don't execute commands on a command list" ) do
109
+ @@command_line_params["skip_command_list"] = true
110
+ end
111
+
100
112
  opts.on( '--emulate', 'enable emulation mode' ) do
101
113
  @@command_line_params["emulate"] = true
102
114
  end
@@ -115,7 +127,7 @@ class Sqld4r_options < Hash
115
127
  exit
116
128
  end
117
129
 
118
- opts.on( '--init', 'setup a template of conf file' ) do
130
+ opts.on( '--init', 'setup a template of conf file and execute_command_list' ) do
119
131
  self["init"] = true
120
132
  end
121
133
 
@@ -145,6 +157,7 @@ class Sqld4r_options < Hash
145
157
  end
146
158
  if self["init"] or "--init" == self["sqld_path"]
147
159
  put_conf_file
160
+ put_commandlist_file
148
161
  exit
149
162
  end
150
163
  self
@@ -184,6 +197,40 @@ class Sqld4r_options < Hash
184
197
  end
185
198
  end
186
199
 
200
+ # write a template command list file to command_list_path
201
+ def put_commandlist_file
202
+ # check put path
203
+ Sqld4r_options::error_with_show_usage "command list path is empty. set --command_list paramater." if self["command_list_path"].empty?
204
+
205
+ unless "y" == Readline.readline("Would a template file put to #{self["command_list_path"]}? [y/N] > ").downcase
206
+ puts "Set your command list path to --command_list paramater."
207
+ exit
208
+ end
209
+
210
+ begin
211
+ File.open(self["command_list_path"]) do |textfile|
212
+ # check overwrite?
213
+ exit unless "y" == Readline.readline("Overwrite? [y/N]").downcase
214
+ end
215
+ rescue
216
+ end
217
+
218
+ begin
219
+ File.open(self["command_list_path"], "w") do |textfile|
220
+ textfile.puts "# command list file for executing it before finish"
221
+ textfile.puts ""
222
+ textfile.puts "# <- this line is comment."
223
+ textfile.puts "# next line is executable commands:"
224
+ textfile.puts "rake db:migrate"
225
+ textfile.puts "capify ."
226
+ textfile.puts "# NOTE:recommend 'rake db:migrate' command to write here."
227
+ end
228
+ puts "Put template command list file to #{self["command_list_path"]}"
229
+ rescue
230
+ puts "Warning:Could not open for writing. check parmitions."
231
+ end
232
+ end
233
+
187
234
  def self.error_with_show_usage(message)
188
235
  puts "Error:" + message
189
236
  Sqld4r_options::show_usage
@@ -207,7 +254,7 @@ class Sqld4r_options < Hash
207
254
  def self.static_default_values
208
255
  defaults = {}
209
256
  defaults["sqld4r_conf_path"] = ENV["HOME"] + "/.sqld4r"
210
- defaults["copy_sqld_to"] = "../docs/sqldesigner.xml"
257
+ defaults["copy_sqld_to"] = "../../docs/sqldesigner.xml"
211
258
  defaults["svn"] = false
212
259
  defaults["git"] = false
213
260
  defaults["skip-timestamps"] = false
@@ -216,11 +263,12 @@ class Sqld4r_options < Hash
216
263
  defaults["rspec"] = false
217
264
  defaults["skip-relation"] = false
218
265
  defaults["skip-index"] = false
219
- defaults["execute_command_list"] = ENV["HOME"] + "/.sqld4r_execute_commands"
266
+ defaults["command_list_path"] = ENV["HOME"] + "/sqld4r_execute_commands"
267
+ defaults["skip_command_list"] = false
220
268
  defaults["verbose"] = false
221
269
  defaults["sudo"] = false
222
270
  defaults["logging"] = false
223
- defaults["log_file"] = "./sqld4r.log"
271
+ defaults["log_file"] = "../../docs/sqld4r.log"
224
272
  defaults["emulate"] = false
225
273
  defaults
226
274
  end
@@ -2,7 +2,7 @@ module Sqld4r
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
File without changes
@@ -0,0 +1 @@
1
+ platform.active=Ruby
@@ -0,0 +1,7 @@
1
+ javac.classpath=
2
+ main.file=
3
+ ruby.includejava=false
4
+ source.encoding=UTF-8
5
+ src.bin.dir=bin
6
+ src.lib.dir=lib
7
+ test.spec.dir=spec
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://www.netbeans.org/ns/project/1">
3
+ <type>org.netbeans.modules.ruby.rubyproject</type>
4
+ <configuration>
5
+ <data xmlns="http://www.netbeans.org/ns/ruby-project/1">
6
+ <name>sqld4r</name>
7
+ <source-roots>
8
+ <root id="src.bin.dir"/>
9
+ <root id="src.lib.dir"/>
10
+ </source-roots>
11
+ <test-roots>
12
+ <root id="test.spec.dir"/>
13
+ </test-roots>
14
+ </data>
15
+ </configuration>
16
+ </project>
@@ -33,7 +33,7 @@
33
33
  <h1>sqld4r</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/sqld4r"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/sqld4r" class="numbers">0.0.1</a>
36
+ <a href="http://rubyforge.org/projects/sqld4r" class="numbers">0.0.2</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;sqld4r&#8217;</h1>
39
39
 
@@ -46,6 +46,18 @@ If you have a xml file of the SQLDesigner, you will be able to generate migratio
46
46
  I recommend that you use it with a rocketstarter gem.<br /></p>
47
47
 
48
48
 
49
+ <h2>Features</h2>
50
+
51
+
52
+ <ul>
53
+ <li>generate migration files and model files from SQLDesigner xml file.<br /></li>
54
+ <li>generate migration file for your model&#8217;s PKs and FKs.<br /></li>
55
+ <li>execute command list before finish.<br />
56
+ (exp., execute &#8216;rake db:create:all&#8217; for migrate to your database).<br /></li>
57
+ <li>save the DBDesigner xml file.<br /></li>
58
+ </ul>
59
+
60
+
49
61
  <h2>Installing</h2>
50
62
 
51
63
 
@@ -71,6 +83,54 @@ I recommend that you use it with a rocketstarter gem.<br /></p>
71
83
  </pre></p>
72
84
 
73
85
 
86
+ <h2>How to use</h2>
87
+
88
+
89
+ <p>1. Set environment valiable if you want to change a config file path.</p>
90
+
91
+
92
+ <p><pre class='syntax'>
93
+ <span class="global">$ </span><span class="ident">export</span> <span class="constant">SQLD4R_CONF</span><span class="punct">=~/</span><span class="regex">.sqld4r<span class="normal">
94
+ </span></span></pre></p>
95
+
96
+
97
+ <p>- Default is $HOME/.sqld4r</p>
98
+
99
+
100
+ <p>2. Create config file.</p>
101
+
102
+
103
+ <p><pre class='syntax'>
104
+ <span class="global">$ </span><span class="ident">sqld4r</span> <span class="punct">--</span><span class="ident">init</span>
105
+ </pre></p>
106
+
107
+
108
+ <p>3. Modify default values and command list.</p>
109
+
110
+
111
+ <p><pre class='syntax'>
112
+ <span class="global">$ </span><span class="ident">vi</span> ~<span class="punct">/.</span><span class="ident">sqld4r</span>
113
+ <span class="global">$ </span><span class="ident">vi</span> ~<span class="punct">/</span><span class="ident">sqld4r_execute_commands</span>
114
+ </pre></p>
115
+
116
+
117
+ <p>4. Test for setting</p>
118
+
119
+
120
+ <p><pre class='syntax'>
121
+ <span class="global">$ </span><span class="ident">sqld4r</span> <span class="punct">--</span><span class="ident">check</span>
122
+ </pre></p>
123
+
124
+
125
+ <p>5. Generate migration files and model files from SQLDesigner xml file.</p>
126
+
127
+
128
+ <p><pre class='syntax'>
129
+ <span class="global">$ </span><span class="ident">cd</span> <span class="ident">your</span><span class="punct">-</span><span class="ident">rails</span><span class="punct">-</span><span class="ident">root</span>
130
+ <span class="global">$ </span><span class="ident">sqld4r</span> <span class="punct">/</span><span class="ident">path</span><span class="punct">/</span><span class="ident">to</span><span class="punct">/</span><span class="constant">SQLDesigner</span><span class="punct">.</span><span class="ident">xml</span>
131
+ </pre></p>
132
+
133
+
74
134
  <h2>Forum</h2>
75
135
 
76
136
 
@@ -120,7 +180,7 @@ rake install_gem</pre>
120
180
 
121
181
  <p>Comments are welcome. Send an email to <a href="mailto:maimuzo@gmail.com" title="maimuzo">Yusuke Ohmichi</a> via the <a href="http://groups.google.com/group/sqld4r">forum</a></p>
122
182
  <p class="coda">
123
- <a href="maimuzo@gmail.com">Yusuke Ohmichi(maimuzo)</a>, 22nd June 2008<br>
183
+ <a href="maimuzo@gmail.com">Yusuke Ohmichi(maimuzo)</a>, 24th June 2008<br>
124
184
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
125
185
  </p>
126
186
  </div>
@@ -9,6 +9,14 @@ The sqld4r is model generator for SQLDesigner(http://ondras.zarovi.cz/sql/demo/)
9
9
  If you have a xml file of the SQLDesigner, you will be able to generate migration files and model files on a minute.<br />
10
10
  I recommend that you use it with a rocketstarter gem.<br />
11
11
 
12
+ h2. Features
13
+
14
+ * generate migration files and model files from SQLDesigner xml file.<br />
15
+ * generate migration file for your model's PKs and FKs.<br />
16
+ * execute command list before finish.<br />
17
+ (exp., execute 'rake db:create:all' for migrate to your database).<br />
18
+ * save the DBDesigner xml file.<br />
19
+
12
20
  h2. Installing
13
21
 
14
22
  <pre syntax="ruby">gem install sqld4r</pre>
@@ -28,6 +36,42 @@ and more...
28
36
  Usage: sqld4r --help
29
37
  </pre>
30
38
 
39
+ h2. How to use
40
+
41
+ 1. Set environment valiable if you want to change a config file path.
42
+
43
+ <pre syntax="ruby">
44
+ $ export SQLD4R_CONF=~/.sqld4r
45
+ </pre>
46
+
47
+ - Default is $HOME/.sqld4r
48
+
49
+ 2. Create config file.
50
+
51
+ <pre syntax="ruby">
52
+ $ sqld4r --init
53
+ </pre>
54
+
55
+ 3. Modify default values and command list.
56
+
57
+ <pre syntax="ruby">
58
+ $ vi ~/.sqld4r
59
+ $ vi ~/sqld4r_execute_commands
60
+ </pre>
61
+
62
+ 4. Test for setting
63
+
64
+ <pre syntax="ruby">
65
+ $ sqld4r --check
66
+ </pre>
67
+
68
+ 5. Generate migration files and model files from SQLDesigner xml file.
69
+
70
+ <pre syntax="ruby">
71
+ $ cd your-rails-root
72
+ $ sqld4r /path/to/SQLDesigner.xml
73
+ </pre>
74
+
31
75
  h2. Forum
32
76
 
33
77
  "http://groups.google.com/group/sqld4r (English)":http://groups.google.com/group/sqld4r
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqld4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke Ohmichi(maimuzo)
@@ -30,7 +30,7 @@ cert_chain:
30
30
  KWTqcg==
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2008-06-22 00:00:00 +09:00
33
+ date: 2008-06-25 00:00:00 +09:00
34
34
  default_executable:
35
35
  dependencies: []
36
36
 
@@ -49,7 +49,6 @@ extra_rdoc_files:
49
49
  - README.txt
50
50
  - website/index.txt
51
51
  files:
52
- - .gitignore
53
52
  - History.txt
54
53
  - License.txt
55
54
  - Manifest.txt
@@ -60,7 +59,6 @@ files:
60
59
  - config/hoe.rb
61
60
  - config/requirements.rb
62
61
  - lib/sqld4r.rb
63
- - lib/sqld4r/er2.xml
64
62
  - lib/sqld4r/sqld4r_core.rb
65
63
  - lib/sqld4r/sqld4r_options.rb
66
64
  - lib/sqld4r/sqld4r_parser.rb
@@ -77,6 +75,7 @@ files:
77
75
  - spec/spec.opts
78
76
  - spec/spec_helper.rb
79
77
  - spec/sqld4r_spec.rb
78
+ - spec/dbdesigner.xml
80
79
  - tasks/deployment.rake
81
80
  - tasks/environment.rake
82
81
  - tasks/rspec.rake
@@ -89,7 +88,7 @@ files:
89
88
  has_rdoc: true
90
89
  homepage: http://sqld4r.rubyforge.org
91
90
  post_install_message: |+
92
- 1. Set environment valiable.
91
+ 1. Set environment valiable if you want to change a config file path.
93
92
 
94
93
  $ export SQLD4R_CONF=~/.sqld4r
95
94
 
@@ -99,9 +98,10 @@ post_install_message: |+
99
98
 
100
99
  $ sqld4r --init
101
100
 
102
- 3. Modify default values.
101
+ 3. Modify default values and command list.
103
102
 
104
103
  $ vi ~/.sqld4r
104
+ $ vi ~/sqld4r_execute_commands
105
105
 
106
106
  4. Test for setting
107
107
 
metadata.gz.sig CHANGED
Binary file
data/.gitignore DELETED
@@ -1 +0,0 @@
1
- nbproject