Browse files

prevent multiple simultaneous schema versions

  • Loading branch information...
1 parent d4b6602 commit d93a4cc1bf266bef039e198b728b0baef3abdea3 @begriffs committed Jul 2, 2012
Showing with 14 additions and 6 deletions.
  1. +2 −4 Rakefile
  2. +12 −2 spec/rake_spec.rb
View
6 Rakefile
@@ -13,10 +13,8 @@ task 'db:create', :env do |t, args|
opts = DB::Config[ env ]
sh "createdb #{opts['dbname']}"
end
- sql env, <<-eoq
- create table schema_info
- (version integer not null check (version >= 0))
- eoq
+ sql env, 'create table schema_info (version integer not null check (version >= 0))'
+ sql env, 'create unique index schema_info_only_one_row on schema_info ((1))'
sql env, "insert into schema_info (version) values (0)"
end
View
14 spec/rake_spec.rb
@@ -25,11 +25,21 @@
end
describe "db:create" do
- it "starts at schema version 0" do
+ before do
Rake::Task["db:create"].execute 'env' => 'test'
- current_schema_version('test').must_equal '0'
+ end
+ after do
Rake::Task["db:drop"].execute 'env' => 'test'
end
+
+ it "starts at schema version 0" do
+ current_schema_version('test').must_equal '0'
+ end
+ it "prevents multiple simultaneous schema versions" do
+ sql 'test', "insert into schema_info (version) values (42)" rescue nil
+ count = sql('test', "select count(1) from schema_info")[0]['count']
+ count.must_equal '1'
+ end
end
describe "db:migrate" do

0 comments on commit d93a4cc

Please sign in to comment.