feat: 🎸 empty drizzle for dw

This commit is contained in:
amianthus
2026-05-17 15:49:55 +01:00
parent fc311682f6
commit 579d7b3132
4 changed files with 8 additions and 29 deletions

View File

@@ -6,9 +6,6 @@ import { tmuxSessionName, killTmuxSession } from "../helpers/tmux.ts";
import { removeComposeStack } from "../helpers/compose.ts"; import { removeComposeStack } from "../helpers/compose.ts";
import { removeEnvLocalFiles, writeEnvLocalFiles } from "../helpers/env-files.ts"; import { removeEnvLocalFiles, writeEnvLocalFiles } from "../helpers/env-files.ts";
import { setupAgentWorktree } from "../helpers/setup.ts"; import { setupAgentWorktree } from "../helpers/setup.ts";
import { SHARED_DIR, BRANCH_NAME_RE } from "../constants.ts";
import { existsSync, rmSync } from "node:fs";
import { join } from "node:path";
import type { RegistryEntry } from "../types.ts"; import type { RegistryEntry } from "../types.ts";
export async function cmdReset(): Promise<void> { export async function cmdReset(): Promise<void> {
@@ -20,10 +17,7 @@ export async function cmdReset(): Promise<void> {
} }
killTmuxSession(tmuxSessionName(entry.worktreeNum)); killTmuxSession(tmuxSessionName(entry.worktreeNum));
if (entry.branchName) deleteBranch(entry.branchName); if (entry.branchName) deleteBranch(entry.branchName);
if (entry.branchName && BRANCH_NAME_RE.test(entry.branchName)) { // shared/drizzle/ is rewritten on next setupAgentWorktree; no need to clear here.
const localDir = join(SHARED_DIR, "drizzle-local", entry.branchName);
if (existsSync(localDir)) rmSync(localDir, { recursive: true, force: true });
}
removeComposeStack(entry.worktreeNum); removeComposeStack(entry.worktreeNum);
removeEnvLocalFiles(); removeEnvLocalFiles();
const cleared: RegistryEntry = { const cleared: RegistryEntry = {

View File

@@ -11,9 +11,6 @@ import { tmuxSessionName, killTmuxSession } from "../helpers/tmux.ts";
import { removeComposeStack, removeAllAutumnComposeStacks } from "../helpers/compose.ts"; import { removeComposeStack, removeAllAutumnComposeStacks } from "../helpers/compose.ts";
import { removeEnvLocalFiles } from "../helpers/env-files.ts"; import { removeEnvLocalFiles } from "../helpers/env-files.ts";
import { stopEmulateAndPortless } from "../helpers/emulate.ts"; import { stopEmulateAndPortless } from "../helpers/emulate.ts";
import { SHARED_DIR } from "../constants.ts";
import { existsSync, rmSync } from "node:fs";
import { join } from "node:path";
import type { Registry } from "../types.ts"; import type { Registry } from "../types.ts";
export async function cmdTeardown(opts: { all?: boolean }): Promise<void> { export async function cmdTeardown(opts: { all?: boolean }): Promise<void> {
@@ -25,15 +22,6 @@ export async function cmdTeardown(opts: { all?: boolean }): Promise<void> {
if (entry.branchName) deleteBranch(entry.branchName); if (entry.branchName) deleteBranch(entry.branchName);
unregisterPortlessAliases(entry.worktreeNum); unregisterPortlessAliases(entry.worktreeNum);
killTmuxSession(tmuxSessionName(entry.worktreeNum)); killTmuxSession(tmuxSessionName(entry.worktreeNum));
if (entry.branchName) {
const localDir = join(
SHARED_DIR,
"drizzle-local",
entry.branchName,
);
if (existsSync(localDir))
rmSync(localDir, { recursive: true, force: true });
}
} }
removeAllAutumnComposeStacks(); removeAllAutumnComposeStacks();
const next: Registry = {}; const next: Registry = {};
@@ -62,10 +50,6 @@ export async function cmdTeardown(opts: { all?: boolean }): Promise<void> {
unregisterPortlessAliases(entry.worktreeNum); unregisterPortlessAliases(entry.worktreeNum);
killTmuxSession(tmuxSessionName(entry.worktreeNum)); killTmuxSession(tmuxSessionName(entry.worktreeNum));
removeComposeStack(entry.worktreeNum); removeComposeStack(entry.worktreeNum);
if (entry.branchName) {
const localDir = join(SHARED_DIR, "drizzle-local", entry.branchName);
if (existsSync(localDir)) rmSync(localDir, { recursive: true, force: true });
}
delete registry[cwd]; delete registry[cwd];
saveRegistry(registry); saveRegistry(registry);
removeEnvLocalFiles(); removeEnvLocalFiles();

View File

@@ -19,7 +19,12 @@ export function generateAndApplyMigration(
branchName: string, branchName: string,
databaseUrl: string, databaseUrl: string,
): void { ): void {
const outDir = join(SHARED_DIR, "drizzle-local", branchName); // Use the worktree's own shared/drizzle/ as the migration dir (matches
// drizzle.config.ts out: "./drizzle"). Empty it first so the baseline
// generated for this fresh Neon branch isn't a diff against the canonical
// repo's migration history — subsequent `bun db:generate` runs then emit
// clean incrementals against this worktree's actual DB state.
const outDir = join(SHARED_DIR, "drizzle");
if (existsSync(outDir)) rmSync(outDir, { recursive: true, force: true }); if (existsSync(outDir)) rmSync(outDir, { recursive: true, force: true });
mkdirSync(outDir, { recursive: true }); mkdirSync(outDir, { recursive: true });

View File

@@ -1,6 +1,5 @@
import { createHash } from "node:crypto"; import { createHash } from "node:crypto";
import { existsSync, readFileSync, writeFileSync, rmSync } from "node:fs"; import { existsSync, readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { log, fatal } from "./shell.ts"; import { log, fatal } from "./shell.ts";
import { getWorktreeList, getCurrentWorktree } from "./git.ts"; import { getWorktreeList, getCurrentWorktree } from "./git.ts";
import { deleteBranch } from "./neon.ts"; import { deleteBranch } from "./neon.ts";
@@ -9,7 +8,6 @@ import {
MAX_WORKTREE, MAX_WORKTREE,
BRANCH_NAME_RE, BRANCH_NAME_RE,
INACTIVITY_MS, INACTIVITY_MS,
SHARED_DIR,
} from "../constants.ts"; } from "../constants.ts";
import type { Registry, RegistryEntry } from "../types.ts"; import type { Registry, RegistryEntry } from "../types.ts";
@@ -83,8 +81,6 @@ export function reconcile(registry: Registry): Registry {
for (const o of orphaned) { for (const o of orphaned) {
if (!o.branchName || !BRANCH_NAME_RE.test(o.branchName)) continue; if (!o.branchName || !BRANCH_NAME_RE.test(o.branchName)) continue;
deleteBranch(o.branchName); deleteBranch(o.branchName);
const localDir = join(SHARED_DIR, "drizzle-local", o.branchName);
if (existsSync(localDir)) rmSync(localDir, { recursive: true, force: true });
} }
return next; return next;
} }