File tree Expand file tree Collapse file tree
app/sprinkles/core/src/Database/Seeder Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111- ` sprinkle:list ` bakery command
1212- ` NoCache ` middleware to prevent caching of routes with dynamic content
1313- Sample test environment for Docker
14+ - Added ` validateMigrationDependencies ` helper method to ` BaseSeed `
1415
1516### Changed
1617- Sprinkle list in the bakery ` debug ` command to uses the new ` sprinkle:list ` table
Original file line number Diff line number Diff line change @@ -34,6 +34,35 @@ public function __construct(ContainerInterface $ci)
3434 $ this ->ci = $ ci ;
3535 }
3636
37+ /**
38+ * Validate if a specific set of migrations have been ran
39+ *
40+ * @param string|array $migrations List of migraiton or specific migration required
41+ * @throws \Exception If dependent migration is not available
42+ * @return bool True on success
43+ */
44+ protected function validateMigrationDependencies ($ migrations )
45+ {
46+ if (!is_array ($ migrations )) {
47+ $ migrations = [$ migrations ];
48+ }
49+
50+ /** @var \UserFrosting\Sprinkle\Core\Database\Migrator\Migrator; */
51+ $ migrator = $ this ->ci ->migrator ;
52+
53+ // Get ran migrations list
54+ $ ranMigrations = $ migrator ->getRepository ()->getMigrationsList ();
55+
56+ // Make sure required migrations are in the ran list. Throw exception if it isn't.
57+ foreach ($ migrations as $ migration ) {
58+ if (!in_array ($ migration , $ ranMigrations )) {
59+ throw new \Exception ("Migration ` $ migration` doesn't appear to have been run! " );
60+ }
61+ }
62+
63+ return true ;
64+ }
65+
3766 /**
3867 * Function used to execute the seed
3968 */
You can’t perform that action at this time.
0 commit comments