smoonb 1.0.11 → 1.0.12
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 +159 -150
- package/README.md +693 -687
- package/README.pt-BR.md +695 -687
- package/npm-shrinkwrap.json +2030 -0
- package/package.json +71 -68
- package/src/commands/backup/index.js +37 -21
- package/src/commands/backup/outcome.js +8 -0
- package/src/commands/backup/steps/00-license.js +427 -427
- package/src/commands/backup/steps/02-database.js +6 -6
- package/src/commands/backup/steps/03-database-separated.js +129 -161
- package/src/commands/backup/steps/04-database-settings.js +24 -40
- package/src/commands/backup/steps/07-storage.js +11 -10
- package/src/commands/backup/steps/08-custom-roles.js +5 -55
- package/src/commands/backup/steps/10-supabase-temp.js +0 -9
- package/src/commands/backup/steps/11-migrations.js +14 -76
- package/src/i18n/locales/en.json +825 -824
- package/src/i18n/locales/pt-BR.json +824 -823
- package/src/interactive/envMapper.js +6 -12
- package/src/utils/docker.js +6 -53
- package/src/utils/supabaseCli.js +26 -32
|
@@ -1,79 +1,17 @@
|
|
|
1
|
-
const chalk = require('chalk');
|
|
2
1
|
const path = require('path');
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const {
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Etapa 10: Migrations Backup (NOVA ETAPA INDEPENDENTE)
|
|
11
|
-
*/
|
|
12
|
-
module.exports = async (context) => {
|
|
13
|
-
const { projectId, accessToken, databaseUrl, backupDir } = context;
|
|
2
|
+
const fs = require('fs').promises;
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const { runSupabase } = require('../../../utils/supabaseCli');
|
|
5
|
+
const { copyDirectoryRecursive } = require('../../restore/utils');
|
|
6
|
+
module.exports = async ({ databaseUrl, accessToken, backupDir }) => {
|
|
7
|
+
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'smoonb-migrations-'));
|
|
14
8
|
try {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
console.log(chalk.white(` - ${getT('backup.steps.migrations.cleaning')}`));
|
|
24
|
-
|
|
25
|
-
// Baixar todas as migrations do servidor usando migration fetch
|
|
26
|
-
console.log(chalk.white(` - ${getT('backup.steps.migrations.downloading')}`));
|
|
27
|
-
|
|
28
|
-
const env = {
|
|
29
|
-
...process.env,
|
|
30
|
-
SUPABASE_ACCESS_TOKEN: accessToken
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
execSync('supabase migration fetch', {
|
|
35
|
-
cwd: process.cwd(),
|
|
36
|
-
stdio: 'pipe',
|
|
37
|
-
encoding: 'utf8',
|
|
38
|
-
timeout: 120000,
|
|
39
|
-
env
|
|
40
|
-
});
|
|
41
|
-
} catch (error) {
|
|
42
|
-
console.log(chalk.yellow(` ⚠️ ${getT('backup.steps.migrations.fetchError', { message: error.message })}`));
|
|
43
|
-
console.log(chalk.yellow(` 💡 ${getT('backup.steps.migrations.fetchTip')}`));
|
|
44
|
-
return { success: false };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Contar arquivos baixados
|
|
48
|
-
const fileCount = await countFiles(migrationsDir);
|
|
49
|
-
console.log(chalk.white(` - ${getT('backup.steps.migrations.downloaded', { count: fileCount })}`));
|
|
50
|
-
|
|
51
|
-
// Copiar migrations para o backup
|
|
52
|
-
const backupMigrationsDir = path.join(backupDir, 'migrations');
|
|
53
|
-
const copiedCount = await copyDirSafe(migrationsDir, backupMigrationsDir);
|
|
54
|
-
const relativePath = path.relative(process.cwd(), backupMigrationsDir);
|
|
55
|
-
console.log(chalk.white(` - ${getT('backup.steps.migrations.copying', { path: relativePath, count: copiedCount })}`));
|
|
56
|
-
|
|
57
|
-
if (copiedCount > 0) {
|
|
58
|
-
console.log(chalk.green(` ✅ ${getT('backup.steps.migrations.copied', { count: copiedCount })}`));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Usar flag de limpeza do contexto (já foi perguntado no início)
|
|
62
|
-
const shouldClean = context?.cleanupFlags?.cleanMigrations || false;
|
|
63
|
-
|
|
64
|
-
if (shouldClean) {
|
|
65
|
-
await cleanDir(migrationsDir);
|
|
66
|
-
ui.hint(` - ${getT('backup.steps.migrations.cleaned')}`);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
success: true,
|
|
71
|
-
file_count: copiedCount
|
|
72
|
-
};
|
|
73
|
-
} catch (error) {
|
|
74
|
-
const getT = global.smoonbI18n?.t || t;
|
|
75
|
-
console.log(chalk.yellow(` ⚠️ ${getT('backup.steps.migrations.error', { message: error.message })}`));
|
|
76
|
-
return { success: false };
|
|
77
|
-
}
|
|
9
|
+
await fs.mkdir(path.join(root, 'supabase', 'migrations'), { recursive: true });
|
|
10
|
+
await fs.writeFile(path.join(root, 'supabase', 'config.toml'), 'project_id = "smoonb-backup"\n');
|
|
11
|
+
runSupabase('supabase', ['migration', 'fetch', '--db-url', databaseUrl, '--workdir', root, '--yes'], { cwd: root, env: { ...process.env, SUPABASE_ACCESS_TOKEN: accessToken }, stdio: 'pipe' });
|
|
12
|
+
const source = path.join(root, 'supabase', 'migrations');
|
|
13
|
+
await copyDirectoryRecursive(source, path.join(backupDir, 'migrations'));
|
|
14
|
+
return { success: true, file_count: (await fs.readdir(source)).length };
|
|
15
|
+
} catch { return { success: false, reason: 'migration_export_failed' }; }
|
|
16
|
+
finally { await fs.rm(root, { recursive: true, force: true }); }
|
|
78
17
|
};
|
|
79
|
-
|