Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Simplify development by fixing dev mode image behavior, fix migrate cli #3310

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion apps/builder/app/routes/cgi.image.$name.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createReadStream } from "node:fs";
import { createReadStream, existsSync } from "node:fs";
import { join } from "node:path";
import { createReadableStreamFromReadable } from "@remix-run/node";
import type { LoaderFunctionArgs } from "@remix-run/server-runtime";
Expand Down Expand Up @@ -52,6 +52,13 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
}
const fileUploadPath = env.FILE_UPLOAD_PATH;
const filePath = join(process.cwd(), fileUploadPath, name);

if (existsSync(filePath) === false) {
throw new Response("Not found", {
status: 404,
});
}

return new Response(
createReadableStreamFromReadable(createReadStream(filePath))
);
Expand Down
19 changes: 13 additions & 6 deletions packages/prisma-client/migrations-cli/prisma-migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,26 +250,31 @@ export const generateMigrationName = (baseName: string) => {
};

export const resetDatabase = async () => {
const { stdout: sqlToDeleteEverything } =
await $`"prisma migrate diff --from-schema-datasource ${schemaFilePath} --to-empty --script`;
const { stdout: sqlToDeleteEverything } = await $({
cwd: prismaDir,
})`"prisma migrate diff --from-schema-datasource ${schemaFilePath} --to-empty --script`;

await $({
input: sqlToDeleteEverything,
cwd: prismaDir,
})`prisma db execute --stdin --schema ${schemaFilePath}`;

await context.prisma.$executeRaw`DROP TABLE IF EXISTS _prisma_migrations`;
};

// https://www.prisma.io/docs/reference/api-reference/command-reference#migrate-diff
export const cliDiff = async () => {
const { stdout } =
await $`prisma migrate diff --from-schema-datasource ${schemaFilePath} --to-schema-datamodel ${schemaFilePath} --script`;
const { stdout } = await $({
cwd: prismaDir,
})`prisma migrate diff --from-schema-datasource ${schemaFilePath} --to-schema-datamodel ${schemaFilePath} --script`;
return stdout;
};

// https://www.prisma.io/docs/reference/api-reference/command-reference#db-execute
export const cliExecute = async (filePath: string) => {
await $`prisma db execute --file ${filePath} --schema ${schemaFilePath}`;
await $({
cwd: prismaDir,
})`prisma db execute --file ${filePath} --schema ${schemaFilePath}`;
};

export const generateMigrationClient = async (migrationName: string) => {
Expand All @@ -293,5 +298,7 @@ export const generateMigrationClient = async (migrationName: string) => {
}

// https://www.prisma.io/docs/reference/api-reference/command-reference#generate
await $`prisma generate --schema ${schemaPath}`;
await $({
cwd: prismaDir,
})`prisma generate --schema ${schemaPath}`;
};
Loading