@wwchen/stack 0.8.0 → 0.9.0
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/blocks/AGENTS.md +1 -1
- package/blocks/CLAUDE.md +2 -2
- package/dist/cli/db.d.ts +1 -0
- package/dist/cli/db.js +18 -1
- package/dist/cli/index.js +4 -1
- package/dist/db/schema-changes.js +1 -1
- package/package.json +6 -3
package/blocks/AGENTS.md
CHANGED
|
@@ -55,7 +55,7 @@ The design system is LDS (Lew Design System), product theme: `@lew-ds/lds`, `@le
|
|
|
55
55
|
- Local tooling refuses the production database unless you opt in deliberately.
|
|
56
56
|
- Tests run on PGlite (one connection only) and, in CI, a real Postgres.
|
|
57
57
|
- Every user has an email: required, unique, lower-cased and trimmed.
|
|
58
|
-
- Schema changes go through `pnpm db:generate
|
|
58
|
+
- Schema changes go through `pnpm db:generate <name>` and a reviewed migration, never through the Neon console or a database MCP server.
|
|
59
59
|
|
|
60
60
|
## Security
|
|
61
61
|
|
package/blocks/CLAUDE.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
| Lint / format | `pnpm lint` · `pnpm lint:fix` |
|
|
15
15
|
| Tests | `pnpm test` · one file: `pnpm test tests/unit/<name>.test.ts` |
|
|
16
16
|
| Storybook | `pnpm storybook` (http://localhost:6006) · every story built, as CI does: `pnpm storybook:build` |
|
|
17
|
-
| DB generate / apply migration | `pnpm db:generate` · `pnpm db:migrate` |
|
|
17
|
+
| DB generate / apply migration | `pnpm db:generate <name>` (snake_case, what it does: `add_widgets`) · `pnpm db:migrate` |
|
|
18
18
|
| Seed the shared `seed` branch | `stack neon seed` (runs the app's `db/seed.ts`) |
|
|
19
19
|
| Reset the shared preview branch | `stack neon reset-preview` (`--set-vercel` also writes its URLs into Vercel's Preview variables) |
|
|
20
20
|
| Check the Vercel project's setup | `stack doctor` (read-only; exits 1 on an error) |
|
|
@@ -60,7 +60,7 @@ The design system is LDS (Lew Design System), product theme: `@lew-ds/lds`, `@le
|
|
|
60
60
|
|
|
61
61
|
## Database rules
|
|
62
62
|
|
|
63
|
-
- Drizzle schema and migrations: generate with `pnpm db:generate
|
|
63
|
+
- Drizzle schema and migrations: generate with `pnpm db:generate <name>`, review the SQL, never edit a generated migration by hand. Every migration is expand-then-contract, because the old deployment serves while the build migrates.
|
|
64
64
|
- Migrations run in the Vercel build (`stack vercel-build`) or as an explicit command, never on app boot. A preview build migrates its own Neon branch and refuses production's endpoint; a production build migrates production's database before building.
|
|
65
65
|
- The app uses `pg` on the pooled `DATABASE_URL`; migrations use `DATABASE_URL_UNPOOLED` when set.
|
|
66
66
|
- Dev and preview branches come from `seed`, never from production, so other people's data stays out of dev and previews. Previews get their own secrets and no production third-party keys.
|
package/dist/cli/db.d.ts
CHANGED
package/dist/cli/db.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// `stack db:check` — fails when the app's `src/db/schema.ts` has changes `drizzle/` has no migration for: a package table that changed in an upgrade, or the app's own, never generated. App CI runs it.
|
|
2
2
|
//
|
|
3
|
+
// `stack db:generate <name> [drizzle-kit flags]` — the app's `pnpm db:generate`: drizzle-kit generate with a name the person chose, so `drizzle/` says what each migration does instead of drizzle-kit's random words. Flags after the name pass through (`--custom` for an empty migration to write by hand).
|
|
4
|
+
//
|
|
3
5
|
// `stack db:upgrade` — after the stack is upgraded, generates the migration for its tables' changes (`stack_<version>`), so the app's one history carries them. Copier runs it after `pnpm install`.
|
|
4
6
|
//
|
|
5
7
|
// Both run in the app's root and import its schema with Node's type stripping, so it must use relative `.ts` imports.
|
|
@@ -14,9 +16,24 @@ export async function dbCheck(cli) {
|
|
|
14
16
|
const statements = await pending(cli);
|
|
15
17
|
if (statements.length === 0)
|
|
16
18
|
return 0;
|
|
17
|
-
cli.error(`src/db/schema.ts has changes drizzle/ has no migration for:\n\n${statements.join("\n")}\n\nRun \`pnpm
|
|
19
|
+
cli.error(`src/db/schema.ts has changes drizzle/ has no migration for:\n\n${statements.join("\n")}\n\nRun \`pnpm db:generate <name>\`, review the SQL and commit it.`);
|
|
18
20
|
return 1;
|
|
19
21
|
}
|
|
22
|
+
/** A name says what the migration does, in snake_case. `stack_` is the upgrade's, so an app's own migration never reads as the stack's. */
|
|
23
|
+
const MIGRATION_NAME = /^[a-z][a-z0-9_]*$/;
|
|
24
|
+
export async function dbGenerate(cli, [name, ...flags]) {
|
|
25
|
+
if (!name || !MIGRATION_NAME.test(name)) {
|
|
26
|
+
cli.error("usage: stack db:generate <name> [drizzle-kit flags]\nName the migration for what it does, in snake_case: add_widgets, drop_legacy_tokens.");
|
|
27
|
+
return 2;
|
|
28
|
+
}
|
|
29
|
+
if (name.startsWith("stack_")) {
|
|
30
|
+
cli.error(`${name}: names starting stack_ are the stack upgrade's own; name the change itself.`);
|
|
31
|
+
return 2;
|
|
32
|
+
}
|
|
33
|
+
return (await cli.exec("pnpm", ["exec", "drizzle-kit", "generate", "--name", name, ...flags], {
|
|
34
|
+
inherit: true,
|
|
35
|
+
})).code;
|
|
36
|
+
}
|
|
20
37
|
export async function dbUpgrade(cli) {
|
|
21
38
|
if ((await pending(cli)).length === 0)
|
|
22
39
|
return 0;
|
package/dist/cli/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { spawn } from "node:child_process";
|
|
|
3
3
|
import { realpathSync } from "node:fs";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { CliError, resolveDeps } from "./context.js";
|
|
6
|
-
import { dbCheck, dbUpgrade } from "./db.js";
|
|
6
|
+
import { dbCheck, dbGenerate, dbUpgrade } from "./db.js";
|
|
7
7
|
import { dev } from "./dev.js";
|
|
8
8
|
import { doctor } from "./doctor.js";
|
|
9
9
|
import { migrateSuite } from "./migrate-suite.js";
|
|
@@ -27,6 +27,7 @@ const USAGE = `usage: stack <command>
|
|
|
27
27
|
user:role <email> <admin|user> change a user's role through the app's auth; --preview as above
|
|
28
28
|
sync-blocks [--check] refresh the stack-owned blocks in AGENTS.md, CLAUDE.md, .gitignore, .env.example
|
|
29
29
|
db:check fail when src/db/schema.ts has changes drizzle/ has no migration for
|
|
30
|
+
db:generate <name> [flags] drizzle-kit generate, named for what the migration does (snake_case)
|
|
30
31
|
db:upgrade generate drizzle/'s migration for the schema's changes, named stack_<version>
|
|
31
32
|
migrate-suite [--expect <version>] move the app onto the suite's packages (@wwchen/stack-auth, -notify);
|
|
32
33
|
--expect: refuse unless the installed stack is that version`;
|
|
@@ -62,6 +63,8 @@ export async function runCli(argv, deps) {
|
|
|
62
63
|
return await syncBlocksCommand(cli, args);
|
|
63
64
|
case "db:check":
|
|
64
65
|
return await dbCheck(cli);
|
|
66
|
+
case "db:generate":
|
|
67
|
+
return await dbGenerate(cli, args);
|
|
65
68
|
case "db:upgrade":
|
|
66
69
|
return await dbUpgrade(cli);
|
|
67
70
|
case "migrate-suite":
|
|
@@ -42,7 +42,7 @@ export async function pendingStatements(schema, migrationsFolder) {
|
|
|
42
42
|
catch (error) {
|
|
43
43
|
// drizzle-kit asks whether a dropped and an added table or column are a rename, and cannot ask without a terminal.
|
|
44
44
|
if (error instanceof Error && /Interactive prompts require a TTY/.test(error.message)) {
|
|
45
|
-
throw new Error("the schema both drops and adds a table or column, and only a person can say whether it is a rename: run `
|
|
45
|
+
throw new Error("the schema both drops and adds a table or column, and only a person can say whether it is a rename: run `pnpm db:generate <name>` in a terminal.", { cause: error });
|
|
46
46
|
}
|
|
47
47
|
throw error;
|
|
48
48
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wwchen/stack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Shared Next.js, Neon, Better Auth, Resend and lew-ds building blocks.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
"bin": {
|
|
21
21
|
"stack": "dist/cli/index.js"
|
|
22
22
|
},
|
|
23
|
+
"stack": {
|
|
24
|
+
"requiresDeployed": "0.8.0"
|
|
25
|
+
},
|
|
23
26
|
"exports": {
|
|
24
27
|
".": {
|
|
25
28
|
"types": "./dist/index.d.ts",
|
|
@@ -81,8 +84,8 @@
|
|
|
81
84
|
},
|
|
82
85
|
"dependencies": {
|
|
83
86
|
"@vercel/functions": "3.12.0",
|
|
84
|
-
"@wwchen/stack-auth": "0.
|
|
85
|
-
"@wwchen/stack-notify": "0.
|
|
87
|
+
"@wwchen/stack-auth": "0.9.0",
|
|
88
|
+
"@wwchen/stack-notify": "0.9.0",
|
|
86
89
|
"pg": "8.23.1",
|
|
87
90
|
"zod": "4.6.7"
|
|
88
91
|
},
|