databasion 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/README.md +24 -5
  2. data/Rakefile +1 -1
  3. data/bin/databasion +1 -1
  4. data/config/example.google.yml +6 -0
  5. data/databasion.gemspec +22 -22
  6. data/features/build_migration.feature +8 -0
  7. data/features/create_project.feature +8 -0
  8. data/features/cron_system.feature +7 -0
  9. data/features/env/helper_methods.rb +12 -0
  10. data/features/google_loader.feature +8 -0
  11. data/features/step_definitions/build_migration_steps.rb +22 -0
  12. data/features/step_definitions/create_project_steps.rb +13 -0
  13. data/features/step_definitions/cron_system_steps.rb +17 -0
  14. data/features/step_definitions/google_loader_steps.rb +14 -0
  15. data/features/step_definitions/yaml_builder_steps.rb +16 -0
  16. data/features/{databasion/migitize.feature → yaml_builder.feature} +1 -1
  17. data/lib/databasion.rb +37 -37
  18. data/lib/databasion/{applcize.rb → application.rb} +15 -10
  19. data/lib/databasion/{migitize.rb → build_migration.rb} +8 -7
  20. data/lib/databasion/cron_system.rb +53 -0
  21. data/lib/databasion/{gitilize.rb → git_committer.rb} +4 -3
  22. data/lib/databasion/{googlize.rb → google_loader.rb} +58 -18
  23. data/lib/databasion/{loadlize.rb → load_data.rb} +2 -2
  24. data/lib/databasion/{datacize.rb → migrate.rb} +3 -3
  25. data/lib/databasion/{svnilize.rb → svn_committer.rb} +3 -3
  26. data/lib/databasion/{yamalize.rb → yaml_builder.rb} +4 -4
  27. data/lib/tasks/databasion.rake +11 -6
  28. metadata +24 -24
  29. data/features/databasion.feature +0 -23
  30. data/features/databasion/googlize.feature +0 -13
  31. data/features/databasion/step_definitions/googlize_steps.rb +0 -32
  32. data/features/databasion/step_definitions/migitize_steps.rb +0 -26
  33. data/features/databasion/step_definitions/svnilize_steps.rb +0 -14
  34. data/features/databasion/step_definitions/yamalize_steps.rb +0 -29
  35. data/features/databasion/svnilize.feature +0 -8
  36. data/features/databasion/yamalize.feature +0 -9
  37. data/features/step_definitions/databasion_steps.rb +0 -35
  38. data/lib/databasion/csvilize.rb +0 -11
  39. data/lib/databasion/excelize.rb +0 -11
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  A database management tool. The theory is that a designer/planner can edit application data and a programmer can setup the database and it's fields, all in one happy little place. As tables are added and data is changed, if the script is run once again it will update the target database.
6
6
 
7
- TODO: While this system uses Rails Migrations, it isn't taking full advantage of them (i.e. tracking changes, allowing for rollbacks, etc.). This was also created under a high pressure timeline, so it was unfortunate that I could not create a fully working test suite.
7
+ TODO: While this system uses Rails Migrations, it isn't taking full advantage of them (i.e. tracking changes, allowing for rollbacks, etc).
8
8
 
9
9
  ## Requirements
10
10
 
@@ -100,17 +100,17 @@ Edit _config/google.yml_. Then run the scripts.
100
100
 
101
101
  databasion --google
102
102
  databasion --migrate
103
- databasion --update
103
+ databasion --load
104
104
  databasion --svn
105
105
  databasion --git
106
106
 
107
107
  Or run them all in order.
108
108
 
109
- databasion --google --migrate --update --git
109
+ databasion --google --migrate --load --git
110
110
 
111
111
  You can supply a different config path as well.
112
112
 
113
- databasion -g -m -u -i --config config/my.other.config.yml
113
+ databasion -g -m -l -i --config config/my.other.config.yml
114
114
 
115
115
  Someone administrating a production database with this tool would definitely want to run each script sequentially by hand.
116
116
 
@@ -123,6 +123,7 @@ Someone administrating a production database with this tool would definitely wan
123
123
  * _output_: Where to output the relevant data.
124
124
  * _svn_: SVN configuration data.
125
125
  * _git_: GIT configuration data.
126
+ * _cron_: Crontab parameters.
126
127
 
127
128
  ## SVN
128
129
 
@@ -132,13 +133,31 @@ If the currently created databasion project is committed to SVN, running the _--
132
133
 
133
134
  Much like SVN, if the project is commited to a GIT repo, the _--git_ switch will auto-add and commit all the project files. If there isn't a repository, it will also initialize a new one for you.
134
135
 
136
+ ## Version Control
137
+
138
+ There is now a system in place to do crontab driven auto-updates. This allows the data to be updated without anyone having to access any systems.
139
+
140
+ First update _config/google.yml_'s cron section to reflect your project settings. The _options_ are your standard databasion switches. Make sure to supply a location for the version file so that it can be read at a later date.
141
+
142
+ Next, add a _Version_ spreadsheet to the master worksheet. In the A1 field use whichever number works best to start versioning with. When using this to manage the project, if the number is higher than before then the system will be updated. Currently version controlled rollbacks are not implemented.
143
+
144
+ Finally, add the databasion script to crontab.
145
+
146
+ Example crontab:
147
+
148
+ */1 * * * * cd /home/my_user/project && databasion -r
149
+
150
+ This checks the Version spreadsheet once a minute, and if the version has changed runs databasion with the supplied options.
151
+
152
+ Note: This could easily be used from the commandline as well, and not just crontab.
153
+
135
154
  ## Roadmap
136
155
 
137
156
  Long and winding.
138
157
 
139
158
  ## Testing
140
159
 
141
- Currently Databasion uses the cucumber test suite. The tests aren't complete, unfortunately.
160
+ Currently Databasion uses the cucumber test suite. A functional set of rudimentary tests are currently available, but it does not test everything 100%.
142
161
 
