@@ -32,6 +32,23 @@ public function __construct(
3232 $ this ->versionStorage = $ versionStorage ;
3333 }
3434
35+ /**
36+ * Add all the migrations without running them.
37+ * This should be executed on new database installations.
38+ */
39+ public function initialize ()
40+ {
41+ if ($ this ->versionStorage ->hasVersioningNode ()) {
42+ throw MigratorException::cannotInitializeAlreadyHasVersions ();
43+ }
44+
45+ foreach (array_keys ($ this ->versionCollection ->getAllVersions ()) as $ timestamp ) {
46+ $ this ->versionStorage ->add ($ timestamp );
47+ }
48+
49+ $ this ->session ->save ();
50+ }
51+
3552 public function migrate ($ to = null , OutputInterface $ output )
3653 {
3754 if ($ to === null ) {
@@ -60,8 +77,11 @@ public function migrate($to = null, OutputInterface $output)
6077 }
6178
6279 $ start = microtime (true );
80+ $ position = 0 ;
81+ $ output ->writeln (sprintf ('<comment>%s</comment> %d version(s): ' , ($ direction == 'up ' ? 'Upgrading ' : 'Reverting ' ), count ($ versionsToExecute )));
6382 foreach ($ versionsToExecute as $ timestamp => $ version ) {
64- $ output ->writeln ('<info>Executing migration version</info>: %s ' , $ timestamp );
83+ $ position ++;
84+ $ output ->writeln (sprintf (' %s [<info>%d/%d</info>]: %s ' , $ direction == 'up ' ? '+ ' : '- ' , $ position , count ($ versionsToExecute ), $ timestamp ));
6585 $ version ->$ direction ($ this ->session );
6686
6787 if ($ direction === 'down ' ) {
@@ -70,14 +90,10 @@ public function migrate($to = null, OutputInterface $output)
7090 $ this ->versionStorage ->add ($ timestamp );
7191 }
7292
93+ $ this ->session ->save ();
7394 }
7495
75- $ this ->session ->save ();
7696
77- $ output ->writeln (sprintf (
78- '<info>Done. Executed </info>%s<info> migration versions</info> %s ' ,
79- count ($ versionsToExecute ), number_format (microtime (true ) - $ start , 4 )
80- ));
8197
8298 return $ versionsToExecute ;
8399 }
0 commit comments