Skip to content

Commit ea37fd3

Browse files
authored
Merge pull request #10 from ylelievre/fix/60702
[IN:60702] Make PropelMigration preUp failures more explicit
2 parents 42327ee + 6362b48 commit ea37fd3

File tree

6 files changed

+125
-36
lines changed

6 files changed

+125
-36
lines changed

generator/lib/task/PropelMigrationDownTask.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public function main()
4949

5050
$migration = $manager->getMigrationObject($nextMigrationTimestamp);
5151
if (false === $migration->preDown($manager)) {
52-
$this->log('preDown() returned false. Aborting migration.', Project::MSG_ERR);
52+
$this->log(sprintf(
53+
'[%s] preDown() returned false. Aborting migration.',
54+
$manager->getMigrationClassName($nextMigrationTimestamp)
55+
), Project::MSG_ERR);
5356

5457
return false;
5558
}
@@ -71,16 +74,20 @@ public function main()
7174
$stmt->execute();
7275
$res++;
7376
} catch (PDOException $e) {
74-
$this->log(sprintf('Failed to execute SQL "%s"', $statement), Project::MSG_ERR);
77+
$this->log(sprintf(
78+
'[%s] Failed to execute SQL "%s"',
79+
$manager->getMigrationClassName($nextMigrationTimestamp),
80+
$statement
81+
), Project::MSG_ERR);
7582
// continue
7683
}
7784
}
7885
if (!$res) {
79-
$this->log('No statement was executed. The version was not updated.');
86+
$this->log('No statement was executed. The version was not updated.', Project::MSG_ERR);
8087
$this->log(sprintf(
8188
'Please review the code in "%s"',
8289
$manager->getMigrationDir() . DIRECTORY_SEPARATOR . $manager->getMigrationClassName($nextMigrationTimestamp)
83-
));
90+
), Project::MSG_ERR);
8491
$this->log('Migration aborted', Project::MSG_ERR);
8592

8693
return false;

generator/lib/task/PropelMigrationTask.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ public function main()
4646
));
4747
$migration = $manager->getMigrationObject($timestamp);
4848
if (false === $migration->preUp($manager)) {
49-
$this->log('preUp() returned false. Aborting migration.', Project::MSG_ERR);
49+
$this->log(sprintf(
50+
'[%s] preUp() returned false. Aborting migration.',
51+
$manager->getMigrationClassName($timestamp)
52+
), Project::MSG_ERR);
5053

5154
return false;
5255
}
@@ -67,16 +70,20 @@ public function main()
6770
$stmt->execute();
6871
$res++;
6972
} catch (PDOException $e) {
70-
$this->log(sprintf('Failed to execute SQL "%s"', $statement), Project::MSG_ERR);
73+
$this->log(sprintf(
74+
'[%s] Failed to execute SQL "%s"',
75+
$manager->getMigrationClassName($timestamp),
76+
$statement
77+
), Project::MSG_ERR);
7178
// continue
7279
}
7380
}
7481
if (!$res) {
75-
$this->log('No statement was executed. The version was not updated.');
82+
$this->log('No statement was executed. The version was not updated.', Project::MSG_ERR);
7683
$this->log(sprintf(
7784
'Please review the code in "%s"',
7885
$manager->getMigrationDir() . DIRECTORY_SEPARATOR . $manager->getMigrationClassName($timestamp)
79-
));
86+
), Project::MSG_ERR);
8087
$this->log('Migration aborted', Project::MSG_ERR);
8188

8289
return false;

generator/lib/task/PropelMigrationUpTask.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ public function main()
4141

