smoonb 1.0.6 → 1.0.8
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/CHANGELOG.md +44 -0
- package/README.md +679 -644
- package/README.pt-BR.md +679 -644
- package/package.json +68 -66
- package/src/commands/backup/index.js +8 -2
- package/src/commands/backup/steps/03-database-separated.js +161 -114
- package/src/commands/backup/steps/06-realtime-settings.js +19 -33
- package/src/commands/backup/steps/07-storage.js +7 -12
- package/src/commands/backup/steps/09-edge-functions.js +76 -202
- package/src/commands/restore/auth-fields.json +237 -0
- package/src/commands/restore/dump.js +284 -0
- package/src/commands/restore/index.js +4 -126
- package/src/commands/restore/management.js +74 -0
- package/src/commands/restore/pg.js +83 -0
- package/src/commands/restore/runner.js +117 -0
- package/src/commands/restore/steps/03-database.js +18 -84
- package/src/commands/restore/steps/04-edge-functions.js +95 -122
- package/src/commands/restore/steps/05-auth-settings.js +26 -54
- package/src/commands/restore/steps/06-storage.js +203 -584
- package/src/commands/restore/steps/07-database-settings.js +87 -69
- package/src/commands/restore/steps/08-realtime-settings.js +61 -53
- package/src/i18n/locales/en.json +800 -796
- package/src/i18n/locales/pt-BR.json +799 -795
- package/src/utils/pg-dump-diagnostics.js +64 -0
- package/src/utils/supabaseCli.js +32 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const { StringDecoder } = require('string_decoder');
|
|
2
|
+
const fs = require('fs').promises;
|
|
3
|
+
|
|
4
|
+
// Only the exact, known pg_dump circular-FK block is consolidated. All other
|
|
5
|
+
// stderr (including errors and unfamiliar/localized warnings) remains visible.
|
|
6
|
+
function createPgDumpDiagnostics(writeStderr) {
|
|
7
|
+
const decoder = new StringDecoder('utf8');
|
|
8
|
+
let pending = '';
|
|
9
|
+
let inCircularWarning = false;
|
|
10
|
+
const warnings = [];
|
|
11
|
+
const tables = new Set();
|
|
12
|
+
const hints = new Set([
|
|
13
|
+
'pg_dump: hint: You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints.',
|
|
14
|
+
'pg_dump: hint: Consider using a full dump instead of a --data-only dump to avoid this problem.'
|
|
15
|
+
]);
|
|
16
|
+
function line(raw) {
|
|
17
|
+
const text = raw.replace(/\r?\n$/, '');
|
|
18
|
+
if (/^pg_dump: warning: there are circular foreign-key constraints (?:among these tables|on this table):$/.test(text)) {
|
|
19
|
+
inCircularWarning = true;
|
|
20
|
+
warnings.push(text);
|
|
21
|
+
} else if (inCircularWarning && text.startsWith('pg_dump: detail: ')) {
|
|
22
|
+
tables.add(text.slice('pg_dump: detail: '.length));
|
|
23
|
+
warnings.push(text);
|
|
24
|
+
} else if (inCircularWarning && hints.has(text)) {
|
|
25
|
+
warnings.push(text);
|
|
26
|
+
} else {
|
|
27
|
+
inCircularWarning = false;
|
|
28
|
+
writeStderr(raw);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function consume(text) {
|
|
32
|
+
pending += text;
|
|
33
|
+
let end;
|
|
34
|
+
while ((end = pending.indexOf('\n')) !== -1) {
|
|
35
|
+
line(pending.slice(0, end + 1));
|
|
36
|
+
pending = pending.slice(end + 1);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
write(chunk) { consume(decoder.write(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk))); },
|
|
41
|
+
end() {
|
|
42
|
+
consume(decoder.end());
|
|
43
|
+
if (pending) line(pending);
|
|
44
|
+
pending = '';
|
|
45
|
+
return { circularForeignKeys: warnings.length > 0, tables: [...tables], messages: warnings };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Supabase prepends this command before pg_dump output. Check the first line,
|
|
51
|
+
// not arbitrary table contents: a data row containing SQL is not protection.
|
|
52
|
+
async function hasReplicaRolePrologue(file) {
|
|
53
|
+
const handle = await fs.open(file, 'r');
|
|
54
|
+
try {
|
|
55
|
+
const buffer = Buffer.alloc(256);
|
|
56
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
57
|
+
const firstLine = buffer.toString('utf8', 0, bytesRead).split('\n')[0].replace(/^\uFEFF/, '').trim();
|
|
58
|
+
return /^SET\s+session_replication_role\s*=\s*(?:replica|'replica');$/i.test(firstLine);
|
|
59
|
+
} finally {
|
|
60
|
+
await handle.close();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = { createPgDumpDiagnostics, hasReplicaRolePrologue };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { execFileSync } = require('child_process');
|
|
4
|
+
|
|
5
|
+
// npm installs a .cmd shim on Windows; execFile cannot execute that shim safely.
|
|
6
|
+
// Resolve its package entry point instead of interpolating arguments into cmd.exe.
|
|
7
|
+
function runSupabase(_command, args, options = {}) {
|
|
8
|
+
if (process.platform !== 'win32')
|
|
9
|
+
return execFileSync('supabase', args, options);
|
|
10
|
+
for (const directory of (process.env.PATH || '').split(path.delimiter)) {
|
|
11
|
+
const executable = path.join(directory, 'supabase.exe');
|
|
12
|
+
if (fs.existsSync(executable))
|
|
13
|
+
return execFileSync(executable, args, options);
|
|
14
|
+
for (const root of [
|
|
15
|
+
path.join(directory, 'node_modules', 'supabase'),
|
|
16
|
+
path.resolve(directory, '..', 'supabase'),
|
|
17
|
+
]) {
|
|
18
|
+
const file = path.join(root, 'package.json');
|
|
19
|
+
if (!fs.existsSync(file)) continue;
|
|
20
|
+
const pkg = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
21
|
+
const bin = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin?.supabase;
|
|
22
|
+
if (!bin) continue;
|
|
23
|
+
const entry = path.resolve(root, bin);
|
|
24
|
+
if (!fs.existsSync(entry)) continue;
|
|
25
|
+
if (entry.endsWith('.js'))
|
|
26
|
+
return execFileSync(process.execPath, [entry, ...args], options);
|
|
27
|
+
return execFileSync(entry, args, options);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
throw new Error('Supabase CLI executable was not found in PATH');
|
|
31
|
+
}
|
|
32
|
+
module.exports = { runSupabase };
|