"feat: add Student model and migrate user-related data to UserMeta model, update schema and seed data"
This commit is contained in:
@@ -71,6 +71,15 @@ model VerificationToken {
|
|||||||
@@unique([identifier, token])
|
@@unique([identifier, token])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model Student {
|
||||||
|
id Int @id @default(autoincrement())
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
//
|
||||||
|
email String @unique
|
||||||
|
metadata Json @default("{}")
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------
|
// ----------------------------------------------------------------
|
||||||
// frontend/src/_mock/_user.ts
|
// frontend/src/_mock/_user.ts
|
||||||
|
|
||||||
@@ -525,6 +534,7 @@ model UserCard {
|
|||||||
totalFollowing Float
|
totalFollowing Float
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `UserItem` obsoleted, use `UserMeta` instead
|
||||||
model UserItem {
|
model UserItem {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
@@ -550,6 +560,31 @@ model UserItem {
|
|||||||
isAdmin Boolean @default(false)
|
isAdmin Boolean @default(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model UserMeta {
|
||||||
|
id String @id @default(uuid())
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
//
|
||||||
|
name String
|
||||||
|
city String
|
||||||
|
role String
|
||||||
|
email String
|
||||||
|
state String
|
||||||
|
status String
|
||||||
|
address String
|
||||||
|
country String
|
||||||
|
zipCode String
|
||||||
|
company String
|
||||||
|
avatarUrl String
|
||||||
|
phoneNumber String
|
||||||
|
isVerified Boolean
|
||||||
|
//
|
||||||
|
username String
|
||||||
|
password String
|
||||||
|
//
|
||||||
|
isAdmin Boolean @default(false)
|
||||||
|
}
|
||||||
|
|
||||||
model UserAccountBillingHistory {
|
model UserAccountBillingHistory {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
@@ -30,6 +30,7 @@ import { EventItemSeed } from './seeds/eventItem';
|
|||||||
import { EventReviewSeed } from './seeds/eventReview';
|
import { EventReviewSeed } from './seeds/eventReview';
|
||||||
import { appLogSeed } from './seeds/AppLog';
|
import { appLogSeed } from './seeds/AppLog';
|
||||||
import { accessLogSeed } from './seeds/AccessLog';
|
import { accessLogSeed } from './seeds/AccessLog';
|
||||||
|
import { userMetaSeed } from './seeds/userMeta';
|
||||||
|
|
||||||
//
|
//
|
||||||
// import { Blog } from './seeds/blog';
|
// import { Blog } from './seeds/blog';
|
||||||
@@ -46,7 +47,10 @@ import { accessLogSeed } from './seeds/AccessLog';
|
|||||||
await ProductReview;
|
await ProductReview;
|
||||||
await FileStore;
|
await FileStore;
|
||||||
await ProductItem;
|
await ProductItem;
|
||||||
|
|
||||||
await userItemSeed;
|
await userItemSeed;
|
||||||
|
await userMetaSeed;
|
||||||
|
|
||||||
await orderItemSeed;
|
await orderItemSeed;
|
||||||
await invoiceItemSeed;
|
await invoiceItemSeed;
|
||||||
//
|
//
|
||||||
|
130
03_source/cms_backend/prisma/seeds/userMeta.ts
Normal file
130
03_source/cms_backend/prisma/seeds/userMeta.ts
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
import { generateHash } from 'src/utils/hash';
|
||||||
|
import { Config, names, uniqueNamesGenerator } from 'unique-names-generator';
|
||||||
|
import { faker } from '@faker-js/faker';
|
||||||
|
|
||||||
|
import { faker as enFaker } from '@faker-js/faker/locale/en_US';
|
||||||
|
import { faker as zhFaker } from '@faker-js/faker/locale/zh_CN';
|
||||||
|
import { faker as jaFaker } from '@faker-js/faker/locale/ja';
|
||||||
|
import { faker as koFaker } from '@faker-js/faker/locale/ko';
|
||||||
|
import { faker as twFaker } from '@faker-js/faker/locale/zh_TW';
|
||||||
|
|
||||||
|
const SEED_EMAIL_DOMAIN = 'seed.com';
|
||||||
|
|
||||||
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
async function userMeta() {
|
||||||
|
const config: Config = { dictionaries: [names] };
|
||||||
|
const firstName = uniqueNamesGenerator(config);
|
||||||
|
const lastName = uniqueNamesGenerator(config);
|
||||||
|
const username = `${firstName.toLowerCase()}-${lastName.toLowerCase()}`;
|
||||||
|
|
||||||
|
const alice = await prisma.userMeta.upsert({
|
||||||
|
where: { id: 'admin_uuid' },
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
name: `admin test`,
|
||||||
|
city: '',
|
||||||
|
role: '',
|
||||||
|
email: `admin@123.com`,
|
||||||
|
state: '',
|
||||||
|
status: '',
|
||||||
|
address: '',
|
||||||
|
country: '',
|
||||||
|
zipCode: '',
|
||||||
|
company: '',
|
||||||
|
avatarUrl: '',
|
||||||
|
phoneNumber: '',
|
||||||
|
isVerified: true,
|
||||||
|
//
|
||||||
|
username: 'admin@123.com',
|
||||||
|
password: await generateHash('Aa1234567'),
|
||||||
|
//
|
||||||
|
isAdmin: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
for (let i = 1; i < 3; i++) {
|
||||||
|
const CJK_LOCALES = {
|
||||||
|
en: enFaker,
|
||||||
|
zh: zhFaker,
|
||||||
|
ja: jaFaker,
|
||||||
|
ko: koFaker,
|
||||||
|
tw: twFaker,
|
||||||
|
};
|
||||||
|
function getRandomCJKFaker() {
|
||||||
|
const locales = Object.keys(CJK_LOCALES);
|
||||||
|
const randomKey = locales[Math.floor(Math.random() * locales.length)] as keyof typeof CJK_LOCALES;
|
||||||
|
return CJK_LOCALES[randomKey];
|
||||||
|
}
|
||||||
|
const randomFaker = getRandomCJKFaker();
|
||||||
|
|
||||||
|
await prisma.userMeta.upsert({
|
||||||
|
where: { id: i.toString() },
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
name: randomFaker.person.fullName(),
|
||||||
|
city: randomFaker.location.city(),
|
||||||
|
role: ROLE[Math.floor(Math.random() * ROLE.length)],
|
||||||
|
email: randomFaker.internet.email(),
|
||||||
|
state: randomFaker.location.state(),
|
||||||
|
status: STATUS[Math.floor(Math.random() * STATUS.length)],
|
||||||
|
address: randomFaker.location.streetAddress(),
|
||||||
|
country: randomFaker.location.country(),
|
||||||
|
zipCode: randomFaker.location.zipCode(),
|
||||||
|
company: randomFaker.company.name(),
|
||||||
|
avatarUrl: randomFaker.image.avatar(),
|
||||||
|
phoneNumber: randomFaker.phone.number(),
|
||||||
|
isVerified: true,
|
||||||
|
//
|
||||||
|
username: randomFaker.internet.username(),
|
||||||
|
password: await generateHash('Abc1234!'),
|
||||||
|
//
|
||||||
|
isAdmin: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('seed userMeta done');
|
||||||
|
}
|
||||||
|
|
||||||
|
const userMetaSeed = userMeta()
|
||||||
|
.then(async () => {
|
||||||
|
await prisma.$disconnect();
|
||||||
|
})
|
||||||
|
.catch(async (e) => {
|
||||||
|
console.error(e);
|
||||||
|
await prisma.$disconnect();
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
export { userMetaSeed };
|
||||||
|
|
||||||
|
const ROLE = [
|
||||||
|
`CEO`,
|
||||||
|
`CTO`,
|
||||||
|
`Project Coordinator`,
|
||||||
|
`Team Leader`,
|
||||||
|
`Software Developer`,
|
||||||
|
`Marketing Strategist`,
|
||||||
|
`Data Analyst`,
|
||||||
|
`Product Owner`,
|
||||||
|
`Graphic Designer`,
|
||||||
|
`Operations Manager`,
|
||||||
|
`Customer Support Specialist`,
|
||||||
|
`Sales Manager`,
|
||||||
|
`HR Recruiter`,
|
||||||
|
`Business Consultant`,
|
||||||
|
`Financial Planner`,
|
||||||
|
`Network Engineer`,
|
||||||
|
`Content Creator`,
|
||||||
|
`Quality Assurance Tester`,
|
||||||
|
`Public Relations Officer`,
|
||||||
|
`IT Administrator`,
|
||||||
|
`Compliance Officer`,
|
||||||
|
`Event Planner`,
|
||||||
|
`Legal Counsel`,
|
||||||
|
`Training Coordinator`,
|
||||||
|
];
|
||||||
|
|
||||||
|
const STATUS = ['active', 'pending', 'banned'];
|
Reference in New Issue
Block a user