4242
$migration = $manager->getMigrationObject($nextMigrationTimestamp);
4343
if (false === $migration->preUp($manager)) {
44-
$this->log('preUp() returned false. Aborting migration.', Project::MSG_ERR);
44+
$this->log(sprintf(
45+
'[%s] preUp() returned false. Aborting migration.',
46+
$manager->getMigrationClassName($nextMigrationTimestamp)
47+
), Project::MSG_ERR);
4548

4649
return false;
4750
}
@@ -63,18 +66,22 @@ public function main()
6366
$stmt->execute();
6467
$res++;
6568
} catch (PDOException $e) {
66-
$this->log(sprintf('Failed to execute SQL "%s". Aborting migration.', $statement), Project::MSG_ERR);
69+
$this->log(sprintf(
70+
'[%s] Failed to execute SQL "%s"',
71+
$manager->getMigrationClassName($nextMigrationTimestamp),
72+
$statement
73+
), Project::MSG_ERR);
6774

6875
return false;
6976
// continue
7077
}
7178
}
7279
if (!$res) {
73-
$this->log('No statement was executed. The version was not updated.');
80+
$this->log('No statement was executed. The version was not updated.', Project::MSG_ERR);
7481
$this->log(sprintf(
7582
'Please review the code in "%s"',
7683
$manager->getMigrationDir() . DIRECTORY_SEPARATOR . $manager->getMigrationClassName($nextMigrationTimestamp)
77-
));
84+
), Project::MSG_ERR);
7885
$this->log('Migration aborted', Project::MSG_ERR);
7986

8087
return false;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/**
4+
* Class AbstractPropelMigration
5+
*/
6+
abstract class AbstractPropelMigration implements IPropelMigration
7+
{
8+
/**
9+
* @param PropelMigrationManager $manager
10+
* @return bool
11+
*/
12+
public function preUp(PropelMigrationManager $manager)
13+
{
14+
return true;
15+
}
16+
17+
/**
18+
* @param PropelMigrationManager $manager
19+
* @return bool
20+
*/
21+
public function postUp(PropelMigrationManager $manager)
22+
{
23+
return true;
24+
}
25+
26+
/**
27+
* @param PropelMigrationManager $manager
28+
* @return bool
29+
*/
30+
public function preDown(PropelMigrationManager $manager)
31+
{
32+
return true;
33+
}
34+
35+
/**
36+
* @param PropelMigrationManager $manager
37+
* @return bool
38+
*/
39+
public function postDown(PropelMigrationManager $manager)
40+
{
41+
return true;
42+
}
43+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/**
4+
* Interface IPropelMigration
5+
*/
6+
interface IPropelMigration
7+
{
8+
/**
9+
* @param PropelMigrationManager $manager
10+
* @return bool
11+
*/
12+
public function preUp(PropelMigrationManager $manager);
13+
14+
/**
15+
* @param PropelMigrationManager $manager
16+
* @return bool
17+
*/
18+
public function postUp(PropelMigrationManager $manager);
19+
20+
/**
21+
* @param PropelMigrationManager $manager
22+
* @return bool
23+
*/
24+
public function preDown(PropelMigrationManager $manager);
25+
26+
/**
27+
* @param PropelMigrationManager $manager
28+
* @return bool
29+
*/
30+
public function postDown(PropelMigrationManager $manager);
31+
32+
/**
33+
* Get the SQL statements for the Up migration
34+
*
35+
* @return array list of the SQL strings to execute for the Up migration
36+
* the keys being the datasources
37+
*/
38+
public function getUpSQL();
39+
40+
/**
41+
* Get the SQL statements for the Down migration
42+
*
43+
* @return array list of the SQL strings to execute for the Down migration
44+
* the keys being the datasources
45+
*/
46+
public function getDownSQL();
47+
}

generator/lib/util/PropelMigrationManager.php

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -303,31 +303,10 @@ public function getMigrationClassBody($migrationsUp, $migrationsDown, $timestamp
303303
/**
304304
* Data object containing the SQL and PHP code to migrate the database
305305
* up to version $timestamp.
306-
* Generated on $timeInWords $migrationAuthor
306+
* Auto generated on $timeInWords $migrationAuthor
307307
*/
308-
class $migrationClassName
308+
class $migrationClassName extends AbstractPropelMigration
309309
{
310-
311-
public function preUp(\$manager)
312-
{
313-
// add the pre-migration code here
314-
}
315-
316-
public function postUp(\$manager)
317-
{
318-
// add the post-migration code here
319-
}
320-
321-
public function preDown(\$manager)
322-
{
323-
// add the pre-migration code here
324-
}
325-
326-
public function postDown(\$manager)
327-
{
328-
// add the post-migration code here
329-
}
330-
331310
/**
332311
* Get the SQL statements for the Up migration
333312
*
@@ -349,7 +328,6 @@ public function getDownSQL()
349328
{
350329
return $migrationDownString;
351330
}
352-
353331
}
354332
EOP;
355333

0 commit comments

Comments
 (0)