143
162
  ## Author
144
163
 
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.1.0"
11
+ gem.version = "0.1.1"
12
12
 
13
13
  gem.add_dependency('activerecord', '>= 2.3.5')
14
14
  gem.add_dependency('activesupport', '>= 2.3.5')
@@ -3,4 +3,4 @@ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(_
3
3
 
4
4
  require 'databasion'
5
5
 
6
- Databasion::Applcize.run
6
+ Databasion::Application.run
@@ -18,3 +18,9 @@ svn:
18
18
 
19
19
  git:
20
20
  bin: /usr/local/bin/git
21
+
22
+ cron:
23
+ project_base: /home/user/project
24
+ version:
25
+ file: /home/user/project/config/version
26
+ options: -g -m -l -i
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{databasion}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.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-10-28}
12
+ s.date = %q{2010-11-04}
13
13
  s.default_executable = %q{databasion}
14
14
  s.email = %q{mojobojo@gmail.com}
15
15
  s.executables = ["databasion"]
@@ -24,29 +24,29 @@ Gem::Specification.new do |s|
24
24
  "bin/databasion",
25
25
  "config/example.google.yml",
26
26
  "databasion.gemspec",
27
- "features/databasion.feature",
28
- "features/databasion/googlize.feature",
29
- "features/databasion/migitize.feature",
30
- "features/databasion/step_definitions/googlize_steps.rb",
31
- "features/databasion/step_definitions/migitize_steps.rb",
32
- "features/databasion/step_definitions/svnilize_steps.rb",
33
- "features/databasion/step_definitions/yamalize_steps.rb",
34
- "features/databasion/svnilize.feature",
35
- "features/databasion/yamalize.feature",
36
- "features/step_definitions/databasion_steps.rb",
27
+ "features/build_migration.feature",
28
+ "features/create_project.feature",
29
+ "features/cron_system.feature",
30
+ "features/env/helper_methods.rb",
31
+ "features/google_loader.feature",
32
+ "features/step_definitions/build_migration_steps.rb",
33
+ "features/step_definitions/create_project_steps.rb",
34
+ "features/step_definitions/cron_system_steps.rb",
35
+ "features/step_definitions/google_loader_steps.rb",
36
+ "features/step_definitions/yaml_builder_steps.rb",
37
+ "features/yaml_builder.feature",
37
38
  "lib/databasion.rb",
38
- "lib/databasion/applcize.rb",
39
- "lib/databasion/csvilize.rb",
40
- "lib/databasion/datacize.rb",
41
- "lib/databasion/excelize.rb",
42
- "lib/databasion/gitilize.rb",
43
- "lib/databasion/googlize.rb",
44
- "lib/databasion/loadlize.rb",
45
- "lib/databasion/migitize.rb",
46
- "lib/databasion/svnilize.rb",
39
+ "lib/databasion/application.rb",
40
+ "lib/databasion/build_migration.rb",
41
+ "lib/databasion/cron_system.rb",
42
+ "lib/databasion/git_committer.rb",
43
+ "lib/databasion/google_loader.rb",
44
+ "lib/databasion/load_data.rb",
45
+ "lib/databasion/migrate.rb",
46
+ "lib/databasion/svn_committer.rb",
47
47
  "lib/databasion/templates/migration.erb",
48
48
  "lib/databasion/templates/model.erb",
49
- "lib/databasion/yamalize.rb",
49
+ "lib/databasion/yaml_builder.rb",
50
50
  "lib/migration_helpers/MIT-LICENSE",
51
51
  "lib/migration_helpers/README.markdown",
52
52
  "lib/migration_helpers/init.rb",
