@enlt-bakusoku/nuxt4 0.0.0-stage → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -2
- package/dist/module.d.mts +25 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +208 -0
- package/dist/runtime/shared/schemas/user.d.ts +40 -0
- package/dist/runtime/shared/schemas/user.js +21 -0
- package/dist/runtime/tasks-catalog.d.ts +6 -0
- package/dist/runtime/tasks-catalog.js +7 -0
- package/dist/types.d.mts +9 -0
- package/package.json +120 -3
- package/scripts/bakusoku-dev.mjs +387 -0
- package/scripts/dev-log-relay.mjs +96 -0
- package/scripts/predeploy.mjs +24 -0
- package/scripts/prepare-firebase-artifact.mjs +43 -0
- package/scripts/setup-worktree.sh +59 -0
- package/scripts/verify-firebase-artifacts.mjs +70 -0
- package/src/layer/app/components/admin/AdminExecutionHistory.vue +137 -0
- package/src/layer/app/components/admin/TaskRunDialog.vue +162 -0
- package/src/layer/app/components/admin/UserManagementPage.vue +342 -0
- package/src/layer/app/components/debug/DebugApplicationLogs.vue +87 -0
- package/src/layer/app/components/debug/DebugErrorLogs.vue +47 -0
- package/src/layer/app/components/debug/DebugFirestoreOperations.vue +48 -0
- package/src/layer/app/components/debug/DebugHttpRequests.vue +86 -0
- package/src/layer/app/components/debug/DebugNavigation.vue +60 -0
- package/src/layer/app/components/debug/DebugNowControl.vue +243 -0
- package/src/layer/app/components/debug/DebugPublicConfig.vue +24 -0
- package/src/layer/app/components/debug/DebugTestAdmin.vue +67 -0
- package/src/layer/app/components/demo/DemoDebug.vue +266 -0
- package/src/layer/app/components/demo/DemoHome.vue +347 -0
- package/src/layer/app/components/demo/DemoLogin.vue +391 -0
- package/src/layer/app/components/demo/DemoPassword.vue +224 -0
- package/src/layer/app/components/demo/DemoRegister.vue +148 -0
- package/src/layer/app/components/home/HomePage.vue +77 -0
- package/src/layer/app/layouts/dashboard.vue +126 -0
- package/src/layer/app/layouts/default.vue +3 -0
- package/src/layer/app/middleware/admin.ts +15 -0
- package/src/layer/app/middleware/authenticated.ts +19 -0
- package/src/layer/app/pages/admin/migrations.vue +463 -0
- package/src/layer/app/pages/admin/tasks/[id].vue +276 -0
- package/src/layer/app/pages/admin/tasks/index.vue +220 -0
- package/src/layer/app/pages/admin/users.vue +17 -0
- package/src/layer/app/pages/bakusoku-devtools.vue +294 -0
- package/src/layer/app/plugins/auth-init.ts +36 -0
- package/src/layer/app/plugins/debug-devtools.client.ts +20 -0
- package/src/layer/app/plugins/debug-errors.client.ts +78 -0
- package/src/layer/app/plugins/debug-http.client.ts +154 -0
- package/src/layer/app/plugins/debug-nav.client.ts +28 -0
- package/src/layer/app/plugins/vuefire-inspect.ts +18 -0
- package/src/layer/app/stores/auth.ts +462 -0
- package/src/layer/app/stores/datetime.ts +41 -0
- package/src/layer/app/stores/debug.ts +235 -0
- package/src/layer/app/stores/user.ts +170 -0
- package/src/layer/app/utils/admin-execution.ts +48 -0
- package/src/layer/app/utils/dashboard-heading.ts +36 -0
- package/src/layer/app/utils/debug-bridge.ts +270 -0
- package/src/layer/app/utils/debug-firestore.ts +38 -0
- package/src/layer/app/utils/debug-format.ts +19 -0
- package/src/layer/app/utils/execution-refresh.ts +66 -0
- package/src/layer/app/utils/framework-version.ts +4 -0
- package/src/layer/app/utils/inspect-nuxt-vuefire.ts +288 -0
- package/src/layer/app/utils/is-debug-enabled.ts +13 -0
- package/src/layer/app/utils/logger.ts +235 -0
- package/src/layer/app/utils/map-auth-error.ts +11 -0
- package/src/layer/app/utils/mask-secrets.ts +100 -0
- package/src/layer/app/utils/resolve-auth-user.ts +53 -0
- package/src/layer/app/utils/resolve-firestore.ts +20 -0
- package/src/layer/app/utils/task-run.ts +15 -0
- package/src/layer/build-credentials.mjs +33 -0
- package/src/layer/nuxt.config.ts +86 -0
- package/src/layer/package.json +5 -0
- package/src/layer/server/api/debug/test-admin.post.ts +38 -0
- package/src/layer/server/api/tasks/executions/cancel.post.ts +21 -0
- package/src/layer/server/api/tasks/executions/index.get.ts +22 -0
- package/src/layer/server/api/tasks/executions/index.post.ts +25 -0
- package/src/layer/server/api/tasks/index.get.ts +70 -0
- package/src/layer/server/api/tasks/migrations/index.post.ts +27 -0
- package/src/layer/server/api/tasks/migrations/recovery.post.ts +20 -0
- package/src/layer/server/api/users/[id].delete.ts +57 -0
- package/src/layer/server/api/users/[id].put.ts +110 -0
- package/src/layer/server/api/users/index.post.ts +232 -0
- package/src/layer/server/utils/admin-access.ts +32 -0
- package/src/layer/server/utils/debug-test-admin.ts +17 -0
- package/src/layer/server/utils/firebase-admin.ts +22 -0
- package/src/layer/server/utils/logger.ts +172 -0
- package/src/layer/server/utils/tasks-gateway.ts +57 -0
- package/src/layer/server/utils/user-mutations.ts +103 -0
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="flex flex-col gap-6">
|
|
3
|
+
<UAlert v-if="error" color="error" variant="soft" :title="error" />
|
|
4
|
+
<UAlert v-if="notice" color="success" variant="soft" :title="notice" />
|
|
5
|
+
<UAlert
|
|
6
|
+
v-if="migrationPlan?.recovery"
|
|
7
|
+
color="warning"
|
|
8
|
+
variant="soft"
|
|
9
|
+
title="マイグレーション計画が停止しました"
|
|
10
|
+
:description="`${migrationPlan.recovery.migrationId}(${migrationPlan.recovery.direction === 'down' ? 'ロールバック' : '実行'})`"
|
|
11
|
+
>
|
|
12
|
+
<template #actions>
|
|
13
|
+
<UButton color="warning" variant="outline" :disabled="!catalogReady || !!acting" @click="recoveryOpen = true">
|
|
14
|
+
復旧する
|
|
15
|
+
</UButton>
|
|
16
|
+
</template>
|
|
17
|
+
</UAlert>
|
|
18
|
+
|
|
19
|
+
<UCard :ui="{ body: 'p-0 sm:p-0' }">
|
|
20
|
+
<template #header>
|
|
21
|
+
<div class="flex items-center justify-between gap-3">
|
|
22
|
+
<h2 class="text-base font-semibold">マイグレーション一覧</h2>
|
|
23
|
+
<div class="flex shrink-0 items-center gap-2">
|
|
24
|
+
<UBadge color="neutral" variant="subtle">
|
|
25
|
+
{{ migrations.length }}
|
|
26
|
+
</UBadge>
|
|
27
|
+
<UButton icon="i-lucide-refresh-cw" size="sm" variant="outline" class="whitespace-nowrap" :loading="loading" @click="load">
|
|
28
|
+
再読み込み
|
|
29
|
+
</UButton>
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
<p v-if="moveHint" class="mt-2 text-sm text-gray-500">
|
|
33
|
+
{{ moveHint }}
|
|
34
|
+
</p>
|
|
35
|
+
</template>
|
|
36
|
+
<UTable
|
|
37
|
+
:data="migrations"
|
|
38
|
+
:columns="migrationColumns"
|
|
39
|
+
:loading="loading && !catalogReady"
|
|
40
|
+
empty="登録されたマイグレーションはありません。"
|
|
41
|
+
>
|
|
42
|
+
<template #id-header>
|
|
43
|
+
<span class="pl-12">ID</span>
|
|
44
|
+
</template>
|
|
45
|
+
<template #id-cell="{ row }">
|
|
46
|
+
<div class="flex items-center gap-2">
|
|
47
|
+
<span class="inline-flex w-10 shrink-0 items-center">
|
|
48
|
+
<UBadge v-if="row.original.id === headId" color="primary" variant="subtle" size="sm">
|
|
49
|
+
現在
|
|
50
|
+
</UBadge>
|
|
51
|
+
</span>
|
|
52
|
+
<p class="font-mono text-xs text-gray-500">{{ row.original.id }}</p>
|
|
53
|
+
</div>
|
|
54
|
+
</template>
|
|
55
|
+
<template #name-cell="{ row }">
|
|
56
|
+
<p class="font-medium">{{ row.original.name }}</p>
|
|
57
|
+
<p v-if="row.original.description" class="mt-1 max-w-md text-xs text-gray-500">
|
|
58
|
+
{{ row.original.description }}
|
|
59
|
+
</p>
|
|
60
|
+
</template>
|
|
61
|
+
<template #state-cell="{ row }">
|
|
62
|
+
<UBadge :color="stateColor(row.original.state)" variant="subtle">
|
|
63
|
+
{{ stateLabel(row.original.state) }}
|
|
64
|
+
</UBadge>
|
|
65
|
+
</template>
|
|
66
|
+
<template #actions-cell="{ row }">
|
|
67
|
+
<UButton
|
|
68
|
+
v-if="row.index > applied.head"
|
|
69
|
+
size="xs"
|
|
70
|
+
:disabled="!canMove"
|
|
71
|
+
@click="askMove('up', row.index)"
|
|
72
|
+
>
|
|
73
|
+
実行
|
|
74
|
+
</UButton>
|
|
75
|
+
<UButton
|
|
76
|
+
v-else-if="row.index > applied.lastIrreversibleIndex"
|
|
77
|
+
size="xs"
|
|
78
|
+
color="neutral"
|
|
79
|
+
variant="outline"
|
|
80
|
+
:disabled="!canMove"
|
|
81
|
+
@click="askMove('down', row.index)"
|
|
82
|
+
>
|
|
83
|
+
ロールバック
|
|
84
|
+
</UButton>
|
|
85
|
+
</template>
|
|
86
|
+
</UTable>
|
|
87
|
+
</UCard>
|
|
88
|
+
|
|
89
|
+
<AdminExecutionHistory
|
|
90
|
+
:rows="executions"
|
|
91
|
+
:loading="loading && !historyReady"
|
|
92
|
+
subject-label="マイグレーション名"
|
|
93
|
+
:acting="acting"
|
|
94
|
+
@cancel="cancelExecution"
|
|
95
|
+
/>
|
|
96
|
+
|
|
97
|
+
<UModal v-model:open="moveOpen" :title="moveTitle" :description="moveDescription">
|
|
98
|
+
<template #footer>
|
|
99
|
+
<div class="flex justify-end gap-2">
|
|
100
|
+
<UButton color="neutral" variant="ghost" @click="pendingMove = null">
|
|
101
|
+
キャンセル
|
|
102
|
+
</UButton>
|
|
103
|
+
<UButton :color="pendingMove?.direction === 'down' ? 'error' : 'primary'" :loading="acting === 'up' || acting === 'down'" :disabled="!canConfirmMove" @click="confirmMove">
|
|
104
|
+
{{ pendingMove?.direction === 'down' ? '戻す' : '実行する' }}
|
|
105
|
+
</UButton>
|
|
106
|
+
</div>
|
|
107
|
+
</template>
|
|
108
|
+
</UModal>
|
|
109
|
+
<UModal v-if="migrationPlan?.recovery" v-model:open="recoveryOpen" title="停止したマイグレーション計画の復旧">
|
|
110
|
+
<template #description>
|
|
111
|
+
<p class="break-all">{{ migrationPlan.recovery.migrationId }}(実行ID {{ migrationPlan.executionId }})</p>
|
|
112
|
+
<p v-if="migrationPlan.recovery.requiresOutcome" class="mt-2">
|
|
113
|
+
実データを確認し、このバージョンが現在適用されているか選んでください。途中まで変更されている場合は、先にデータを整合した状態にしてください。
|
|
114
|
+
</p>
|
|
115
|
+
<p v-else class="mt-2">停止した計画を終了します。残りのバージョンは一覧から改めて実行できます。</p>
|
|
116
|
+
</template>
|
|
117
|
+
<template #footer>
|
|
118
|
+
<div class="flex flex-wrap justify-end gap-2">
|
|
119
|
+
<UButton color="neutral" variant="ghost" :disabled="!!acting" @click="recoveryOpen = false">
|
|
120
|
+
キャンセル
|
|
121
|
+
</UButton>
|
|
122
|
+
<template v-if="migrationPlan.recovery.requiresOutcome">
|
|
123
|
+
<UButton variant="outline" :disabled="!!acting" @click="confirmRecovery(false)">未適用として確定</UButton>
|
|
124
|
+
<UButton :disabled="!!acting" @click="confirmRecovery(true)">適用済みとして確定</UButton>
|
|
125
|
+
</template>
|
|
126
|
+
<UButton v-else :disabled="!!acting" @click="confirmRecovery()">計画を終了</UButton>
|
|
127
|
+
</div>
|
|
128
|
+
</template>
|
|
129
|
+
</UModal>
|
|
130
|
+
</div>
|
|
131
|
+
</template>
|
|
132
|
+
|
|
133
|
+
<script setup lang="ts">
|
|
134
|
+
import AdminExecutionHistory from '../../components/admin/AdminExecutionHistory.vue'
|
|
135
|
+
import type { MigrationPlanStatus } from '@enlt-bakusoku/functions/enqueue-task'
|
|
136
|
+
import { isExecutionActive, useExecutionRefresh } from '../../utils/execution-refresh'
|
|
137
|
+
import { useDashboardHeading } from '../../utils/dashboard-heading'
|
|
138
|
+
import { computed, navigateTo, ref, useRuntimeConfig, useState } from '#imports'
|
|
139
|
+
|
|
140
|
+
definePageMeta({
|
|
141
|
+
layout: 'dashboard',
|
|
142
|
+
middleware: ['authenticated', 'admin'],
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
useDashboardHeading({
|
|
146
|
+
title: 'マイグレーション管理',
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
const runtimeConfig = useRuntimeConfig()
|
|
150
|
+
type MigrationItem = {
|
|
151
|
+
id: string
|
|
152
|
+
name: string
|
|
153
|
+
description: string
|
|
154
|
+
reversible: boolean
|
|
155
|
+
state: 'running' | 'succeeded' | 'absent'
|
|
156
|
+
}
|
|
157
|
+
type ExecutionRow = {
|
|
158
|
+
id: string
|
|
159
|
+
name: string
|
|
160
|
+
status: string
|
|
161
|
+
source: string
|
|
162
|
+
actorUid: string
|
|
163
|
+
startedAt: string
|
|
164
|
+
endedAt: string
|
|
165
|
+
attempts: number
|
|
166
|
+
error: string
|
|
167
|
+
message: string
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const loading = ref(true)
|
|
171
|
+
const acting = ref('')
|
|
172
|
+
const error = ref('')
|
|
173
|
+
const notice = ref('')
|
|
174
|
+
const catalogReady = ref(false)
|
|
175
|
+
const historyReady = ref(false)
|
|
176
|
+
const migrations = ref<MigrationItem[]>([])
|
|
177
|
+
const executions = ref<ExecutionRow[]>([])
|
|
178
|
+
const migrationPlan = ref<MigrationPlanStatus | null>(null)
|
|
179
|
+
const recoveryOpen = ref(false)
|
|
180
|
+
const trackedPlans = useState<{ executionIds: string[], migrationIds: string[], direction: 'up' | 'down' }[]>(
|
|
181
|
+
'bakusoku-admin-migration-refresh',
|
|
182
|
+
() => [],
|
|
183
|
+
)
|
|
184
|
+
const pendingMove = ref<{
|
|
185
|
+
direction: 'up' | 'down'
|
|
186
|
+
targetId: string
|
|
187
|
+
steps: MigrationItem[]
|
|
188
|
+
} | null>(null)
|
|
189
|
+
const lastRequest = ref<{ direction: 'up' | 'down', targetId: string, executionId: string }>()
|
|
190
|
+
const moveOpen = computed({
|
|
191
|
+
get: () => pendingMove.value !== null,
|
|
192
|
+
set: (open: boolean) => {
|
|
193
|
+
if (!open) pendingMove.value = null
|
|
194
|
+
},
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
const migrationColumns = [
|
|
198
|
+
{ accessorKey: 'id', header: 'ID' },
|
|
199
|
+
{ accessorKey: 'name', header: '名前' },
|
|
200
|
+
{ id: 'state', header: '状態' },
|
|
201
|
+
{ id: 'actions', header: 'アクション' },
|
|
202
|
+
]
|
|
203
|
+
|
|
204
|
+
const applied = computed(() => {
|
|
205
|
+
let head = -1
|
|
206
|
+
let lastIrreversibleIndex = -1
|
|
207
|
+
let broken = false
|
|
208
|
+
let running = false
|
|
209
|
+
migrations.value.forEach((item, index) => {
|
|
210
|
+
if (item.state === 'running') running = true
|
|
211
|
+
if (item.state !== 'succeeded') return
|
|
212
|
+
if (head !== index - 1) broken = true
|
|
213
|
+
head = index
|
|
214
|
+
// ここより前の行を選ぶと、戻せない版がロールバック範囲に含まれる。
|
|
215
|
+
if (!item.reversible) lastIrreversibleIndex = index
|
|
216
|
+
})
|
|
217
|
+
return { head, lastIrreversibleIndex, broken, running }
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
const headId = computed(() => migrations.value[applied.value.head]?.id ?? '')
|
|
221
|
+
const canMove = computed(() => (
|
|
222
|
+
catalogReady.value && !loading.value && !acting.value && !migrationPlan.value && !applied.value.broken && !applied.value.running
|
|
223
|
+
))
|
|
224
|
+
|
|
225
|
+
const canConfirmMove = computed(() => {
|
|
226
|
+
if (canMove.value) return true
|
|
227
|
+
const plan = migrationPlan.value
|
|
228
|
+
const request = lastRequest.value
|
|
229
|
+
return catalogReady.value && !loading.value && !acting.value && !!plan && !plan.recovery
|
|
230
|
+
&& plan.ownerId === request?.executionId && pendingMove.value?.direction === request.direction
|
|
231
|
+
&& pendingMove.value.targetId === request.targetId
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
const moveHint = computed(() => {
|
|
235
|
+
if (migrationPlan.value?.recovery) return ''
|
|
236
|
+
if (applied.value.broken) return '適用順が崩れています。先頭から連続した状態だけ移動できます。'
|
|
237
|
+
if (applied.value.running) return '実行中のマイグレーションがあるため、移動できません。'
|
|
238
|
+
return ''
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
const moveTitle = computed(() => pendingMove.value?.direction === 'down' ? 'マイグレーションをロールバック' : 'マイグレーションを実行')
|
|
242
|
+
const moveDescription = computed(() => {
|
|
243
|
+
const move = pendingMove.value
|
|
244
|
+
if (!move) return ''
|
|
245
|
+
const names = move.steps.map(item => item.name || item.id).join('、')
|
|
246
|
+
if (move.direction === 'down') {
|
|
247
|
+
const target = migrations.value.find(item => item.id === move.targetId)
|
|
248
|
+
const rest = target ? `${target.name || target.id} は適用したままにします。` : 'すべて未適用に戻します。'
|
|
249
|
+
return `${names} をこの順で戻します。${rest}`
|
|
250
|
+
}
|
|
251
|
+
return `${names} をこの順で実行します。`
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
/** マイグレーションの適用状態を表示用のラベルに変換する。 */
|
|
255
|
+
function stateLabel(state: MigrationItem['state']) {
|
|
256
|
+
if (state === 'succeeded') return '適用済み'
|
|
257
|
+
if (state === 'running') return '実行中'
|
|
258
|
+
return '未適用'
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** マイグレーションの適用状態に応じた表示色を返す。 */
|
|
262
|
+
function stateColor(state: MigrationItem['state']) {
|
|
263
|
+
if (state === 'succeeded') return 'success'
|
|
264
|
+
if (state === 'running') return 'primary'
|
|
265
|
+
return 'neutral'
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** 指定された接頭辞を付けて実行 ID を生成する。 */
|
|
269
|
+
function newExecutionId(prefix: string) {
|
|
270
|
+
const stamp = new Date().toISOString().replace(/\D/g, '').slice(0, 14)
|
|
271
|
+
const rand = crypto.randomUUID().replace(/-/g, '').slice(0, 8)
|
|
272
|
+
return `${prefix}_${stamp}_${rand}`
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** API エラーから画面表示用のメッセージを取り出す。 */
|
|
276
|
+
function messageOf(err: unknown) {
|
|
277
|
+
if (typeof err === 'object' && err && 'data' in err) {
|
|
278
|
+
const data = (err as { data?: { message?: string, statusMessage?: string } }).data
|
|
279
|
+
if (data?.message) return data.message
|
|
280
|
+
if (data?.statusMessage) return data.statusMessage
|
|
281
|
+
}
|
|
282
|
+
if (err instanceof Error) return err.message
|
|
283
|
+
return '操作に失敗しました。'
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** API エラーから HTTP ステータスコードを取り出す。 */
|
|
287
|
+
function statusCodeOf(err: unknown) {
|
|
288
|
+
if (typeof err === 'object' && err && 'statusCode' in err) {
|
|
289
|
+
return Number((err as { statusCode?: number }).statusCode)
|
|
290
|
+
}
|
|
291
|
+
if (typeof err === 'object' && err && 'status' in err) {
|
|
292
|
+
return Number((err as { status?: number }).status)
|
|
293
|
+
}
|
|
294
|
+
return 0
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const tasksEnabled = runtimeConfig.public.tasksEnabled === true
|
|
298
|
+
const load = useExecutionRefresh(
|
|
299
|
+
tasksEnabled,
|
|
300
|
+
() => !migrationPlan.value?.recovery && (
|
|
301
|
+
!!migrationPlan.value || trackedPlans.value.length > 0 || applied.value.running
|
|
302
|
+
|| executions.value.some(row => isExecutionActive(row.status))
|
|
303
|
+
),
|
|
304
|
+
readMigrations,
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
if (!tasksEnabled) await navigateTo('/')
|
|
308
|
+
|
|
309
|
+
/** マイグレーションの適用状態と実行履歴を取得する。 */
|
|
310
|
+
async function readMigrations(background: boolean, isCurrent: () => boolean) {
|
|
311
|
+
if (!background) {
|
|
312
|
+
loading.value = true
|
|
313
|
+
error.value = ''
|
|
314
|
+
}
|
|
315
|
+
const [catalogResult, historyResult] = await Promise.allSettled([
|
|
316
|
+
$fetch<{ data?: { migrations?: MigrationItem[], migrationStatesAvailable?: boolean, migrationPlan?: MigrationPlanStatus | null } }>('/api/tasks'),
|
|
317
|
+
$fetch<{ data?: ExecutionRow[] }>('/api/tasks/executions', { query: { kind: 'migration' } }),
|
|
318
|
+
])
|
|
319
|
+
if (!isCurrent()) return
|
|
320
|
+
|
|
321
|
+
const catalog = catalogResult.status === 'fulfilled' ? catalogResult.value.data : undefined
|
|
322
|
+
const statesAvailable = catalog !== undefined && catalog.migrationStatesAvailable !== false
|
|
323
|
+
catalogReady.value = statesAvailable
|
|
324
|
+
if (statesAvailable) {
|
|
325
|
+
const plan = catalog.migrationPlan ?? null
|
|
326
|
+
if (plan?.executionId !== migrationPlan.value?.executionId) recoveryOpen.value = false
|
|
327
|
+
migrationPlan.value = plan
|
|
328
|
+
migrations.value = catalog.migrations ?? []
|
|
329
|
+
if (plan?.recovery) {
|
|
330
|
+
trackedPlans.value = trackedPlans.value.filter(tracked => tracked.executionIds[0] !== plan.ownerId)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (historyResult.status === 'fulfilled') {
|
|
334
|
+
historyReady.value = true
|
|
335
|
+
executions.value = historyResult.value.data ?? []
|
|
336
|
+
const statuses = new Map(executions.value.map(row => [row.id, row.status]))
|
|
337
|
+
const states = new Map(migrations.value.map(row => [row.id, row.state]))
|
|
338
|
+
trackedPlans.value = trackedPlans.value.filter(({ executionIds, migrationIds, direction }) => {
|
|
339
|
+
const stopped = executionIds.some(id => {
|
|
340
|
+
const status = statuses.get(id)
|
|
341
|
+
return status === 'failed' || status === 'cancelled' || status === 'unknown'
|
|
342
|
+
})
|
|
343
|
+
if (stopped) return false
|
|
344
|
+
// 次の版がまだキューに現れない間も、最後の版と適用状態を確認するまで更新を続ける。
|
|
345
|
+
const lastId = executionIds.at(-1)
|
|
346
|
+
const expectedState = direction === 'down' ? 'absent' : 'succeeded'
|
|
347
|
+
return !statesAvailable || !lastId || statuses.get(lastId) !== 'succeeded'
|
|
348
|
+
|| migrationIds.some(id => states.get(id) !== expectedState)
|
|
349
|
+
})
|
|
350
|
+
} else if (!background) {
|
|
351
|
+
historyReady.value = false
|
|
352
|
+
}
|
|
353
|
+
if (!background) {
|
|
354
|
+
const failed = [catalogResult, historyResult].find(result => result.status === 'rejected')
|
|
355
|
+
if (failed?.status === 'rejected') error.value = messageOf(failed.reason)
|
|
356
|
+
else if (!statesAvailable) error.value = 'マイグレーションの適用状態を読み込めませんでした。'
|
|
357
|
+
loading.value = false
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** 適用またはロールバックの確認ダイアログを開く。 */
|
|
362
|
+
function askMove(direction: 'up' | 'down', index: number) {
|
|
363
|
+
const item = migrations.value[index]
|
|
364
|
+
if (!canMove.value || !item) return
|
|
365
|
+
|
|
366
|
+
const { head, lastIrreversibleIndex } = applied.value
|
|
367
|
+
if (direction === 'up' && index > head) {
|
|
368
|
+
pendingMove.value = { direction, targetId: item.id, steps: migrations.value.slice(head + 1, index + 1) }
|
|
369
|
+
} else if (direction === 'down' && index <= head && index > lastIrreversibleIndex) {
|
|
370
|
+
// API の到達点は適用済みとして残るため、選んだ版の直前を指定する。
|
|
371
|
+
pendingMove.value = {
|
|
372
|
+
direction,
|
|
373
|
+
targetId: migrations.value[index - 1]?.id ?? '',
|
|
374
|
+
steps: migrations.value.slice(index, head + 1).reverse(),
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** 確認した方向と対象版を送信し、マイグレーションの受付結果を表示する。 */
|
|
380
|
+
async function confirmMove() {
|
|
381
|
+
const move = pendingMove.value
|
|
382
|
+
if (!move || !canConfirmMove.value) return
|
|
383
|
+
acting.value = move.direction
|
|
384
|
+
error.value = ''
|
|
385
|
+
notice.value = ''
|
|
386
|
+
const previous = lastRequest.value
|
|
387
|
+
const executionId = previous?.direction === move.direction && previous.targetId === move.targetId
|
|
388
|
+
? previous.executionId
|
|
389
|
+
: newExecutionId(move.direction === 'down' ? 'migrate-down' : 'migrate-up')
|
|
390
|
+
lastRequest.value = { direction: move.direction, targetId: move.targetId, executionId }
|
|
391
|
+
try {
|
|
392
|
+
const result = await $fetch<{ data?: { executionId?: string, steps?: string[] } }>('/api/tasks/migrations', {
|
|
393
|
+
method: 'POST',
|
|
394
|
+
body: {
|
|
395
|
+
executionId,
|
|
396
|
+
targetId: move.targetId,
|
|
397
|
+
direction: move.direction,
|
|
398
|
+
},
|
|
399
|
+
})
|
|
400
|
+
const accepted = result.data?.executionId ?? executionId
|
|
401
|
+
const steps = result.data?.steps ?? move.steps.map(step => step.id)
|
|
402
|
+
if (!trackedPlans.value.some(plan => plan.executionIds[0] === accepted)) {
|
|
403
|
+
trackedPlans.value.push({
|
|
404
|
+
executionIds: steps.map((id, index) => index === 0 ? accepted : `${executionId}_${id}`),
|
|
405
|
+
migrationIds: steps,
|
|
406
|
+
direction: move.direction,
|
|
407
|
+
})
|
|
408
|
+
}
|
|
409
|
+
notice.value = steps.length === 1
|
|
410
|
+
? `${migrations.value.find(item => item.id === steps[0])?.name ?? 'マイグレーション'}を受け付けました。実行IDは ${accepted} です。`
|
|
411
|
+
: `${steps.length}件を順に実行します。先頭の実行IDは ${accepted} です。`
|
|
412
|
+
lastRequest.value = undefined
|
|
413
|
+
pendingMove.value = null
|
|
414
|
+
await load()
|
|
415
|
+
} catch (err) {
|
|
416
|
+
error.value = messageOf(err)
|
|
417
|
+
if (statusCodeOf(err) === 409) lastRequest.value = undefined
|
|
418
|
+
} finally {
|
|
419
|
+
acting.value = ''
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** 確認した適用状態を API に送り、停止した計画を終了する。 */
|
|
424
|
+
async function confirmRecovery(applied?: boolean) {
|
|
425
|
+
const plan = migrationPlan.value
|
|
426
|
+
if (!catalogReady.value || !plan?.recovery || acting.value) return
|
|
427
|
+
acting.value = 'recovery'
|
|
428
|
+
error.value = ''
|
|
429
|
+
notice.value = ''
|
|
430
|
+
try {
|
|
431
|
+
await $fetch('/api/tasks/migrations/recovery', {
|
|
432
|
+
method: 'POST',
|
|
433
|
+
body: { executionId: plan.executionId, applied },
|
|
434
|
+
})
|
|
435
|
+
lastRequest.value = undefined
|
|
436
|
+
recoveryOpen.value = false
|
|
437
|
+
await load()
|
|
438
|
+
notice.value = '停止した計画を終了しました。'
|
|
439
|
+
} catch (err) {
|
|
440
|
+
if (statusCodeOf(err) === 409) {
|
|
441
|
+
recoveryOpen.value = false
|
|
442
|
+
await load()
|
|
443
|
+
}
|
|
444
|
+
error.value = messageOf(err)
|
|
445
|
+
} finally {
|
|
446
|
+
acting.value = ''
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/** 指定した実行の取り消しを API に依頼し、画面を更新する。 */
|
|
451
|
+
async function cancelExecution(id: string) {
|
|
452
|
+
acting.value = id
|
|
453
|
+
error.value = ''
|
|
454
|
+
try {
|
|
455
|
+
await $fetch('/api/tasks/executions/cancel', { method: 'POST', body: { executionId: id } })
|
|
456
|
+
await load()
|
|
457
|
+
} catch (err) {
|
|
458
|
+
error.value = messageOf(err)
|
|
459
|
+
} finally {
|
|
460
|
+
acting.value = ''
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
</script>
|