mirror of
https://github.com/Lifeforge-app/lifeforge.git
synced 2026-06-28 06:46:24 +00:00
fix: prevent duplicate indexes from being added to collections during migration generation.
This commit is contained in:
@@ -22,21 +22,30 @@ async function mapCollectionRelation(
|
||||
|
||||
const mapped = { ...raw }
|
||||
|
||||
const realCollectionId = allCollectionsInPB.find(
|
||||
const realCollection = allCollectionsInPB.find(
|
||||
collection => collection.name === raw.name
|
||||
)?.id
|
||||
)
|
||||
|
||||
if (!realCollectionId) {
|
||||
if (!realCollection?.id) {
|
||||
throw new Error(
|
||||
`Collection "${raw.name}" not found in PocketBase for relation field "${raw.name}"`
|
||||
)
|
||||
}
|
||||
|
||||
mapped.id = realCollectionId
|
||||
mapped.id = realCollection.id
|
||||
|
||||
delete mapped.created
|
||||
delete mapped.updated
|
||||
|
||||
for (const index of mapped.indexes) {
|
||||
const found = realCollection.indexes.find(idx => idx === index)
|
||||
|
||||
// If the index is already in the collection, we don't need to add it again
|
||||
if (found) {
|
||||
mapped.indexes = mapped.indexes.filter(idx => idx !== index)
|
||||
}
|
||||
}
|
||||
|
||||
if (mapped.fields && Array.isArray(mapped.fields)) {
|
||||
mapped.fields = mapped.fields.map(field => {
|
||||
const cleanedField = { ...field }
|
||||
|
||||
Reference in New Issue
Block a user