@@ -0,0 +1,8 @@
1
+ Feature: Build Ruby Migrations
2
+ In order to run ruby migrations
3
+ We must build a file suite
4
+
5
+ Scenario: Build Ruby Migrations
6
+ Given a set of YAML data
7
+ When we run the BuildMigration system
8
+ Then it should build a migration, model, and database file
@@ -0,0 +1,8 @@
1
+ Feature: Create Project
2
+ In order to run databasion
3
+ A project directory should be built
4
+
5
+ Scenario: User runs databasion with the --create command
6
+ Given a project named test_project
7
+ When the databasion create command is ran
8
+ Then a project folder and config file should exist
@@ -0,0 +1,7 @@
1
+ Feature: Crontab
2
+ Allow a user to run databasion updates via crontab
3
+
4
+ Scenario: User configures the Version spreadsheet
5
+ Given a version spreadsheet in Google Docs
6
+ When the cron system is ran and the version changes
7
+ Then databasion should have been ran
@@ -0,0 +1,12 @@
1
+ def load_parse_data
2
+ {
3
+ 'name' => 'mock',
4
+ 'plural' => true,
5
+ 'indexes' => ["id"],
6
+ 'fields' => ["id", "name", "power"],
7
+ 'types' => ["integer", "string, 20", "string, 40"],
8
+ 'data' => [[1, "Brian Jones", "Super Intelligence"], [2, "Superman", "Invincible"], [3, "Batman", "Strength"]],
9
+ 'ignore_cols' => [2],
10
+ 'connection' => {'database' => 'moon', 'dbname' => 'db1'}
11
+ }
12
+ end
@@ -0,0 +1,8 @@
1
+ Feature: Use GoogleLoader
2
+ In order for a user to access google
3
+ They need to connect first
4
+
5
+ Scenario: Log into Google
6
+ Given a google account from the yaml config
7
+ When GoogleLoader logs in
8
+ Then we should have a GoogleSpreadsheet session
@@ -0,0 +1,22 @@
1
+ require 'lib/databasion'
2
+
3
+ Given /a set of YAML data/ do
4
+ @config = YAML.load(File.open('config/google.yml'))
5
+
6
+ @parse_data = load_parse_data
7
+ Databasion::YamlBuilder.run(@parse_data, @config['output']['yaml_path'])
8
+ end
9
+
10
+ When /we run the BuildMigration system/ do
11
+ Databasion::BuildMigration.run(Dir['%s/**.yml' % @config['output']['yaml_path']], @config)
12
+ end
13
+
14
+ Then /it should build a migration, model, and database file/ do
15
+ File.exist?('%s/%s/100_%s_migration.rb' % [@config['output']['migrations']['path'], @parse_data['connection']['dbname'], @parse_data['name']]).should == true
16
+ File.exist?('%s/%s.rb' % [@config['output']['migrations']['models'], @parse_data['name']]).should == true
17
+ File.exist?('config/database.yml').should == true
18
+ FileUtils.rm_rf @config['output']['migrations']['path']
19
+ FileUtils.rm_rf @config['output']['migrations']['models']
20
+ FileUtils.rm_rf @config['output']['yaml_path']
21
+ FileUtils.rm 'config/database.yml'
22
+ end
@@ -0,0 +1,13 @@
1
+ Given /a project named (.*)/ do |project_name|
2
+ @project = project_name
3
+ end
4
+
5
+ When /the databasion create command is ran/ do
6
+ system 'bin/databasion -c %s' % @project
7
+ end
8
+
9
+ Then /a project folder and config file should exist/ do
10
+ File.exists?('%s' % @project).should == true
11
+ File.exists?('%s/config/google.yml' % @project).should == true
12
+ FileUtils.rm_rf '%s/' % @project
13
+ end
@@ -0,0 +1,17 @@
1
+ require 'lib/databasion'
2
+
3
+ Given /a version spreadsheet in Google Docs/ do
4
+ @config = YAML.load(File.open('config/google.yml'))
5
+ end
6
+
7
+ When /the cron system is ran and the version changes/ do
8
+ Databasion::CronSystem.config = @config
9
+ Databasion::CronSystem.run
10
+ end
11
+
12
+ Then /databasion should have been ran/ do
13
+ Databasion::GoogleLoader.config = @config
14
+ version = Databasion::GoogleLoader.run_version
15
+ File.open(@config['cron']['version']['file']).readline.strip.should == version
16
+ FileUtils.rm_rf @config['cron']['version']['file']
17
+ end
@@ -0,0 +1,14 @@
1
+ require 'lib/databasion'
2
+
3
+ Given /a google account from the yaml config/ do
4
+ @config = YAML.load(File.open('config/google.yml'))
5
+ end
6
+
7
+ When /GoogleLoader logs in/ do
8
+ Databasion::GoogleLoader.config = @config
9
+ Databasion::GoogleLoader.login
10
+ end
11
+
12
+ Then /we should have a GoogleSpreadsheet session/ do
13
+ Databasion::GoogleLoader.session.should be_kind_of(GoogleSpreadsheet::Session)
14
+ end
@@ -0,0 +1,16 @@
1
+ require 'lib/databasion'
2
+
3
+ Given /a complete set of YAML definitions/ do
4
+ @config = YAML.load(File.open('config/google.yml'))
5
+
6
+ @parse_data = load_parse_data
7
+ end
8
+
9
+ When /the YAML files are parsed/ do
10
+ Databasion::YamlBuilder.run(@parse_data, @config['output']['yaml_path'])
11
+ end
12
+
13
+ Then /the result is Ruby migration files/ do
14
+ File.exist?("%s/%s.yml" % [@config['output']['yaml_path'], @parse_data['name']]).should == true
15
+ FileUtils.rm_rf @config['output']['yaml_path']
16
+ end
@@ -5,4 +5,4 @@ Feature: Parse YAML into Ruby migrations
5
5
  Scenario: Build Ruby migrations
6
6
  Given a complete set of YAML definitions
7
7
  When the YAML files are parsed
8
- Then the result is Ruby migration files
8
+ Then the result is Ruby migration files
@@ -14,7 +14,7 @@ module Databasion
14
14
 
15
15
  @@config = nil
16
16
 
17
- def self.databate(system, config=nil)
17
+ def self.run(system, config=nil, opts=nil)
18
18
  LOGGER.level = Logger::INFO
19
19
 
20
20
  raise DatabasionError, 'Databasion requires a YAML config file path.' if config.nil?
@@ -22,63 +22,63 @@ module Databasion
22
22
 
23
23
  case system
24
24
  when "google"
25
- googlize
26
- when "excel"
27
- excelize
25
+ run_google
28
26
  when "migrate"
29
- datacize
30
- when "update"
31
- loadalize
27
+ run_migrate
28
+ when "load"
29
+ run_load(opts)
32
30
  when "svn"
33
- svnilize
31
+ run_svn
34
32
  when "git"
35
- gitilize
33
+ run_git
34
+ when "cron"
35
+ run_cron
36
36
  end
37
37
  end
38
38
 
39
39
  private
40
- def self.googlize
41
- Databasion::Googlize.config = @@config
42
- Databasion::Googlize.googlebate
40
+ def self.run_google
41
+ Databasion::GoogleLoader.config = @@config
42
+ Databasion::GoogleLoader.run
43
43
  end
44
-
45
- def self.excelize
46
- Databasion::Excelize.excelbate
44
+
45
+ def self.run_migrate
46
+ Databasion::Migrate.config = @@config
47
+ Databasion::Migrate.run
47
48
  end
48
49
 
49
- def self.datacize
50
- Databasion::Datacize.config = @@config
51
- Databasion::Datacize.datacize
50
+ def self.run_load(opts)
51
+ Databasion::LoadData.config = @@config
52
+ Databasion::LoadData.run(opts)
52
53
  end
53
54
 
