databasion 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,7 +1,12 @@
1
+ ### 0.2.1
2
+ * [FIXED] Tables without an 'id' field weren't updating via the load command and bailing, a dramatic oversight on my part. Databasion now includes the composite primary keys gem for ActiveRecord, and correctly drops and loads master data now.
3
+
1
4
  ### 0.2.0
2
5
 
3
6
  * [FIXED] Fields flagged with an index were not properly referenced.
7
+ * [FIXED] Default field values are now correctly inserted into database.
4
8
  * [CHANGE] There is now an Environment spreadsheet to define environments, and each environment replaces the old Database spreadsheet. Databasion data is also broken down by directory, named after the relevant environment. Specific environments are called with the new -e switch.
9
+ * [CHANGE] If an id field is assigned as "id, auto" then it will be set as an auto incrementing primary key, and all other primary keys are ignored.
5
10
  * [NEW] Version control is now handled in the Environment spreadsheet, and works via the -r switch. Ideal for near-realtime updates using crontab.
6
11
  * [NEW] Multiple primary keys can now be assigned by adding a comma delimited _primary_ to a field.
7
12
  * [NEW] The _options_ field in a spreadsheet environment definition now works according to the Rails Migration rules.
data/README.md CHANGED
@@ -20,6 +20,7 @@ NOTE: The system is currently undergoing major changes, and will not remain back
20
20
  * ActiveSupport >= 2.3.5
21
21
  * Google Spreadsheet >= 0.1.2
22
22
  * Spreadsheet >= 0.6.4.1
23
+ * Composite Primary Keys >= 3.0.9
23
24
 
24
25
  ## Installation
25
26
 
@@ -76,7 +77,7 @@ Next we define the actual table spreadsheets.
76
77
  | comment | | | |
77
78
  | table | superheroes | | |
78
79
  | index | yes | | |
79
- | field | id | name | power | cape
80
+ | field | id, primary | name | power | cape
80
81
  | type | integer | string, 20 | string, 20, Wimp | boolean
81
82
  | | 1 | Brian Jones | Ruby Hacker | false
82
83
  | | 2 | Superman | Invincible | true
@@ -89,7 +90,7 @@ Next we define the actual table spreadsheets.
89
90
  * comment - Ideally a description of the field, what the values means, etc.
90
91
  * table - The name of the table, and an optional comma delimited 'false' if the table name should not be auto-pluralized.
91
92
  * index - This will create an index on the designated field. If a multi-index is required, indices will be grouped by unique names. Multiple multi-indices are possible.
92
- * field - The name of the table column, with an optional comma delimited 'auto' or 'primary' parameter. Auto is strictly limited to an 'id' field, and enables auto incrementation.
93
+ * field - The name of the table column, with an optional comma delimited 'auto' or 'primary' parameter. Auto is strictly limited to an 'id' field, and enables auto incrementation. At least one field _must_ be labeled 'primary' or 'auto', otherwise the system will bail while trying to build that table.
93
94
  * type - A comma delimited list giving the type of the column (using Ruby migration terms), optional size, and optional default value.
94
95
 
95
96
  __Ruby Migration Types__
@@ -172,7 +173,7 @@ Keywords are also supported in the _ignore_ columns and rows of table definition
172
173
  | comment | | | | |
173
174
  | table | superheroes | | | |
174
175
  | index | yes | | | |
175
- | field | id | name | power | cape | mask
176
+ | field | id, primary | name | power | cape | mask
176
177
  | type | integer | string, 20 | string, 20, Wimp | boolean | boolean
177
178
  | | 1 | Brian Jones | Ruby Hacker | false | false
178
179
  | | 2 | Superman | Invincible | true | false
data/Rakefile CHANGED
@@ -8,12 +8,13 @@ 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.2.0"
11
+ gem.version = "0.2.1"
12
12
 
13
13
  gem.add_dependency('activerecord', '>= 2.3.5')
14
14
  gem.add_dependency('activesupport', '>= 2.3.5')
15
15
  gem.add_dependency('google-spreadsheet-ruby', '>= 0.1.2')
16
16
  gem.add_dependency('spreadsheet', '>= 0.6.4.1')
17
+ gem.add_dependency('composite_primary_keys', '>= 3.0.9')
17
18
  end
18
19
 
19
20
  Jeweler::GemcutterTasks.new
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.2.0"
8
+ s.version = "0.2.1"
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-12-03}
12
+ s.date = %q{2010-12-15}
13
13
  s.default_executable = %q{databasion}
14
14
  s.email = %q{mojobojo@gmail.com}
15
15
  s.executables = ["databasion"]
@@ -71,17 +71,20 @@ Gem::Specification.new do |s|
71
71
  s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
