115 lines
2.9 KiB
JavaScript
115 lines
2.9 KiB
JavaScript
import { PrismaClient } from '@prisma/client'
|
|
|
|
/**
|
|
* Fix misclassified tenant: new.gholaktala.ir is Hamkar (user calls /site/settings),
|
|
* not Khanegi modular. Run on production API host:
|
|
* set -a && . ./.env && set +a && node scripts/fix-gholaktala-to-hamkar.mjs
|
|
*/
|
|
const prisma = new PrismaClient()
|
|
const APPLY = process.argv.includes('--apply')
|
|
const DOMAIN = 'new.gholaktala.ir'
|
|
|
|
function bumpAppVersion(current) {
|
|
const v = String(current || '1').trim() || '1'
|
|
if (/^\d+$/.test(v)) return String(Number(v) + 1)
|
|
const semver = v.match(/^(\d+)\.(\d+)\.(\d+)$/)
|
|
if (semver) return `${semver[1]}.${semver[2]}.${Number(semver[3]) + 1}`
|
|
return String(Date.now())
|
|
}
|
|
|
|
async function main() {
|
|
const tenants = await prisma.tenant.findMany({
|
|
where: {
|
|
OR: [
|
|
{ domain: { contains: 'gholaktala', mode: 'insensitive' } },
|
|
{ domains: { string_contains: 'gholaktala' } },
|
|
{ slug: { contains: 'gholak', mode: 'insensitive' } },
|
|
],
|
|
},
|
|
select: {
|
|
id: true,
|
|
nameFa: true,
|
|
domain: true,
|
|
domains: true,
|
|
slug: true,
|
|
product: true,
|
|
uiVariant: true,
|
|
appVersion: true,
|
|
nodeServer: true,
|
|
notes: true,
|
|
},
|
|
})
|
|
|
|
console.log(
|
|
'MATCHES',
|
|
JSON.stringify(
|
|
tenants.map((t) => ({
|
|
id: t.id,
|
|
domain: t.domain,
|
|
product: t.product,
|
|
uiVariant: t.uiVariant,
|
|
appVersion: t.appVersion,
|
|
})),
|
|
null,
|
|
2,
|
|
),
|
|
)
|
|
|
|
const tenant =
|
|
tenants.find((t) => String(t.domain).toLowerCase() === DOMAIN) ||
|
|
tenants.find((t) => String(t.domain).toLowerCase().includes('new.gholaktala'))
|
|
|
|
if (!tenant) throw new Error(`Tenant not found for ${DOMAIN}`)
|
|
|
|
console.log('SELECTED', tenant)
|
|
|
|
if (!APPLY) {
|
|
console.log('DRY_RUN — re-run with --apply to set product=hamkar')
|
|
return
|
|
}
|
|
|
|
const nextVersion = bumpAppVersion(tenant.appVersion)
|
|
const full = await prisma.tenant.findUnique({ where: { id: tenant.id } })
|
|
const ui = full?.appUiConfig
|
|
const keepUi =
|
|
ui && typeof ui === 'object' && !Array.isArray(ui) && ui.kind === 'hamkar'
|
|
? ui
|
|
: null
|
|
|
|
const updated = await prisma.tenant.update({
|
|
where: { id: tenant.id },
|
|
data: {
|
|
product: 'hamkar',
|
|
appUiConfig: keepUi,
|
|
appVersion: nextVersion,
|
|
notes: [
|
|
String(tenant.notes || '')
|
|
.replace(/\s*\|?\s*misclassified-as-khanegi/g, '')
|
|
.trim(),
|
|
'product=hamkar (fixed; was wrongly khanegi/modular)',
|
|
]
|
|
.filter(Boolean)
|
|
.join(' | '),
|
|
},
|
|
})
|
|
|
|
console.log('UPDATED', {
|
|
id: updated.id,
|
|
domain: updated.domain,
|
|
product: updated.product,
|
|
appVersion: updated.appVersion,
|
|
})
|
|
console.log(
|
|
'NOTE: Live frontend is Hamkar (/site/settings). Server must be Hamkar Laravel too — Khanegi api/get_settings alone is not enough.',
|
|
)
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e)
|
|
process.exitCode = 1
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect()
|
|
})
|