forked from supabase/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull.command.ts
More file actions
93 lines (89 loc) · 3.48 KB
/
Copy pathpull.command.ts
File metadata and controls
93 lines (89 loc) · 3.48 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { Argument, 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 { legacyParseSchemaFlags } from "../../../shared/legacy-schema-flags.ts";
import { withLegacyCommandInstrumentation } from "../../../telemetry/legacy-command-instrumentation.ts";
import { legacyDbPull } from "./pull.handler.ts";
import { legacyDbPullRuntimeLayer } from "./pull.layers.ts";
const config = {
name: Argument.string("migration name").pipe(
Argument.withDescription("Optional name for the migration file."),
Argument.optional,
),
// `--declarative` and the deprecated `--use-pg-delta` both bind to the same
// declarative-output mode in Go (`cmd/db.go:464-465`); both are mutually
// exclusive with `--diff-engine`. Modelled as `Option` so the mutex tracks
// pflag `Changed`.
declarative: Flag.boolean("declarative").pipe(
Flag.withDescription(
"Pull schema as declarative files using pg-delta instead of creating a migration.",
),
Flag.optional,
),
usePgDelta: Flag.boolean("use-pg-delta").pipe(
Flag.withDescription("Use pg-delta to pull declarative schema."),
// Go marks this deprecated (`cmd/db.go:466`); Effect V4 has no
// `Flag.withDeprecated`, so it is hidden and the handler emits the
// deprecation line to stderr, matching cobra's behaviour.
Flag.withHidden,
Flag.optional,
),
diffEngine: Flag.choice("diff-engine", ["migra", "pg-delta"] as const).pipe(
Flag.withDescription("Diff engine to use for migration-style db pull."),
Flag.optional,
),
schema: Flag.string("schema").pipe(
Flag.withAlias("s"),
Flag.withDescription("Comma separated list of schema to include."),
Flag.atLeast(0),
Flag.mapTryCatch(
(rawValues) => legacyParseSchemaFlags(rawValues),
(err) => (err instanceof Error ? err.message : String(err)),
),
),
dbUrl: Flag.string("db-url").pipe(
Flag.withDescription(
"Pulls from the database specified by the connection string (must be percent-encoded).",
),
Flag.optional,
),
linked: Flag.boolean("linked").pipe(
Flag.withDescription("Pulls from the linked project."),
Flag.optional,
),
local: Flag.boolean("local").pipe(
Flag.withDescription("Pulls from the local database."),
Flag.optional,
),
password: Flag.string("password").pipe(
Flag.withAlias("p"),
Flag.withDescription("Password to your remote Postgres database."),
Flag.optional,
),
} as const;
export type LegacyDbPullFlags = CliCommand.Command.Config.Infer<typeof config>;
export const legacyDbPullCommand = Command.make("pull", config).pipe(
Command.withDescription("Pull schema from the remote database."),
Command.withShortDescription("Pull schema from the remote database"),
Command.withHandler((flags) =>
legacyDbPull(flags).pipe(
withLegacyCommandInstrumentation({
flags: {
declarative: flags.declarative,
"use-pg-delta": flags.usePgDelta,
"diff-engine": flags.diffEngine,
schema: flags.schema,
"db-url": flags.dbUrl,
linked: flags.linked,
local: flags.local,
// `password` is a credential — always reaches telemetry as `<redacted>`.
password: flags.password,
},
aliases: { s: "schema", p: "password" },
config,
}),
withJsonErrorHandling,
),
),
Command.provide(legacyDbPullRuntimeLayer),
);