Skip to content

Commit 6b35c56

Browse files
committed
fix: Allow hooks when running seeds
1 parent b564616 commit 6b35c56

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

models/IMigrationManager.cfc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ interface {
5959
*
6060
* @invocationPath the component invocation path for the seed
6161
*/
62-
public void function runSeed( required string invocationPath );
62+
public void function runSeed(
63+
required string invocationPath,
64+
function postProcessHook,
65+
function preProcessHook
66+
);
6367

6468
}

models/MigrationService.cfc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ component accessors="true" {
44
property name="configSettings" inject="box:configSettings";
55
property name="environment" default="development";
66
property name="manager" default="cfmigrations.models.QBMigrationManager";
7-
property name="migrationsDirectory" default="/resources/database/migrations";
8-
property name="seedsDirectory" default="/resources/database/seeds";
7+
property name="migrationsDirectory" default="resources/database/migrations/";
8+
property name="seedsDirectory" default="resources/database/seeds/";
99
property name="seedEnvironments" default="development";
1010
property name="managerProperties";
1111

@@ -156,7 +156,11 @@ component accessors="true" {
156156
*
157157
* @seedName string when provided, only this seed will be run
158158
*/
159-
public MigrationService function seed( string seedName ) {
159+
public MigrationService function seed(
160+
string seedName,
161+
function postProcessHook = variables.noop,
162+
function preProcessHook = variables.noop
163+
) {
160164
if (
161165
!isNull( variables.environment ) && !arrayContainsNoCase(
162166
variables.seedEnvironments,
@@ -171,7 +175,11 @@ component accessors="true" {
171175
if ( !directoryExists( expandPath( variables.seedsDirectory ) ) ) return this;
172176

173177
findSeeds( argumentCollection = arguments ).each( function( file ) {
174-
variables.manager.runSeed( file.componentPath );
178+
variables.manager.runSeed(
179+
file.componentPath,
180+
postProcessHook,
181+
preProcessHook
182+
);
175183
} );
176184

177185
return this;

models/QBMigrationManager.cfc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,18 @@ component accessors="true" {
171171
*
172172
* @invocationPath the component invocation path for the seed
173173
*/
174-
public void function runSeed( required string invocationPath ) {
174+
public void function runSeed(
175+
required string invocationPath,
176+
function postProcessHook = variables.noop,
177+
function preProcessHook = variables.noop
178+
) {
179+
arguments.preProcessHook( invocationPath );
175180
var seeder = wirebox.getInstance( arguments.invocationPath );
176181
var query = wirebox.getInstance( "QueryBuilder@qb" ).setGrammar( wirebox.getInstance( defaultGrammar ) );
177182
$transactioned( function() {
178183
invoke( seeder, "run", [ query, variables.mockData ] );
179184
} );
185+
arguments.postProcessHook( invocationPath );
180186
}
181187

182188

0 commit comments

Comments
 (0)