mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-04 01:55:10 +02:00
Add ensureActions
This commit is contained in:
parent
8213036729
commit
98ba10cb50
3 changed files with 42 additions and 1 deletions
38
server/db/ensureActions.ts
Normal file
38
server/db/ensureActions.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { ActionsEnum } from "@server/auth/actions";
|
||||
import { db } from "@server/db";
|
||||
import { actions } from "./schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
// Ensure actions are in the database
|
||||
export async function ensureActions() {
|
||||
const actionIds = Object.values(ActionsEnum);
|
||||
for (const actionId of actionIds) {
|
||||
const existing = await db
|
||||
.select()
|
||||
.from(actions)
|
||||
.where(eq(actions.name, actionId))
|
||||
.execute();
|
||||
if (existing.length === 0) {
|
||||
await db
|
||||
.insert(actions)
|
||||
.values({
|
||||
actionId
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
||||
// make sure all actions are in the database
|
||||
const existingActions = await db
|
||||
.select()
|
||||
.from(actions)
|
||||
.execute();
|
||||
for (const action of existingActions) {
|
||||
if (!actionIds.includes(action.actionId as ActionsEnum)) {
|
||||
await db
|
||||
.delete(actions)
|
||||
.where(eq(actions.actionId, action.actionId))
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -131,7 +131,7 @@ export const passwordResetTokens = sqliteTable("passwordResetTokens", {
|
|||
|
||||
export const actions = sqliteTable("actions", {
|
||||
actionId: text("actionId").primaryKey(),
|
||||
name: text("name").notNull(),
|
||||
name: text("name"),
|
||||
description: text("description"),
|
||||
});
|
||||
|
||||
|
|
|
@ -24,6 +24,9 @@ const externalPort = environment.EXTERNAL_PORT;
|
|||
const internalPort = environment.INTERNAL_PORT;
|
||||
|
||||
app.prepare().then(() => {
|
||||
|
||||
|
||||
|
||||
// External server
|
||||
const externalServer = express();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue