-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,054 additions
and
6,671 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,12 +28,6 @@ const customers = [ | |
email: '[email protected]', | ||
image_url: '/customers/lee-robinson.png', | ||
}, | ||
{ | ||
id: '3958dc9e-787f-4377-85e9-fec4b6a6442a', | ||
name: 'Steph Dietz', | ||
email: '[email protected]', | ||
image_url: '/customers/steph-dietz.png', | ||
}, | ||
{ | ||
id: '76d65c26-f784-44a2-ac19-586678f7c2f2', | ||
name: 'Michael Novotny', | ||
|
@@ -86,7 +80,7 @@ const invoices = [ | |
date: '2023-08-05', | ||
}, | ||
{ | ||
customer_id: customers[7].id, | ||
customer_id: customers[2].id, | ||
amount: 54246, | ||
status: 'pending', | ||
date: '2023-07-16', | ||
|
@@ -150,9 +144,4 @@ const revenue = [ | |
{ month: 'Dec', revenue: 4800 }, | ||
]; | ||
|
||
module.exports = { | ||
users, | ||
customers, | ||
invoices, | ||
revenue, | ||
}; | ||
export { users, customers, invoices, revenue }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import bcrypt from 'bcrypt'; | ||
import { db } from '@vercel/postgres'; | ||
import { invoices, customers, revenue, users } from '../lib/placeholder-data'; | ||
|
||
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; | ||
} | ||
|
||
async function seedInvoices() { | ||
await client.sql`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`; | ||
|
||
await client.sql` | ||
CREATE TABLE IF NOT EXISTS invoices ( | ||
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 | ||
); | ||
`; | ||
|
||
const insertedInvoices = await Promise.all( | ||
invoices.map( | ||
(invoice) => client.sql` | ||
INSERT INTO invoices (customer_id, amount, status, date) | ||
VALUES (${invoice.customer_id}, ${invoice.amount}, ${invoice.status}, ${invoice.date}) | ||
ON CONFLICT (id) DO NOTHING; | ||
`, | ||
), | ||
); | ||
|
||
return insertedInvoices; | ||
} | ||
|
||
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() { | ||
try { | ||
await client.sql`BEGIN`; | ||
await seedUsers(); | ||
await seedCustomers(); | ||
await seedInvoices(); | ||
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 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
/** @type {import('next').NextConfig} */ | ||
|
||
const nextConfig = { | ||
experimental: { | ||
ppr: 'incremental', | ||
}, | ||
}; | ||
const nextConfig = {}; | ||
|
||
export default nextConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.