72
72
  s.add_runtime_dependency(%q<google-spreadsheet-ruby>, [">= 0.1.2"])
73
73
  s.add_runtime_dependency(%q<spreadsheet>, [">= 0.6.4.1"])
74
+ s.add_runtime_dependency(%q<composite_primary_keys>, [">= 3.0.9"])
74
75
  else
75
76
  s.add_dependency(%q<activerecord>, [">= 2.3.5"])
76
77
  s.add_dependency(%q<activesupport>, [">= 2.3.5"])
77
78
  s.add_dependency(%q<google-spreadsheet-ruby>, [">= 0.1.2"])
78
79
  s.add_dependency(%q<spreadsheet>, [">= 0.6.4.1"])
80
+ s.add_dependency(%q<composite_primary_keys>, [">= 3.0.9"])
79
81
  end
80
82
  else
81
83
  s.add_dependency(%q<activerecord>, [">= 2.3.5"])
82
84
  s.add_dependency(%q<activesupport>, [">= 2.3.5"])
83
85
  s.add_dependency(%q<google-spreadsheet-ruby>, [">= 0.1.2"])
84
86
  s.add_dependency(%q<spreadsheet>, [">= 0.6.4.1"])
87
+ s.add_dependency(%q<composite_primary_keys>, [">= 3.0.9"])
85
88
  end
86
89
  end
87
90
 
@@ -73,6 +73,14 @@ module Databasion
73
73
  fields.delete('spreadsheet')
74
74
  fields.delete('options')
75
75
  fields.delete('dbname')
76
+
77
+ keys = []
78
+ if meta['auto'] == false
79
+ meta['primaries'].each do |key|
80
+ keys << key
81
+ end
82
+ keys << 'id' if meta['fields'].collect { |field| field['field'] }.include?('id') and !keys.include?('id')
83
+ end
76
84
 
77
85
  model = ERB.new(template, nil, ">")
78
86
  model.result(binding)
@@ -172,6 +172,8 @@ module Databasion
172
172
  end
173
173
  end
174
174
  end
175
+
176
+ raise DatabasionError, "You cannot create a table without at least one 'auto' field, and/or one or more 'primary' fields." if primaries.empty? and !auto
175
177
 
176
178
  {
177
179
  'name' => name,
@@ -32,16 +32,16 @@ module Databasion
32
32
  yaml_file = YAML.load_file('%s/%s.yml' % [opts[:env] + "/" + @@config['output']['yaml_path'], normal_name])
33
33
  end
34
34
 
35
- for row in yaml_file['data']
36
- klass = eval("%s.new" % camel_name)
37
- model = camel_name.constantize.find(:first, :conditions => ['id = ?', row['id']])
38
- if model
39
- camel_name.constantize.update(model.id, row)
40
- else
41
- klass.id = row['id']
42
- klass.update_attributes(row)
35
+ if yaml_file['data']
36
+ camel_name.constantize.delete_all
37
+ yaml_file['data'].each do |row|
38
+ klass = eval("%s.new" % camel_name)
39
+ row.each do |key, value|
40
+ eval("klass.%s = '%s'" % [key, value])
41
+ end
42
+ klass.save
43
43
  end
44
- end if yaml_file['data']
44
+ end
45
45
  end
46
46
  end
47
47
 
@@ -1,4 +1,7 @@
1
1
  class <%= class_name %> < ActiveRecord::Base
2
+ <% if !keys.empty? %>
3
+ set_primary_keys <%= keys.collect { |key| ":%s, " % key }.to_s.strip.chop %>
4
+ <% end %>
2
5
  <%= 'set_table_name "%s"' % table_name unless table_name.nil? %><%= "\n" %>
3
6
  end
4
7
  <%= class_name %>.establish_connection(
data/lib/databasion.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'logger'
3
3
  require 'active_record'
4
+ require 'composite_primary_keys'
4
5
 
5
6
  APP_PATH = File.dirname(File.expand_path(__FILE__))
6
7
  $: << APP_PATH
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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
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-12-03 00:00:00 +09:00
19
+ date: 2010-12-15 00:00:00 +09:00
20
20
  default_executable: databasion
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -84,6 +84,22 @@ dependencies:
84
84
  version: 0.6.4.1
85
85
  type: :runtime
86
86
  version_requirements: *id004
87
+ - !ruby/object:Gem::Dependency
88
+ name: composite_primary_keys
89
+ prerelease: false
90
+ requirement: &id005 !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 21
96
+ segments:
97
+ - 3
98
+ - 0
99
+ - 9
100
+ version: 3.0.9
101
+ type: :runtime
102
+ version_requirements: *id005
87
103
  description:
88
104
  email: mojobojo@gmail.com
89
105
  executables: