databasion 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.md CHANGED
@@ -4,7 +4,9 @@
4
4
 
5
5
  If we were all part of a hive mind, we wouldn't need management anything. Databases would get built, the correct columns would get used, programmers would align their ORMs, and keeping it all together wouldn't be some kind of management nightmare.
6
6
 
7
- Fortunately we aren't a hive mind (and if we were I would be just as confused as I am any other day, our office's main language is Japanese). Still, even though my coworkers can't read my mind, we've come up with a tool that allows top end planners to describe system data in a spreadsheet, programmers to fudge in the column types, sizes, and database relationships, and everyone to export it out into YAML and Ruby migration scripts which update your infrastructure. Ideally the fully automated suite is used in your test environment so your planner can quickly test changes, and a step by step process used if you are updating production machines.
7
+ Fortunately we aren't a hive mind*. Still, even though my coworkers can't read my mind, we've come up with a tool that allows top end planners to describe system data in a spreadsheet, programmers to fudge in the column types, sizes, and database relationships, and everyone to export it out into YAML and Ruby migration scripts which update your infrastructure. Ideally the fully automated suite is used in your test environment so your planner can quickly test changes, and a step by step process used if you are updating production machines.
8
+
9
+ * If we were I would be just as confused as I am any other day, our office's main language is Japanese. Although I've been studying it for 9 years...
8
10
 
9
11
  ## Requirements
10
12
 
@@ -96,16 +98,20 @@ Setup the project space.
96
98
 
97
99
  Edit _config/google.yml_. Then run the scripts.
98
100
 
99
- databasion --system google
101
+ databasion --google
100
102
  databasion --migrate
103
+ databasion --update
104
+ databasion --svn
101
105
 
102
- Or run them both in order.
106
+ Or run them all in order.
103
107
 
104
- databasion --system google --migrate
108
+ databasion --google --migrate --update --svn
105
109
 
106
110
  You can supply a different config path as well.
107
111
 
108
- databasion -s google -m --config config/my.other.config.yml
112
+ databasion -g -m -u -s --config config/my.other.config.yml
113
+
114
+ Someone administrating a production database with this tool would definitely want to run each script sequentially by hand.
109
115
 
110
116
  ### YAML Configuration
111
117
 
@@ -114,13 +120,22 @@ You can supply a different config path as well.
114
120
  * _login_: A valid Google username and password.
115
121
  * _sheets_: A list of the keys gleaned from the Google Docs URL, and a human readable name.
116
122
  * _output_: Where to output the relevant data.
123
+ * _svn_: SVN configuration data.
124
+
125
+ ## SVN
126
+
127
+ If the currently created databasion project is committed to SVN, running the _--svn_ switch will auto-add and commit all the project files. This is useful for maintaining version control of the system, especially if something goes wrong and you need to do a rollback.
117
128
 
118
129
  ## Roadmap
119
130
 
120
- __0.0.2__
131
+ __0.0.3__
121
132
 
122
133
  * Add ability to read existing tables, and make relative alter table migration scripts.
123
134
 
135
+ __0.0.2__
136
+
137
+ * <del>Add SVN hooks.</del>
138
+
124
139
  __0.0.1__
125
140
 
126
141
  * <del>Write this documentation.</del>
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.1"
11
+ gem.version = "0.0.2"
12
12
 
13
13
  gem.add_dependency('activerecord', '>= 2.3.5')
14
14
  gem.add_dependency('activesupport', '>= 2.3.5')
@@ -10,4 +10,8 @@ output:
10
10
  yaml_path: 'data'
11
11
  migrations:
12
12
  path: 'migrations'
13
- models: 'models'
13
+ models: 'models'
14
+
15
+ svn:
16
+ bin: /usr/bin/svn
17
+ repo: svn://repo/path
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.1"
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 = ["Brian Jones", "Istpika"]
12
- s.date = %q{2010-05-19}
12
+ s.date = %q{2010-05-20}
13
13
  s.default_executable = %q{databasion}
14
14
  s.email = %q{mojobojo@gmail.com}
15
15
  s.executables = ["databasion"]
@@ -29,15 +29,20 @@ Gem::Specification.new do |s|
29
29
  "features/databasion/migitize.feature",
30
30
  "features/databasion/step_definitions/googlize_steps.rb",
31
31
  "features/databasion/step_definitions/migitize_steps.rb",