54
- def self.loadalize
55
- Databasion::Loadlize.config = @@config
56
- Databasion::Loadlize.loadalize
55
+ def self.run_svn
56
+ Databasion::SvnCommitter.config = @@config
57
+ Databasion::SvnCommitter.commit
57
58
  end
58
59
 
59
- def self.svnilize
60
- Databasion::Svnilize.config = @@config
61
- Databasion::Svnilize.commit
60
+ def self.run_git
61
+ Databasion::GitCommitter.config = @@config
62
+ Databasion::GitCommitter.commit
62
63
  end
63
64
 
64
- def self.gitilize
65
- Databasion::Gitilize.config = @@config
66
- Databasion::Gitilize.commit
65
+ def self.run_cron
66
+ Databasion::CronSystem.config = @@config
67
+ Databasion::CronSystem.run
67
68
  end
68
69
 
69
70
  def self.set_ar_logger
70
71
  ActiveRecord::Base.logger = Databasion::LOGGER
71
72
  end
72
73
 
73
- autoload :Applcize, APP_PATH + '/databasion/applcize.rb'
74
- autoload :Googlize, APP_PATH + '/databasion/googlize.rb'
75
- autoload :Yamalize, APP_PATH + '/databasion/yamalize.rb'
76
- autoload :Excelize, APP_PATH + '/databasion/excelize.rb'
77
- autoload :Csvilize, APP_PATH + '/databasion/csvilize.rb'
78
- autoload :Migitize, APP_PATH + '/databasion/migitize.rb'
79
- autoload :Loadlize, APP_PATH + '/databasion/loadlize.rb'
80
- autoload :Datacize, APP_PATH + '/databasion/datacize.rb'
81
- autoload :Svnilize, APP_PATH + '/databasion/svnilize.rb'
82
- autoload :Gitilize, APP_PATH + '/databasion/gitilize.rb'
74
+ autoload :Application, APP_PATH + '/databasion/application.rb'
75
+ autoload :GoogleLoader, APP_PATH + '/databasion/google_loader.rb'
76
+ autoload :YamlBuilder, APP_PATH + '/databasion/yaml_builder.rb'
77
+ autoload :Migrate, APP_PATH + '/databasion/migrate.rb'
78
+ autoload :BuildMigration, APP_PATH + '/databasion/build_migration.rb'
79
+ autoload :LoadData, APP_PATH + '/databasion/load_data.rb'
80
+ autoload :SvnCommitter, APP_PATH + '/databasion/svn_committer.rb'
81
+ autoload :GitCommitter, APP_PATH + '/databasion/git_committer.rb'
82
+ autoload :CronSystem, APP_PATH + '/databasion/cron_system.rb'
83
83
 
84
84
  end
@@ -3,7 +3,7 @@ require 'fileutils'
3
3
 
4
4
  module Databasion
5
5
 
6
- class Applcize
6
+ class Application
7
7
 
8
8
  def self.run
9
9
  opts = Trollop::options do
@@ -16,11 +16,13 @@ module Databasion
16
16
  EOS
17
17
  opt :create, "Create a base deploy directory", :type => String
18
18
  opt :config, "Path to YAML config. Looks for config/google.yml by default", :type => String
19
- opt :google, "Googlize data from Google Spreadsheets"
20
- opt :migrate, "Migrate after Googlizing or Excelizing"
21
- opt :update, "Load parsed YAML into migrated database"
19
+ opt :google, "Load data from Google Spreadsheets"
20
+ opt :migrate, "Migrate after GoogleLoading"
21
+ opt :load, "Load parsed YAML data into migrated database"
22
+ opt :diff, "Manually check the diff of each database update from the load command"
22
23
  opt :svn, "Auto commit the project files (assuming it has been committed to SVN)"
23
24
  opt :git, "Auto commit the project files (assuming a working git repo)"
25
+ opt :cron, "Run the version control system via crontab and update on version changes"
24
26
  end
25
27
  if opts[:config].nil? and opts[:create].nil?
26
28
  config = "config/google.yml"
@@ -40,20 +42,23 @@ module Databasion
40
42
  end
41
43
 
42
44
  def self.execute_databasion(opts)
45
+ if opts[:cron]
46
+ Databasion.run('cron', opts[:config], opts)
47
+ end
43
48
  if opts[:google]
44
- Databasion.databate('google', opts[:config])
49
+ Databasion.run('google', opts[:config], opts)
45
50
  end
46
51
  if opts[:migrate]
47
- Databasion.databate('migrate', opts[:config])
52
+ Databasion.run('migrate', opts[:config], opts)
48
53
  end
49
- if opts[:update]
50
- Databasion.databate('update', opts[:config])
54
+ if opts[:load]
55
+ Databasion.run('load', opts[:config], opts)
51
56
  end
52
57
  if opts[:svn]
53
- Databasion.databate('svn', opts[:config])
58
+ Databasion.run('svn', opts[:config], opts)
54
59
  end
55
60
  if opts[:git]
56
- Databasion.databate('git', opts[:config])
61
+ Databasion.run('git', opts[:config], opts)
57
62
  end
58
63
  end
59
64
 
@@ -4,20 +4,18 @@ require 'fileutils'
4
4
 
5
5
  module Databasion
6
6
 
7
- class MigitizeError < StandardError; end
7
+ class BuildMigrationError < StandardError; end
8
8
 
9
- class Migitize
9
+ class BuildMigration
10
10
 
11
11
  @@migration_start = 100
12
12
 
13
- def self.migrabate(file_list=[], config=nil)
14
- raise MigitizeError, 'Databasion::Migitize requires an array list of files. Try Yamalizing first.' if file_list.empty?
15
- raise MigitizeError, 'Databasion::Migitize requires a parsed YAML config.' if config.nil?
13
+ def self.run(file_list=[], config=nil)
14
+ raise BuildMigrationError, 'Databasion::BuildMigration requires an array list of files. Try GoogleLoading first.' if file_list.empty?
15
+ raise BuildMigrationError, 'Databasion::BuildMigration requires a parsed YAML config.' if config.nil?
16
16
  @@config = config
