run method
Runs this command.
The return value is wrapped in a Future
if necessary and returned by
CommandRunner.runCommand
.
Implementation
@override
Future<int> run() async
{
final config = await loadConfig();
final env = await loadEnv(config);
if (env == null) {
usageException(
'Failed to find the env.\nPlease, specify a valid env in your config.'
);
}
final migrationIdentity = argument('migration identity');
final executor = MigrationExecutor(
config: config,
env: env,
passwordProvider: () => getPassword(env.user),
allowRollback: argResults?.flag('rollback') ?? true,
);
try {
await executor.migrate(delegate: this, targetIdentity: migrationIdentity);
return resultOk;
} on AbortedException {
return resultError;
} on ConnectionException catch (e) {
errorLn('Failed to connect: ${e.message}.');
return resultError;
} on MigrationException catch (e) {
errorCLn('Failed to migrate the database: ${e.message}.');
return resultError;
} catch (e) {
errorCLn('Failed to migrate the database: $e.');
return resultError;
}
}