32
+ "features/databasion/step_definitions/svnilize_steps.rb",
32
33
  "features/databasion/step_definitions/yamalize_steps.rb",
34
+ "features/databasion/svnilize.feature",
33
35
  "features/databasion/yamalize.feature",
34
36
  "features/step_definitions/databasion_steps.rb",
35
37
  "lib/databasion.rb",
36
38
  "lib/databasion/applcize.rb",
37
39
  "lib/databasion/csvilize.rb",
40
+ "lib/databasion/datacize.rb",
38
41
  "lib/databasion/excelize.rb",
39
42
  "lib/databasion/googlize.rb",
43
+ "lib/databasion/loadlize.rb",
40
44
  "lib/databasion/migitize.rb",
45
+ "lib/databasion/svnilize.rb",
41
46
  "lib/databasion/yamalize.rb",
42
47
  "lib/migration_helpers/MIT-LICENSE",
43
48
  "lib/migration_helpers/README.markdown",
@@ -0,0 +1,14 @@
1
+ require 'lib/databasion'
2
+
3
+ Given /a databasion created file structure/ do
4
+ Databasion::Applcize.create_project({ :create => 'cucumber_test' })
5
+ end
6
+
7
+ When /the commit command is ran/ do
8
+ Databasion::Svnilize.commit('cucumber_test')
9
+ end
10
+
11
+ Then /the data should be stored in SVN/ do
12
+
13
+ FileUtils.rm_rf 'cucumber_test'
14
+ end
@@ -0,0 +1,8 @@
1
+ Feature: SVN Auto Commit
2
+ In order to save files in SVN
3
+ We need a system that runs the commands for us
4
+
5
+ Scenario: A typical auto commit
6
+ Given a databasion created file structure
7
+ When the commit command is ran
8
+ Then the data should be stored in SVN
@@ -15,9 +15,10 @@ module Databasion
15
15
  EOS
16
16
  opt :create, "Create a base deploy directory", :type => String
17
17
  opt :config, "Path to YAML config. Looks for config/google.yml by default", :type => String
18
- opt :system, "google, excel, migrate, update", :type => String
18
+ opt :google, "Googlize data from Google Spreadsheets"
19
19
  opt :migrate, "Migrate after Googlizing or Excelizing"
20
20
  opt :update, "Load parsed YAML into migrated database"
21
+ opt :svn, "Auto commit the project files (assuming it has been committed to SVN)"
21
22
  end
22
23
  if opts[:config].nil? and opts[:create].nil?
23
24
  config = "config/google.yml"
@@ -28,7 +29,6 @@ module Databasion
28
29
  Trollop::die :config, "A YAML config must be specified"
29
30
  end
30
31
  end
31
- Trollop::die :system, "System requires a parameter" if opts[:system].nil? and opts[:create].nil?
32
32
 
33
33
  if opts[:create]
34
34
  create_project(opts)
@@ -38,14 +38,17 @@ module Databasion
38
38
  end
39
39
 
40
40
  def self.execute_databasion(opts)
41
- if opts[:system] and opts[:config]
42
- Databasion.databate(opts[:system], opts[:config])
43
- if opts[:migrate] and opts[:system] != 'migrate'
44
- Databasion.databate('migrate', opts[:config])
45
- end
46
- if opts[:update] and opts[:system] != 'update'
47
- Databasion.databate('update', opts[:config])
48
- end
41
+ if opts[:google]
42
+ Databasion.databate('google', opts[:config])
43
+ end
44
+ if opts[:migrate]
45
+ Databasion.databate('migrate', opts[:config])
46
+ end
47
+ if opts[:update]
48
+ Databasion.databate('update', opts[:config])
49
+ end
50
+ if opts[:svn]
51
+ Databasion.databate('svn', opts[:config])
49
52
  end
50
53
  end
51
54
 
