Permalink
Browse files

Merged {base.sql, cm.sql} into a single sql-path/{database}/{schema}.…

…sql file.

Base is now the first change in the {schema}.sql CM file.

Made Configuration Managment table name configurable via cli using -c|--cm-table=

Made debug message output more structured and clear.

Created {drop,create,setup,dump,restore} rake tasks for qa-ing.
  • Loading branch information...
1 parent ba5ab04 commit 02117c865d740661add3a4ae64d3a953464218f6 @wayneeseguin committed Apr 20, 2012
Showing with 361 additions and 166 deletions.
  1. +34 −0 .rvmrc
  2. +12 −0 History.md
  3. +35 −5 README.md
  4. +70 −21 Rakefile
  5. +5 −0 lib/psql-cm.rb
  6. +67 −126 lib/psql-cm/base.rb
  7. +14 −10 lib/psql-cm/cli.rb
  8. +3 −3 lib/psql-cm/database.rb
  9. +30 −0 lib/psql-cm/dump.rb
  10. +49 −0 lib/psql-cm/restore.rb
  11. +27 −0 lib/psql-cm/setup.rb
  12. +14 −0 lib/psql-cm/submit.rb
  13. +1 −1 lib/psql-cm/version.rb
View
34 .rvmrc
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+
+# This is an RVM Project .rvmrc file, used to automatically load the ruby
+# development environment upon cd'ing into the directory
+
+# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
+# Only full ruby name is supported here, for short names use:
+# echo "rvm use 1.9.3" > .rvmrc
+environment_id="ruby-1.9.3-p125@psql-cm"
+
+# Uncomment the following lines if you want to verify rvm version per project
+# rvmrc_rvm_version="1.12.3 (stable)" # 1.10.1 seams as a safe start
+# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
+# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
+# return 1
+# }
+
+# First we attempt to load the desired environment directly from the environment
+# file. This is very fast and efficient compared to running through the entire
+# CLI and selector. If you want feedback on which environment was used then
+# insert the word 'use' after --create as this triggers verbose mode.
+if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
+then
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
+else
+ # If the environment file has not yet been created, use the RVM CLI to select.
+ rvm --create "$environment_id" || {
+ echo "Failed to create RVM environment '${environment_id}'."
+ return 1
+ }
+fi
View
@@ -1,3 +1,15 @@
+# 0.0.6 - 2012-04-20
+
+Merged {base.sql, cm.sql} into a single sql-path/{database}/{schema}.sql file.
+
+Base is now the first change in the {schema}.sql CM file.
+
+Made Configuration Managment table name configurable via cli using -c|--cm-table=
+
+Made debug message output more structured and clear.
+
+Created {drop,create,setup,dump,restore} rake tasks for qa-ing.
+
# 0.0.5 - 2012-04-18
Added git repository feature to sql-path for dump action, a commit per run of
View
@@ -60,12 +60,16 @@ database cluster.
$ psql-cm --databases psqlcm_test --uri "postgres://127.0.0.1:5432" restore
+## Change
+
+TODO: Document how to commit a change.
+
## Command line parameters
--databases argument may take multiple database targets, to do this pass them
in ',' separated format, no spaces. Specifically the format is,
- $ psql-cm --databases psqlcm_test,psqlcm_test2,... ...
+ $ psql-cm --databases adatabase,anotherdatabase,... ...
--uri has the format,
@@ -140,9 +144,35 @@ psql-cm restore action.
$ dropdb psqlcm_test
$ psql-cm --databases psqlcm_test --uri "postgres://127.0.0.1:5432" restore
-Once again use yoru favorite client tool and verify that the schema is inded
-what it was after setup was run.
+Once again useing a client tool and verify that the schema is inded what it was
+after setup was run.
+
+NOTE: one caveat is that psql-cm does not handle ROLEs and USERs so these will
+have to be accounted for after doing a restore.
+
+## Debugging
+
+Debugging output can be enabled by exporting DEBUG=true in the environment
+before calling the psql-cm command:
+
+ $ export debug=true
+
+## Development
+
+To play around inside of a running psql-cm Ruby environment use the console:
+
+ rake console # Development console, builds installs then runs console
+
+The 'Walkthrough' from above is encoded as rake tasks, each step can be
+seen including all debugging output by running:
-Note that one caveat is that psql-cm does not handle ROLEs and USERs so these
-will have to be accounted for after doing a restore.
+ rake clean # Remove the sql/ directory in the current working directory.
+ rake create # Create the development database psqlcm_development, including two schemas.
+ rake debug # Enable debugging using environment variable DEBUG
+ rake drop # Drop the development database psqlcm_development
+ rake dump # Remove sql/ from CWD and then run the psql-cm dump action on psqlcm_development
+ rake build # Build the psql-cm gem.
+ rake install # Build then install the psql-cm gem.
+ rake restore # Create psqlcm_development, run psql-cm actions {setup, dump, restore} in order.
+ rake setup # Create psqlcm_development and run psql-cm setup on it
View
@@ -2,46 +2,95 @@ lib = File.expand_path('../lib/', __FILE__)
$:.unshift lib unless $:.include?(lib)
-def psqlcm(params = {})
- command = ["psql-cm"]
- command << "--database #{params["database"] ? params["database"] : 'psqlcm_development'}"
- command << '-D' if ENV['debug']
- command << params[:actions].split
+def database
+ @database ||= ENV["database"] || 'psqlcm_development'
+end
+
+def psqlcm(action, params = {})
+ command = %Q|psql-cm --databases #{database} #{action}|
+ sh command, params
+end
+
+def sh(command, options = {})
+ $stdout.puts command if ENV['debug'] || ENV['DEBUG']
+ exec command if options[:exec]
+ if ENV['verbose'] || ENV["VERBOSE"]
+ puts %x{#{command}}
+ else
+ %x{#{command}}
+ end
+end
- $stdout.puts command.join(' ') if ENV['debug']
- exec command.join(' ')
+desc "Enable debugging using environment variable DEBUG"
+task :debug do
+ ENV['DEBUG'] = "true"
end
desc "Build the psql-cm gem."
task :build do
- %x{gem build psql-cm.gemspec}
+ sh "gem build psql-cm.gemspec"
end
desc "Build then install the psql-cm gem."
task :install => :build do
require 'psql-cm/version'
- %x{gem install psql-cm-#{::PSQLCM::Version}.gem}
+ sh "gem install psql-cm-#{::PSQLCM::Version}.gem"
end
-task :default => :install
+desc "Development console, builds installs then runs console"
+task :console => :install do
+ psqlcm 'console', :exec => true
+end
-task :dev => :install do
- Rake::Task['install'].invoke
- ENV['debug'] = "true"
+desc "Drop the development database #{database}"
+task :drop do
+ sh "dropdb #{database};"
end
-desc "Development console, builds installs then runs console"
-task :console => :install do
- psqlcm :actions => 'console'
+desc "Create the development database #{database}, including two schemas."
+task :create => [:debug, :install] do
+ sh "
+ createdb #{database} &&
+ psql #{database} -c '
+ CREATE SCHEMA schema_one;
+ CREATE SCHEMA schema_two;
+ CREATE TABLE schema_one.first(an integer);
+ CREATE TABLE schema_two.second(a timestamptz);'
+ "
+end
+
+desc "Create #{database} and run psql-cm setup on it"
+task :setup => [:create] do
+ psqlcm "setup"
+end
+
+desc "Remove the sql/ directory in the current working directory."
+task :clean do
+ FileUtils.rm_rf("#{ENV['PWD']}/sql") if Dir.exists?("#{ENV['PWD']}/sql")
+end
+
+desc "Remove sql/ from CWD and then run the psql-cm dump action on #{database}"
+task :dump => [:clean] do
+ psqlcm "dump"
+end
+
+desc "Create #{database}, run psql-cm actions {setup, dump, restore} in order."
+task :restore => [:setup, :dump] do
+ psqlcm "setup"
+end
+
+task :submit => [:setup] do
+ # TODO: Implement psql-cm "submit", ...
end
task :release do
require 'psql-cm/version'
-
- %x{git tag #{::PSQLCM::Version}}
- %x{git push origin --tags}
- %x{gem build psql-cm.gemspec}
- %x{gem push psql-cm-#{::PSQLCM::Version}.gem}
+ sh "
+ git tag #{::PSQLCM::Version};
+ git push origin --tags;
+ gem build psql-cm.gemspec;
+ gem push psql-cm-#{::PSQLCM::Version}.gem
+ "
end
require 'rake/testtask'
View
@@ -3,7 +3,12 @@
require 'ostruct'
require 'uri'
require 'delegate'
+require 'tempfile'
require_relative 'psql-cm/base'
require_relative 'psql-cm/database'
+require_relative 'psql-cm/setup'
+require_relative 'psql-cm/dump'
+require_relative 'psql-cm/restore'
+require_relative 'psql-cm/submit'
Oops, something went wrong.

0 comments on commit 02117c8

Please sign in to comment.