feat: implement home page, business directory, and administrative management features with updated schema and API routes
Some checks failed
Build and Push App / build (push) Failing after 51s
Some checks failed
Build and Push App / build (push) Failing after 51s
This commit is contained in:
15
scratch/check-cats.ts
Normal file
15
scratch/check-cats.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
const prisma = new PrismaClient();
|
||||
async function check() {
|
||||
try {
|
||||
const count = await prisma.businessCategory.count();
|
||||
console.log('Category count:', count);
|
||||
const cats = await prisma.businessCategory.findMany({take: 5});
|
||||
console.log('Sample:', cats);
|
||||
} catch (e: any) {
|
||||
console.error('Error:', e.message);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
check();
|
||||
38
scratch/migrate-categories.ts
Normal file
38
scratch/migrate-categories.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
import pg from 'pg';
|
||||
import { config } from 'dotenv';
|
||||
|
||||
config();
|
||||
config({ path: '.env.local', override: true });
|
||||
|
||||
const connectionString = process.env.DATABASE_URL!;
|
||||
const pool = new pg.Pool({ connectionString });
|
||||
const adapter = new PrismaPg(pool);
|
||||
const prisma = new PrismaClient({ adapter });
|
||||
|
||||
async function migrate() {
|
||||
console.log('Starting migration...');
|
||||
const categories = await prisma.businessCategory.findMany();
|
||||
const categoryMap = new Map(categories.map(c => [c.name, c.id]));
|
||||
|
||||
const businesses = await prisma.business.findMany();
|
||||
let updatedCount = 0;
|
||||
|
||||
for (const biz of businesses) {
|
||||
const catId = categoryMap.get(biz.category);
|
||||
if (catId) {
|
||||
await prisma.business.update({
|
||||
where: { id: biz.id },
|
||||
data: { categoryId: catId }
|
||||
});
|
||||
updatedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Migration finished. Updated ${updatedCount} businesses.`);
|
||||
}
|
||||
|
||||
migrate()
|
||||
.catch(console.error)
|
||||
.finally(() => prisma.$disconnect());
|
||||
Reference in New Issue
Block a user