mirror of
https://github.com/pockethost/pockethost.git
synced 2025-03-30 15:08:30 +00:00
enh: adjust instance defaults migration
This commit is contained in:
parent
b229cd5c35
commit
67f8763dcf
@ -0,0 +1,38 @@
|
||||
migrate(
|
||||
(db) => {
|
||||
try {
|
||||
const APP_DEFAULTS = {
|
||||
appName: 'Acme',
|
||||
appUrl: 'http://localhost:8090',
|
||||
senderName: 'Support',
|
||||
senderAddress: 'support@example.com',
|
||||
}
|
||||
|
||||
const { PH_APP_NAME, PH_INSTANCE_URL, PH_APEX_DOMAIN } = process.env
|
||||
|
||||
const dao = new Dao(db)
|
||||
|
||||
const settings = dao.findSettings()
|
||||
if (!settings) {
|
||||
throw new Error(`Expected settings here`)
|
||||
}
|
||||
|
||||
const fix = (field, newValue) => {
|
||||
if (!newValue || settings.meta[field] !== APP_DEFAULTS[field]) return
|
||||
settings.meta[field] = newValue
|
||||
}
|
||||
const { hostname } = new URL(PH_INSTANCE_URL)
|
||||
fix(`appName`, PH_APP_NAME)
|
||||
fix(`appUrl`, PH_INSTANCE_URL)
|
||||
fix(`senderName`, PH_APP_NAME)
|
||||
fix(`senderAddress`, `${PH_APP_NAME}@${hostname}`)
|
||||
|
||||
dao.saveSettings(settings)
|
||||
} catch (e) {
|
||||
console.error(`***error applying defaults: ${e}`)
|
||||
}
|
||||
},
|
||||
(db) => {
|
||||
// add down queries...
|
||||
},
|
||||
)
|
@ -4,6 +4,7 @@ import {
|
||||
INSTANCE_APP_MIGRATIONS_DIR,
|
||||
mkAppUrl,
|
||||
mkDocUrl,
|
||||
mkEdgeUrl,
|
||||
MOTHERSHIP_NAME,
|
||||
} from '$constants'
|
||||
import {
|
||||
@ -254,7 +255,6 @@ export const instanceService = mkSingleton(
|
||||
name: instance.subdomain,
|
||||
slug: instance.id,
|
||||
port: newPort,
|
||||
env: instance.secrets || {},
|
||||
extraBinds: flatten([
|
||||
globSync(join(INSTANCE_APP_MIGRATIONS_DIR(), '*.js')).map(
|
||||
(file) =>
|
||||
@ -267,6 +267,11 @@ export const instanceService = mkSingleton(
|
||||
`${file}:/home/pocketbase/pb_hooks/${basename(file)}:ro`,
|
||||
),
|
||||
]),
|
||||
env: {
|
||||
...instance.secrets,
|
||||
PH_APP_NAME: instance.subdomain,
|
||||
PH_INSTANCE_URL: mkEdgeUrl(instance.subdomain),
|
||||
},
|
||||
version,
|
||||
})
|
||||
return cp
|
||||
|
Loading…
x
Reference in New Issue
Block a user