mirror of
https://github.com/soconnor0919/hristudio.git
synced 2025-12-12 07:04:44 -05:00
refactor(db): Improve table dropping and seeding logic
- Updated the dropAllTables function to drop tables in a specific order, considering foreign key dependencies, ensuring data integrity during the drop process. - Refactored the seed function to utilize role and permission data objects for cleaner insertion logic, enhancing readability and maintainability of the code.
This commit is contained in:
@@ -21,25 +21,29 @@ async function seed() {
|
||||
// Insert roles
|
||||
console.log("Inserting roles...");
|
||||
for (const [roleKey, roleName] of Object.entries(ROLES)) {
|
||||
const roleData = {
|
||||
name: roleName,
|
||||
description: getRoleDescription(roleKey),
|
||||
} as const;
|
||||
|
||||
await db
|
||||
.insert(rolesTable)
|
||||
.values({
|
||||
name: roleName,
|
||||
description: getRoleDescription(roleKey),
|
||||
})
|
||||
.values(roleData)
|
||||
.onConflictDoNothing();
|
||||
}
|
||||
|
||||
// Insert permissions
|
||||
console.log("Inserting permissions...");
|
||||
for (const [permKey, permCode] of Object.entries(PERMISSIONS)) {
|
||||
const permData = {
|
||||
name: formatPermissionName(permKey),
|
||||
code: permCode,
|
||||
description: getPermissionDescription(permKey),
|
||||
} as const;
|
||||
|
||||
await db
|
||||
.insert(permissionsTable)
|
||||
.values({
|
||||
name: formatPermissionName(permKey),
|
||||
code: permCode,
|
||||
description: getPermissionDescription(permKey),
|
||||
})
|
||||
.values(permData)
|
||||
.onConflictDoNothing();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user