@@ -0,0 +1,30 @@
1
+ module Databasion
2
+
3
+ class Datacize
4
+
5
+ @@config = nil
6
+
7
+ def self.config=(config)
8
+ @@config = config
9
+ end
10
+
11
+ def self.datacize
12
+ require 'migration_helpers/init'
13
+
14
+ files = Dir["%s/*.yml" % @@config['output']['yaml_path']]
15
+ Databasion::Migitize.migrabate(files, @@config)
16
+
17
+ Databasion.set_ar_logger
18
+ Databasion::LOGGER.info "Migrating..."
19
+
20
+ YAML.load_file('config/database.yml').each do |config|
21
+ ActiveRecord::Base.establish_connection(config[1])
22
+ path = @@config['output']['migrations']['path'] + "/" + config[0]
23
+ ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
24
+ ActiveRecord::Migrator.migrate(path, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,45 @@
1
+ module Databasion
2
+
3
+ class Loadlize
4
+
5
+ @@config = nil
6
+
7
+ def self.config=(config)
8
+ @@config = config
9
+ end
10
+
11
+ def self.config
12
+ @@config
13
+ end
14
+
15
+ def self.loadalize
16
+ Databasion.set_ar_logger
17
+ Databasion::LOGGER.info "Updating from YAML..."
18
+
19
+ models = Dir[@@config['output']['migrations']['models'] + "/*.rb"].each { |file| load file }
20
+
21
+ models.each do |model|
22
+ f = model.split('/')
23
+ plural_name = f[f.size-1].split(".")[0].pluralize
24
+ camel_name = f[f.size-1].split(".")[0].camelize
25
+
26
+ Databasion::LOGGER.info "Loading %s into database..." % camel_name
27
+
28
+ yaml_file = YAML.load_file('%s/%s.yml' % [@@config['output']['yaml_path'], plural_name])
29
+
30
+ for row in yaml_file['data']
31
+ klass = eval("%s.new" % camel_name)
32
+ model = camel_name.constantize.find(:first, :conditions => ['id = ?', row['id']])
33
+ if model
34
+ camel_name.constantize.update(model.id, row)
35
+ else
36
+ klass.id = row['id']
37
+ klass.update_attributes(row)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,62 @@
1
+ require 'fileutils'
2
+
3
+ module Databasion
4
+
5
+ class Svnilize
6
+
7
+ @@config = nil
8
+
9
+ class SvnilizeError < StandardError; end
10
+
11
+ def self.config=(config)
12
+ @@config = config
13
+ end
14
+
15
+ def self.config
16
+ @@config
17
+ end
18
+
19
+ def self.svn_path
20
+ @@config['svn']['bin']
21
+ end
22
+
23
+ def self.commit(path=Dir.pwd)
24
+ raise SvnilizeError, "A file lock is in place. Cannot commit." if check_lock?
25
+ create_lock
26
+ svn_add_files(path)
27
+ begin
28
+ Databasion::LOGGER.info 'running: svn commit -m "svn auto commit"'
29
+ system svn_path + ' commit -m "svn auto commit"'
30
+ Databasion::LOGGER.info 'running: svn update'
31
+ system svn_path + ' update'
32
+ rescue
33
+ remove_lock
34
+ raise SvnilizeError, "This isn't a valid SVN project."
35
+ end
36
+ remove_lock
37
+ end
38
+
39
+ def self.svn_add_files(path)
40
+ files = Dir[Dir.pwd + "/" + path + "/**/*"]
41
+ files.each do |file|
42
+ Databasion::LOGGER.info 'running: svn add %s' % file
43
+ system svn_path + ' add %s' % file
44
+ end
45
+ end
46
+
47
+ def self.check_lock?
48
+ return true if File.exist?('svn.lock')
49
+ false
50
+ end
51
+
52
+ def self.create_lock
53
+ File.new('svn.lock', 'w') unless check_lock?
54
+ end
55
+
56
+ def self.remove_lock
57
+ FileUtils.rm 'svn.lock'
58
+ end
59
+
60
+ end
61
+
62
+ end
data/lib/databasion.rb CHANGED
@@ -26,9 +26,11 @@ module Databasion
26
26
  when "excel"
27
27
  excelize
28
28
  when "migrate"
29
- migrate
29
+ datacize
30
30
  when "update"
31
- load_yaml
31
+ loadalize
32
+ when "svn"
33
+ svnilize
32
34
  end
33
35
  end
34
36
 
@@ -41,51 +43,19 @@ module Databasion
41
43
  Databasion::Excelize.excelbate
42
44
  end
43
45
 
44
- def self.migrate
45
- require 'migration_helpers/init'
46
-
47
- files = Dir["%s/*.yml" % @@config['output']['yaml_path']]
48
- Databasion::Migitize.migrabate(files, @@config)
49
-
50
- Databasion::LOGGER.info "Migrating..."
51
-
52
- set_ar_logger
53
-
54
- YAML.load_file('config/database.yml').each do |config|
55
- ActiveRecord::Base.establish_connection(config[1])
56
- path = @@config['output']['migrations']['path'] + "/" + config[0]
57
- ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
58
- ActiveRecord::Migrator.migrate(path, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
59
- end
46
+ def datacize
47
+ Databasion::Datacize.config = @@config
48
+ Databasion::Datacize.loadalize
60
49
  end
61
50
 
62
- def self.load_yaml
63
- Databasion::LOGGER.info "Updating from YAML..."
64
-
65
- set_ar_logger
66
-
67
- models = Dir[@@config['output']['migrations']['models'] + "/*.rb"].each { |file| load file }
68
-
69
- models.each do |model|
70
- f = model.split('/')
71
- plural_name = f[f.size-1].split(".")[0].pluralize
72
- camel_name = f[f.size-1].split(".")[0].camelize
73
-
74
- Databasion::LOGGER.info "Loading %s into database..." % camel_name
75
-
76
- yaml_file = YAML.load_file('%s/%s.yml' % [@@config['output']['yaml_path'], plural_name])
77
-
78
- for row in yaml_file['data']
79
- klass = eval("%s.new" % camel_name)
80
- model = camel_name.constantize.find(:first, :conditions => ['id = ?', row['id']])
81
- if model
82
- camel_name.constantize.update(model.id, row)
83
- else
84
- klass.id = row['id']
85
- klass.update_attributes(row)
86
- end
87
- end
88
- end
51
+ def loadalize
52
+ Databasion::Loadlize.config = @@config
53
+ Databasion::Loadlize.loadalize
54
+ end
55
+
56
+ def self.svnilize
57
+ Databasion::Svnilize.config = @@config
58
+ Databasion::Svnilize.commit
89
59
  end
90
60
 
91
61
  private
@@ -99,5 +69,8 @@ module Databasion
99
69
  autoload :Excelize, APP_PATH + '/databasion/excelize.rb'
100
70
  autoload :Csvilize, APP_PATH + '/databasion/csvilize.rb'
101
71
  autoload :Migitize, APP_PATH + '/databasion/migitize.rb'
72
+ autoload :Loadlize, APP_PATH + '/databasion/loadlize.rb'
73
+ autoload :Datacize, APP_PATH + '/databasion/datacize.rb'
74
+ autoload :Svnilize, APP_PATH + '/databasion/svnilize.rb'
102
75
 
103
76
  end
@@ -10,4 +10,14 @@ namespace :databasion do
10
10
  task :migrate do
11
11
  Databasion.databate('migrate', 'config/google.yml')
12
12
  end
13
+
14
+ desc "Run the update script to stuff YAML data into database"
15
+ task :update do
16
+ Databasion.databate('update', 'config/google.yml')
17
+ end
18
+
19
+ desc "Run the SVN auto-commit system"
20
+ task :svn do
21
+ Databasion.databate('svn', 'config/google.yml')
22
+ end
13
23
  end
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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
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-05-19 00:00:00 +09:00
19
+ date: 2010-05-20 00:00:00 +09:00
20
20
  default_executable: databasion
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -105,15 +105,20 @@ files:
105
105
  - features/databasion/migitize.feature
106
106
  - features/databasion/step_definitions/googlize_steps.rb
107
107
  - features/databasion/step_definitions/migitize_steps.rb
108
+ - features/databasion/step_definitions/svnilize_steps.rb
108
109
  - features/databasion/step_definitions/yamalize_steps.rb
110
+ - features/databasion/svnilize.feature
109
111
  - features/databasion/yamalize.feature
110
112
  - features/step_definitions/databasion_steps.rb
111
113
  - lib/databasion.rb
112
114
  - lib/databasion/applcize.rb
113
115
  - lib/databasion/csvilize.rb
116
+ - lib/databasion/datacize.rb
114
117
  - lib/databasion/excelize.rb
115
118
  - lib/databasion/googlize.rb
119
+ - lib/databasion/loadlize.rb
116
120
  - lib/databasion/migitize.rb
121
+ - lib/databasion/svnilize.rb
117
122
  - lib/databasion/yamalize.rb
118
123
  - lib/migration_helpers/MIT-LICENSE
119
124
  - lib/migration_helpers/README.markdown