supabee 0.3.2 → 0.3.3
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 +410 -330
- package/dist/commands/cutoff.d.ts +5 -0
- package/dist/commands/cutoff.js +49 -0
- package/dist/commands/cutoff.js.map +1 -0
- package/dist/commands/db-reset.d.ts +1 -0
- package/dist/commands/db-reset.js +101 -182
- package/dist/commands/db-reset.js.map +1 -1
- package/dist/commands/init.js +9 -4
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/migration.d.ts +16 -0
- package/dist/commands/migration.js +234 -0
- package/dist/commands/migration.js.map +1 -0
- package/dist/commands/sync.d.ts +1 -0
- package/dist/commands/sync.js +50 -2
- package/dist/commands/sync.js.map +1 -1
- package/dist/index.js +111 -90
- package/dist/index.js.map +1 -1
- package/dist/lib/constants.d.ts +3 -0
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/migration-classifier.d.ts +22 -0
- package/dist/lib/migration-classifier.js +240 -0
- package/dist/lib/migration-classifier.js.map +1 -0
- package/dist/lib/post-seed-cutoff.d.ts +24 -0
- package/dist/lib/post-seed-cutoff.js +195 -0
- package/dist/lib/post-seed-cutoff.js.map +1 -0
- package/dist/lib/subprocess.js +7 -7
- package/package.json +54 -53
- package/supabee.config.example.json +34 -29
package/README.md
CHANGED
|
@@ -1,413 +1,493 @@
|
|
|
1
|
-
# Supabee
|
|
2
|
-
|
|
3
|
-
[](https://github.com/kaihochak/supabee/actions/workflows/ci.yml)
|
|
4
|
-
[](https://www.npmjs.com/package/supabee)
|
|
5
|
-
[](./LICENSE)
|
|
6
|
-
|
|
7
|
-
Orchestrate local Supabase schema/data workflows: split giant SQL dumps into organized files, and apply post-seed migrations in a production-like order.
|
|
8
|
-
|
|
9
|
-
## Why?
|
|
10
|
-
|
|
11
|
-
Supabase workflows often end up with two pain points:
|
|
12
|
-
|
|
13
|
-
1. **One huge dump file** (`supabase db dump` / `--data-only`) that's painful to review, edit, or selectively seed from.
|
|
14
|
-
2. **Local reset/start ordering** (migrations → seeds) that can diverge from production deploys (new migrations applied onto an already-populated database).
|
|
15
|
-
|
|
16
|
-
`supabee` addresses both:
|
|
17
|
-
|
|
18
|
-
- **Split + validate dumps:** split schema and data dumps into focused files (by category / by table), then reconstruct and validate round-trip (PR-friendly diffs, easier navigation, and smaller merge conflicts).
|
|
19
|
-
- **Defer post-seed migrations:** temporarily move newer migrations out of the way for `supabase db reset` / `supabase start`, then restore + reapply them after seeds load.
|
|
20
|
-
|
|
21
|
-
### Use cases
|
|
22
|
-
|
|
23
|
-
- **Seed data you can control:** keep per-table seed files and point `[db.seed].sql_paths` at only the ones you want.
|
|
24
|
-
- **Schema as docs / source of truth:** keep schema readable in-repo (tables, functions, RLS, permissions, etc.).
|
|
25
|
-
- **Mimic production locally:** catch “works on reset” vs “works on deploy” issues by applying post-seed migrations after data exists.
|
|
26
|
-
- **One-liners with validation:** `sync schema` / `sync data` run dump → split → reconstruct → validate.
|
|
27
|
-
|
|
28
|
-
### Repo hygiene (recommended)
|
|
29
|
-
|
|
30
|
-
Commit split outputs (for example `supabase/schemas/split/**` and `supabase/seeds/split/**`), and ignore large generated artifacts in your repo:
|
|
31
|
-
|
|
32
|
-
```gitignore
|
|
33
|
-
# raw dumps (generated from prod; optional to keep locally)
|
|
34
|
-
supabase/schemas/prod-schemas.sql
|
|
35
|
-
supabase/seeds/prod-data.sql
|
|
36
|
-
|
|
37
|
-
# reconstructed outputs (validation artifacts)
|
|
38
|
-
supabase/schemas/reconstructed-schemas.sql
|
|
39
|
-
supabase/seeds/reconstructed-data.sql
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Prerequisites
|
|
43
|
-
|
|
44
|
-
- [Node.js](https://nodejs.org/) >= 18
|
|
45
|
-
- [Supabase CLI](https://supabase.com/docs/guides/cli/getting-started) installed and authenticated
|
|
46
|
-
|
|
47
|
-
## Install
|
|
48
|
-
|
|
49
|
-
Global install (recommended):
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
npm i -g supabee
|
|
53
|
-
pnpm add -g supabee
|
|
54
|
-
bun add -g supabee
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
One-off run without global install:
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
npx supabee --help
|
|
61
|
-
pnpm dlx supabee --help
|
|
62
|
-
bunx supabee --help
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
Project-local install (optional):
|
|
66
|
-
|
|
67
|
-
```bash
|
|
68
|
-
npm install --save-dev supabee
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## Setup
|
|
72
|
-
|
|
73
|
-
### 1. Initialize config
|
|
74
|
-
|
|
75
|
-
Run `init` to generate `supabee.config.json` (if it doesn't exist) and update `supabase/config.toml` seed paths:
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
supabee init
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
Review the generated `supabee.config.json` and adjust paths/limits for your project.
|
|
82
|
-
|
|
83
|
-
### 2. Link your Supabase project
|
|
84
|
-
|
|
85
|
-
If you haven't already, link your local repo to your Supabase project. This is required before you can dump schema or data:
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
supabase link
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
You'll be prompted for your project ref and database password. See the [Supabase CLI docs](https://supabase.com/docs/reference/cli/supabase-link) for details.
|
|
92
|
-
|
|
93
|
-
### 3. Run the primary workflows
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
supabee sync schema
|
|
97
|
-
supabee sync data
|
|
98
|
-
supabee db reset [cutoff_timestamp]
|
|
99
|
-
supabee start [cutoff_timestamp]
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
`sync` commands run end-to-end:
|
|
103
|
-
|
|
104
|
-
- schema: `supabase db dump` -> split -> reconstruct -> validate
|
|
105
|
-
- data: `supabase db dump --data-only` -> split -> reconstruct -> validate
|
|
106
|
-
|
|
107
|
-
### Selective seeding example (optional)
|
|
108
|
-
|
|
109
|
-
By default, `supabee init` configures `supabase/config.toml` to load all split seed files (for example `./seeds/split/*.sql`).
|
|
110
|
-
To seed only a subset, replace `[db.seed].sql_paths` with an explicit ordered list (keep `001_setup.sql` and `999_cleanup.sql`; add the generated `*_sequences.sql` file if you need sequence values):
|
|
111
|
-
|
|
112
|
-
```toml
|
|
113
|
-
[db.seed]
|
|
114
|
-
sql_paths = [
|
|
115
|
-
"./seeds/split/001_setup.sql",
|
|
116
|
-
"./seeds/split/002_public_users.sql",
|
|
117
|
-
"./seeds/split/003_public_projects.sql",
|
|
118
|
-
"./seeds/split/999_cleanup.sql",
|
|
119
|
-
]
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
## Commands
|
|
123
|
-
|
|
124
|
-
### `init`
|
|
125
|
-
|
|
126
|
-
Creates `supabee.config.json` if missing, then updates `supabase/config.toml` `[db.seed].sql_paths` so Supabase knows where to find your split seed files.
|
|
127
|
-
|
|
128
|
-
```bash
|
|
129
|
-
supabee init
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### `schema`
|
|
133
|
-
|
|
134
|
-
Processes an existing schema dump into categorized folders:
|
|
135
|
-
|
|
136
|
-
```
|
|
137
|
-
supabase/schemas/split/
|
|
138
|
-
├── 00_extensions/
|
|
139
|
-
├── 01_setup/
|
|
140
|
-
├── 02_types/
|
|
141
|
-
├── 03_functions/
|
|
142
|
-
├── 04_tables/
|
|
143
|
-
├── 05_views/
|
|
144
|
-
├── 06_constraints/
|
|
145
|
-
├── 07_indexes/
|
|
146
|
-
├── 08_foreign_keys/
|
|
147
|
-
├── 09_rls/
|
|
148
|
-
├── 10_permissions/
|
|
149
|
-
├── 11_ownership/
|
|
150
|
-
└── 12_others/
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
```bash
|
|
154
|
-
# Full chain (split → reconstruct → validate)
|
|
155
|
-
supabee schema
|
|
156
|
-
|
|
157
|
-
# Individual steps
|
|
158
|
-
supabee schema split
|
|
159
|
-
supabee schema reconstruct
|
|
160
|
-
supabee schema validate
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
### `data`
|
|
164
|
-
|
|
165
|
-
Processes an existing data dump into per-table files with configurable row/statement limits:
|
|
166
|
-
|
|
167
|
-
```bash
|
|
168
|
-
# Full chain (split → reconstruct → validate)
|
|
169
|
-
supabee data
|
|
170
|
-
|
|
171
|
-
# Individual steps
|
|
172
|
-
supabee data split
|
|
173
|
-
supabee data reconstruct
|
|
174
|
-
supabee data validate
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
### `sync schema`
|
|
178
|
-
|
|
179
|
-
Dumps schema from the linked Supabase project, then runs full schema processing:
|
|
180
|
-
|
|
1
|
+
# Supabee
|
|
2
|
+
|
|
3
|
+
[](https://github.com/kaihochak/supabee/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/supabee)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
|
|
7
|
+
Orchestrate local Supabase schema/data workflows: split giant SQL dumps into organized files, and apply post-seed migrations in a production-like order.
|
|
8
|
+
|
|
9
|
+
## Why?
|
|
10
|
+
|
|
11
|
+
Supabase workflows often end up with two pain points:
|
|
12
|
+
|
|
13
|
+
1. **One huge dump file** (`supabase db dump` / `--data-only`) that's painful to review, edit, or selectively seed from.
|
|
14
|
+
2. **Local reset/start ordering** (migrations → seeds) that can diverge from production deploys (new migrations applied onto an already-populated database).
|
|
15
|
+
|
|
16
|
+
`supabee` addresses both:
|
|
17
|
+
|
|
18
|
+
- **Split + validate dumps:** split schema and data dumps into focused files (by category / by table), then reconstruct and validate round-trip (PR-friendly diffs, easier navigation, and smaller merge conflicts).
|
|
19
|
+
- **Defer post-seed migrations:** temporarily move newer migrations out of the way for `supabase db reset` / `supabase start`, then restore + reapply them after seeds load.
|
|
20
|
+
|
|
21
|
+
### Use cases
|
|
22
|
+
|
|
23
|
+
- **Seed data you can control:** keep per-table seed files and point `[db.seed].sql_paths` at only the ones you want.
|
|
24
|
+
- **Schema as docs / source of truth:** keep schema readable in-repo (tables, functions, RLS, permissions, etc.).
|
|
25
|
+
- **Mimic production locally:** catch “works on reset” vs “works on deploy” issues by applying post-seed migrations after data exists.
|
|
26
|
+
- **One-liners with validation:** `sync schema` / `sync data` run dump → split → reconstruct → validate.
|
|
27
|
+
|
|
28
|
+
### Repo hygiene (recommended)
|
|
29
|
+
|
|
30
|
+
Commit split outputs (for example `supabase/schemas/split/**` and `supabase/seeds/split/**`), and ignore large generated artifacts in your repo:
|
|
31
|
+
|
|
32
|
+
```gitignore
|
|
33
|
+
# raw dumps (generated from prod; optional to keep locally)
|
|
34
|
+
supabase/schemas/prod-schemas.sql
|
|
35
|
+
supabase/seeds/prod-data.sql
|
|
36
|
+
|
|
37
|
+
# reconstructed outputs (validation artifacts)
|
|
38
|
+
supabase/schemas/reconstructed-schemas.sql
|
|
39
|
+
supabase/seeds/reconstructed-data.sql
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Prerequisites
|
|
43
|
+
|
|
44
|
+
- [Node.js](https://nodejs.org/) >= 18
|
|
45
|
+
- [Supabase CLI](https://supabase.com/docs/guides/cli/getting-started) installed and authenticated
|
|
46
|
+
|
|
47
|
+
## Install
|
|
48
|
+
|
|
49
|
+
Global install (recommended):
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm i -g supabee
|
|
53
|
+
pnpm add -g supabee
|
|
54
|
+
bun add -g supabee
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
One-off run without global install:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npx supabee --help
|
|
61
|
+
pnpm dlx supabee --help
|
|
62
|
+
bunx supabee --help
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Project-local install (optional):
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npm install --save-dev supabee
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Setup
|
|
72
|
+
|
|
73
|
+
### 1. Initialize config
|
|
74
|
+
|
|
75
|
+
Run `init` to generate `supabee.config.json` (if it doesn't exist) and update `supabase/config.toml` seed paths:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
supabee init
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Review the generated `supabee.config.json` and adjust paths/limits for your project.
|
|
82
|
+
|
|
83
|
+
### 2. Link your Supabase project
|
|
84
|
+
|
|
85
|
+
If you haven't already, link your local repo to your Supabase project. This is required before you can dump schema or data:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
supabase link
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
You'll be prompted for your project ref and database password. See the [Supabase CLI docs](https://supabase.com/docs/reference/cli/supabase-link) for details.
|
|
92
|
+
|
|
93
|
+
### 3. Run the primary workflows
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
supabee sync schema
|
|
97
|
+
supabee sync data
|
|
98
|
+
supabee db reset [cutoff_timestamp]
|
|
99
|
+
supabee start [cutoff_timestamp]
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`sync` commands run end-to-end:
|
|
103
|
+
|
|
104
|
+
- schema: `supabase db dump` -> split -> reconstruct -> validate
|
|
105
|
+
- data: `supabase db dump --data-only` -> split -> reconstruct -> validate
|
|
106
|
+
|
|
107
|
+
### Selective seeding example (optional)
|
|
108
|
+
|
|
109
|
+
By default, `supabee init` configures `supabase/config.toml` to load all split seed files (for example `./seeds/split/*.sql`).
|
|
110
|
+
To seed only a subset, replace `[db.seed].sql_paths` with an explicit ordered list (keep `001_setup.sql` and `999_cleanup.sql`; add the generated `*_sequences.sql` file if you need sequence values):
|
|
111
|
+
|
|
112
|
+
```toml
|
|
113
|
+
[db.seed]
|
|
114
|
+
sql_paths = [
|
|
115
|
+
"./seeds/split/001_setup.sql",
|
|
116
|
+
"./seeds/split/002_public_users.sql",
|
|
117
|
+
"./seeds/split/003_public_projects.sql",
|
|
118
|
+
"./seeds/split/999_cleanup.sql",
|
|
119
|
+
]
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Commands
|
|
123
|
+
|
|
124
|
+
### `init`
|
|
125
|
+
|
|
126
|
+
Creates `supabee.config.json` if missing, then updates `supabase/config.toml` `[db.seed].sql_paths` so Supabase knows where to find your split seed files.
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
supabee init
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### `schema`
|
|
133
|
+
|
|
134
|
+
Processes an existing schema dump into categorized folders:
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
supabase/schemas/split/
|
|
138
|
+
├── 00_extensions/
|
|
139
|
+
├── 01_setup/
|
|
140
|
+
├── 02_types/
|
|
141
|
+
├── 03_functions/
|
|
142
|
+
├── 04_tables/
|
|
143
|
+
├── 05_views/
|
|
144
|
+
├── 06_constraints/
|
|
145
|
+
├── 07_indexes/
|
|
146
|
+
├── 08_foreign_keys/
|
|
147
|
+
├── 09_rls/
|
|
148
|
+
├── 10_permissions/
|
|
149
|
+
├── 11_ownership/
|
|
150
|
+
└── 12_others/
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Full chain (split → reconstruct → validate)
|
|
155
|
+
supabee schema
|
|
156
|
+
|
|
157
|
+
# Individual steps
|
|
158
|
+
supabee schema split
|
|
159
|
+
supabee schema reconstruct
|
|
160
|
+
supabee schema validate
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### `data`
|
|
164
|
+
|
|
165
|
+
Processes an existing data dump into per-table files with configurable row/statement limits:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
# Full chain (split → reconstruct → validate)
|
|
169
|
+
supabee data
|
|
170
|
+
|
|
171
|
+
# Individual steps
|
|
172
|
+
supabee data split
|
|
173
|
+
supabee data reconstruct
|
|
174
|
+
supabee data validate
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### `sync schema`
|
|
178
|
+
|
|
179
|
+
Dumps schema from the linked Supabase project, then runs full schema processing:
|
|
180
|
+
|
|
181
181
|
```bash
|
|
182
182
|
supabee sync schema
|
|
183
183
|
supabee sync schema --input supabase/schemas/prod-schemas.sql --output supabase/schemas/split
|
|
184
184
|
supabee sync schema --backup
|
|
185
|
+
supabee sync schema --force
|
|
185
186
|
```
|
|
186
|
-
|
|
187
|
-
### `sync data`
|
|
188
|
-
|
|
189
|
-
Dumps data (`--data-only`) from the linked Supabase project, then runs full data processing:
|
|
190
|
-
|
|
187
|
+
|
|
188
|
+
### `sync data`
|
|
189
|
+
|
|
190
|
+
Dumps data (`--data-only`) from the linked Supabase project, then runs full data processing:
|
|
191
|
+
|
|
191
192
|
```bash
|
|
192
193
|
supabee sync data
|
|
193
194
|
supabee sync data --input supabase/seeds/prod-data.sql --output supabase/seeds/split
|
|
194
195
|
supabee sync data --backup
|
|
195
196
|
supabee sync data --no-backup
|
|
197
|
+
supabee sync data --force
|
|
196
198
|
```
|
|
197
|
-
|
|
199
|
+
|
|
198
200
|
### `db reset`
|
|
199
201
|
|
|
200
202
|
Defers post-seed migrations newer than the cutoff timestamp, runs `supabase db reset`, restores deferred migrations, then reapplies them.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
For historical data migrations at or before cutoff, `supabee` executes a temporary no-op stub during reset, then restores original SQL.
|
|
204
|
+
Classification is automatic by SQL patterns (`INSERT/UPDATE/DELETE/...` vs `CREATE/ALTER/DROP ...`), and optional markers can override classification.
|
|
205
|
+
Mixed schema+DML migrations are blocked and must be split.
|
|
206
|
+
|
|
207
|
+
If `[cutoff_timestamp]` is omitted, `supabee` auto-detects it from `supabase migration list --linked` by taking the latest migration version that exists in both local and remote (works even when remote has gaps).
|
|
208
|
+
When linked lookup succeeds, `supabee` stores the value in `supabee.config.json` as `postSeedCutoff` (or `postSeedCutoffByEnv.<env>` when `--env` is set).
|
|
209
|
+
If linked lookup fails (for example in CI), it falls back to `postSeedCutoffByEnv.<env>` when `--env` is set, otherwise `postSeedCutoff`.
|
|
205
210
|
If not linked, `supabee` runs `supabase link` and retries once.
|
|
206
|
-
|
|
207
|
-
```bash
|
|
211
|
+
|
|
212
|
+
```bash
|
|
208
213
|
# default re-apply mode: supabase migration up
|
|
209
214
|
supabee db reset 20260309180959
|
|
210
215
|
supabee db reset
|
|
216
|
+
supabee db reset --env staging
|
|
211
217
|
|
|
212
218
|
# optional re-apply mode: psql
|
|
213
219
|
supabee db reset 20260309180959 --psql
|
|
214
220
|
```
|
|
215
|
-
|
|
221
|
+
|
|
216
222
|
### `start`
|
|
217
223
|
|
|
218
224
|
Defers post-seed migrations newer than the cutoff timestamp, runs `supabase start`, restores deferred migrations, then reapplies them.
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
225
|
+
For historical data-migration files, `supabee` temporarily swaps the file body to a no-op during the run, then restores the original SQL file content.
|
|
226
|
+
|
|
227
|
+
If `[cutoff_timestamp]` is omitted, `supabee` auto-detects it from `supabase migration list --linked` the same way as `db reset`.
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
# explicit cutoff
|
|
231
|
+
supabee start 20260309180959
|
|
232
|
+
|
|
226
233
|
# auto cutoff from linked migration alignment
|
|
227
234
|
supabee start
|
|
228
235
|
|
|
229
236
|
# optional re-apply mode: psql
|
|
230
237
|
supabee start --psql
|
|
238
|
+
supabee start --env production
|
|
231
239
|
```
|
|
232
240
|
|
|
233
|
-
###
|
|
241
|
+
### `cutoff detect`
|
|
234
242
|
|
|
235
|
-
|
|
243
|
+
Resolves cutoff from argument, linked migration alignment, or config fallback.
|
|
236
244
|
|
|
237
245
|
```bash
|
|
238
|
-
supabee
|
|
239
|
-
supabee
|
|
246
|
+
supabee cutoff detect
|
|
247
|
+
supabee cutoff detect --env staging
|
|
248
|
+
supabee cutoff detect 20260309180959 --json
|
|
240
249
|
```
|
|
241
250
|
|
|
242
|
-
###
|
|
251
|
+
### `migration audit`
|
|
243
252
|
|
|
244
|
-
`schema`, `
|
|
253
|
+
Classifies migration files as `data`, `schema`, `mixed`, or `unknown`, and shows recommended marker actions.
|
|
245
254
|
|
|
246
255
|
```bash
|
|
247
|
-
supabee
|
|
248
|
-
supabee
|
|
249
|
-
supabee data split --input path/to/data.sql --output path/to/split
|
|
250
|
-
supabee data split --input path/to/data.sql --output path/to/split --no-backup
|
|
256
|
+
supabee migration audit
|
|
257
|
+
supabee migration audit --migrations-dir supabase/migrations
|
|
251
258
|
```
|
|
252
259
|
|
|
253
|
-
|
|
254
|
-
Use `--backup` to keep a timestamped backup before replacement.
|
|
260
|
+
### `migration mark`
|
|
255
261
|
|
|
256
|
-
|
|
262
|
+
Adds suggested marker comments by default with interactive confirmation prompts.
|
|
257
263
|
|
|
258
|
-
|
|
264
|
+
```bash
|
|
265
|
+
# default: interactive apply
|
|
266
|
+
supabee migration mark
|
|
267
|
+
|
|
268
|
+
# preview only (no writes)
|
|
269
|
+
supabee migration mark --dry-run
|
|
270
|
+
|
|
271
|
+
# non-interactive apply (CI/scripts)
|
|
272
|
+
supabee migration mark --yes
|
|
273
|
+
```
|
|
259
274
|
|
|
260
|
-
|
|
275
|
+
### `migration unmark`
|
|
261
276
|
|
|
262
|
-
|
|
277
|
+
Removes marker comments with the same interaction model as `mark`.
|
|
263
278
|
|
|
264
|
-
|
|
279
|
+
```bash
|
|
280
|
+
# default: interactive remove
|
|
281
|
+
supabee migration unmark
|
|
282
|
+
|
|
283
|
+
# preview only (no writes)
|
|
284
|
+
supabee migration unmark --dry-run
|
|
265
285
|
|
|
266
|
-
|
|
286
|
+
# non-interactive remove
|
|
287
|
+
supabee migration unmark --yes
|
|
288
|
+
```
|
|
267
289
|
|
|
290
|
+
### Supabase passthrough
|
|
291
|
+
|
|
292
|
+
Unknown commands are forwarded to Supabase CLI:
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
supabee migration up # forwards to: supabase migration up
|
|
296
|
+
supabee db dump # forwards to: supabase db dump
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Overriding paths
|
|
300
|
+
|
|
301
|
+
`schema`, `data`, and `sync` commands accept `--input` and `--output` flags:
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
supabee schema split --input path/to/schema.sql --output path/to/split
|
|
305
|
+
supabee schema split --input path/to/schema.sql --output path/to/split --backup
|
|
306
|
+
supabee data split --input path/to/data.sql --output path/to/split
|
|
307
|
+
supabee data split --input path/to/data.sql --output path/to/split --no-backup
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
By default, split operations replace existing output in-place (while preserving configured `keepFiles`) without creating a backup folder.
|
|
311
|
+
Use `--backup` to keep a timestamped backup before replacement.
|
|
312
|
+
|
|
313
|
+
## Configuration
|
|
314
|
+
|
|
315
|
+
`supabee` reads `supabee.config.json` from your project root.
|
|
316
|
+
|
|
317
|
+
**Precedence:** CLI flags > config file > built-in defaults.
|
|
318
|
+
|
|
319
|
+
If the config file is missing, built-in defaults are used. Run `supabee init` to generate one.
|
|
320
|
+
|
|
321
|
+
Legacy support: `supabase-splitter.config.json` is still recognized, but `supabee.config.json` is preferred.
|
|
322
|
+
|
|
323
|
+
### Full config reference
|
|
324
|
+
|
|
268
325
|
```json
|
|
269
326
|
{
|
|
270
327
|
"postSeedCutoff": "",
|
|
271
|
-
"
|
|
272
|
-
"
|
|
273
|
-
"
|
|
274
|
-
"reconstructed": "supabase/schemas/reconstructed-schemas.sql",
|
|
275
|
-
"backup": false,
|
|
276
|
-
"keepFiles": []
|
|
277
|
-
},
|
|
278
|
-
"data": {
|
|
279
|
-
"input": "supabase/seeds/prod-data.sql",
|
|
280
|
-
"output": "supabase/seeds/split",
|
|
281
|
-
"reconstructed": "supabase/seeds/reconstructed-data.sql",
|
|
282
|
-
"backup": false,
|
|
283
|
-
"maxLinesPerFile": 2000,
|
|
284
|
-
"maxStatementsPerFile": 20,
|
|
285
|
-
"maxRowsPerInsert": 200,
|
|
286
|
-
"tableRules": {},
|
|
287
|
-
"keepFiles": [],
|
|
288
|
-
"ignoreInReconstruct": []
|
|
328
|
+
"postSeedCutoffByEnv": {
|
|
329
|
+
"staging": "",
|
|
330
|
+
"production": ""
|
|
289
331
|
},
|
|
290
|
-
"
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
332
|
+
"dataMigrationMarker": "supabee:data-migration",
|
|
333
|
+
"schemaMigrationMarker": "supabee:schema-migration",
|
|
334
|
+
"schema": {
|
|
335
|
+
"input": "supabase/schemas/prod-schemas.sql",
|
|
336
|
+
"output": "supabase/schemas/split",
|
|
337
|
+
"reconstructed": "supabase/schemas/reconstructed-schemas.sql",
|
|
338
|
+
"backup": false,
|
|
339
|
+
"keepFiles": []
|
|
340
|
+
},
|
|
341
|
+
"data": {
|
|
342
|
+
"input": "supabase/seeds/prod-data.sql",
|
|
343
|
+
"output": "supabase/seeds/split",
|
|
344
|
+
"reconstructed": "supabase/seeds/reconstructed-data.sql",
|
|
345
|
+
"backup": false,
|
|
346
|
+
"maxLinesPerFile": 2000,
|
|
347
|
+
"maxStatementsPerFile": 20,
|
|
348
|
+
"maxRowsPerInsert": 200,
|
|
349
|
+
"tableRules": {},
|
|
350
|
+
"keepFiles": [],
|
|
351
|
+
"ignoreInReconstruct": []
|
|
352
|
+
},
|
|
353
|
+
"init": {
|
|
354
|
+
"seedSqlPaths": ["./seeds/split/*.sql"]
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
| Key | Description |
|
|
360
|
+
|-----|-------------|
|
|
361
|
+
| `schema.input` | Path to your schema dump file |
|
|
362
|
+
| `schema.output` | Directory for split schema files |
|
|
363
|
+
| `schema.reconstructed` | Path for the reconstructed schema (used in validation) |
|
|
364
|
+
| `schema.backup` | Whether split should create backup folder before replacing output (default: `false`) |
|
|
365
|
+
| `schema.keepFiles` | Files in the split dir to preserve across re-splits |
|
|
366
|
+
| `data.input` | Path to your data dump file |
|
|
367
|
+
| `data.output` | Directory for split data files |
|
|
368
|
+
| `data.reconstructed` | Path for the reconstructed data (used in validation) |
|
|
369
|
+
| `data.backup` | Whether split should create backup folder before replacing output (default: `false`) |
|
|
370
|
+
| `data.maxLinesPerFile` | Max lines per split file (default: 2000) |
|
|
371
|
+
| `data.maxStatementsPerFile` | Max INSERT statements per file (default: 20) |
|
|
372
|
+
| `data.maxRowsPerInsert` | Max rows per INSERT statement (default: 200) |
|
|
373
|
+
| `data.tableRules` | Per-table overrides (see below) |
|
|
311
374
|
| `data.keepFiles` | Files in the split dir to preserve across re-splits |
|
|
312
375
|
| `data.ignoreInReconstruct` | Files to skip during reconstruction |
|
|
313
376
|
| `init.seedSqlPaths` | Paths written to `supabase/config.toml` `[db.seed].sql_paths` |
|
|
314
377
|
| `postSeedCutoff` | Fallback cutoff timestamp used by `db reset`/`start` when linked lookup is unavailable (for example in CI) |
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
"
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
378
|
+
| `postSeedCutoffByEnv` | Optional per-environment fallback cutoff map (for example `staging`, `production`) |
|
|
379
|
+
| `dataMigrationMarker` | Optional override marker for data migrations (default: `supabee:data-migration`) |
|
|
380
|
+
| `schemaMigrationMarker` | Optional override marker for schema migrations (default: `supabee:schema-migration`) |
|
|
381
|
+
|
|
382
|
+
### Table-specific rules
|
|
383
|
+
|
|
384
|
+
Override limits or skip specific tables:
|
|
385
|
+
|
|
386
|
+
```json
|
|
387
|
+
{
|
|
388
|
+
"data": {
|
|
389
|
+
"tableRules": {
|
|
390
|
+
"public.cities": {
|
|
391
|
+
"maxLinesPerFile": 800,
|
|
392
|
+
"maxStatementsPerFile": 8,
|
|
393
|
+
"maxRowsPerInsert": 80
|
|
394
|
+
},
|
|
395
|
+
"public.audit_logs": {
|
|
396
|
+
"skip": true
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
## Flags
|
|
404
|
+
|
|
339
405
|
`schema`, `data`, `sync schema`, and `sync data` support:
|
|
340
406
|
|
|
341
407
|
- `--input`: source SQL file
|
|
342
408
|
- `--output`: output path (split dir for `split`, reconstructed file for `reconstruct`/`validate`)
|
|
343
409
|
- `--backup`: create backup of dirty split directory before running split
|
|
344
410
|
- `--no-backup`: disable backup of dirty split directory before running split
|
|
411
|
+
- `--force` (sync commands only): skip linked migration alignment preflight
|
|
345
412
|
|
|
346
413
|
For `validate`, you can pass reconstructed path either as `--output <path>` or as the second positional argument.
|
|
347
|
-
|
|
348
|
-
`db reset` supports:
|
|
349
|
-
|
|
414
|
+
|
|
415
|
+
`db reset` supports:
|
|
416
|
+
|
|
350
417
|
- `--psql`: apply deferred migrations via `psql` instead of `supabase migration up`
|
|
351
418
|
- `--migrations-dir <path>`: override migrations directory (default `supabase/migrations`)
|
|
352
419
|
- `--temp-dir <path>`: override temporary defer directory (default `supabase/.tmp-migrations`)
|
|
420
|
+
- `--env <name>`: use `postSeedCutoffByEnv.<name>` as fallback cutoff source
|
|
353
421
|
|
|
354
422
|
`start` supports:
|
|
355
423
|
|
|
356
424
|
- `--psql`: apply deferred migrations via `psql` instead of `supabase migration up`
|
|
357
425
|
- `--migrations-dir <path>`: override migrations directory (default `supabase/migrations`)
|
|
358
426
|
- `--temp-dir <path>`: override temporary defer directory (default `supabase/.tmp-migrations`)
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
427
|
+
- `--env <name>`: use `postSeedCutoffByEnv.<name>` as fallback cutoff source
|
|
428
|
+
|
|
429
|
+
`cutoff detect` supports:
|
|
430
|
+
|
|
431
|
+
- `--env <name>`: include environment fallback lookup
|
|
432
|
+
- `--json`: print machine-readable output
|
|
433
|
+
|
|
434
|
+
## Deep dive: why `supabee db reset` and `supabee start`
|
|
435
|
+
|
|
436
|
+
The short version is in the **Why?** section above. These commands matter most when local replay order diverges from how production data actually evolved:
|
|
437
|
+
|
|
438
|
+
1. Seed files may be shaped for pre-migration schema.
|
|
439
|
+
2. Some migrations intentionally mutate/seed production data for traceability (for example RBAC rows).
|
|
440
|
+
3. Local `migrations -> seed` replay can fail even when production worked on already-populated data.
|
|
441
|
+
|
|
442
|
+
By deferring post-seed migrations and applying them after seed load, `supabee` better matches this production-style path.
|
|
443
|
+
|
|
444
|
+
## Migration + Seed Duplication Caveat
|
|
445
|
+
|
|
446
|
+
If the same logical data mutation exists in both migration SQL and seed files, local replay can become order-dependent and brittle.
|
|
447
|
+
|
|
448
|
+
Typical symptoms:
|
|
449
|
+
- enum/value already exists errors,
|
|
450
|
+
- duplicate key or constraint violations,
|
|
451
|
+
- reset/start-only failures that don’t appear on incremental production deploys.
|
|
452
|
+
|
|
379
453
|
Recommended approach:
|
|
380
454
|
|
|
381
455
|
1. Keep schema structure changes in migrations.
|
|
382
456
|
2. Keep baseline/reference seed rows in seed files.
|
|
383
|
-
3.
|
|
384
|
-
4.
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
supabee
|
|
392
|
-
supabee
|
|
393
|
-
supabee sync
|
|
394
|
-
supabee schema --help
|
|
457
|
+
3. Put data mutations in dedicated migration files; `supabee` auto-detects these by SQL patterns.
|
|
458
|
+
4. Use `supabee migration audit` to review classification and `supabee migration mark` if you want explicit marker comments in files.
|
|
459
|
+
5. Keep data migrations free of schema DDL (`CREATE`/`ALTER`/`DROP ...`); mixed files are blocked and must be split.
|
|
460
|
+
6. Make migration-time data mutations idempotent (`IF NOT EXISTS`, `ON CONFLICT DO NOTHING`, guarded updates).
|
|
461
|
+
|
|
462
|
+
## Help
|
|
463
|
+
|
|
464
|
+
```bash
|
|
465
|
+
supabee --help
|
|
466
|
+
supabee init --help
|
|
467
|
+
supabee sync --help
|
|
468
|
+
supabee sync schema --help
|
|
469
|
+
supabee sync data --help
|
|
470
|
+
supabee schema --help
|
|
395
471
|
supabee data --help
|
|
396
472
|
supabee start --help
|
|
397
473
|
supabee db --help
|
|
398
474
|
supabee db reset --help
|
|
475
|
+
supabee cutoff detect --help
|
|
476
|
+
supabee migration audit --help
|
|
477
|
+
supabee migration mark --help
|
|
478
|
+
supabee migration unmark --help
|
|
399
479
|
```
|
|
400
|
-
|
|
401
|
-
Legacy CLI alias is still available: `supabase-splitter --help`.
|
|
402
|
-
|
|
403
|
-
## Development
|
|
404
|
-
|
|
405
|
-
```bash
|
|
406
|
-
npm install
|
|
407
|
-
npm run typecheck
|
|
408
|
-
npm run build
|
|
409
|
-
npm run test
|
|
410
|
-
npm run pack:check
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
RC gate checklist: `docs/rc-checklist.md`
|
|
480
|
+
|
|
481
|
+
Legacy CLI alias is still available: `supabase-splitter --help`.
|
|
482
|
+
|
|
483
|
+
## Development
|
|
484
|
+
|
|
485
|
+
```bash
|
|
486
|
+
npm install
|
|
487
|
+
npm run typecheck
|
|
488
|
+
npm run build
|
|
489
|
+
npm run test
|
|
490
|
+
npm run pack:check
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
RC gate checklist: `docs/rc-checklist.md`
|