support setting for writing supabase migration files (#427)

This commit is contained in:
Will Chen
2025-06-17 15:14:02 -07:00
committed by GitHub
parent ff4e93d747
commit 382fe9bab5
10 changed files with 206 additions and 20 deletions

View File

@@ -0,0 +1,7 @@
Example SQL
<dyad-execute-sql description="create_users_table">
CREATE TABLE users (id serial primary key);
</dyad-execute-sql>
Done.

View File

@@ -0,0 +1,7 @@
No description!
<dyad-execute-sql>
DROP TABLE users;
</dyad-execute-sql>
Done.

View File

@@ -579,6 +579,10 @@ export class PageObject {
await this.page.getByRole("link", { name: "Apps" }).click();
}
async goToChatTab() {
await this.page.getByRole("link", { name: "Chat" }).click();
}
async goToHubTab() {
await this.page.getByRole("link", { name: "Hub" }).click();
}

View File

@@ -0,0 +1,61 @@
import { expect } from "@playwright/test";
import { test } from "./helpers/test_helper";
import fs from "fs-extra";
import path from "path";
test("supabase migrations", async ({ po }) => {
await po.setUp({ autoApprove: true });
await po.sendPrompt("tc=add-supabase");
// Connect to Supabase
await po.page.getByText("Set up supabase").click();
await po.clickConnectSupabaseButton();
await po.clickBackButton();
const appPath = await po.getCurrentAppPath();
const migrationsDir = path.join(appPath, "supabase", "migrations");
// --- SCENARIO 1: OFF BY DEFAULT ---
await po.sendPrompt("tc=execute-sql-1");
await po.waitForChatCompletion();
expect(fs.existsSync(migrationsDir)).toBe(false);
// --- SCENARIO 2: TOGGLE ON ---
// Go to settings to find the Supabase integration
await po.goToSettingsTab();
const migrationsSwitch = po.page.locator("#supabase-migrations");
await migrationsSwitch.click();
await po.goToChatTab();
// Send a prompt that triggers a migration
await po.sendPrompt("tc=execute-sql-1");
await po.waitForChatCompletion();
let files: string[] = [];
await expect(async () => {
// Check that one migration file was created
files = await fs.readdir(migrationsDir);
expect(files).toHaveLength(1);
}).toPass();
expect(files[0]).toMatch(/0000_create_users_table\.sql/);
expect(await fs.readFile(path.join(migrationsDir, files[0]), "utf8")).toEqual(
"CREATE TABLE users (id serial primary key);",
);
// Send a prompt that triggers a migration
await po.sendPrompt("tc=execute-sql-no-description");
await po.waitForChatCompletion();
await expect(async () => {
// Check that one migration file was created
files = await fs.readdir(migrationsDir);
expect(files).toHaveLength(2);
}).toPass();
expect(files[1]).toMatch(/0001_\w+_\w+_\w+\.sql/);
expect(await fs.readFile(path.join(migrationsDir, files[1]), "utf8")).toEqual(
"DROP TABLE users;",
);
});