forked from supabase/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdown.command.ts
More file actions
61 lines (57 loc) · 2.31 KB
/
Copy pathdown.command.ts
File metadata and controls
61 lines (57 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Command, Flag } from "effect/unstable/cli";
import type * as CliCommand from "effect/unstable/cli/Command";
import { withJsonErrorHandling } from "../../../../shared/output/json-error-handling.ts";
import { withLegacyCommandInstrumentation } from "../../../telemetry/legacy-command-instrumentation.ts";
import { legacyMigrationDbRuntimeLayer } from "../migration.layers.ts";
import { legacyMigrationDown } from "./down.handler.ts";
const config = {
// Go's `--last` is a `uint` (`down.go`), default 1. Effect has no uint, so reject
// negatives explicitly to reproduce cobra's `ParseUint` rejection (the message
// differs slightly — an accepted small divergence).
last: Flag.integer("last").pipe(
Flag.withDescription("Reset up to the last n migration versions."),
Flag.withDefault(1),
Flag.mapTryCatch(
(value) => {
if (value < 0) {
throw new Error(`invalid argument "${value}" for "--last" flag: must be greater than 0`);
}
return value;
},
(err) => (err instanceof Error ? err.message : String(err)),
),
),
dbUrl: Flag.string("db-url").pipe(
Flag.withDescription(
"Resets applied migrations on the database specified by the connection string (must be percent-encoded).",
),
Flag.optional,
),
linked: Flag.boolean("linked").pipe(
Flag.withDescription("Resets applied migrations on the linked project."),
),
local: Flag.boolean("local").pipe(
Flag.withDescription("Resets applied migrations on the local database."),
// Go: `downFlags.Bool("local", true, …)`.
Flag.withDefault(true),
),
} as const;
export type LegacyMigrationDownFlags = CliCommand.Command.Config.Infer<typeof config>;
export const legacyMigrationDownCommand = Command.make("down", config).pipe(
Command.withDescription("Resets applied migrations up to the last n versions."),
Command.withShortDescription("Resets applied migrations up to the last n versions"),
Command.withHandler((flags) =>
legacyMigrationDown(flags).pipe(
withLegacyCommandInstrumentation({
flags: {
last: flags.last,
"db-url": flags.dbUrl,
linked: flags.linked,
local: flags.local,
},
}),
withJsonErrorHandling,
),
),
Command.provide(legacyMigrationDbRuntimeLayer(["migration", "down"])),
);