Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
update orgname migration and revert changes to old migration
Browse files Browse the repository at this point in the history
  • Loading branch information
HexaField committed Aug 17, 2024
1 parent f2c2e79 commit 4b77f59
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,14 @@ export async function up(knex: Knex): Promise<void> {
for (const asset of assets) {
if (
asset.assetURL.startsWith('projects/default-project') &&
!asset.assetURL.startsWith('projects/etherealengine/default-project/public/scenes')
!asset.assetURL.startsWith('projects/default-project/public/scenes')
) {
await knex(assetPath)
.where({ id: asset.id })
.update({
assetURL: asset.assetURL.replace(
'projects/default-project',
'projects/etherealengine/default-project/public/scenes'
),
assetURL: asset.assetURL.replace('projects/default-project', 'projects/default-project/public/scenes'),
thumbnailURL: asset.thumbnailURL
? asset.thumbnailURL.replace(
'projects/default-project',
'projects/etherealengine/default-project/public/scenes'
)
? asset.thumbnailURL.replace('projects/default-project', 'projects/default-project/public/scenes')
: null
})
}
Expand All @@ -83,19 +77,13 @@ export async function down(knex: Knex): Promise<void> {
if (project) {
const assets = await knex.select().from(assetPath).where({ projectId: project.id })
for (const asset of assets) {
if (asset.assetURL.startsWith('projects/etherealengine/default-project/public/scenes')) {
if (asset.assetURL.startsWith('projects/default-project/public/scenes')) {
await knex(assetPath)
.where({ id: asset.id })
.update({
assetURL: asset.assetURL.replace(
'projects/etherealengine/default-project/public/scenes',
'projects/default-project'
),
assetURL: asset.assetURL.replace('projects/default-project/public/scenes', 'projects/default-project'),
thumbnailURL: asset.thumbnailURL
? asset.thumbnailURL.replace(
'projects/etherealengine/default-project/public/scenes',
'projects/default-project'
)
? asset.thumbnailURL.replace('projects/default-project/public/scenes', 'projects/default-project')
: null
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Ethereal Engine. All Rights Reserved.
import { ProjectType, projectPath } from '@etherealengine/common/src/schemas/projects/project.schema'
import type { Knex } from 'knex'

const routePath = 'route'
const staticResourcePath = 'static-resource'
const avatarPath = 'avatar'

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
Expand All @@ -38,16 +42,34 @@ export async function up(knex: Knex): Promise<void> {

for (const project of projects) {
if (project.name === 'default-project') {
const newName = 'etherealengine/default-project'
await knex(projectPath).where('id', project.id).update({
name: 'etherealengine/default-project'
name: newName
})
await knex(routePath).where('projectName', project.name).update({
projectName: newName
})
await knex(staticResourcePath).where('project', project.name).update({
project: newName
})
await knex(avatarPath).where('project', project.name).update({
project: newName
})
} else if (project.repositoryPath) {
const repositorySplit = project.repositoryPath.split('/')
await knex(projectPath)
.where('id', project.id)
.update({
name: `${repositorySplit[repositorySplit.length - 2].toLowerCase()}/${project.name}`
})
const newName = `${repositorySplit[repositorySplit.length - 2].toLowerCase()}/${project.name}`
await knex(projectPath).where('id', project.id).update({
name: newName
})
await knex(routePath).where('projectName', project.name).update({
projectName: newName
})
await knex(staticResourcePath).where('project', project.name).update({
project: newName
})
await knex(avatarPath).where('project', project.name).update({
project: newName
})
}
}
}
Expand All @@ -66,11 +88,20 @@ export async function down(knex: Knex): Promise<void> {
for (const project of projects) {
if (project.repositoryPath) {
const repositorySplit = project.repositoryPath.split('/')
await knex(projectPath)
.where('id', project.id)
.update({
name: `${repositorySplit[repositorySplit.length - 1]}`
})
const newName = `${repositorySplit[repositorySplit.length - 1]}`
const oldName = project.name
await knex(projectPath).where('id', project.id).update({
name: newName
})
await knex(routePath).where('projectName', oldName).update({
projectName: newName
})
await knex(staticResourcePath).where('project', oldName).update({
project: newName
})
await knex(avatarPath).where('project', oldName).update({
project: newName
})
}
}
}
Expand Down

0 comments on commit 4b77f59

Please sign in to comment.