17
17
 
18
- Databasion::LOGGER.info "Migrabating..."
19
18
  parse(file_list)
20
- Databasion::LOGGER.info "Migrabated!"
21
19
  end
22
20
 
23
21
  private
@@ -28,6 +26,7 @@ module Databasion
28
26
  end
29
27
 
30
28
  def self.parse(file_list)
29
+ Databasion::LOGGER.info "Migrabating..."
31
30
  database_configs = []
32
31
  file_list.each do |file|
33
32
  meta = YAML.load(File.open(file))['meta']
@@ -35,6 +34,7 @@ module Databasion
35
34
  process(meta)
36
35
  end
37
36
  write_database_yaml(database_configs)
37
+ Databasion::LOGGER.info "Migrabated!"
38
38
  end
39
39
 
40
40
  def self.process(meta)
@@ -116,6 +116,7 @@ module Databasion
116
116
  f = File.open("config/database.yml", 'w')
117
117
  f.write(YAML.dump(output))
118
118
  f.close
119
+ Databasion::LOGGER.info "Wrote database config..."
119
120
  end
120
121
 
121
122
  def self.migration_exists?(file_name)
@@ -0,0 +1,53 @@
1
+ module Databasion
2
+
3
+ class CronSystemError < StandardError; end
4
+
5
+ class CronSystem
6
+
7
+ @@config = nil
8
+
9
+ def self.config?
10
+ raise CronSystemError, 'CronSystem cannot load without a config.' unless defined?(@@config)
11
+ true
12
+ end
13
+
14
+ def self.config=(data)
15
+ @@config = data
16
+ end
17
+
18
+ def self.config
19
+ config?
20
+ @@config
21
+ end
22
+
23
+ def self.run
24
+ Databasion::GoogleLoader.config = @@config
25
+ version = Databasion::GoogleLoader.run_version
26
+
27
+ if File.exist?(@@config['cron']['version']['file'])
28
+ old_version = File.open(@@config['cron']['version']['file']).readline.strip
29
+ if version > old_version
30
+ Databasion::LOGGER.info "Version changed, running databasion."
31
+ system "cd %s && databasion %s" % [@@config['cron']['project_base'], @@config['cron']['options']]
32
+ write_version(version)
33
+ elsif version < old_version
34
+ Databasion::LOGGER.info "Version rollback is currently not implemented."
35
+ else
36
+ Databasion::LOGGER.info "Version has not changed."
37
+ end
38
+ else
39
+ Databasion::LOGGER.info "CronSystem running for the first time."
40
+ system "cd %s && databasion %s" % [@@config['cron']['project_base'], @@config['cron']['options']]
41
+ write_version(version)
42
+ end
43
+ end
44
+
45
+ def self.write_version(version)
46
+ File.open(@@config['cron']['version']['file'], 'w') do |file|
47
+ file.write version
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -1,10 +1,10 @@
1
1
  module Databasion
2
2
 
3
- class Gitilize
3
+ class GitCommitter
4
4
 
5
5
  @@config = nil
6
6
 
7
- class GitilizeError < StandardError; end
7
+ class GitCommitterError < StandardError; end
8
8
 
9
9
  def self.config=(config)
10
10
  @@config = config
@@ -19,7 +19,7 @@ module Databasion
19
19
  end
20
20
 
21
21
  def self.commit(path=Dir.pwd)
22
- raise GitilizeError, "A file lock is in place. Cannot commit." if check_lock?
22
+ raise GitCommitterError, "A file lock is in place. Cannot commit." if check_lock?
23
23
  create unless check_repo?
24
24
  create_lock
25
25
  Databasion::LOGGER.info 'running: git commit -am "databasion auto commit"'
@@ -31,6 +31,7 @@ module Databasion
31
31
  Databasion::LOGGER.info 'creating new git repository'
32
32
  Databasion::LOGGER.info 'running: git init'
33
33
  system git_path + ' init'
34
+ system git_path + ' add .'
34
35
  end
35
36
 
36
37
  def self.check_repo?
@@ -2,14 +2,21 @@ require "google_spreadsheet"
2
2
 
3
3
  module Databasion
4
4
 
5
- class GooglizeError < StandardError; end
5
+ class GoogleLoaderError < StandardError; end
6
6
 
7
- class Googlize
7
+ class GoogleLoader
8
8
 
9
- @@master_sheet = 'Database'
9
+ @@master_sheet = 'Database'
10
+ @@version_sheet = 'Version'
11
+
12
+ @@table_def = 'table'
13
+ @@field_def = 'field'
14
+ @@type_def = 'type'
15
+ @@index_def = 'index'
16
+ @@ignore_def = 'ignore'
10
17
 
11
18
  def self.config?
12
- raise 'Googlize cannot load without a config.' unless defined?(@@config)
19
+ raise GoogleLoaderError, 'GoogleLoader cannot load without a config.' unless defined?(@@config)
13
20
  true
14
21
  end
15
22
 
@@ -34,25 +41,40 @@ module Databasion
34
41
  @@master_sheet
35
42
  end
36
43
 
44
+ def self.version_sheet=(version)
45
+ @@version_sheet = version
46
+ end
47
+
48
+ def self.version_sheet
49
+ @@version_sheet
50
+ end
51
+
37
52
  def self.login
38
53
  begin
39
54
  @@session = GoogleSpreadsheet.login(@@config['login']['username'], @@config['login']['password'])
40
55
  rescue
41
- raise GooglizeError, "Couldn't log into Google."
56
+ raise GoogleLoaderError, "Couldn't log into Google."
42
57
  end
43
58
  end
44
59
 
45
- def self.googlebate
60
+ def self.run
46
61
  config?
