Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const {
setRuntimeMode_migration,
setRuntimeMode_undo_migration,
setRuntimeMode_generate_migration,
setRuntimeMode_apply_migration,
} = modDefs;
const modRuntime: typeof import('agentlang/out/utils/runtime.js') = await import(`${agPath}/out/utils/runtime.js`);
const { isNodeEnv } = modRuntime;
Expand Down Expand Up @@ -319,48 +320,54 @@ ${ui.format.boldWhite('EXAMPLES')}
.command('initSchema')
.argument('[file]', `Agentlang source file (${fileExtensions})`, '.')
.option('-c, --config <config>', 'Path to configuration file')
.description('Initialize database schema')
.addHelpText('after', migrationHelp('initSchema', 'Initializes the database schema from your Agentlang module.'))
.description('Initialize the database schema from your Agentlang module.')
.addHelpText('after', migrationHelp('initSchema', 'Initialize the database schema from your Agentlang module.'))
.action(initSchemaCommand);

program
.command('runMigrations')
.argument('[file]', `Agentlang source file (${fileExtensions})`, '.')
.option('-c, --config <config>', 'Path to configuration file')
.description('Run pending schema migrations')
.description('Generate and run simulation of pending migrations to bring the database schema up to date.')
.addHelpText(
'after',
migrationHelp('runMigrations', 'Applies pending migrations to bring the database schema up to date.'),
migrationHelp(
'runMigrations',
'Generate and run simulation of pending migrations to bring the database schema up to date.',
),
)
.action(runMigrationsCommand);

program
.command('applyMigration')
.argument('[file]', `Agentlang source file (${fileExtensions})`, '.')
.option('-c, --config <config>', 'Path to configuration file')
.description('Apply pending migrations (alias for runMigrations)')
.description('Apply the migrations generated via runMigrations command to the database.')
.addHelpText(
'after',
migrationHelp('applyMigration', 'Same behavior as runMigrations: applies pending schema migrations.'),
migrationHelp('applyMigration', 'Apply the migrations generated via runMigrations command to the database.'),
)
.action(applyMigrationCommand);

program
.command('undoLastMigration')
.argument('[file]', `Agentlang source file (${fileExtensions})`, '.')
.option('-c, --config <config>', 'Path to configuration file')
.description('Undo the last schema migration')
.addHelpText('after', migrationHelp('undoLastMigration', 'Reverts the most recently applied migration.'))
.description('Revert the most recently applied migration.')
.addHelpText('after', migrationHelp('undoLastMigration', 'Revert the most recently applied migration.'))
.action(undoLastMigrationCommand);

program
.command('generateMigration')
.argument('[file]', `Agentlang source file (${fileExtensions})`, '.')
.option('-c, --config <config>', 'Path to configuration file')
.description('Generate migration script from schema changes')
.description('Generate and store (in migration entity) the migration script for pending schema changes.')
.addHelpText(
'after',
migrationHelp('generateMigration', 'Generates a migration script for pending schema changes.'),
migrationHelp(
'generateMigration',
'Generate and store (in migration entity) the migration script for pending schema changes.',
),
)
.action(generateMigrationCommand);

Expand Down Expand Up @@ -690,7 +697,10 @@ export const runMigrationsCommand = async (fileName: string, options?: { config?
await runModule(fileName, { ...options, releaseDb: true });
};

export const applyMigrationCommand = runMigrationsCommand;
export const applyMigrationCommand = async (fileName: string, options?: { config?: string }): Promise<void> => {
setRuntimeMode_apply_migration();
await runModule(fileName, { ...options, releaseDb: true });
};

export const undoLastMigrationCommand = async (fileName: string, options?: { config?: string }): Promise<void> => {
setRuntimeMode_undo_migration();
Expand Down
Loading