@@ -2,9 +2,12 @@ import { expect } from "@playwright/test";
|
|||||||
import { test } from "./helpers/test_helper";
|
import { test } from "./helpers/test_helper";
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { execSync } from "child_process";
|
||||||
|
|
||||||
test("supabase migrations", async ({ po }) => {
|
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");
|
await po.sendPrompt("tc=add-supabase");
|
||||||
|
|
||||||
// Connect to Supabase
|
// Connect to Supabase
|
||||||
@@ -43,6 +46,12 @@ test("supabase migrations", async ({ po }) => {
|
|||||||
expect(await fs.readFile(path.join(migrationsDir, files[0]), "utf8")).toEqual(
|
expect(await fs.readFile(path.join(migrationsDir, files[0]), "utf8")).toEqual(
|
||||||
"CREATE TABLE users (id serial primary key);",
|
"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
|
// Send a prompt that triggers a migration
|
||||||
await po.sendPrompt("tc=execute-sql-no-description");
|
await po.sendPrompt("tc=execute-sql-no-description");
|
||||||
|
|||||||
@@ -92,7 +92,6 @@ export async function processFullResponseActions(
|
|||||||
const dyadExecuteSqlQueries = chatWithApp.app.supabaseProjectId
|
const dyadExecuteSqlQueries = chatWithApp.app.supabaseProjectId
|
||||||
? getDyadExecuteSqlTags(fullResponse)
|
? getDyadExecuteSqlTags(fullResponse)
|
||||||
: [];
|
: [];
|
||||||
let writtenSqlMigrationFiles = 0;
|
|
||||||
|
|
||||||
const message = await db.query.messages.findFirst({
|
const message = await db.query.messages.findFirst({
|
||||||
where: and(
|
where: and(
|
||||||
@@ -119,12 +118,12 @@ export async function processFullResponseActions(
|
|||||||
// Only write migration file if SQL execution succeeded
|
// Only write migration file if SQL execution succeeded
|
||||||
if (settings.enableSupabaseWriteSqlMigration) {
|
if (settings.enableSupabaseWriteSqlMigration) {
|
||||||
try {
|
try {
|
||||||
await writeMigrationFile(
|
const migrationFilePath = await writeMigrationFile(
|
||||||
appPath,
|
appPath,
|
||||||
query.content,
|
query.content,
|
||||||
query.description,
|
query.description,
|
||||||
);
|
);
|
||||||
writtenSqlMigrationFiles++;
|
writtenFiles.push(migrationFilePath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errors.push({
|
errors.push({
|
||||||
message: `Failed to write SQL migration file for: ${query.description}`,
|
message: `Failed to write SQL migration file for: ${query.description}`,
|
||||||
@@ -322,8 +321,7 @@ export async function processFullResponseActions(
|
|||||||
writtenFiles.length > 0 ||
|
writtenFiles.length > 0 ||
|
||||||
renamedFiles.length > 0 ||
|
renamedFiles.length > 0 ||
|
||||||
deletedFiles.length > 0 ||
|
deletedFiles.length > 0 ||
|
||||||
dyadAddDependencyPackages.length > 0 ||
|
dyadAddDependencyPackages.length > 0;
|
||||||
writtenSqlMigrationFiles > 0;
|
|
||||||
|
|
||||||
let uncommittedFiles: string[] = [];
|
let uncommittedFiles: string[] = [];
|
||||||
let extraFilesError: string | undefined;
|
let extraFilesError: string | undefined;
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export async function writeMigrationFile(
|
|||||||
appPath: string,
|
appPath: string,
|
||||||
queryContent: string,
|
queryContent: string,
|
||||||
queryDescription?: string,
|
queryDescription?: string,
|
||||||
) {
|
): Promise<string> {
|
||||||
const migrationsDir = path.join(appPath, "supabase", "migrations");
|
const migrationsDir = path.join(appPath, "supabase", "migrations");
|
||||||
await fsExtra.ensureDir(migrationsDir);
|
await fsExtra.ensureDir(migrationsDir);
|
||||||
|
|
||||||
@@ -94,6 +94,7 @@ export async function writeMigrationFile(
|
|||||||
const migrationFilePath = path.join(migrationsDir, migrationFileName);
|
const migrationFilePath = path.join(migrationsDir, migrationFileName);
|
||||||
|
|
||||||
await fsExtra.writeFile(migrationFilePath, queryContent);
|
await fsExtra.writeFile(migrationFilePath, queryContent);
|
||||||
|
return path.relative(appPath, migrationFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fileExists(filePath: string) {
|
export async function fileExists(filePath: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user