47
62
  login
48
-
49
- Databasion::LOGGER.info "Googlizing..."
50
- process
51
- Databasion::LOGGER.info "Googlized!"
63
+ process.each do |data_hash|
64
+ Databasion::YamlBuilder.run(data_hash, @@config['output']['yaml_path'])
65
+ end
66
+ end
67
+
68
+ def self.run_version
69
+ config?
70
+ login
71
+ fetch_version
52
72
  end
53
73
 
54
74
  private
55
75
  def self.process
76
+ Databasion::LOGGER.info "Googlizing..."
77
+ data_list = []
56
78
  @@config['sheets'].each do |token|
57
79
  spreadsheet = @@session.spreadsheet_by_key(token['key'])
58
80
  master_list = get_master(spreadsheet)
@@ -60,16 +82,18 @@ module Databasion
60
82
  next unless master_list.collect { |row| row['spreadsheet'] }.include?(worksheet.title)
61
83
  data_hash = parse(worksheet)
62
84
  data_hash['connection'] = master_list.collect { |row| row if row['spreadsheet'] == worksheet.title }.reject { |d| d.nil? }[0]
63
- Databasion::Yamalize.yamlbate(data_hash, @@config['output']['yaml_path'])
85
+ data_list << data_hash
64
86
  end
65
87
  end
88
+ Databasion::LOGGER.info "Googlized!"
89
+ data_list
66
90
  end
67
91
 
68
92
  def self.get_master(spreadsheet)
69
93
  master_list = []
70
94
  header_info = nil
71
95
  spreadsheet.worksheets.each do |worksheet|
72
- if worksheet.title == @@master_sheet
96
+ if worksheet.title == master_sheet
73
97
  worksheet.rows.each_with_index do |row, index|
74
98
  if index == 0
75
99
  header_info = row
@@ -84,7 +108,7 @@ module Databasion
84
108
  break
85
109
  end
86
110
  end
87
- raise GooglizeError, "There was no master sheet defined in the spreadsheet %s." % token['name'] if master_list.size == 0
111
+ raise GoogleLoaderError, "There was no master sheet defined in the spreadsheet %s." % token['name'] if master_list.size == 0
88
112
  master_list
89
113
  end
90
114
 
@@ -102,7 +126,7 @@ module Databasion
102
126
  next if (row.reject { |s| s.strip.empty? }).size == 0
103
127
 
104
128
  case row[0]
105
- when "table"
129
+ when @@table_def
106
130
  begin
107
131
  d = row[1].split(",")
108
132
  name = d[0].strip
@@ -111,19 +135,19 @@ module Databasion
111
135
  name = row[1]
112
136
  plural = true
113
137
  end
114
- when "field"
138
+ when @@field_def
115
139
  row.each do |field|
116
140
  fields.push field unless field.empty?
117
141
  end
118
- when "type"
142
+ when @@type_def
119
143
  row.each do |type|
120
144
  types.push type unless type.empty?
121
145
  end
122
- when "index"
146
+ when @@index_def
123
147
  row.each_with_index do |index, i|
124
148
  indexes.push i-1 unless index.empty? or i == 0
125
149
  end
126
- when "ignore"
150
+ when @@ignore_def
127
151
  row.each_with_index do |ignore, i|
128
152
  ignore_cols.push i-1 unless ignore.empty? or i == 0
129
153
  end
@@ -145,6 +169,22 @@ module Databasion
145
169
  }
146
170
  end
147
171
 
172
+ def self.fetch_version
173
+ version = nil
174
+ @@config['sheets'].each do |token|
175
+ spreadsheet = @@session.spreadsheet_by_key(token['key'])
176
+ spreadsheet.worksheets.each do |worksheet|
177
+ if worksheet.title == version_sheet
178
+ worksheet.rows.each do |row|
179
+ version = row[0]
180
+ end
181
+ end
182
+ end
183
+ end
184
+ raise GoogleLoaderError, "A Version spreadsheet was not found in any of the Google Spreadsheets supplied in google.yml" if version.nil?
185
+ version
186
+ end
187
+
148
188
  end
149
189
 
150
190
  end
@@ -1,6 +1,6 @@
1
1
  module Databasion
2
2
 
3
- class Loadlize
3
+ class LoadData
4
4
 
5
5
  @@config = nil
6
6
 
@@ -12,7 +12,7 @@ module Databasion
12
12
  @@config
13
13
  end
14
14
 
15
- def self.loadalize
15
+ def self.run(opts)
16
16
  Databasion.set_ar_logger
17
17
  Databasion::LOGGER.info "Updating from YAML..."
18
18
 
@@ -1,6 +1,6 @@
1
1
  module Databasion
2
2
 
3
- class Datacize
3
+ class Migrate
4
4
 
5
5
  @@config = nil
6
6
 
@@ -8,11 +8,11 @@ module Databasion
8
8
  @@config = config
9
9
  end
10
10
 
11
- def self.datacize
11
+ def self.run
12
12
  require 'migration_helpers/init'
13
13
 
14
14
  files = Dir["%s/*.yml" % @@config['output']['yaml_path']]
15
- Databasion::Migitize.migrabate(files, @@config)
15
+ Databasion::BuildMigration.run(files, @@config)
16
16
 
17
17
  Databasion.set_ar_logger
18
18
  Databasion::LOGGER.info "Migrating..."
@@ -2,11 +2,11 @@ require 'fileutils'
2
2
 
3
3
  module Databasion
4
4
 
5
- class Svnilize
5
+ class SvnCommitter
6
6
 
7
7
  @@config = nil
8
8
 
9
- class SvnilizeError < StandardError; end
9
+ class SvnCommitterError < StandardError; end
10
10
 
11
11
  def self.config=(config)
12
12
  @@config = config
@@ -21,7 +21,7 @@ module Databasion
21
21
  end
22
22
 
