Unverified 提交 65b3d9cb authored 作者: Will Chen's avatar Will Chen 提交者: GitHub

Fix git migration edge case (#612)

Fixes #608
上级 94281146
......@@ -2,9 +2,12 @@ import { expect } from "@playwright/test";
import { test } from "./helpers/test_helper";
import fs from "fs-extra";
import path from "path";
import { execSync } from "child_process";
test("supabase migrations", async ({ po }) => {
await po.setUp({ autoApprove: true });
// Turning on native Git to catch this edge case:
// https://github.com/dyad-sh/dyad/issues/608
await po.setUp({ autoApprove: true, nativeGit: true });
await po.sendPrompt("tc=add-supabase");
// Connect to Supabase
......@@ -43,6 +46,12 @@ test("supabase migrations", async ({ po }) => {
expect(await fs.readFile(path.join(migrationsDir, files[0]), "utf8")).toEqual(
"CREATE TABLE users (id serial primary key);",
);
// Make sure git is clean.
const gitStatus = execSync("git status --porcelain", {
cwd: appPath,
encoding: "utf8",
}).trim();
expect(gitStatus).toBe("");
// Send a prompt that triggers a migration
await po.sendPrompt("tc=execute-sql-no-description");
......
......@@ -92,7 +92,6 @@ export async function processFullResponseActions(
const dyadExecuteSqlQueries = chatWithApp.app.supabaseProjectId
? getDyadExecuteSqlTags(fullResponse)
: [];
let writtenSqlMigrationFiles = 0;
const message = await db.query.messages.findFirst({
where: and(
......@@ -119,12 +118,12 @@ export async function processFullResponseActions(
// Only write migration file if SQL execution succeeded
if (settings.enableSupabaseWriteSqlMigration) {
try {
await writeMigrationFile(
const migrationFilePath = await writeMigrationFile(
appPath,
query.content,
query.description,
);
writtenSqlMigrationFiles++;
writtenFiles.push(migrationFilePath);
} catch (error) {
errors.push({
message: `Failed to write SQL migration file for: ${query.description}`,
......@@ -322,8 +321,7 @@ export async function processFullResponseActions(
writtenFiles.length > 0 ||
renamedFiles.length > 0 ||
deletedFiles.length > 0 ||
dyadAddDependencyPackages.length > 0 ||
writtenSqlMigrationFiles > 0;
dyadAddDependencyPackages.length > 0;
let uncommittedFiles: string[] = [];
let extraFilesError: string | undefined;
......
......@@ -67,7 +67,7 @@ export async function writeMigrationFile(
appPath: string,
queryContent: string,
queryDescription?: string,
) {
): Promise<string> {
const migrationsDir = path.join(appPath, "supabase", "migrations");
await fsExtra.ensureDir(migrationsDir);
......@@ -94,6 +94,7 @@ export async function writeMigrationFile(
const migrationFilePath = path.join(migrationsDir, migrationFileName);
await fsExtra.writeFile(migrationFilePath, queryContent);
return path.relative(appPath, migrationFilePath);
}
export async function fileExists(filePath: string) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论