Skip to content

Commit

Permalink
more destructive
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed May 21, 2024
1 parent 99f6709 commit dd2f8bc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
1 change: 1 addition & 0 deletions packages/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"express": "^4.18.2",
"fetchomatic": "^0.0.2",
"lucide-react": "^0.373.0",
"markdown-to-jsx": "^7.4.7",
"next-themes": "^0.3.0",
"p-memoize": "^7.1.1",
"pgsql-ast-parser": "^12.0.1",
Expand Down
17 changes: 7 additions & 10 deletions packages/admin/src/client/utils/destructive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@ export function useConfirmable<T extends RQMutationLike<any[]>>(input: T, option
if (confirmation) {
const yes =
options?.auto ||
(await alerter.confirm(
'This action may be destructive. Please confirm you want to run the following SQL:',
{
description: (
<div className="max-h-[300px] overflow-auto">
<pre>{confirmation}</pre>
</div>
),
},
))
(await alerter.confirm('This action may be destructive. Please confirm you want to run the following:', {
description: (
<div className="max-h-[300px] overflow-auto">
<pre>{confirmation}</pre>
</div>
),
}))
if (yes) return input.mutateAsync({...params, confirmation})
}
}
Expand Down
25 changes: 16 additions & 9 deletions packages/admin/src/client/views/Migrations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,26 +372,33 @@ export const FileTree = (tree: File | Folder) => {
{fileInfo?.status === 'pending' && (
<ContextMenuContent className="mt-5 bg-gray-800 text-gray-100">
<ContextMenuItem className="p-0">
<Button className="gap-2 flex-1 justify-start" onClick={() => up.mutate({to: fileInfo.name})}>
<icons.CircleArrowUp />
<MutationButton icon="CircleArrowUp" mutation={trpc.migrations.up} args={[{to: fileInfo.name}]}>
Apply migrations up to this one
</Button>
</MutationButton>
</ContextMenuItem>
</ContextMenuContent>
)}
{fileInfo?.status === 'executed' && (
<ContextMenuContent className="mt-5 bg-gray-800 text-gray-100">
<ContextMenuItem className="p-0">
<Button className="gap-2 flex-1 justify-start" onClick={() => down.mutate({name: fileInfo.name})}>
<icons.CircleArrowDown />
<MutationButton
className="gap-2 flex-1 justify-start"
icon="CircleArrowDown"
mutation={trpc.migrations.goto}
args={[{name: fileInfo.name}]}
>
Revert migrations down to this one
</Button>
</MutationButton>
</ContextMenuItem>
<ContextMenuItem className="p-0">
<Button className="gap-2 flex-1 justify-start" onClick={() => rebase.mutate({from: fileInfo.name})}>
<icons.CircleArrowDown />
<MutationButton
className="gap-2 flex-1 justify-start"
icon="Briefcase"
mutation={trpc.migrations.rebase}
args={[{from: fileInfo.name}]}
>
Rebase migrations from this one
</Button>
</MutationButton>
</ContextMenuItem>
</ContextMenuContent>
)}
Expand Down
10 changes: 9 additions & 1 deletion packages/migrator/src/migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,15 @@ export class Migrator {
*/
async rebase(params: {from: string; confirm: Confirm; name?: string}) {
const diff = await this.getDiffFrom({name: params.from})
if (await params.confirm(diff)) {
const steps = [
`- Baseline migrations to ${params.from}`, //
`- Delete all subsequent migration files`,
`- Create new migration named ${nameQuery([diff]).replace(/_[\da-z]+$/, '')} with content:\n ${diff.replaceAll('\n', '\n ')}`,
`- Baseline migrations to the created migration`,
'',
`Note: this will not update the database other than the migrations table. It will modify your filesystem.`,
]
if (await params.confirm(`## Steps:\n\n${steps.join('\n')}`)) {
await this.baseline({to: params.from, purgeDisk: true})
const created = await this.create({content: diff})
await this.baseline({to: created.name})
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dd2f8bc

Please sign in to comment.