2024-08-11 12:03:11 +02:00
|
|
|
// import bcrypt from 'bcrypt';
|
|
|
|
// import { db } from '@vercel/postgres';
|
2024-08-11 12:34:16 +02:00
|
|
|
// import { guests, customers, revenue, users } from '../lib/placeholder-data';
|
2024-08-11 12:03:11 +02:00
|
|
|
|
|
|
|
// const client = await db.connect();
|
|
|
|
|
|
|
|
// async function seedUsers() {
|
|
|
|
// await client.sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`;
|
|
|
|
// await client.sql`
|
|
|
|
// CREATE TABLE IF NOT EXISTS users (
|
|
|
|
// id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
|
|
|
|
// name VARCHAR(255) NOT NULL,
|
|
|
|
// email TEXT NOT NULL UNIQUE,
|
|
|
|
// password TEXT NOT NULL
|
|
|
|
// );
|
|
|
|
// `;
|
|
|
|
|
|
|
|
// const insertedUsers = await Promise.all(
|
|
|
|
// users.map(async (user) => {
|
|
|
|
// const hashedPassword = await bcrypt.hash(user.password, 10);
|
|
|
|
// return client.sql`
|
|
|
|
// INSERT INTO users (id, name, email, password)
|
|
|
|
// VALUES (${user.id}, ${user.name}, ${user.email}, ${hashedPassword})
|
|
|
|
// ON CONFLICT (id) DO NOTHING;
|
|
|
|
// `;
|
|
|
|
// }),
|
|
|
|
// );
|
|
|
|
|
|
|
|
// return insertedUsers;
|
|
|
|
// }
|
|
|
|
|
2024-08-11 12:34:16 +02:00
|
|
|
// async function seedguests() {
|
2024-08-11 12:03:11 +02:00
|
|
|
// await client.sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`;
|
|
|
|
|
|
|
|
// await client.sql`
|
2024-08-11 12:34:16 +02:00
|
|
|
// CREATE TABLE IF NOT EXISTS guests (
|
2024-08-11 12:03:11 +02:00
|
|
|
// id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
|
|
|
|
// customer_id UUID NOT NULL,
|
|
|
|
// amount INT NOT NULL,
|
|
|
|
// status VARCHAR(255) NOT NULL,
|
|
|
|
// date DATE NOT NULL
|
|
|
|
// );
|
|
|
|
// `;
|
|
|
|
|
2024-08-11 12:34:16 +02:00
|
|
|
// const insertedguests = await Promise.all(
|
|
|
|
// guests.map(
|
2024-08-11 12:03:11 +02:00
|
|
|
// (invoice) => client.sql`
|
2024-08-11 12:34:16 +02:00
|
|
|
// INSERT INTO guests (customer_id, amount, status, date)
|
2024-08-11 12:03:11 +02:00
|
|
|
// VALUES (${invoice.customer_id}, ${invoice.amount}, ${invoice.status}, ${invoice.date})
|
|
|
|
// ON CONFLICT (id) DO NOTHING;
|
|
|
|
// `,
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
|
2024-08-11 12:34:16 +02:00
|
|
|
// return insertedguests;
|
2024-08-11 12:03:11 +02:00
|
|
|
// }
|
|
|
|
|
|
|
|
// async function seedCustomers() {
|
|
|
|
// await client.sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`;
|
|
|
|
|
|
|
|
// await client.sql`
|
|
|
|
// CREATE TABLE IF NOT EXISTS customers (
|
|
|
|
// id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
|
|
|
|
// name VARCHAR(255) NOT NULL,
|
|
|
|
// email VARCHAR(255) NOT NULL,
|
|
|
|
// image_url VARCHAR(255) NOT NULL
|
|
|
|
// );
|
|
|
|
// `;
|
|
|
|
|
|
|
|
// const insertedCustomers = await Promise.all(
|
|
|
|
// customers.map(
|
|
|
|
// (customer) => client.sql`
|
|
|
|
// INSERT INTO customers (id, name, email, image_url)
|
|
|
|
// VALUES (${customer.id}, ${customer.name}, ${customer.email}, ${customer.image_url})
|
|
|
|
// ON CONFLICT (id) DO NOTHING;
|
|
|
|
// `,
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
|
|
|
|
// return insertedCustomers;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// async function seedRevenue() {
|
|
|
|
// await client.sql`
|
|
|
|
// CREATE TABLE IF NOT EXISTS revenue (
|
|
|
|
// month VARCHAR(4) NOT NULL UNIQUE,
|
|
|
|
// revenue INT NOT NULL
|
|
|
|
// );
|
|
|
|
// `;
|
|
|
|
|
|
|
|
// const insertedRevenue = await Promise.all(
|
|
|
|
// revenue.map(
|
|
|
|
// (rev) => client.sql`
|
|
|
|
// INSERT INTO revenue (month, revenue)
|
|
|
|
// VALUES (${rev.month}, ${rev.revenue})
|
|
|
|
// ON CONFLICT (month) DO NOTHING;
|
|
|
|
// `,
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
|
|
|
|
// return insertedRevenue;
|
|
|
|
// }
|
|
|
|
|
|
|
|
export async function GET() {
|
|
|
|
return Response.json({
|
|
|
|
message:
|
|
|
|
'Uncomment this file and remove this line. You can delete this file when you are finished.',
|
|
|
|
});
|
|
|
|
// try {
|
|
|
|
// await client.sql`BEGIN`;
|
|
|
|
// await seedUsers();
|
|
|
|
// await seedCustomers();
|
2024-08-11 12:34:16 +02:00
|
|
|
// await seedguests();
|
2024-08-11 12:03:11 +02:00
|
|
|
// await seedRevenue();
|
|
|
|
// await client.sql`COMMIT`;
|
|
|
|
|
|
|
|
// return Response.json({ message: 'Database seeded successfully' });
|
|
|
|
// } catch (error) {
|
|
|
|
// await client.sql`ROLLBACK`;
|
|
|
|
// return Response.json({ error }, { status: 500 });
|
|
|
|
// }
|
|
|
|
}
|