mirror of
https://github.com/Lifeforge-app/lifeforge.git
synced 2026-06-28 14:55:45 +00:00
feat: implement migration cleanup and disable PocketBase automigrate during migration generation.
This commit is contained in:
32
bun.lock
32
bun.lock
@@ -62,6 +62,34 @@
|
||||
"shared": "workspace:*",
|
||||
},
|
||||
},
|
||||
"apps/lifeforge--movies": {
|
||||
"name": "@lifeforge/lifeforge--movies",
|
||||
"version": "0.0.5",
|
||||
"dependencies": {
|
||||
"qrcode.react": "^4.2.0",
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@lifeforge/server-utils": "workspace:*",
|
||||
"lifeforge-ui": "workspace:*",
|
||||
"shared": "workspace:*",
|
||||
},
|
||||
},
|
||||
"apps/lifeforge--pomodoro-timer": {
|
||||
"name": "@lifeforge/lifeforge--pomodoro-timer",
|
||||
"version": "0.0.5",
|
||||
"dependencies": {
|
||||
"culori": "^4.0.2",
|
||||
"react-virtualized": "^9.22.6",
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react-virtualized": "^9.22.3",
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@lifeforge/server-utils": "workspace:*",
|
||||
"lifeforge-ui": "workspace:*",
|
||||
"shared": "workspace:*",
|
||||
},
|
||||
},
|
||||
"client": {
|
||||
"name": "@lifeforge/client",
|
||||
"version": "0.0.0",
|
||||
@@ -654,6 +682,10 @@
|
||||
|
||||
"@lifeforge/lifeforge--achievements": ["@lifeforge/lifeforge--achievements@workspace:apps/lifeforge--achievements"],
|
||||
|
||||
"@lifeforge/lifeforge--movies": ["@lifeforge/lifeforge--movies@workspace:apps/lifeforge--movies"],
|
||||
|
||||
"@lifeforge/lifeforge--pomodoro-timer": ["@lifeforge/lifeforge--pomodoro-timer@workspace:apps/lifeforge--pomodoro-timer"],
|
||||
|
||||
"@lifeforge/log": ["@lifeforge/log@workspace:packages/lifeforge-log"],
|
||||
|
||||
"@lifeforge/server": ["@lifeforge/server@workspace:server"],
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import fs from 'fs'
|
||||
|
||||
import { PB_MIGRATIONS_DIR } from '@/constants/db'
|
||||
import logger from '@/utils/logger'
|
||||
|
||||
/**
|
||||
* Cleans up old migrations
|
||||
*/
|
||||
export async function cleanupOldMigrations(): Promise<void> {
|
||||
try {
|
||||
logger.debug('Cleaning up old migrations directory...')
|
||||
|
||||
fs.rmSync(PB_MIGRATIONS_DIR, { recursive: true, force: true })
|
||||
} catch {
|
||||
// Migrations directory doesn't exist, no cleanup needed
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,6 @@ export default async function generateContent(
|
||||
pb: Pocketbase,
|
||||
schema: Record<string, { raw: CollectionModel }>
|
||||
) {
|
||||
// console.log(await pb.collections.getFullList())
|
||||
|
||||
for (const [_, { raw }] of Object.entries(schema)) {
|
||||
const collectionName = raw.name as string
|
||||
|
||||
@@ -39,7 +37,7 @@ export default async function generateContent(
|
||||
continue
|
||||
}
|
||||
|
||||
const stubCollection: Record<string, unknown> = {
|
||||
const stubCollection: Partial<CollectionModel> = {
|
||||
name: collectionName,
|
||||
type: raw.type || 'base',
|
||||
listRule: raw.listRule,
|
||||
@@ -49,6 +47,8 @@ export default async function generateContent(
|
||||
deleteRule: raw.deleteRule
|
||||
}
|
||||
|
||||
console.log(stubCollection)
|
||||
|
||||
// View collections require a viewQuery
|
||||
if (raw.type === 'view') {
|
||||
// Use placeholder query with required id column - real query will be set in structure migration
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import logger from '@/utils/logger'
|
||||
import getPBInstance from '@/utils/pocketbase'
|
||||
|
||||
import { cleanupOldMigrations } from '../functions/migration-generation/cleanupOldMigrations'
|
||||
import stageMigration from '../functions/migration-generation/stageMigrations'
|
||||
import { importSchemaModules } from '../utils'
|
||||
|
||||
@@ -10,17 +11,20 @@ import { importSchemaModules } from '../utils'
|
||||
export async function generateMigrationsHandler(
|
||||
targetModule?: string
|
||||
): Promise<void> {
|
||||
cleanupOldMigrations()
|
||||
|
||||
const { pb, killPB } = await getPBInstance()
|
||||
|
||||
try {
|
||||
const importedSchemas = await importSchemaModules(targetModule)
|
||||
|
||||
const { pb, killPB } = await getPBInstance()
|
||||
|
||||
for (const [index, phase] of Object.entries([
|
||||
'skeleton',
|
||||
'structure',
|
||||
'views'
|
||||
] as const)) {
|
||||
await stageMigration(pb, phase, Number(index), importedSchemas)
|
||||
cleanupOldMigrations()
|
||||
}
|
||||
|
||||
killPB?.()
|
||||
@@ -34,6 +38,8 @@ export async function generateMigrationsHandler(
|
||||
logger.debug(
|
||||
`Error details: ${error instanceof Error ? error.message : String(error)}`
|
||||
)
|
||||
|
||||
killPB?.()
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ export default function cleanModuleSource(targetDir: string): void {
|
||||
// Clean client directory - keep only dist and dist-docker
|
||||
if (fs.existsSync(clientDir)) {
|
||||
for (const item of fs.readdirSync(clientDir)) {
|
||||
if (item !== 'dist' && item !== 'dist-docker') {
|
||||
if (item !== 'dist' && item !== 'dist-docker' && item !== 'assets') {
|
||||
const itemPath = path.join(clientDir, item)
|
||||
|
||||
fs.rmSync(itemPath, { recursive: true, force: true })
|
||||
|
||||
@@ -28,7 +28,8 @@ export const PB_BINARY_PATH = path.resolve(
|
||||
|
||||
export const PB_KWARGS = [
|
||||
`--dir=${PB_DATA_DIR}`,
|
||||
`--migrationsDir=${PB_MIGRATIONS_DIR}`
|
||||
`--migrationsDir=${PB_MIGRATIONS_DIR}`,
|
||||
'--automigrate=0'
|
||||
]
|
||||
|
||||
// Straightaway exit if PB_DIR is not accessible (skip in Docker mode)
|
||||
|
||||
Reference in New Issue
Block a user