Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added a more advanced db migration task

  • Loading branch information...
commit 5c252937afa6597d28e6219e650253bfb9abc02c 1 parent 5464f03
@schmittjoh schmittjoh authored committed
Showing with 28 additions and 1 deletion.
  1. +28 −1 lib/symfony2.rb
View
29 lib/symfony2.rb
@@ -68,7 +68,34 @@
desc "Migrate Symfony2 Doctrine ORM database."
task :migrate do
- symfony.doctrine.migrations.migrate
+ currentVersion = nil
+ run "#{php-bin} #{app-path}/console doctrine:migrations:status" do |ch, stream, out|
+ if stream == :out and out =~ /Current Version:[^$]+\(([0-9]+)\)/
+ currentVersion = Regexp.last_match(1)
+ end
+ if stream == :out and out =~ /Current Version:\s*0\s*$/
+ currentVersion = 0
+ end
+ end
+
+ if currentVersion == nil
+ raise "Could not find current database migration version"
+ end
+ puts "Current database version #{currentVersion}"
+
+ on_rollback {
+ run "#{php-bin} #{app-path}/console doctrine:migrations:migrate #{currentVersion}" do |ch, stream, out|
+ if out =~ /Are you sure you wish to continue/
+ ch.send_data("y\r\n")
+ end
+ end
+ }
+
+ run "#{php-bin} #{app-path}/console doctrine:migrations:migrate" do |ch, stream, out|
+ if out =~ /Are you sure you wish to continue/
+ ch.send_data("y\r\n")
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.