smoonb 0.0.7 → 0.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/README.md +164 -169
- package/bin/smoonb.js +7 -23
- package/package.json +1 -1
- package/src/commands/backup.js +140 -249
- package/src/commands/check.js +209 -349
- package/src/commands/functions.js +123 -349
- package/src/commands/restore.js +122 -294
- package/src/index.js +12 -21
- package/src/services/introspect.js +299 -0
- package/src/utils/cli.js +87 -0
- package/src/utils/config.js +140 -0
- package/src/utils/fsx.js +110 -0
- package/src/utils/hash.js +40 -0
- package/src/commands/secrets.js +0 -361
package/README.md
CHANGED
|
@@ -1,232 +1,227 @@
|
|
|
1
|
-
# smoonb
|
|
1
|
+
# smoonb
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Complete Supabase backup and migration tool**
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## ⚠️ EXPERIMENTAL VERSION - NÃO TESTADA - USE POR SUA CONTA E RISCO
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
**🚨 AVISO IMPORTANTE:**
|
|
8
|
+
- Este software **NUNCA** foi testado em produção
|
|
9
|
+
- **USE POR SUA CONTA E RISCO** - Pode causar perda irreparável de dados
|
|
10
|
+
- **NÃO NOS RESPONSABILIZAMOS** por qualquer perda de dados
|
|
11
|
+
- **NENHUM SUPORTE** é oferecido nesta fase - apenas aceitamos contribuições
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
- ❌ **NÃO USE** em dados críticos ou produção
|
|
11
|
-
- ⚠️ **RESULTADOS IMPREVISÍVEIS** - podem causar perdas irreparáveis de dados
|
|
12
|
-
- ⚠️ **NÃO NOS RESPONSABILIZAMOS** por qualquer perda de dados
|
|
13
|
-
- ⚠️ **USE POR SUA CONTA E RISCO** - você é o único responsável
|
|
13
|
+
**Desenvolvido por:** Goalmoon Tecnologia LTDA (https://goalmoon.com)
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
## 🎯 Objetivo
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
O **smoonb** resolve o problema das ferramentas existentes que fazem backup apenas da database PostgreSQL, ignorando componentes críticos do Supabase:
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
- ✅ **Database PostgreSQL** (roles, schema, data)
|
|
20
|
+
- ✅ **Edge Functions** (código local)
|
|
21
|
+
- ✅ **Auth Settings** (configurações de autenticação)
|
|
22
|
+
- ✅ **Storage Objects** (buckets e metadados)
|
|
23
|
+
- ✅ **Realtime Settings** (publicações e configurações)
|
|
24
|
+
- ✅ **Inventário Completo** (extensões, políticas RLS, etc.)
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
- ❌ **Auth Settings** - Configurações de autenticação perdidas
|
|
23
|
-
- ❌ **Storage Objects** - Arquivos e buckets perdidos
|
|
24
|
-
- ❌ **Realtime Settings** - Configurações de tempo real perdidas
|
|
26
|
+
## 🚀 Instalação
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
smoonb é a **primeira ferramenta** que faz backup **COMPLETO** do Supabase:
|
|
28
|
+
```bash
|
|
29
|
+
# Instalar localmente no projeto
|
|
30
|
+
npm install smoonb
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
- ✅ **Storage Objects** - Arquivos e metadados
|
|
36
|
-
- ✅ **Realtime Settings** - Configurações de tempo real
|
|
37
|
-
- ✅ **Metadados** - Todas as configurações do projeto
|
|
32
|
+
# Usar com npx
|
|
33
|
+
npx smoonb --help
|
|
34
|
+
```
|
|
38
35
|
|
|
39
|
-
##
|
|
36
|
+
## 📋 Pré-requisitos
|
|
40
37
|
|
|
38
|
+
### 1. Supabase CLI
|
|
41
39
|
```bash
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
npm install -g supabase
|
|
41
|
+
```
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
### 2. PostgreSQL (psql)
|
|
44
|
+
- **Windows**: https://www.postgresql.org/download/windows/
|
|
45
|
+
- **macOS**: `brew install postgresql`
|
|
46
|
+
- **Linux**: `sudo apt-get install postgresql-client`
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
npx smoonb secrets export
|
|
50
|
-
npx smoonb secrets import
|
|
48
|
+
## ⚙️ Configuração
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
### 1. Inicializar configuração
|
|
51
|
+
```bash
|
|
52
|
+
npx smoonb config --init
|
|
53
|
+
```
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
### 2. Editar `.smoonbrc`
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"supabase": {
|
|
59
|
+
"projectId": "seu-project-id",
|
|
60
|
+
"url": "https://seu-project-id.supabase.co",
|
|
61
|
+
"serviceKey": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
|
62
|
+
"anonKey": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
|
63
|
+
"databaseUrl": "postgresql://postgres:[senha]@db.seu-project-id.supabase.co:5432/postgres"
|
|
64
|
+
},
|
|
65
|
+
"backup": {
|
|
66
|
+
"includeFunctions": true,
|
|
67
|
+
"includeStorage": true,
|
|
68
|
+
"includeAuth": true,
|
|
69
|
+
"includeRealtime": true,
|
|
70
|
+
"outputDir": "./backups"
|
|
71
|
+
},
|
|
72
|
+
"restore": {
|
|
73
|
+
"cleanRestore": true,
|
|
74
|
+
"verifyAfterRestore": true
|
|
75
|
+
}
|
|
76
|
+
}
|
|
57
77
|
```
|
|
58
78
|
|
|
59
|
-
|
|
79
|
+
### 3. Obter credenciais no Dashboard Supabase
|
|
60
80
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
| Auth Settings | ✅ Backup + Restore | ❌ Não suportado |
|
|
66
|
-
| Storage Objects | ✅ Backup + Restore | ❌ Não suportado |
|
|
67
|
-
| Realtime Settings | ✅ Backup + Restore | ❌ Não suportado |
|
|
68
|
-
| Metadados | ✅ Completo | ❌ Parcial |
|
|
69
|
-
| CLI Simples | ✅ Intuitivo | ⚠️ Complexo |
|
|
70
|
-
| Restauração Confiável | ✅ 100% | ⚠️ Parcial |
|
|
81
|
+
1. **Project ID**: Settings → General → Reference ID
|
|
82
|
+
2. **URL**: Settings → API → Project URL
|
|
83
|
+
3. **Keys**: Settings → API → Project API keys
|
|
84
|
+
4. **Database URL**: Settings → Database → Connection string
|
|
71
85
|
|
|
72
|
-
##
|
|
86
|
+
## 🎯 Uso
|
|
73
87
|
|
|
88
|
+
### Backup Completo
|
|
74
89
|
```bash
|
|
75
|
-
|
|
76
|
-
npm install smoonb
|
|
77
|
-
|
|
78
|
-
# Usar com npx
|
|
79
|
-
npx smoonb --version
|
|
80
|
-
|
|
81
|
-
# Ou adicionar script no package.json
|
|
82
|
-
npm pkg set scripts.backup="npx smoonb backup"
|
|
83
|
-
npm run backup
|
|
90
|
+
npx smoonb backup
|
|
84
91
|
```
|
|
85
92
|
|
|
86
|
-
|
|
93
|
+
**Resultado:**
|
|
94
|
+
```
|
|
95
|
+
backups/backup-2024-01-15T10-30-45-123Z/
|
|
96
|
+
├── backup-manifest.json
|
|
97
|
+
├── roles.sql
|
|
98
|
+
├── schema.sql
|
|
99
|
+
├── data.sql
|
|
100
|
+
├── inventory/
|
|
101
|
+
│ ├── extensions.json
|
|
102
|
+
│ ├── tables.json
|
|
103
|
+
│ ├── policies.json
|
|
104
|
+
│ ├── realtime.json
|
|
105
|
+
│ └── storage.json
|
|
106
|
+
└── functions/
|
|
107
|
+
└── [código das Edge Functions locais]
|
|
108
|
+
```
|
|
87
109
|
|
|
110
|
+
### Restauração
|
|
88
111
|
```bash
|
|
89
|
-
|
|
90
|
-
npm install smoonb
|
|
91
|
-
|
|
92
|
-
# 2. Configure suas credenciais Supabase
|
|
93
|
-
npx npx smoonb config --init
|
|
94
|
-
|
|
95
|
-
# 3. Edite o arquivo .smoonbrc com suas credenciais
|
|
96
|
-
# 4. Execute o backup completo
|
|
97
|
-
npx npx smoonb backup
|
|
98
|
-
|
|
99
|
-
# 5. Restaure em outro projeto
|
|
100
|
-
npx npx smoonb restore --backup-dir ./backups/backup-2024-01-15T10-30-00Z
|
|
112
|
+
npx smoonb restore --backup-dir backups/backup-2024-01-15T10-30-45-123Z
|
|
101
113
|
```
|
|
102
114
|
|
|
103
|
-
|
|
115
|
+
**Processo:**
|
|
116
|
+
1. Verifica se database está vazia (clean restore)
|
|
117
|
+
2. Executa `roles.sql` (roles e permissões)
|
|
118
|
+
3. Executa `schema.sql` (estrutura das tabelas)
|
|
119
|
+
4. Executa `data.sql` (dados com COPY)
|
|
104
120
|
|
|
105
|
-
###
|
|
121
|
+
### Verificação Pós-Restore
|
|
106
122
|
```bash
|
|
107
|
-
npx smoonb
|
|
108
|
-
--project-id abc123def456 \
|
|
109
|
-
--output ./backup-$(date +%Y%m%d) \
|
|
110
|
-
--include-functions \
|
|
111
|
-
--include-storage \
|
|
112
|
-
--include-auth
|
|
123
|
+
npx smoonb check
|
|
113
124
|
```
|
|
114
125
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
```
|
|
126
|
+
**Verifica:**
|
|
127
|
+
- ✅ Conexão com database
|
|
128
|
+
- ✅ Extensões instaladas
|
|
129
|
+
- ✅ Tabelas criadas
|
|
130
|
+
- ✅ Políticas RLS
|
|
131
|
+
- ✅ Publicações Realtime
|
|
132
|
+
- ✅ Buckets de Storage
|
|
123
133
|
|
|
124
|
-
###
|
|
134
|
+
### Edge Functions
|
|
125
135
|
```bash
|
|
126
|
-
#
|
|
127
|
-
npx smoonb
|
|
128
|
-
|
|
129
|
-
# 2. Export secrets (opcional)
|
|
130
|
-
npx smoonb secrets export --project-id source-project
|
|
131
|
-
|
|
132
|
-
# 3. Restore no projeto destino
|
|
133
|
-
npx smoonb restore --project-id target-project
|
|
136
|
+
# Listar functions
|
|
137
|
+
npx smoonb functions list
|
|
134
138
|
|
|
135
|
-
#
|
|
136
|
-
npx smoonb
|
|
137
|
-
|
|
138
|
-
# 5. Verificação final
|
|
139
|
-
npx smoonb check --project-id target-project
|
|
139
|
+
# Deploy functions
|
|
140
|
+
npx smoonb functions push
|
|
140
141
|
```
|
|
141
142
|
|
|
142
|
-
## 🔧
|
|
143
|
+
## 🔧 Comandos Disponíveis
|
|
143
144
|
|
|
144
|
-
|
|
145
|
+
| Comando | Descrição |
|
|
146
|
+
|---------|-----------|
|
|
147
|
+
| `npx smoonb backup` | Backup completo usando Supabase CLI |
|
|
148
|
+
| `npx smoonb restore` | Restauração usando psql |
|
|
149
|
+
| `npx smoonb check` | Verificação de integridade |
|
|
150
|
+
| `npx smoonb functions` | Gerenciar Edge Functions |
|
|
151
|
+
| `npx smoonb config` | Configurar credenciais |
|
|
145
152
|
|
|
146
|
-
|
|
147
|
-
{
|
|
148
|
-
"supabase": {
|
|
149
|
-
"url": "https://your-project.supabase.co",
|
|
150
|
-
"serviceKey": "your-service-key"
|
|
151
|
-
},
|
|
152
|
-
"backup": {
|
|
153
|
-
"includeFunctions": true,
|
|
154
|
-
"includeStorage": true,
|
|
155
|
-
"includeAuth": true,
|
|
156
|
-
"outputDir": "./backups"
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
```
|
|
153
|
+
## 🏗️ Arquitetura Técnica
|
|
160
154
|
|
|
161
|
-
|
|
155
|
+
### Backup Strategy
|
|
156
|
+
- **Database**: `supabase db dump` → `roles.sql`, `schema.sql`, `data.sql`
|
|
157
|
+
- **Inventário**: Queries SQL + Supabase API para metadados
|
|
158
|
+
- **Edge Functions**: Cópia do código local (`supabase/functions/`)
|
|
162
159
|
|
|
163
|
-
###
|
|
160
|
+
### Restore Strategy
|
|
161
|
+
- **Clean Restore**: Verifica database vazia antes de restaurar
|
|
162
|
+
- **Ordem**: roles → schema → data (com transação única para dados)
|
|
163
|
+
- **Verificação**: Checklist automático pós-restore
|
|
164
164
|
|
|
165
|
-
|
|
166
|
-
-
|
|
167
|
-
-
|
|
168
|
-
-
|
|
165
|
+
### Multiplataforma
|
|
166
|
+
- **Windows/macOS/Linux**: Detecção automática de binários
|
|
167
|
+
- **Cross-platform**: Usa `fs.promises.cp`, `path.join`, `spawn`
|
|
168
|
+
- **Sem dependências específicas**: Funciona em qualquer SO
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
## 📊 Fluxo Recomendado
|
|
171
171
|
|
|
172
|
-
|
|
172
|
+
```bash
|
|
173
|
+
# 1. Backup do projeto origem
|
|
174
|
+
npx smoonb backup
|
|
173
175
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
- 🔄 **Migração suave**: Processo transparente e bem comunicado
|
|
176
|
+
# 2. Criar novo projeto Supabase
|
|
177
|
+
# (via Dashboard ou Supabase CLI)
|
|
177
178
|
|
|
178
|
-
|
|
179
|
+
# 3. Configurar .smoonbrc com credenciais do novo projeto
|
|
180
|
+
npx smoonb config --init
|
|
179
181
|
|
|
180
|
-
|
|
182
|
+
# 4. Restaurar backup
|
|
183
|
+
npx smoonb restore --backup-dir backups/backup-YYYY-MM-DDTHH-MM-SS-sssZ
|
|
181
184
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
1. Fork o projeto
|
|
185
|
-
2. Crie uma branch (`git checkout -b feature/nova-funcionalidade`)
|
|
186
|
-
3. Commit suas mudanças (`git commit -m 'Adiciona nova funcionalidade'`)
|
|
187
|
-
4. Push para a branch (`git push origin feature/nova-funcionalidade`)
|
|
188
|
-
5. Abra um Pull Request
|
|
185
|
+
# 5. Verificar integridade
|
|
186
|
+
npx smoonb check
|
|
189
187
|
|
|
190
|
-
|
|
188
|
+
# 6. Deploy Edge Functions (se necessário)
|
|
189
|
+
npx smoonb functions push
|
|
190
|
+
```
|
|
191
191
|
|
|
192
|
-
|
|
192
|
+
## 🐛 Troubleshooting
|
|
193
193
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
### Supabase CLI não encontrado
|
|
195
|
+
```bash
|
|
196
|
+
npm install -g supabase
|
|
197
|
+
```
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
### psql não encontrado
|
|
200
|
+
- **Windows**: Instalar PostgreSQL
|
|
201
|
+
- **macOS**: `brew install postgresql`
|
|
202
|
+
- **Linux**: `sudo apt-get install postgresql-client`
|
|
200
203
|
|
|
201
|
-
|
|
202
|
-
-
|
|
203
|
-
-
|
|
204
|
-
-
|
|
204
|
+
### Database URL incorreta
|
|
205
|
+
- Verificar senha na URL de conexão
|
|
206
|
+
- Usar Connection string do Dashboard Supabase
|
|
207
|
+
- Testar conexão: `psql "sua-database-url" -c "SELECT 1"`
|
|
205
208
|
|
|
206
|
-
|
|
209
|
+
## 📝 Licença
|
|
207
210
|
|
|
208
|
-
|
|
211
|
+
**Versões 0.x.x**: Uso gratuito (experimental)
|
|
212
|
+
**Versões 1.0.0+**: Licença comercial (anúncio com 90 dias de antecedência)
|
|
209
213
|
|
|
210
|
-
|
|
211
|
-
- ⭐ **Dê uma estrela** no GitHub
|
|
212
|
-
- 🐛 **Reporte bugs** e contribua com melhorias
|
|
213
|
-
- 📢 **Compartilhe** com outros desenvolvedores
|
|
214
|
+
## 🤝 Contribuição
|
|
214
215
|
|
|
215
|
-
|
|
216
|
+
Contribuições são bem-vindas! Este é um projeto experimental e precisamos de feedback da comunidade.
|
|
216
217
|
|
|
217
|
-
##
|
|
218
|
+
## ☕ Apoie o Projeto
|
|
218
219
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
- ⚠️ **NUNCA TESTADO EM PRODUÇÃO** - use por sua conta e risco
|
|
222
|
-
- ✅ Backup completo de projetos Supabase (implementação inicial)
|
|
223
|
-
- ✅ Restauração com verificação (implementação inicial)
|
|
224
|
-
- ✅ Suporte a Edge Functions, Auth, Storage e Realtime (implementação inicial)
|
|
225
|
-
- ✅ CLI intuitivo e documentação completa
|
|
226
|
-
- 🏢 Desenvolvido por Goalmoon Tecnologia LTDA
|
|
220
|
+
Se este projeto for útil para você, considere comprar um café:
|
|
221
|
+
[Compre um café](https://pag.ae/7Yj8QjQjQ)
|
|
227
222
|
|
|
228
223
|
---
|
|
229
224
|
|
|
230
|
-
**
|
|
231
|
-
|
|
232
|
-
|
|
225
|
+
**Desenvolvido por:** Goalmoon Tecnologia LTDA
|
|
226
|
+
**Website:** https://goalmoon.com
|
|
227
|
+
**GitHub:** https://github.com/almmello/smoonb
|
package/bin/smoonb.js
CHANGED
|
@@ -68,43 +68,27 @@ program
|
|
|
68
68
|
// Comandos principais
|
|
69
69
|
program
|
|
70
70
|
.command('backup')
|
|
71
|
-
.description('Fazer backup completo do projeto Supabase')
|
|
72
|
-
.option('-
|
|
73
|
-
.option('-o, --output <dir>', 'Diretório de saída do backup', './backups')
|
|
74
|
-
.option('--include-functions', 'Incluir Edge Functions no backup', true)
|
|
75
|
-
.option('--include-storage', 'Incluir Storage Objects no backup', true)
|
|
76
|
-
.option('--include-auth', 'Incluir Auth Settings no backup', true)
|
|
77
|
-
.option('--include-realtime', 'Incluir Realtime Settings no backup', true)
|
|
71
|
+
.description('Fazer backup completo do projeto Supabase usando Supabase CLI')
|
|
72
|
+
.option('-o, --output <dir>', 'Diretório de saída do backup')
|
|
78
73
|
.action(commands.backup);
|
|
79
74
|
|
|
80
75
|
program
|
|
81
76
|
.command('restore')
|
|
82
|
-
.description('Restaurar backup completo
|
|
83
|
-
.option('-p, --project-id <id>', 'ID do projeto Supabase destino')
|
|
77
|
+
.description('Restaurar backup completo usando psql')
|
|
84
78
|
.option('-b, --backup-dir <dir>', 'Diretório do backup a ser restaurado')
|
|
85
|
-
.option('--
|
|
86
|
-
.option('--verify', 'Verificar restauração após completar', true)
|
|
79
|
+
.option('--db-url <url>', 'URL da database de destino (override)')
|
|
87
80
|
.action(commands.restore);
|
|
88
81
|
|
|
89
|
-
program
|
|
90
|
-
.command('secrets')
|
|
91
|
-
.description('Gerenciar secrets do projeto Supabase')
|
|
92
|
-
.option('export', 'Exportar secrets (sem commitar)')
|
|
93
|
-
.option('import', 'Importar secrets no projeto alvo')
|
|
94
|
-
.action(commands.secrets);
|
|
95
82
|
|
|
96
83
|
program
|
|
97
84
|
.command('functions')
|
|
98
|
-
.description('Gerenciar Edge Functions')
|
|
99
|
-
.option('push', 'Deploy de Edge Functions')
|
|
100
|
-
.option('pull', 'Baixar Edge Functions do projeto')
|
|
85
|
+
.description('Gerenciar Edge Functions do Supabase')
|
|
101
86
|
.action(commands.functions);
|
|
102
87
|
|
|
103
88
|
program
|
|
104
89
|
.command('check')
|
|
105
|
-
.description('
|
|
106
|
-
.option('-
|
|
107
|
-
.option('--verbose', 'Saída detalhada', false)
|
|
90
|
+
.description('Verificar integridade do projeto Supabase após restauração')
|
|
91
|
+
.option('-o, --output <file>', 'Arquivo de saída do relatório', 'check-report.json')
|
|
108
92
|
.action(commands.check);
|
|
109
93
|
|
|
110
94
|
program
|