databasion 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -50,6 +50,7 @@ Next we define the actual table spreadsheets.
50
50
  | ignore | | |
51
51
  | comment | | |
52
52
  | table | superheroes | |
53
+ | index | yes | |
53
54
  | field | id | name | power
54
55
  | type | integer | string, 20 | string, 20, Wimp
55
56
  | | 1 | Brian Jones | Ruby Hacker
@@ -60,6 +61,7 @@ Next we define the actual table spreadsheets.
60
61
 
61
62
  * ignore - Anything written in this column will cause this column and it's data to be ignored.
62
63
  * table - The name of the table, and an optional comma delimited 'false' if the table name should not be auto-pluralized.
64
+ * index - If something is written in a columns field here, it will get flagged as an index and created via add_index(table, [fields]).
63
65
  * field - The name of the table column.
64
66
  * type - A comma delimited list giving the type of the column (using Ruby migration terms), optional size, and optional default value.
65
67
 
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ Jeweler::Tasks.new do |gem|
8
8
  gem.email = "mojobojo@gmail.com"
9
9
  gem.homepage = "http://github.com/boj/databasion"
10
10
  gem.authors = ["Brian Jones", "Istpika"]
11
- gem.version = "0.0.7"
11
+ gem.version = "0.0.8"
12
12
 
13
13
  gem.add_dependency('activerecord', '>= 2.3.5')
14
14
  gem.add_dependency('activesupport', '>= 2.3.5')
data/databasion.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{databasion}
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Jones", "Istpika"]
12
- s.date = %q{2010-06-23}
12
+ s.date = %q{2010-07-05}
13
13
  s.default_executable = %q{databasion}
14
14
  s.email = %q{mojobojo@gmail.com}
15
15
  s.executables = ["databasion"]
@@ -93,6 +93,7 @@ module Databasion
93
93
  plural = true
94
94
  fields = []
95
95
  types = []
96
+ indexes = []
96
97
  data = []
97
98
 
98
99
  ignore_cols = []
@@ -116,6 +117,10 @@ module Databasion
116
117
  row.each do |type|
117
118
  types.push type unless type.empty?
118
119
  end
120
+ when "index"
121
+ row.each_with_index do |index, i|
122
+ indexes.push i-1 unless index.empty? or i == 0
123
+ end
119
124
  when "ignore"
120
125
  row.each_with_index do |ignore, i|
121
126
  ignore_cols.push i-1 unless ignore.empty? or i == 0
@@ -132,6 +137,7 @@ module Databasion
132
137
  'plural' => plural,
133
138
  'fields' => fields[1..fields.size],
134
139
  'types' => types[1..types.size],
140
+ 'indexes' => indexes,
135
141
  'data' => data,
136
142
  'ignore_cols' => ignore_cols
137
143
  }
@@ -49,6 +49,7 @@ module Databasion
49
49
  File.open(File.expand_path(File.dirname(__FILE__)) + '/templates/migration.erb', 'r') { |f| template = f.read }
50
50
  class_name = meta['name'].camelize
51
51
  table_name = meta['name']
52
+ indexes = meta['indexes']
52
53
  fields = meta['fields']
53
54
 
54
55
  migration = ERB.new(template, nil, ">")
@@ -5,6 +5,11 @@ class <%= class_name %>Migration < ActiveRecord::Migration
5
5
  t.<%= field['type'] %> :<%= field['field'] %><%= ', :limit => %s' % field['size'] if field['size'] %><%= ', :default => %s' % field['default'] if field['default'] %><%= ', :options => "PRIMARY KEY"' if field['field'] == 'id' %><%= "\n" %>
6
6
  <% end %>
7
7
  end
8
+ <% if indexes.size > 1 %>
9
+ add_index :<%= table_name %>, [<%= indexes.collect {|i| ":%s" % i }.join(",") %>]
10
+ <% elsif indexes.size == 1 %>
11
+ add_index :<%= table_name %>, :<%= indexes[0] %><%= "\n" %>
12
+ <% end %>
8
13
  end
9
14
  def self.down
10
15
  drop_table :<%= table_name %><%= "\n" %>
@@ -31,6 +31,11 @@ module Databasion
31
31
  yaml_output += " size: %s\n" % type_data[1] if type_data[1]
32
32
  yaml_output += " default: %s\n" % type_data[2] if type_data[2]
33
33
  end
34
+ indexes = ''
35
+ data_hash['indexes'].each_with_index do |index, i|
36
+ indexes += data_hash['fields'][i] + ","
37
+ end
38
+ yaml_output += " indexes: [%s]\n" % indexes.chop
34
39
  yaml_output += " connection:\n"
35
40
  data_hash['connection'].each do |key, value|
36
41
  yaml_output += " %s: %s\n" % [key, value] unless ['spreadsheet', 'options'].include?(key)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: databasion
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Jones
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-06-23 00:00:00 +09:00
19
+ date: 2010-07-05 00:00:00 +09:00
20
20
  default_executable: databasion
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency