Initial commit - QR Master application
This commit is contained in:
135
prisma/schema.prisma
Normal file
135
prisma/schema.prisma
Normal file
@@ -0,0 +1,135 @@
|
||||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(cuid())
|
||||
email String @unique
|
||||
name String?
|
||||
password String?
|
||||
image String?
|
||||
emailVerified DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
qrCodes QRCode[]
|
||||
integrations Integration[]
|
||||
accounts Account[]
|
||||
sessions Session[]
|
||||
}
|
||||
|
||||
model Account {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
type String
|
||||
provider String
|
||||
providerAccountId String
|
||||
refresh_token String? @db.Text
|
||||
access_token String? @db.Text
|
||||
expires_at Int?
|
||||
token_type String?
|
||||
scope String?
|
||||
id_token String? @db.Text
|
||||
session_state String?
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([provider, providerAccountId])
|
||||
}
|
||||
|
||||
model Session {
|
||||
id String @id @default(cuid())
|
||||
sessionToken String @unique
|
||||
userId String
|
||||
expires DateTime
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
model VerificationToken {
|
||||
identifier String
|
||||
token String @unique
|
||||
expires DateTime
|
||||
|
||||
@@unique([identifier, token])
|
||||
}
|
||||
|
||||
model QRCode {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
title String
|
||||
type QRType @default(DYNAMIC)
|
||||
contentType ContentType @default(URL)
|
||||
content Json
|
||||
tags String[]
|
||||
status QRStatus @default(ACTIVE)
|
||||
style Json
|
||||
slug String @unique
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
scans QRScan[]
|
||||
|
||||
@@index([userId, createdAt])
|
||||
}
|
||||
|
||||
enum QRType {
|
||||
STATIC
|
||||
DYNAMIC
|
||||
}
|
||||
|
||||
enum ContentType {
|
||||
URL
|
||||
WIFI
|
||||
VCARD
|
||||
PHONE
|
||||
EMAIL
|
||||
SMS
|
||||
TEXT
|
||||
WHATSAPP
|
||||
}
|
||||
|
||||
enum QRStatus {
|
||||
ACTIVE
|
||||
PAUSED
|
||||
}
|
||||
|
||||
model QRScan {
|
||||
id String @id @default(cuid())
|
||||
qrId String
|
||||
ts DateTime @default(now())
|
||||
ipHash String
|
||||
userAgent String?
|
||||
device String?
|
||||
os String?
|
||||
country String?
|
||||
referrer String?
|
||||
utmSource String?
|
||||
utmMedium String?
|
||||
utmCampaign String?
|
||||
isUnique Boolean @default(false)
|
||||
|
||||
qr QRCode @relation(fields: [qrId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([qrId, ts])
|
||||
}
|
||||
|
||||
model Integration {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
provider String
|
||||
status String @default("inactive")
|
||||
config Json
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
108
prisma/seed.ts
Normal file
108
prisma/seed.ts
Normal file
@@ -0,0 +1,108 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
// Create demo user
|
||||
const hashedPassword = await bcrypt.hash('demo123', 12);
|
||||
|
||||
const user = await prisma.user.upsert({
|
||||
where: { email: 'demo@qrmaster.com' },
|
||||
update: {},
|
||||
create: {
|
||||
email: 'demo@qrmaster.com',
|
||||
name: 'Demo User',
|
||||
password: hashedPassword,
|
||||
},
|
||||
});
|
||||
|
||||
console.log('Created demo user:', user.email);
|
||||
|
||||
// Create demo QR codes
|
||||
const qrCodes = [
|
||||
{
|
||||
title: 'Support Phone',
|
||||
contentType: 'PHONE' as const,
|
||||
content: { phone: '+1-555-0123' },
|
||||
tags: ['support', 'contact'],
|
||||
slug: 'support-phone-demo',
|
||||
},
|
||||
{
|
||||
title: 'Event Details',
|
||||
contentType: 'URL' as const,
|
||||
content: { url: 'https://example.com/event-2025' },
|
||||
tags: ['event', 'conference'],
|
||||
slug: 'event-details-demo',
|
||||
},
|
||||
{
|
||||
title: 'Product Demo',
|
||||
contentType: 'URL' as const,
|
||||
content: { url: 'https://example.com/product-demo' },
|
||||
tags: ['product', 'demo'],
|
||||
slug: 'product-demo-qr',
|
||||
},
|
||||
{
|
||||
title: 'Company Website',
|
||||
contentType: 'URL' as const,
|
||||
content: { url: 'https://company.example.com' },
|
||||
tags: ['website', 'company'],
|
||||
slug: 'company-website-qr',
|
||||
},
|
||||
{
|
||||
title: 'Contact Email',
|
||||
contentType: 'EMAIL' as const,
|
||||
content: { email: 'contact@company.com', subject: 'Inquiry' },
|
||||
tags: ['contact', 'email'],
|
||||
slug: 'contact-email-qr',
|
||||
},
|
||||
{
|
||||
title: 'Event Details',
|
||||
contentType: 'URL' as const,
|
||||
content: { url: 'https://example.com/event-duplicate' },
|
||||
tags: ['event', 'duplicate'],
|
||||
slug: 'event-details-dup',
|
||||
},
|
||||
];
|
||||
|
||||
const baseDate = new Date('2025-08-07T10:00:00Z');
|
||||
|
||||
for (let i = 0; i < qrCodes.length; i++) {
|
||||
const qrData = qrCodes[i];
|
||||
const createdAt = new Date(baseDate.getTime() + i * 60000); // 1 minute apart
|
||||
|
||||
await prisma.qRCode.upsert({
|
||||
where: { slug: qrData.slug },
|
||||
update: {},
|
||||
create: {
|
||||
userId: user.id,
|
||||
title: qrData.title,
|
||||
type: 'DYNAMIC',
|
||||
contentType: qrData.contentType,
|
||||
content: qrData.content,
|
||||
tags: qrData.tags,
|
||||
status: 'ACTIVE',
|
||||
style: {
|
||||
foregroundColor: '#000000',
|
||||
backgroundColor: '#FFFFFF',
|
||||
cornerStyle: 'square',
|
||||
size: 200,
|
||||
},
|
||||
slug: qrData.slug,
|
||||
createdAt,
|
||||
updatedAt: createdAt,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
console.log('Created 6 demo QR codes');
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user