feat: add script and data to update state and city location options for CO, NE, ND, and SD
This commit is contained in:
54
prisma/update-location-options.ts
Normal file
54
prisma/update-location-options.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
import { Pool } from 'pg';
|
||||
import {
|
||||
US_STATES_CO_NE_ND_SD,
|
||||
US_CITIES_CO_NE_ND_SD,
|
||||
} from './data/us-cities-co-ne-nd-sd';
|
||||
|
||||
const connectionString = process.env.DATABASE_URL;
|
||||
if (!connectionString) {
|
||||
console.error('❌ DATABASE_URL env var is required');
|
||||
process.exit(1);
|
||||
}
|
||||
const pool = new Pool({ connectionString });
|
||||
const adapter = new PrismaPg(pool);
|
||||
const prisma = new PrismaClient({ adapter });
|
||||
|
||||
async function updateFieldOptions(slug: 'state' | 'city', options: unknown[]) {
|
||||
const fields = await prisma.profileField.findMany({
|
||||
where: { slug },
|
||||
select: { id: true, name: true, section: { select: { slug: true } } },
|
||||
});
|
||||
|
||||
if (fields.length === 0) {
|
||||
console.log(` ⚠️ No ProfileField rows found with slug="${slug}"`);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const field of fields) {
|
||||
await prisma.profileField.update({
|
||||
where: { id: field.id },
|
||||
data: { options: options as object },
|
||||
});
|
||||
console.log(
|
||||
` ✅ Updated ${field.section.slug}/${slug} (${options.length} options)`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('🌱 Updating state + city ProfileField options from Excel source...');
|
||||
await updateFieldOptions('state', US_STATES_CO_NE_ND_SD);
|
||||
await updateFieldOptions('city', US_CITIES_CO_NE_ND_SD);
|
||||
console.log('✅ Done.');
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error('❌ Failed to update location options:', e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user