chore: rename maintenance to power

This commit is contained in:
Ben Allfree 2024-12-04 08:23:23 -08:00
parent 3f4ed487eb
commit 6569e5ad03
13 changed files with 96 additions and 46 deletions

View File

@ -10,12 +10,12 @@
const { updateInstance } = client()
const handleMaintenanceChange = (id: InstanceId) => (e: Event) => {
const handlePowerChange = (id: InstanceId) => (e: Event) => {
const target = e.target as HTMLInputElement
const maintenance = !target.checked
const power = !target.checked
// Update the database with the new value
updateInstance({ id, fields: { maintenance } })
updateInstance({ id, fields: { power } })
.then(() => 'saved')
.catch((error) => {
error.data.message || error.message
@ -25,7 +25,7 @@
{#each values($globalInstancesStore).sort( (a, b) => a.subdomain.localeCompare(b.subdomain), ) as instance, index}
<button
class={`card min-w-80 lg:max-w-80 flex-1 m-4 transition hover:bg-base-300 ${instance.maintenance ? 'bg-base-200' : 'bg-neutral'}`}
class={`card min-w-80 lg:max-w-80 flex-1 m-4 transition hover:bg-base-300 ${instance.power ? 'bg-base-200' : 'bg-neutral'}`}
on:click={(_) => goto(`/instances/${instance.id}`)}
>
<div class="card-body w-full">
@ -34,20 +34,19 @@
<span>{instance.subdomain}</span>
<input
type="checkbox"
class="toggle {instance.maintenance
class="toggle {instance.power
? 'bg-red-500 hover:bg-red-500'
: 'toggle-success'}"
checked={!instance.maintenance}
checked={!instance.power}
on:click={(e) => e.stopPropagation()}
on:change={handleMaintenanceChange(instance.id)}
on:change={handlePowerChange(instance.id)}
/>
</div>
</div>
<p class="text-left">
<span class="text-gray-400"
>Version {instance.version}
<span class={!instance.maintenance ? 'hidden' : ''}
>- Powered Off</span
<span class={!instance.power ? 'hidden' : ''}>- Powered Off</span
></span
>
</p>

View File

@ -29,11 +29,11 @@
const { updateInstance } = client()
const handleMaintenanceChange = (id: InstanceId) => (isChecked: boolean) => {
const maintenance = !isChecked
const handlePowerChange = (id: InstanceId) => (isChecked: boolean) => {
const power = !isChecked
// Update the database with the new value
updateInstance({ id, fields: { maintenance } })
updateInstance({ id, fields: { power } })
.then(() => 'saved')
.catch((error) => {
error.data.message || error.message
@ -78,13 +78,13 @@
<div>
<Toggle
checked={!$instance.maintenance}
onChange={handleMaintenanceChange($instance.id)}
checked={!$instance.power}
onChange={handlePowerChange($instance.id)}
/>
</div>
</div>
{#if $instance.maintenance}
{#if $instance.power}
<div class="px-4 mb-8">
<AlertBar
message="This instance is turned off and will not respond to requests"

View File

@ -8,7 +8,7 @@
import ErrorMessage from '../settings/ErrorMessage.svelte'
import AlertBar from '$src/components/AlertBar.svelte'
$: ({ id, maintenance, version } = $instance)
$: ({ id, power, version } = $instance)
// Create a copy of the version
let selectedVersion = version
@ -65,7 +65,7 @@
<CardHeader documentation={`/docs/delete`}>Delete Instance</CardHeader>
{#if !maintenance}
{#if !power}
<AlertBar
message="Instance must be powered off before deleting."
type="error"
@ -93,7 +93,7 @@
<button
type="submit"
class="btn btn-error"
disabled={!maintenance || isButtonDisabled}>Delete Instance</button
disabled={!power || isButtonDisabled}>Delete Instance</button
>
</form>

View File

@ -6,7 +6,7 @@
import AlertBar from '$components/AlertBar.svelte'
import { versions as allVersions, is23Available } from '$src/util/stores'
$: ({ id, maintenance, version } = $instance)
$: ({ id, power, version } = $instance)
let is22OrLower = false
let is23OrHigher = false
@ -80,7 +80,7 @@
<CardHeader documentation={`/docs/upgrading`}>Version Change</CardHeader>
<div class="max-w-xl">
{#if !maintenance}
{#if !power}
<AlertBar
message="Your instance must be powered off to change the version."
type="error"
@ -147,7 +147,7 @@
<button
type="submit"
class="btn btn-error"
disabled={!maintenance || isButtonDisabled}>Change Version</button
disabled={!power || isButtonDisabled}>Change Version</button
>
</form>
</div>

View File

@ -21,7 +21,6 @@ You can start by creating `*.pb.js` file(s) inside the `pb_hooks` directory. The
## Important Notes
- Altering the `pb_hooks` directory will cause your PocketHost instance to be restarted so changes are picked up automatically.
- If code in `pb_hooks` causes your `pocketbase` instance to exit unexpectedly, your instance will be placed in [Maintenance Mode](/docs/usage/maintenance/) until you can correct the problem and manually move your instance out of Maintenance Mode.
## Code Samples

View File

@ -15,7 +15,7 @@ import { FileStat, FileSystem, FtpConnection } from 'ftp-srv'
import { dirname, isAbsolute, join, normalize, resolve, sep } from 'path'
import { DATA_ROOT } from '../../../../..'
import * as fsAsync from './fs-async'
import { MAINTENANCE_ONLY_INSTANCE_ROOTS } from './guards'
import { POWERED_OFF_ONLY } from './guards'
export type PathError = {
cause: {
@ -165,12 +165,10 @@ export class PhFs implements FileSystem {
const instanceRootDir = restOfVirtualPath[0]
if (
instanceRootDir &&
MAINTENANCE_ONLY_INSTANCE_ROOTS.includes(instanceRootDir) &&
!instance.maintenance
POWERED_OFF_ONLY.includes(instanceRootDir) &&
!instance.power
) {
throw new Error(
`Instance must be in maintenance mode to access ${instanceRootDir}`,
)
throw new Error(`Instance must be powered off first`)
}
if (instance.volume) {
fsPathParts.push(instance.volume)

View File

@ -15,9 +15,7 @@ export enum PhysicalFolderNames {
Migrations = 'pb_migrations',
Hooks = 'pb_hooks',
}
export const MAINTENANCE_ONLY_INSTANCE_ROOTS: string[] = [
VirtualFolderNames.Data,
]
export const POWERED_OFF_ONLY: string[] = [VirtualFolderNames.Data]
export const FolderNamesMap: {
[_ in VirtualFolderNames]: PhysicalFolderNames

View File

@ -26,7 +26,7 @@ export type InstanceFields<TExtra = {}> = BaseFields & {
status: InstanceStatus
version: VersionId
secrets: InstanceSecretCollection | null
maintenance: boolean
power: boolean
suspension: string
syncAdmin: boolean
cname: string

View File

@ -6,7 +6,7 @@ export type UpdateInstancePayload = {
fields: Partial<
Pick<
InstanceFields,
| 'maintenance'
| 'power'
| 'secrets'
| 'subdomain'
| 'syncAdmin'
@ -34,7 +34,7 @@ export const UpdateInstancePayloadSchema: JSONSchemaType<UpdateInstancePayload>
properties: {
syncAdmin: { type: 'boolean', nullable: true },
subdomain: { type: 'string', nullable: true },
maintenance: { type: 'boolean', nullable: true },
power: { type: 'boolean', nullable: true },
version: {
type: 'string',
nullable: true,

View File

@ -207,7 +207,7 @@ var HandleInstanceUpdate = (c) => {
id: "",
fields: {
subdomain: null,
maintenance: null,
power: null,
version: null,
secrets: null,
syncAdmin: null,
@ -220,14 +220,14 @@ var HandleInstanceUpdate = (c) => {
data = JSON.parse(JSON.stringify(data));
const id = c.pathParam("id");
const {
fields: { subdomain, maintenance, version, secrets, syncAdmin, dev, cname }
fields: { subdomain, power, version, secrets, syncAdmin, dev, cname }
} = data;
log(
`vars`,
JSON.stringify({
id,
subdomain,
maintenance,
power,
version,
secrets,
syncAdmin,
@ -247,7 +247,7 @@ var HandleInstanceUpdate = (c) => {
const sanitized = removeEmptyKeys({
subdomain,
version,
maintenance,
power,
secrets,
syncAdmin,
dev,

View File

@ -0,0 +1,56 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("etae8tuiaxl6xfv")
collection.indexes = [
"CREATE UNIQUE INDEX `idx_unique_qdtuuld1` ON `instances` (`subdomain`)",
"CREATE INDEX `idx_DKUSkMx` ON `instances` (`status`)",
"CREATE INDEX `idx_fhfKrpl` ON `instances` (`uid`)",
"CREATE INDEX `idx_TfdgNnO` ON `instances` (`power`)",
"CREATE INDEX `idx_FrmHehp` ON `instances` (`created`)",
"CREATE INDEX `idx_tNMeylJ` ON `instances` (`updated`)",
"CREATE UNIQUE INDEX `idx_rBYwAXi` ON `instances` (`cname`) WHERE cname != ''"
]
// update
collection.schema.addField(new SchemaField({
"system": false,
"id": "mexrkb5z",
"name": "power",
"type": "bool",
"required": false,
"presentable": false,
"unique": false,
"options": {}
}))
return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("etae8tuiaxl6xfv")
collection.indexes = [
"CREATE UNIQUE INDEX `idx_unique_qdtuuld1` ON `instances` (`subdomain`)",
"CREATE INDEX `idx_DKUSkMx` ON `instances` (`status`)",
"CREATE INDEX `idx_fhfKrpl` ON `instances` (`uid`)",
"CREATE INDEX `idx_TfdgNnO` ON `instances` (`maintenance`)",
"CREATE INDEX `idx_FrmHehp` ON `instances` (`created`)",
"CREATE INDEX `idx_tNMeylJ` ON `instances` (`updated`)",
"CREATE UNIQUE INDEX `idx_rBYwAXi` ON `instances` (`cname`) WHERE cname != ''"
]
// update
collection.schema.addField(new SchemaField({
"system": false,
"id": "mexrkb5z",
"name": "maintenance",
"type": "bool",
"required": false,
"presentable": false,
"unique": false,
"options": {}
}))
return dao.saveCollection(collection)
})

View File

@ -11,7 +11,7 @@ export const HandleInstanceUpdate = (c: echo.Context) => {
id: '',
fields: {
subdomain: null,
maintenance: null,
power: null,
version: null,
secrets: null,
syncAdmin: null,
@ -22,7 +22,7 @@ export const HandleInstanceUpdate = (c: echo.Context) => {
id: string
fields: {
subdomain: string | null
maintenance: boolean | null
power: boolean | null
version: string | null
secrets: StringKvLookup | null
syncAdmin: boolean | null
@ -39,7 +39,7 @@ export const HandleInstanceUpdate = (c: echo.Context) => {
const id = c.pathParam('id')
const {
fields: { subdomain, maintenance, version, secrets, syncAdmin, dev, cname },
fields: { subdomain, power, version, secrets, syncAdmin, dev, cname },
} = data
log(
@ -47,7 +47,7 @@ export const HandleInstanceUpdate = (c: echo.Context) => {
JSON.stringify({
id,
subdomain,
maintenance,
power,
version,
secrets,
syncAdmin,
@ -70,7 +70,7 @@ export const HandleInstanceUpdate = (c: echo.Context) => {
const sanitized = removeEmptyKeys({
subdomain,
version,
maintenance,
power,
secrets,
syncAdmin,
dev,

View File

@ -343,10 +343,10 @@ export const instanceService = mkSingleton(
}
/*
Maintenance check
power check
*/
dbg(`Checking for maintenance mode`)
if (instance.maintenance) {
dbg(`Checking for power`)
if (instance.power) {
throw new Error(
`This instance is powered off. See ${DOC_URL(
`power`,