MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / main

Function main

packages/core/fumadb/src/cli/index.ts:71–185  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

69
70 return {
71 async main() {
72 const program = new Command();
73 program
74 .name(options.command)
75 .description(
76 options.description ??
77 "FumaDB CLI for migrations and schema generation"
78 )
79 .version(options.version);
80
81 program
82 .command("migrate:up")
83 .description("Migrate to the next schema version")
84 .action(async () => {
85 const migrator = db.createMigrator();
86 const next = await migrator.next();
87 if (!next) {
88 console.log("Already up to date.");
89 process.exit(1);
90 }
91
92 const result = await migrator.migrateTo(next.version);
93 await result.execute();
94 console.log(`Migration to ${next.version} executed.`);
95 });
96
97 program
98 .command("migrate:down")
99 .description("Rollback to the previous schema version")
100 .action(async () => {
101 const migrator = db.createMigrator();
102 const prev = await migrator.previous();
103 if (!prev) {
104 console.log("Cannot downgrade.");
105 process.exit(1);
106 }
107
108 const result = await migrator.migrateTo(prev.version);
109 await result.execute();
110 console.log(`Migration to ${prev.version} executed.`);
111 });
112
113 program
114 .command("migrate:to [version]")
115 .alias("migrate")
116 .description(
117 "Migrate to a specific schema version (interactive if not provided)"
118 )
119 .action(async (version: string | undefined) => {
120 const migrator = db.createMigrator();
121 version ??= await selectVersion(await migrator.getVersion());
122 const result =
123 version === "latest"
124 ? await migrator.migrateToLatest()
125 : await migrator.migrateTo(version);
126
127 await result.execute();
128 console.log(`Migrated to version ${version}.`);

Callers 1

cli.tsFile · 0.50

Calls 4

selectVersionFunction · 0.85
inputOutputPathFunction · 0.85
logMethod · 0.80
executeMethod · 0.65

Tested by

no test coverage detected