diff --git a/packages/admin/src/client/views/Migrations.tsx b/packages/admin/src/client/views/Migrations.tsx index 1f3bf7aa..a84dea52 100644 --- a/packages/admin/src/client/views/Migrations.tsx +++ b/packages/admin/src/client/views/Migrations.tsx @@ -55,6 +55,8 @@ const workingFSContext = createCascadingState({} as Record, v => export const Migrations = file.wrap(workingFSContext.wrap(_Migrations)) const useMigrations = () => { + const [_, setFileState] = file.useState() + const util = trpc.useUtils() const mutationConfig = { onSuccess: () => util.migrations.invalidate(), @@ -71,7 +73,12 @@ const useMigrations = () => { description: `This may delete data, which will not be restored even if you reapply the migration.`, }) const update = trpc.migrations.update.useMutation(mutationConfig) - const downify = trpc.migrations.downify.useMutation(mutationConfig) + const downify = trpc.migrations.downify.useMutation({ + onSuccess: data => { + setFileState(data.downPath) + return util.migrations.invalidate() + }, + }) const definitions = trpc.migrations.definitions.useMutation(mutationConfig) return {list, create, up, down, update, downify, definitions} @@ -134,7 +141,7 @@ function _Migrations() { - {!numExecuted && No executed migrations!} + {!numExecuted && No migrations to revert} {Boolean(numExecuted) && ( down.mutate({to: 0})}> @@ -151,7 +158,7 @@ function _Migrations() { - {!numPending && No pending migrations!} + {!numPending && No migrations to apply} {Array.from({length: numPending || 0}).map((_, i) => { const step = i + 1 @@ -282,7 +289,7 @@ const _sampleFilesJson: Record = { } export const FileTree = (tree: File | Folder) => { - const [_, setFileState] = file.useState() + const [fileState, setFileState] = file.useState() const {up, down, list} = useMigrations() @@ -297,7 +304,7 @@ export const FileTree = (tree: File | Folder) => { title={tree.path} onClick={() => setFileState(tree.path)} > - + {basename(tree.path)} @@ -343,7 +350,7 @@ export const FileTree = (tree: File | Folder) => { return ( <> - +
{ const {content, info} = await ctx.migrator.generateDownMigration({name: input.name}) - await fs.promises.writeFile(ctx.migrator.downPath(info.migration.path as string), content) + const downPath = ctx.migrator.downPath(info.migration.path as string) + await fs.promises.writeFile(downPath, content) + return {downPath, content, info} }), update: migrationsProcedure .input(