23
23
  def self.commit(path=Dir.pwd)
24
- raise SvnilizeError, "A file lock is in place. Cannot commit." if check_lock?
24
+ raise SvnCommitterError, "A file lock is in place. Cannot commit." if check_lock?
25
25
  create_lock
26
26
  svn_add_files(path)
27
27
  Databasion::LOGGER.info 'running: svn commit -m "databasion auto commit"'
@@ -2,12 +2,12 @@ require 'fileutils'
2
2
 
3
3
  module Databasion
4
4
 
5
- class YamalizeError < StandardError; end
5
+ class YamlBuilderError < StandardError; end
6
6
 
7
- class Yamalize
7
+ class YamlBuilder
8
8
 
9
- def self.yamlbate(data_hash, output_path=nil)
10
- raise YamalizeError, 'Databasion::Yamalize requires an output path.' if output_path.nil?
9
+ def self.run(data_hash, output_path=nil)
10
+ raise YamalizeError, 'Databasion::YamlBuilder requires an output path.' if output_path.nil?
11
11
  @@output_path = output_path
12
12
 
13
13
  Databasion::LOGGER.info "Yamlbating %s..." % data_hash['name']
@@ -3,21 +3,26 @@ require 'lib/databasion'
3
3
  namespace :databasion do
4
4
  desc "Run Databasion for Google Spreadsheets"
5
5
  task :google do
6
- Databasion.databate('google', 'config/google.yml')
6
+ Databasion.run('google', 'config/google.yml')
7
7
  end
8
8
 
9
9
  desc "Run Ruby Migration scripts"
10
10
  task :migrate do
11
- Databasion.databate('migrate', 'config/google.yml')
11
+ Databasion.run('migrate', 'config/google.yml')
12
12
  end
13
13
 
14
- desc "Run the update script to stuff YAML data into database"
15
- task :update do
16
- Databasion.databate('update', 'config/google.yml')
14
+ desc "Run the load script to stuff YAML data into database"
15
+ task :load do
16
+ Databasion.run('load', 'config/google.yml')
17
17
  end
18
18
 
19
19
  desc "Run the SVN auto-commit system"
20
20
  task :svn do
21
- Databasion.databate('svn', 'config/google.yml')
21
+ Databasion.run('svn', 'config/google.yml')
22
+ end
23
+
24
+ desc "Run the GIT auto-commit system"
25
+ task :git do
26
+ Databasion.run('git', 'config/google.yml')
22
27
  end
23
28
  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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.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-10-28 00:00:00 +09:00
19
+ date: 2010-11-04 00:00:00 +09:00
20
20
  default_executable: databasion
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -100,29 +100,29 @@ files:
100
100
  - bin/databasion
101
101
  - config/example.google.yml
102
102
  - databasion.gemspec
103
- - features/databasion.feature
104
- - features/databasion/googlize.feature
105
- - features/databasion/migitize.feature
106
- - features/databasion/step_definitions/googlize_steps.rb
107
- - features/databasion/step_definitions/migitize_steps.rb
108
- - features/databasion/step_definitions/svnilize_steps.rb
109
- - features/databasion/step_definitions/yamalize_steps.rb
110
- - features/databasion/svnilize.feature
111
- - features/databasion/yamalize.feature
112
- - features/step_definitions/databasion_steps.rb
103
+ - features/build_migration.feature
104
+ - features/create_project.feature
105
+ - features/cron_system.feature
106
+ - features/env/helper_methods.rb
107
+ - features/google_loader.feature
108
+ - features/step_definitions/build_migration_steps.rb
109
+ - features/step_definitions/create_project_steps.rb
110
+ - features/step_definitions/cron_system_steps.rb
111
+ - features/step_definitions/google_loader_steps.rb
112
+ - features/step_definitions/yaml_builder_steps.rb
113
+ - features/yaml_builder.feature
113
114
  - lib/databasion.rb
114
- - lib/databasion/applcize.rb
115
- - lib/databasion/csvilize.rb
116
- - lib/databasion/datacize.rb
117
- - lib/databasion/excelize.rb
118
- - lib/databasion/gitilize.rb
119
- - lib/databasion/googlize.rb
120
- - lib/databasion/loadlize.rb
121
- - lib/databasion/migitize.rb
122
- - lib/databasion/svnilize.rb
115
+ - lib/databasion/application.rb
116
+ - lib/databasion/build_migration.rb
117
+ - lib/databasion/cron_system.rb
118
+ - lib/databasion/git_committer.rb
119
+ - lib/databasion/google_loader.rb
120
+ - lib/databasion/load_data.rb
121
+ - lib/databasion/migrate.rb
122
+ - lib/databasion/svn_committer.rb
123
123
  - lib/databasion/templates/migration.erb
124
124
  - lib/databasion/templates/model.erb
125
- - lib/databasion/yamalize.rb
125
+ - lib/databasion/yaml_builder.rb
126
126
  - lib/migration_helpers/MIT-LICENSE
127
127
  - lib/migration_helpers/README.markdown
128
128
  - lib/migration_helpers/init.rb
