@motherbase/cli 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +247 -247
- package/bin/motherbase.js +10 -10
- package/package.json +35 -26
- package/src/api.js +233 -241
- package/src/commands/_util.js +106 -93
- package/src/commands/backups.js +16 -16
- package/src/commands/branches.js +113 -113
- package/src/commands/completion.js +90 -90
- package/src/commands/config.js +47 -47
- package/src/commands/cron.js +65 -65
- package/src/commands/db-catalog.js +326 -326
- package/src/commands/db.js +103 -103
- package/src/commands/domains.js +124 -124
- package/src/commands/functions.js +304 -297
- package/src/commands/gen.js +172 -172
- package/src/commands/import.js +55 -55
- package/src/commands/index.js +85 -85
- package/src/commands/inspect.js +178 -178
- package/src/commands/keys.js +72 -72
- package/src/commands/link.js +35 -35
- package/src/commands/local.js +294 -273
- package/src/commands/login.js +39 -39
- package/src/commands/logout.js +16 -16
- package/src/commands/mcp.js +61 -61
- package/src/commands/migrate.js +207 -179
- package/src/commands/migration.js +108 -108
- package/src/commands/network.js +83 -83
- package/src/commands/orgs.js +40 -40
- package/src/commands/postgres-config.js +113 -113
- package/src/commands/projects.js +130 -130
- package/src/commands/queues.js +133 -133
- package/src/commands/realtime.js +35 -35
- package/src/commands/rls.js +176 -176
- package/src/commands/secrets.js +66 -66
- package/src/commands/signing.js +130 -130
- package/src/commands/snippets.js +44 -44
- package/src/commands/status.js +42 -42
- package/src/commands/storage.js +261 -261
- package/src/commands/test.js +9 -9
- package/src/commands/unlink.js +15 -15
- package/src/commands/users.js +142 -142
- package/src/commands/vault.js +82 -82
- package/src/commands/webhooks.js +62 -62
- package/src/commands/whoami.js +20 -20
- package/src/commands/wrappers.js +150 -150
- package/src/config.js +98 -98
- package/src/context.js +106 -102
- package/src/docs.js +68 -0
- package/src/edge-templates.js +194 -194
- package/src/format.js +92 -92
- package/src/inspect/csv.js +22 -22
- package/src/inspect/queries.js +562 -562
- package/src/main.js +224 -194
- package/src/mcp/platform-tools.js +233 -233
- package/src/mcp/protocol.js +152 -149
- package/src/mcp/storage-tools.js +93 -93
- package/src/mcp/tools.js +478 -478
- package/src/migration/commands.js +375 -375
- package/src/migration/files.js +245 -245
- package/src/prompt.js +91 -91
- package/src/storage/remote.js +62 -62
- package/src/ui.js +111 -111
package/src/commands/gen.js
CHANGED
|
@@ -1,172 +1,172 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Code generation from the live schema: TypeScript types and zod schemas.
|
|
4
|
-
//
|
|
5
|
-
// The server owns both emitters (apps/server/services/admin/typegen/).
|
|
6
|
-
// This command is a transport: it asks `GET /admin/schema/types` for the
|
|
7
|
-
// rendered file and writes it. Re-implementing the emitter here would guarantee
|
|
8
|
-
// drift between the CLI, the Studio download and the MCP tool within a release.
|
|
9
|
-
|
|
10
|
-
const fs = require('fs');
|
|
11
|
-
const path = require('path');
|
|
12
|
-
const api = require('../api');
|
|
13
|
-
const config = require('../config');
|
|
14
|
-
const { output } = require('./_util');
|
|
15
|
-
const { outputFormat } = require('../format');
|
|
16
|
-
const { CliError } = require('../context');
|
|
17
|
-
|
|
18
|
-
const DEFAULT_OUTPUT = 'database.types.ts';
|
|
19
|
-
const DEFAULT_ZOD_OUTPUT = 'database.schemas.ts';
|
|
20
|
-
const DEFAULT_LOCAL_URL = 'http://localhost:5001';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* `--local` bypasses the Console proxy and talks straight to a project API on
|
|
24
|
-
* this machine, which is how someone iterating on a local stack works: there is
|
|
25
|
-
* no console account, no link file, just a server on a port. Everything else
|
|
26
|
-
* about the context (flags, cwd, json mode) is preserved.
|
|
27
|
-
*/
|
|
28
|
-
function resolveTarget(ctx, flags) {
|
|
29
|
-
if (!flags.local) return ctx;
|
|
30
|
-
const baseUrl = config.normalizeUrl(flags.url || ctx.env.MOTHERBASE_URL || DEFAULT_LOCAL_URL);
|
|
31
|
-
const token = flags.token || ctx.env.MOTHERBASE_ADMIN_TOKEN || ctx.token;
|
|
32
|
-
return Object.assign({}, ctx, {
|
|
33
|
-
mode: 'direct',
|
|
34
|
-
requireProject: () => ({ mode: 'direct', baseUrl, token }),
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Git checkouts on Windows may rewrite line endings. The generator always emits
|
|
39
|
-
// LF, so compare on normalised text: a CRLF working copy is not schema drift.
|
|
40
|
-
function normalize(text) {
|
|
41
|
-
return String(text).replace(/\r\n/g, '\n');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** First line where the two files diverge, 1-based, for a useful error. */
|
|
45
|
-
function firstDifference(a, b) {
|
|
46
|
-
const left = normalize(a).split('\n');
|
|
47
|
-
const right = normalize(b).split('\n');
|
|
48
|
-
for (let i = 0; i < Math.max(left.length, right.length); i++) {
|
|
49
|
-
if (left[i] !== right[i]) {
|
|
50
|
-
return { line: i + 1, expected: right[i], actual: left[i] };
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Both targets are the same transport: ask the server for the rendered file,
|
|
58
|
-
* then write it, diff it or print it. `field` names which rendering to take
|
|
59
|
-
* from the one response, so a new target is a few lines rather than a copy of
|
|
60
|
-
* this whole flow.
|
|
61
|
-
*/
|
|
62
|
-
function emitter({ field, defaultOutput, label, command }) {
|
|
63
|
-
return async function run(ctx, args, flags) {
|
|
64
|
-
const schema = flags.schema || 'public';
|
|
65
|
-
const data = await api.adminRequest(resolveTarget(ctx, flags), 'GET', '/schema/types', {
|
|
66
|
-
query: { schema },
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const types = data && typeof data[field] === 'string' ? data[field] : null;
|
|
70
|
-
if (!types) {
|
|
71
|
-
throw new CliError(
|
|
72
|
-
`The server returned no generated ${label}. Check that the project serves ` +
|
|
73
|
-
`GET /admin/schema/types with a build new enough for \`${command}\`.`,
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const outputPath = flags.output && flags.output !== true ? String(flags.output) : null;
|
|
78
|
-
const DEFAULT_OUTPUT = defaultOutput;
|
|
79
|
-
|
|
80
|
-
// --check is the CI drift gate: compare the committed file with a fresh
|
|
81
|
-
// generation and fail loudly, without ever writing.
|
|
82
|
-
if (flags.check) {
|
|
83
|
-
const target = path.resolve(ctx.cwd, outputPath || DEFAULT_OUTPUT);
|
|
84
|
-
if (!fs.existsSync(target)) {
|
|
85
|
-
throw new CliError(`${target} does not exist. Run \`${command} --output ${outputPath || DEFAULT_OUTPUT}\`.`);
|
|
86
|
-
}
|
|
87
|
-
const onDisk = fs.readFileSync(target, 'utf8');
|
|
88
|
-
const diff = firstDifference(onDisk, types);
|
|
89
|
-
if (diff) {
|
|
90
|
-
throw new CliError(
|
|
91
|
-
`${target} is out of date with the ${schema} schema (first difference at line ${diff.line}).\n` +
|
|
92
|
-
` on disk: ${diff.actual === undefined ? '(end of file)' : diff.actual}\n` +
|
|
93
|
-
` generated: ${diff.expected === undefined ? '(end of file)' : diff.expected}\n` +
|
|
94
|
-
'Re-run without --check to update it.',
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
output(ctx, { schema, output: target, upToDate: true }, (d, ui) =>
|
|
98
|
-
ui.success(`${target} is up to date`),
|
|
99
|
-
);
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// No --output: write the file to stdout so `... > database.types.ts` works.
|
|
104
|
-
// Nothing else may go to stdout on this path or it lands in the file.
|
|
105
|
-
if (!outputPath) {
|
|
106
|
-
if (outputFormat(ctx.flags) !== 'pretty') {
|
|
107
|
-
output(ctx, { schema, types }, () => {});
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
process.stdout.write(types);
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const target = path.resolve(ctx.cwd, outputPath);
|
|
115
|
-
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
116
|
-
fs.writeFileSync(target, types, 'utf8');
|
|
117
|
-
output(ctx, { schema, output: target, bytes: Buffer.byteLength(types) }, (d, ui) =>
|
|
118
|
-
ui.success(`Wrote ${target} (${schema} schema)`),
|
|
119
|
-
);
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const typescript = {
|
|
124
|
-
summary: 'Generate TypeScript types for the database schema',
|
|
125
|
-
usage:
|
|
126
|
-
'motherbase gen types typescript [--schema public] [--local] [--output database.types.ts] [--check]',
|
|
127
|
-
// Here `--output` names the file to write, not the `-o` output format.
|
|
128
|
-
outputIsPath: true,
|
|
129
|
-
run: emitter({
|
|
130
|
-
field: 'types',
|
|
131
|
-
defaultOutput: DEFAULT_OUTPUT,
|
|
132
|
-
label: 'types',
|
|
133
|
-
command: 'motherbase gen types typescript',
|
|
134
|
-
}),
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const zod = {
|
|
138
|
-
summary: 'Generate zod schemas for the database schema',
|
|
139
|
-
usage:
|
|
140
|
-
'motherbase gen types zod [--schema public] [--local] [--output database.schemas.ts] [--check]',
|
|
141
|
-
outputIsPath: true,
|
|
142
|
-
run: emitter({
|
|
143
|
-
field: 'zod',
|
|
144
|
-
defaultOutput: DEFAULT_ZOD_OUTPUT,
|
|
145
|
-
label: 'schemas',
|
|
146
|
-
command: 'motherbase gen types zod',
|
|
147
|
-
}),
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
const LANGS = { typescript, zod };
|
|
151
|
-
|
|
152
|
-
// `gen types --lang typescript` is the Supabase spelling; `gen types typescript`
|
|
153
|
-
// reaches the same emitter through the subcommand.
|
|
154
|
-
const types = {
|
|
155
|
-
summary: 'Generate types from the database schema',
|
|
156
|
-
usage: 'motherbase gen types [--lang typescript|zod] [flags] | motherbase gen types <typescript|zod> [flags]',
|
|
157
|
-
subcommands: LANGS,
|
|
158
|
-
outputIsPath: true,
|
|
159
|
-
async run(ctx, args, flags) {
|
|
160
|
-
const lang = flags.lang || 'typescript';
|
|
161
|
-
if (!LANGS[lang]) throw new CliError(`--lang must be one of: ${Object.keys(LANGS).join(', ')}`);
|
|
162
|
-
return LANGS[lang].run(ctx, args, flags);
|
|
163
|
-
},
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const signing = require('./signing');
|
|
167
|
-
|
|
168
|
-
module.exports = {
|
|
169
|
-
summary: 'Generate code from the live schema, and signing keys, tokens and secrets',
|
|
170
|
-
usage: 'motherbase gen <types|signing-key|bearer-jwt|keys> ...',
|
|
171
|
-
subcommands: { types, 'signing-key': signing.signingKey, 'bearer-jwt': signing.bearerJwt, keys: signing.keys },
|
|
172
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Code generation from the live schema: TypeScript types and zod schemas.
|
|
4
|
+
//
|
|
5
|
+
// The server owns both emitters (apps/server/services/admin/typegen/).
|
|
6
|
+
// This command is a transport: it asks `GET /admin/schema/types` for the
|
|
7
|
+
// rendered file and writes it. Re-implementing the emitter here would guarantee
|
|
8
|
+
// drift between the CLI, the Studio download and the MCP tool within a release.
|
|
9
|
+
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const api = require('../api');
|
|
13
|
+
const config = require('../config');
|
|
14
|
+
const { output } = require('./_util');
|
|
15
|
+
const { outputFormat } = require('../format');
|
|
16
|
+
const { CliError } = require('../context');
|
|
17
|
+
|
|
18
|
+
const DEFAULT_OUTPUT = 'database.types.ts';
|
|
19
|
+
const DEFAULT_ZOD_OUTPUT = 'database.schemas.ts';
|
|
20
|
+
const DEFAULT_LOCAL_URL = 'http://localhost:5001';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* `--local` bypasses the Console proxy and talks straight to a project API on
|
|
24
|
+
* this machine, which is how someone iterating on a local stack works: there is
|
|
25
|
+
* no console account, no link file, just a server on a port. Everything else
|
|
26
|
+
* about the context (flags, cwd, json mode) is preserved.
|
|
27
|
+
*/
|
|
28
|
+
function resolveTarget(ctx, flags) {
|
|
29
|
+
if (!flags.local) return ctx;
|
|
30
|
+
const baseUrl = config.normalizeUrl(flags.url || ctx.env.MOTHERBASE_URL || DEFAULT_LOCAL_URL);
|
|
31
|
+
const token = flags.token || ctx.env.MOTHERBASE_ADMIN_TOKEN || ctx.token;
|
|
32
|
+
return Object.assign({}, ctx, {
|
|
33
|
+
mode: 'direct',
|
|
34
|
+
requireProject: () => ({ mode: 'direct', baseUrl, token }),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Git checkouts on Windows may rewrite line endings. The generator always emits
|
|
39
|
+
// LF, so compare on normalised text: a CRLF working copy is not schema drift.
|
|
40
|
+
function normalize(text) {
|
|
41
|
+
return String(text).replace(/\r\n/g, '\n');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** First line where the two files diverge, 1-based, for a useful error. */
|
|
45
|
+
function firstDifference(a, b) {
|
|
46
|
+
const left = normalize(a).split('\n');
|
|
47
|
+
const right = normalize(b).split('\n');
|
|
48
|
+
for (let i = 0; i < Math.max(left.length, right.length); i++) {
|
|
49
|
+
if (left[i] !== right[i]) {
|
|
50
|
+
return { line: i + 1, expected: right[i], actual: left[i] };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Both targets are the same transport: ask the server for the rendered file,
|
|
58
|
+
* then write it, diff it or print it. `field` names which rendering to take
|
|
59
|
+
* from the one response, so a new target is a few lines rather than a copy of
|
|
60
|
+
* this whole flow.
|
|
61
|
+
*/
|
|
62
|
+
function emitter({ field, defaultOutput, label, command }) {
|
|
63
|
+
return async function run(ctx, args, flags) {
|
|
64
|
+
const schema = flags.schema || 'public';
|
|
65
|
+
const data = await api.adminRequest(resolveTarget(ctx, flags), 'GET', '/schema/types', {
|
|
66
|
+
query: { schema },
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const types = data && typeof data[field] === 'string' ? data[field] : null;
|
|
70
|
+
if (!types) {
|
|
71
|
+
throw new CliError(
|
|
72
|
+
`The server returned no generated ${label}. Check that the project serves ` +
|
|
73
|
+
`GET /admin/schema/types with a build new enough for \`${command}\`.`,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const outputPath = flags.output && flags.output !== true ? String(flags.output) : null;
|
|
78
|
+
const DEFAULT_OUTPUT = defaultOutput;
|
|
79
|
+
|
|
80
|
+
// --check is the CI drift gate: compare the committed file with a fresh
|
|
81
|
+
// generation and fail loudly, without ever writing.
|
|
82
|
+
if (flags.check) {
|
|
83
|
+
const target = path.resolve(ctx.cwd, outputPath || DEFAULT_OUTPUT);
|
|
84
|
+
if (!fs.existsSync(target)) {
|
|
85
|
+
throw new CliError(`${target} does not exist. Run \`${command} --output ${outputPath || DEFAULT_OUTPUT}\`.`);
|
|
86
|
+
}
|
|
87
|
+
const onDisk = fs.readFileSync(target, 'utf8');
|
|
88
|
+
const diff = firstDifference(onDisk, types);
|
|
89
|
+
if (diff) {
|
|
90
|
+
throw new CliError(
|
|
91
|
+
`${target} is out of date with the ${schema} schema (first difference at line ${diff.line}).\n` +
|
|
92
|
+
` on disk: ${diff.actual === undefined ? '(end of file)' : diff.actual}\n` +
|
|
93
|
+
` generated: ${diff.expected === undefined ? '(end of file)' : diff.expected}\n` +
|
|
94
|
+
'Re-run without --check to update it.',
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
output(ctx, { schema, output: target, upToDate: true }, (d, ui) =>
|
|
98
|
+
ui.success(`${target} is up to date`),
|
|
99
|
+
);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// No --output: write the file to stdout so `... > database.types.ts` works.
|
|
104
|
+
// Nothing else may go to stdout on this path or it lands in the file.
|
|
105
|
+
if (!outputPath) {
|
|
106
|
+
if (outputFormat(ctx.flags) !== 'pretty') {
|
|
107
|
+
output(ctx, { schema, types }, () => {});
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
process.stdout.write(types);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const target = path.resolve(ctx.cwd, outputPath);
|
|
115
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
116
|
+
fs.writeFileSync(target, types, 'utf8');
|
|
117
|
+
output(ctx, { schema, output: target, bytes: Buffer.byteLength(types) }, (d, ui) =>
|
|
118
|
+
ui.success(`Wrote ${target} (${schema} schema)`),
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const typescript = {
|
|
124
|
+
summary: 'Generate TypeScript types for the database schema',
|
|
125
|
+
usage:
|
|
126
|
+
'motherbase gen types typescript [--schema public] [--local] [--output database.types.ts] [--check]',
|
|
127
|
+
// Here `--output` names the file to write, not the `-o` output format.
|
|
128
|
+
outputIsPath: true,
|
|
129
|
+
run: emitter({
|
|
130
|
+
field: 'types',
|
|
131
|
+
defaultOutput: DEFAULT_OUTPUT,
|
|
132
|
+
label: 'types',
|
|
133
|
+
command: 'motherbase gen types typescript',
|
|
134
|
+
}),
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const zod = {
|
|
138
|
+
summary: 'Generate zod schemas for the database schema',
|
|
139
|
+
usage:
|
|
140
|
+
'motherbase gen types zod [--schema public] [--local] [--output database.schemas.ts] [--check]',
|
|
141
|
+
outputIsPath: true,
|
|
142
|
+
run: emitter({
|
|
143
|
+
field: 'zod',
|
|
144
|
+
defaultOutput: DEFAULT_ZOD_OUTPUT,
|
|
145
|
+
label: 'schemas',
|
|
146
|
+
command: 'motherbase gen types zod',
|
|
147
|
+
}),
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const LANGS = { typescript, zod };
|
|
151
|
+
|
|
152
|
+
// `gen types --lang typescript` is the Supabase spelling; `gen types typescript`
|
|
153
|
+
// reaches the same emitter through the subcommand.
|
|
154
|
+
const types = {
|
|
155
|
+
summary: 'Generate types from the database schema',
|
|
156
|
+
usage: 'motherbase gen types [--lang typescript|zod] [flags] | motherbase gen types <typescript|zod> [flags]',
|
|
157
|
+
subcommands: LANGS,
|
|
158
|
+
outputIsPath: true,
|
|
159
|
+
async run(ctx, args, flags) {
|
|
160
|
+
const lang = flags.lang || 'typescript';
|
|
161
|
+
if (!LANGS[lang]) throw new CliError(`--lang must be one of: ${Object.keys(LANGS).join(', ')}`);
|
|
162
|
+
return LANGS[lang].run(ctx, args, flags);
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const signing = require('./signing');
|
|
167
|
+
|
|
168
|
+
module.exports = {
|
|
169
|
+
summary: 'Generate code from the live schema, and signing keys, tokens and secrets',
|
|
170
|
+
usage: 'motherbase gen <types|signing-key|bearer-jwt|keys> ...',
|
|
171
|
+
subcommands: { types, 'signing-key': signing.signingKey, 'bearer-jwt': signing.bearerJwt, keys: signing.keys },
|
|
172
|
+
};
|
package/src/commands/import.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const api = require('../api');
|
|
4
|
-
const prompt = require('../prompt');
|
|
5
|
-
const { output } = require('./_util');
|
|
6
|
-
const { CliError } = require('../context');
|
|
7
|
-
|
|
8
|
-
// Sections beyond the database need their own credential, because that is where
|
|
9
|
-
// Supabase keeps them: object bytes behind the Storage API (service_role key),
|
|
10
|
-
// edge functions and project secrets behind the Management API (a personal
|
|
11
|
-
// access token). Both are optional; without one, that section reports what it
|
|
12
|
-
// could not read instead of failing the import.
|
|
13
|
-
module.exports = {
|
|
14
|
-
summary: 'Import a Supabase project (schema, data, auth, storage, edge functions, secrets)',
|
|
15
|
-
usage:
|
|
16
|
-
'motherbase import --from-supabase <connectionString> [--service-role-key <key>] [--management-token <sbp_…>] ' +
|
|
17
|
-
'[--preview] [--no-data] [--no-auth] [--no-storage] [--no-edge-functions] [--no-secrets]',
|
|
18
|
-
async run(ctx, args, flags) {
|
|
19
|
-
const connectionString = flags['from-supabase'] || flags.fromSupabase;
|
|
20
|
-
if (!connectionString) throw new CliError('--from-supabase <connectionString> is required');
|
|
21
|
-
|
|
22
|
-
const include = {
|
|
23
|
-
schema: true,
|
|
24
|
-
data: !flags['no-data'],
|
|
25
|
-
auth: !flags['no-auth'],
|
|
26
|
-
storage: !flags['no-storage'],
|
|
27
|
-
edgeFunctions: !flags['no-edge-functions'],
|
|
28
|
-
secrets: !flags['no-secrets'],
|
|
29
|
-
};
|
|
30
|
-
const preview = Boolean(flags.preview);
|
|
31
|
-
|
|
32
|
-
const body = { connectionString, include };
|
|
33
|
-
const serviceRoleKey = flags['service-role-key'] || flags.serviceRoleKey;
|
|
34
|
-
const managementToken = flags['management-token'] || flags.managementToken;
|
|
35
|
-
if (serviceRoleKey) body.serviceRoleKey = serviceRoleKey;
|
|
36
|
-
if (managementToken) body.managementToken = managementToken;
|
|
37
|
-
if (flags['project-ref'] || flags.projectRef) body.projectRef = flags['project-ref'] || flags.projectRef;
|
|
38
|
-
|
|
39
|
-
if (preview) {
|
|
40
|
-
body.preview = true;
|
|
41
|
-
} else {
|
|
42
|
-
if (!flags.yes) {
|
|
43
|
-
const ok = await prompt.confirm('This will import into the linked project. Continue?');
|
|
44
|
-
if (!ok) throw new CliError('Aborted.');
|
|
45
|
-
}
|
|
46
|
-
body.confirm = 'IMPORT';
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const data = await api.adminRequest(ctx, 'POST', '/import/supabase', { body });
|
|
50
|
-
output(ctx, data, (d, ui) => {
|
|
51
|
-
if (preview) { ui.info('Import preview (dry run):'); ui.json(d); }
|
|
52
|
-
else { ui.success('Import complete'); ui.json(d); }
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const api = require('../api');
|
|
4
|
+
const prompt = require('../prompt');
|
|
5
|
+
const { output } = require('./_util');
|
|
6
|
+
const { CliError } = require('../context');
|
|
7
|
+
|
|
8
|
+
// Sections beyond the database need their own credential, because that is where
|
|
9
|
+
// Supabase keeps them: object bytes behind the Storage API (service_role key),
|
|
10
|
+
// edge functions and project secrets behind the Management API (a personal
|
|
11
|
+
// access token). Both are optional; without one, that section reports what it
|
|
12
|
+
// could not read instead of failing the import.
|
|
13
|
+
module.exports = {
|
|
14
|
+
summary: 'Import a Supabase project (schema, data, auth, storage, edge functions, secrets)',
|
|
15
|
+
usage:
|
|
16
|
+
'motherbase import --from-supabase <connectionString> [--service-role-key <key>] [--management-token <sbp_…>] ' +
|
|
17
|
+
'[--preview] [--no-data] [--no-auth] [--no-storage] [--no-edge-functions] [--no-secrets]',
|
|
18
|
+
async run(ctx, args, flags) {
|
|
19
|
+
const connectionString = flags['from-supabase'] || flags.fromSupabase;
|
|
20
|
+
if (!connectionString) throw new CliError('--from-supabase <connectionString> is required');
|
|
21
|
+
|
|
22
|
+
const include = {
|
|
23
|
+
schema: true,
|
|
24
|
+
data: !flags['no-data'],
|
|
25
|
+
auth: !flags['no-auth'],
|
|
26
|
+
storage: !flags['no-storage'],
|
|
27
|
+
edgeFunctions: !flags['no-edge-functions'],
|
|
28
|
+
secrets: !flags['no-secrets'],
|
|
29
|
+
};
|
|
30
|
+
const preview = Boolean(flags.preview);
|
|
31
|
+
|
|
32
|
+
const body = { connectionString, include };
|
|
33
|
+
const serviceRoleKey = flags['service-role-key'] || flags.serviceRoleKey;
|
|
34
|
+
const managementToken = flags['management-token'] || flags.managementToken;
|
|
35
|
+
if (serviceRoleKey) body.serviceRoleKey = serviceRoleKey;
|
|
36
|
+
if (managementToken) body.managementToken = managementToken;
|
|
37
|
+
if (flags['project-ref'] || flags.projectRef) body.projectRef = flags['project-ref'] || flags.projectRef;
|
|
38
|
+
|
|
39
|
+
if (preview) {
|
|
40
|
+
body.preview = true;
|
|
41
|
+
} else {
|
|
42
|
+
if (!flags.yes) {
|
|
43
|
+
const ok = await prompt.confirm('This will import into the linked project. Continue?');
|
|
44
|
+
if (!ok) throw new CliError('Aborted.');
|
|
45
|
+
}
|
|
46
|
+
body.confirm = 'IMPORT';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const data = await api.adminRequest(ctx, 'POST', '/import/supabase', { body });
|
|
50
|
+
output(ctx, data, (d, ui) => {
|
|
51
|
+
if (preview) { ui.info('Import preview (dry run):'); ui.json(d); }
|
|
52
|
+
else { ui.success('Import complete'); ui.json(d); }
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
};
|
package/src/commands/index.js
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Command registry: name -> { summary, usage, subcommands?, run? }.
|
|
4
|
-
// `main.js` builds all help/dispatch from this single map.
|
|
5
|
-
|
|
6
|
-
const local = require('./local');
|
|
7
|
-
const { alias } = require('./_util');
|
|
8
|
-
const migration = require('./migration');
|
|
9
|
-
|
|
10
|
-
const registry = {
|
|
11
|
-
// ── Connection ─────────────────────────────────────────────────────────────
|
|
12
|
-
login: require('./login'),
|
|
13
|
-
logout: require('./logout'),
|
|
14
|
-
whoami: require('./whoami'),
|
|
15
|
-
link: require('./link'),
|
|
16
|
-
unlink: require('./unlink'),
|
|
17
|
-
status: require('./status'),
|
|
18
|
-
|
|
19
|
-
// ── Orgs & projects (Platform Console) ─────────────────────────────────────
|
|
20
|
-
orgs: require('./orgs'),
|
|
21
|
-
projects: require('./projects'),
|
|
22
|
-
branches: require('./branches'),
|
|
23
|
-
domains: require('./domains').domains,
|
|
24
|
-
'vanity-subdomains': require('./domains').vanitySubdomains,
|
|
25
|
-
|
|
26
|
-
// ── Local self-host (docker compose) ───────────────────────────────────────
|
|
27
|
-
init: local.init,
|
|
28
|
-
start: local.start,
|
|
29
|
-
stop: local.stop,
|
|
30
|
-
deploy: local.deploy,
|
|
31
|
-
logs: local.logs,
|
|
32
|
-
|
|
33
|
-
// ── Database / migrations / import ─────────────────────────────────────────
|
|
34
|
-
db: require('./db'),
|
|
35
|
-
backups: require('./backups'),
|
|
36
|
-
migration,
|
|
37
|
-
// The name Motherbase used before it matched Supabase's `migration`.
|
|
38
|
-
migrations: alias(migration, 'motherbase migrations <new|list|up|down|repair|squash|fetch|diff|get|create|apply|rollback> ... (alias of `migration`)'),
|
|
39
|
-
import: require('./import'),
|
|
40
|
-
migrate: require('./migrate'),
|
|
41
|
-
test: require('./test'),
|
|
42
|
-
'postgres-config': require('./postgres-config'),
|
|
43
|
-
|
|
44
|
-
// ── Resource domains ───────────────────────────────────────────────────────
|
|
45
|
-
rls: require('./rls'),
|
|
46
|
-
users: require('./users'),
|
|
47
|
-
storage: require('./storage'),
|
|
48
|
-
functions: require('./functions'),
|
|
49
|
-
secrets: require('./secrets'),
|
|
50
|
-
keys: require('./keys'),
|
|
51
|
-
realtime: require('./realtime'),
|
|
52
|
-
webhooks: require('./webhooks'),
|
|
53
|
-
cron: require('./cron'),
|
|
54
|
-
queues: require('./queues'),
|
|
55
|
-
vault: require('./vault'),
|
|
56
|
-
wrappers: require('./wrappers'),
|
|
57
|
-
config: require('./config'),
|
|
58
|
-
inspect: require('./inspect'),
|
|
59
|
-
'network-restrictions': require('./network').networkRestrictions,
|
|
60
|
-
'ssl-enforcement': require('./network').sslEnforcement,
|
|
61
|
-
snippets: require('./snippets'),
|
|
62
|
-
|
|
63
|
-
// ── Codegen ────────────────────────────────────────────────────────────────
|
|
64
|
-
gen: require('./gen'),
|
|
65
|
-
|
|
66
|
-
// ── AI agents ──────────────────────────────────────────────────────────────
|
|
67
|
-
mcp: require('./mcp'),
|
|
68
|
-
|
|
69
|
-
// ── Shell ──────────────────────────────────────────────────────────────────
|
|
70
|
-
completion: require('./completion'),
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// Grouping used only to render a tidy top-level help listing.
|
|
74
|
-
const groups = [
|
|
75
|
-
{ title: 'Connection', names: ['login', 'logout', 'whoami', 'link', 'unlink', 'status'] },
|
|
76
|
-
{ title: 'Orgs & projects (Console)', names: ['orgs', 'projects', 'branches', 'domains', 'vanity-subdomains'] },
|
|
77
|
-
{ title: 'Local self-host', names: ['init', 'start', 'stop', 'deploy', 'logs'] },
|
|
78
|
-
{ title: 'Database', names: ['db', 'backups', 'migrations', 'migration', 'import', 'test', 'postgres-config'] },
|
|
79
|
-
{ title: 'Resources', names: ['rls', 'users', 'storage', 'functions', 'secrets', 'keys', 'realtime', 'webhooks', 'cron', 'queues', 'vault', 'wrappers', 'config', 'inspect', 'snippets', 'network-restrictions', 'ssl-enforcement'] },
|
|
80
|
-
{ title: 'Codegen', names: ['gen'] },
|
|
81
|
-
{ title: 'AI agents', names: ['mcp'] },
|
|
82
|
-
{ title: 'Shell', names: ['completion'] },
|
|
83
|
-
];
|
|
84
|
-
|
|
85
|
-
module.exports = { registry, groups };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Command registry: name -> { summary, usage, subcommands?, run? }.
|
|
4
|
+
// `main.js` builds all help/dispatch from this single map.
|
|
5
|
+
|
|
6
|
+
const local = require('./local');
|
|
7
|
+
const { alias } = require('./_util');
|
|
8
|
+
const migration = require('./migration');
|
|
9
|
+
|
|
10
|
+
const registry = {
|
|
11
|
+
// ── Connection ─────────────────────────────────────────────────────────────
|
|
12
|
+
login: require('./login'),
|
|
13
|
+
logout: require('./logout'),
|
|
14
|
+
whoami: require('./whoami'),
|
|
15
|
+
link: require('./link'),
|
|
16
|
+
unlink: require('./unlink'),
|
|
17
|
+
status: require('./status'),
|
|
18
|
+
|
|
19
|
+
// ── Orgs & projects (Platform Console) ─────────────────────────────────────
|
|
20
|
+
orgs: require('./orgs'),
|
|
21
|
+
projects: require('./projects'),
|
|
22
|
+
branches: require('./branches'),
|
|
23
|
+
domains: require('./domains').domains,
|
|
24
|
+
'vanity-subdomains': require('./domains').vanitySubdomains,
|
|
25
|
+
|
|
26
|
+
// ── Local self-host (docker compose) ───────────────────────────────────────
|
|
27
|
+
init: local.init,
|
|
28
|
+
start: local.start,
|
|
29
|
+
stop: local.stop,
|
|
30
|
+
deploy: local.deploy,
|
|
31
|
+
logs: local.logs,
|
|
32
|
+
|
|
33
|
+
// ── Database / migrations / import ─────────────────────────────────────────
|
|
34
|
+
db: require('./db'),
|
|
35
|
+
backups: require('./backups'),
|
|
36
|
+
migration,
|
|
37
|
+
// The name Motherbase used before it matched Supabase's `migration`.
|
|
38
|
+
migrations: alias(migration, 'motherbase migrations <new|list|up|down|repair|squash|fetch|diff|get|create|apply|rollback> ... (alias of `migration`)'),
|
|
39
|
+
import: require('./import'),
|
|
40
|
+
migrate: require('./migrate'),
|
|
41
|
+
test: require('./test'),
|
|
42
|
+
'postgres-config': require('./postgres-config'),
|
|
43
|
+
|
|
44
|
+
// ── Resource domains ───────────────────────────────────────────────────────
|
|
45
|
+
rls: require('./rls'),
|
|
46
|
+
users: require('./users'),
|
|
47
|
+
storage: require('./storage'),
|
|
48
|
+
functions: require('./functions'),
|
|
49
|
+
secrets: require('./secrets'),
|
|
50
|
+
keys: require('./keys'),
|
|
51
|
+
realtime: require('./realtime'),
|
|
52
|
+
webhooks: require('./webhooks'),
|
|
53
|
+
cron: require('./cron'),
|
|
54
|
+
queues: require('./queues'),
|
|
55
|
+
vault: require('./vault'),
|
|
56
|
+
wrappers: require('./wrappers'),
|
|
57
|
+
config: require('./config'),
|
|
58
|
+
inspect: require('./inspect'),
|
|
59
|
+
'network-restrictions': require('./network').networkRestrictions,
|
|
60
|
+
'ssl-enforcement': require('./network').sslEnforcement,
|
|
61
|
+
snippets: require('./snippets'),
|
|
62
|
+
|
|
63
|
+
// ── Codegen ────────────────────────────────────────────────────────────────
|
|
64
|
+
gen: require('./gen'),
|
|
65
|
+
|
|
66
|
+
// ── AI agents ──────────────────────────────────────────────────────────────
|
|
67
|
+
mcp: require('./mcp'),
|
|
68
|
+
|
|
69
|
+
// ── Shell ──────────────────────────────────────────────────────────────────
|
|
70
|
+
completion: require('./completion'),
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Grouping used only to render a tidy top-level help listing.
|
|
74
|
+
const groups = [
|
|
75
|
+
{ title: 'Connection', names: ['login', 'logout', 'whoami', 'link', 'unlink', 'status'] },
|
|
76
|
+
{ title: 'Orgs & projects (Console)', names: ['orgs', 'projects', 'branches', 'domains', 'vanity-subdomains'] },
|
|
77
|
+
{ title: 'Local self-host', names: ['init', 'start', 'stop', 'deploy', 'logs'] },
|
|
78
|
+
{ title: 'Database', names: ['db', 'backups', 'migrations', 'migration', 'import', 'test', 'postgres-config'] },
|
|
79
|
+
{ title: 'Resources', names: ['rls', 'users', 'storage', 'functions', 'secrets', 'keys', 'realtime', 'webhooks', 'cron', 'queues', 'vault', 'wrappers', 'config', 'inspect', 'snippets', 'network-restrictions', 'ssl-enforcement'] },
|
|
80
|
+
{ title: 'Codegen', names: ['gen'] },
|
|
81
|
+
{ title: 'AI agents', names: ['mcp'] },
|
|
82
|
+
{ title: 'Shell', names: ['completion'] },
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
module.exports = { registry, groups };
|