mirror of
https://github.com/stack-auth/stack.git
synced 2026-07-20 21:29:36 +08:00
Keep local emulator removal in a new migration, not edits to applied ones (#1694)
This commit is contained in:
parent
09bb1a8974
commit
09c8ef1946
@ -0,0 +1,30 @@
|
||||
import { randomUUID } from "crypto";
|
||||
import type { Sql } from "postgres";
|
||||
import { expect } from "vitest";
|
||||
|
||||
export const preMigration = async (sql: Sql) => {
|
||||
const projectId = `test-${randomUUID()}`;
|
||||
await sql`
|
||||
INSERT INTO "Project" ("id", "createdAt", "updatedAt", "displayName", "description", "isProductionMode")
|
||||
VALUES (${projectId}, NOW(), NOW(), 'Cascade Test Project', '', false)
|
||||
`;
|
||||
return { projectId };
|
||||
};
|
||||
|
||||
export const postMigration = async (sql: Sql, ctx: Awaited<ReturnType<typeof preMigration>>) => {
|
||||
const absoluteFilePath = `/tmp/${randomUUID()}/stack.config.ts`;
|
||||
|
||||
await sql`
|
||||
INSERT INTO "LocalEmulatorProject" ("absoluteFilePath", "projectId", "createdAt", "updatedAt")
|
||||
VALUES (${absoluteFilePath}, ${ctx.projectId}, NOW(), NOW())
|
||||
`;
|
||||
|
||||
await sql`DELETE FROM "Project" WHERE "id" = ${ctx.projectId}`;
|
||||
|
||||
const rows = await sql`
|
||||
SELECT "absoluteFilePath"
|
||||
FROM "LocalEmulatorProject"
|
||||
WHERE "absoluteFilePath" = ${absoluteFilePath}
|
||||
`;
|
||||
expect(rows).toHaveLength(0);
|
||||
};
|
||||
@ -0,0 +1,44 @@
|
||||
import { randomUUID } from "crypto";
|
||||
import type { Sql } from "postgres";
|
||||
import { expect } from "vitest";
|
||||
|
||||
export const preMigration = async (sql: Sql) => {
|
||||
const projectId1 = `test-${randomUUID()}`;
|
||||
const projectId2 = `test-${randomUUID()}`;
|
||||
|
||||
await sql`
|
||||
INSERT INTO "Project" ("id", "createdAt", "updatedAt", "displayName", "description", "isProductionMode")
|
||||
VALUES (${projectId1}, NOW(), NOW(), 'Local Emulator Project 1', '', false)
|
||||
`;
|
||||
await sql`
|
||||
INSERT INTO "Project" ("id", "createdAt", "updatedAt", "displayName", "description", "isProductionMode")
|
||||
VALUES (${projectId2}, NOW(), NOW(), 'Local Emulator Project 2', '', false)
|
||||
`;
|
||||
|
||||
return { projectId1, projectId2 };
|
||||
};
|
||||
|
||||
export const postMigration = async (sql: Sql, ctx: Awaited<ReturnType<typeof preMigration>>) => {
|
||||
const path1 = `/tmp/${randomUUID()}/stack.config.ts`;
|
||||
const path2 = `/tmp/${randomUUID()}/stack.config.ts`;
|
||||
|
||||
await sql`
|
||||
INSERT INTO "LocalEmulatorProject" ("absoluteFilePath", "projectId", "createdAt", "updatedAt")
|
||||
VALUES (${path1}, ${ctx.projectId1}, NOW(), NOW())
|
||||
`;
|
||||
|
||||
await expect(sql`
|
||||
INSERT INTO "LocalEmulatorProject" ("absoluteFilePath", "projectId", "createdAt", "updatedAt")
|
||||
VALUES (${path1}, ${ctx.projectId2}, NOW(), NOW())
|
||||
`).rejects.toThrow(/LocalEmulatorProject_pkey/);
|
||||
|
||||
await expect(sql`
|
||||
INSERT INTO "LocalEmulatorProject" ("absoluteFilePath", "projectId", "createdAt", "updatedAt")
|
||||
VALUES (${path2}, ${ctx.projectId1}, NOW(), NOW())
|
||||
`).rejects.toThrow(/LocalEmulatorProject_projectId_key/);
|
||||
|
||||
await sql`
|
||||
INSERT INTO "LocalEmulatorProject" ("absoluteFilePath", "projectId", "createdAt", "updatedAt")
|
||||
VALUES (${path2}, ${ctx.projectId2}, NOW(), NOW())
|
||||
`;
|
||||
};
|
||||
@ -1,2 +1,9 @@
|
||||
ALTER TABLE "Project"
|
||||
ADD COLUMN "isDevelopmentEnvironment" BOOLEAN NOT NULL DEFAULT false;
|
||||
|
||||
UPDATE "Project"
|
||||
SET "isDevelopmentEnvironment" = true
|
||||
WHERE "id" IN (
|
||||
SELECT "projectId"
|
||||
FROM "LocalEmulatorProject"
|
||||
);
|
||||
|
||||
@ -4,11 +4,20 @@ import { expect } from "vitest";
|
||||
|
||||
export const preMigration = async (sql: Sql) => {
|
||||
const projectId = `test-${randomUUID()}`;
|
||||
const localEmulatorProjectId = `test-${randomUUID()}`;
|
||||
await sql`
|
||||
INSERT INTO "Project" ("id", "createdAt", "updatedAt", "displayName", "description", "isProductionMode")
|
||||
VALUES (${projectId}, NOW(), NOW(), 'Development Environment Flag Project', '', false)
|
||||
`;
|
||||
return { projectId };
|
||||
await sql`
|
||||
INSERT INTO "Project" ("id", "createdAt", "updatedAt", "displayName", "description", "isProductionMode")
|
||||
VALUES (${localEmulatorProjectId}, NOW(), NOW(), 'Existing Local Emulator Project', '', false)
|
||||
`;
|
||||
await sql`
|
||||
INSERT INTO "LocalEmulatorProject" ("absoluteFilePath", "projectId", "createdAt", "updatedAt")
|
||||
VALUES (${`/tmp/${randomUUID()}/stack.config.ts`}, ${localEmulatorProjectId}, NOW(), NOW())
|
||||
`;
|
||||
return { projectId, localEmulatorProjectId };
|
||||
};
|
||||
|
||||
export const postMigration = async (sql: Sql, ctx: Awaited<ReturnType<typeof preMigration>>) => {
|
||||
@ -20,4 +29,11 @@ export const postMigration = async (sql: Sql, ctx: Awaited<ReturnType<typeof pre
|
||||
expect(rows).toHaveLength(1);
|
||||
expect(rows[0].isDevelopmentEnvironment).toBe(false);
|
||||
|
||||
const localEmulatorRows = await sql`
|
||||
SELECT "isDevelopmentEnvironment"
|
||||
FROM "Project"
|
||||
WHERE "id" = ${ctx.localEmulatorProjectId}
|
||||
`;
|
||||
expect(localEmulatorRows).toHaveLength(1);
|
||||
expect(localEmulatorRows[0].isDevelopmentEnvironment).toBe(true);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user