mirror of
https://github.com/Lifeforge-app/lifeforge.git
synced 2026-06-28 14:55:45 +00:00
Former-commit-id: 84b8e07ff5794e9839cf1520f41d281f439c0fa5 [formerly ae751441bdab7c4aa8bd40aeb3ff1c2452065836] [formerly 30ae7721401cc7297602d0ca3d53bf5f26485787 [formerly 3d747773edfa69f506c5213c1d619d83f9f98bea]] Former-commit-id: 1e33f0617ba4c4e8909b5c7d61bf30892e4cee2d [formerly ea69c1708fa4b73d8cc3d71d01fc0556260e7030] Former-commit-id: 9b4a9835c82178c55794b683cc821916877522bf
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import fs from 'fs'
|
|
import Pocketbase from 'pocketbase'
|
|
|
|
if (!process.env.PB_HOST || !process.env.PB_EMAIL || !process.env.PB_PASSWORD) {
|
|
console.error(
|
|
'Please provide PB_HOST, PB_EMAIL, and PB_PASSWORD in your environment variables.'
|
|
)
|
|
process.exit(1)
|
|
}
|
|
|
|
const pb = new Pocketbase(process.env.PB_HOST)
|
|
|
|
try {
|
|
await pb
|
|
.collection('_superusers')
|
|
.authWithPassword(process.env.PB_EMAIL, process.env.PB_PASSWORD)
|
|
|
|
if (!pb.authStore.isSuperuser || !pb.authStore.isValid) {
|
|
console.error('Invalid credentials.')
|
|
process.exit(1)
|
|
}
|
|
} catch {
|
|
console.error('Invalid credentials.')
|
|
process.exit(1)
|
|
}
|
|
|
|
const schemaFiles = fs
|
|
.readdirSync('./src', { recursive: true })
|
|
.filter(file => typeof file === 'string' && file.endsWith('schema.json'))
|
|
|
|
console.log(`Found ${schemaFiles.length} schema files. Importing...`)
|
|
|
|
const allCollectionsSchemas = schemaFiles
|
|
.map(file => {
|
|
return JSON.parse(fs.readFileSync(`./src/${file}`, { encoding: 'utf-8' }))
|
|
})
|
|
.flat()
|
|
|
|
await pb.collections.import(allCollectionsSchemas)
|
|
|
|
console.log('Done.')
|