@@ -1,23 +0,0 @@
1
- Feature: Run System
2
- In order for the user to choose what they want to do
3
- The user should be able to pass in configuration settings
4
-
5
- Scenario: User calls google databate with config
6
- Given there is an actual yaml config file for google
7
- When the user runs databate for google
8
- Then Databasion should not fail for google
9
-
10
- Scenario: User calls google databate without config
11
- Given there is no config file for google
12
- When the user calls databate without config for google
13
- Then Databasion should fail for google
14
-
15
- Scenario: User calls excel databate with config
16
- Given there is an actual yaml config file for excel
17
- When the user runs databate for excel
18
- Then Databasion should not fail for excel
19
-
20
- Scenario: User calls excel databate without config
21
- Given there is no config file for excel
22
- When the user calls databate without config for excel
23
- Then Databasion should fail for excel
@@ -1,13 +0,0 @@
1
- Feature: Use Googlize
2
- In order for a user to access google
3
- They need to connect first
4
-
5
- Scenario: Log into Google
6
- Given a google account
7
- When Googlize logs in
8
- Then we should have a GoogleSpreadsheet session
9
-
10
- Scenario: Run system with config
11
- Given a google yaml config
12
- When Googlize starts up
13
- Then Googlize should not fail
@@ -1,32 +0,0 @@
1
- require 'lib/databasion'
2
-
3
- Given /a google account/ do
4
- @config = YAML.load(File.open('config/google.yml'))
5
- end
6
-
7
- When /Googlize logs in/ do
8
- Databasion::Googlize.config = @config
9
- Databasion::Googlize.login
10
- end
11
-
12
- Then /we should have a GoogleSpreadsheet session/ do
13
- Databasion::Googlize.session.should be_kind_of(GoogleSpreadsheet::Session)
14
- end
15
-
16
- Given /a google yaml config/ do
17
- @config = YAML.load(File.open('config/google.yml'))
18
- end
19
-
20
- When /Googlize starts up/ do
21
- Databasion::Googlize.config = @config
22
- begin
23
- Databasion::Googlize.googlebate
24
- @error = false
25
- rescue
26
- @error = true
27
- end
28
- end
29
-
30
- Then /Googlize should not fail/ do
31
- @error.should == false
32
- end
@@ -1,26 +0,0 @@
1
- require 'lib/databasion'
2
-
3
- Given /a complete set of YAML definitions/ do
4
- @config = YAML.load(File.open('config/google.yml'))
5
-
6
- @parse_data = {
7
- 'name' => 'mock',
8
- 'plural' => true,
9
- 'fields' => ["id", "name", "power"],
10
- 'types' => ["integer", "string, 20", "string, 40"],
11
- 'data' => [[1, "Brian Jones", "Super Intelligence"], [2, "Superman", "Invincible"], [3, "Batman", "Strength"]],
12
- 'ignore_cols' => [2],
13
- 'connection' => [{'database' => 'moon'}]
14
- }
15
- Databasion::Yamalize.yamlbate(@parse_data, @config['output']['yaml_path'])
16
-
17
- @files = Dir["%s/%s.yml" % [@config['output']['yaml_path'], @parse_data['name']]]
18
- end
19
-
20
- When /the YAML files are parsed/ do
21
- Databasion::Migitize.migrabate(@files, @config)
22
- end
23
-
24
- Then /the result is Ruby migration files/ do
25
- File.exist?("%s/100_%s.rb" % [@config['output']['migrations']['path'], @parse_data['name']]).should == true
26
- end
@@ -1,14 +0,0 @@
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
@@ -1,29 +0,0 @@
1
- require 'lib/databasion'
2
-
3
- Given /a chunk of (.*) data/ do |name|
4
- @config = YAML.load(File.open('config/google.yml'))
5
- @parse_data = {
6
- 'name' => 'mock',
7
- 'plural' => true,
8
- 'fields' => ["id", "name", "power"],
9
- 'types' => ["integer", "string, 20", "string, 40"],
10
- 'data' => [[1, "Brian Jones", "Super Intelligence"], [2, "Superman", "Invincible"], [3, "Batman", "Strength"]],
11
- 'ignore_cols' => [2],
12
- 'connection' => [{'database' => 'moon'}]
13
- }
14
- end
15
-
16
- When /we parse it/ do
17
- Databasion::Yamalize.yamlbate(@parse_data, @config['output']['yaml_path'])
18
- end
19
-
20
- Then /it should create a relevant YAML file/ do
21
- File.exist?("%s/%s.yml" % [@config['output']['yaml_path'], @parse_data['name']]).should == true
22
- end
23
-
24
- And /should contain the correct data/ do
25
- data = YAML.load(File.open("%s/%s.yml" % [@config['output']['yaml_path'], @parse_data['name']]))
26
- data.should include('meta')
27
- data.should include('data')
28
- data['meta'].should include('connection')
29
- end
@@ -1,8 +0,0 @@
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
@@ -1,9 +0,0 @@
1
- Feature: Convert parsed hash into YAML
2
- In order to convert the higher level into YAML
3
- We need to process it and write it out to files
4
-
5
- Scenario: Google passes data
6
- Given a chunk of google data
7
- When we parse it
8
- Then it should create a relevant YAML file
9
- And should contain the correct data
@@ -1,35 +0,0 @@
1
- require 'lib/databasion'
2
-
3
- Given /there is an actual yaml config file for (.*)/ do |name|
4
- @config = 'config/google.yml'
5
- end
6
-
7
- When /the user runs databate for (.*)/ do |name|
8
- begin
9
- Databasion.databate(name, @config)
10
- @error = false
11
- rescue
12
- @error = true
13
- end
14
- end
15
-
16
- Then /Databasion should not fail for (.*)/ do |name|
17
- @error.should == false
18
- end
19
-
20
- Given /there is no config file for (.*)/ do |name|
21
- @config = nil
22
- end
23
-
24
- When /the user calls databate without config for (.*)/ do |name|
25
- begin
26
- Databasion.databate(name, @config)
27
- @error = false
28
- rescue
29
- @error = true
30
- end
31
- end
32
-
33
- Then /Databasion should fail for (.*)/ do |name|
34
- @error.should == true
35
- end
@@ -1,11 +0,0 @@
1
- module Databasion
2
-
3
- class Csvilize
4
-
5
- def self.csvbate
6
-
7
- end
8
-
9
- end
10
-
11
- end
@@ -1,11 +0,0 @@
1
- module Databasion
2
-
3
- class Excelize
4
-
5
- def self.excelbate
6
-
7
- end
8
-
9
- end
10
-
11
- end