Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@
"superjson": "^2.2.5",
"zeptomail": "^6.2.1",
"zod": "^4.1.9"
},
"prisma": {
"seed": "tsx prisma/seed.ts"
}
}
130 changes: 130 additions & 0 deletions apps/api/prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { PrismaClient } from '@prisma/client';

const MILLIS_PER_YEAR = 365 * 24 * 60 * 60 * 1000;

const prisma = new PrismaClient();

async function main() {
console.log('🌱 Starting database seed...');

// Clear existing data (optional - only if you want fresh data each time)
// Uncomment if you want to reset data on each seed
// await prisma.payment.deleteMany();
// await prisma.subscription.deleteMany();
// await prisma.account.deleteMany();
// await prisma.user.deleteMany();
// await prisma.plan.deleteMany();

// Create test plan (1 rupee test plan)
const testPlan = await prisma.plan.upsert({
where: { id: '385b8215-d70f-473e-81c9-68a673c0d2fc-test' },
update: {},
create: {
id: '385b8215-d70f-473e-81c9-68a673c0d2fc-test',
name: 'Test Plan',
interval: 'yearly',
price: 100, // 1 rupee in paise
currency: 'INR',
},
});
console.log('✅ Created test plan:', testPlan.id);

// Create test user
const testUser = await prisma.user.upsert({
where: { email: 'test@example.com' },
update: {},
create: {
email: 'test@example.com',
firstName: 'Test User',
authMethod: 'google',
},
});
console.log('✅ Created test user:', testUser.email);

// Create test user with premium subscription
const premiumUser = await prisma.user.upsert({
where: { email: 'premium@example.com' },
update: {},
create: {
email: 'premium@example.com',
firstName: 'Premium User',
authMethod: 'github',
},
});
console.log('✅ Created premium user:', premiumUser.email);

// Create premium subscription for premium user
const existingSubscription = await prisma.subscription.findFirst({
where: {
userId: premiumUser.id,
},
});

const premiumSubscription = existingSubscription
? await prisma.subscription.update({
where: { id: existingSubscription.id },
data: {
planId: testPlan.id,
status: 'active',
startDate: new Date(),
endDate: new Date(Date.now() + MILLIS_PER_YEAR), // 1 year from now
autoRenew: true,
},
})
: await prisma.subscription.create({
data: {
userId: premiumUser.id,
planId: testPlan.id,
status: 'active',
startDate: new Date(),
endDate: new Date(Date.now() + MILLIS_PER_YEAR), // 1 year from now
autoRenew: true,
},
});
console.log('✅ Created/updated premium subscription');

// Create test payment
const testPayment = await prisma.payment.upsert({
where: {
razorpayPaymentId: 'pay_test_123456789',
},
update: {},
create: {
userId: premiumUser.id,
subscriptionId: premiumSubscription.id,
razorpayPaymentId: 'pay_test_123456789',
razorpayOrderId: 'order_test_123456789',
amount: 100, // 1 rupee in paise
currency: 'INR',
status: 'captured',
},
});
console.log('✅ Created test payment');

// Create QueryCount if it doesn't exist
try {
await prisma.queryCount.upsert({
where: { id: 1 },
update: {},
create: {
id: 1,
total_queries: BigInt(2212),
},
});
console.log('✅ Created QueryCount');
} catch (error) {
console.log('⚠️ QueryCount already exists or error:', error);
}

console.log('✅ Database seed completed successfully!');
}

main()
.catch((e) => {
console.error('❌ Error seeding database:', e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});

10 changes: 9 additions & 1 deletion apps/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,13 @@
"noUncheckedSideEffectImports": true,
"moduleDetection": "force",
"skipLibCheck": true,
}
},
"include": [
"src/**/*"
],
"exclude": [
"prisma",
"node_modules",
"dist"
]
}
4 changes: 2 additions & 2 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@repo/ui": "workspace:*",
"next": "14.2.15",
"next": "14.2.35",
"react": "18.3.1",
"react-dom": "18.3.1"
},
Expand All @@ -21,7 +21,7 @@
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.6",
"eslint-config-next": "14.2.35",
"typescript": "^5"
}
}
4 changes: 2 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"gray-matter": "^4.0.3",
"lucide-react": "^0.456.0",
"marked": "^17.0.0",
"next": "16.0.7",
"next": "16.0.10",
"next-auth": "^4.24.11",
"next-themes": "^0.4.3",
"posthog-js": "^1.203.1",
Expand All @@ -53,7 +53,7 @@
"@types/sanitize-html": "^2.16.0",
"depcheck": "^1.4.7",
"eslint": "^8",
"eslint-config-next": "16.0.7",
"eslint-config-next": "16.0.10",
"postcss": "^8",
"prettier": "^3.4.1",
"tailwindcss": "^3.4.1",
Expand Down
Loading