♻️ Migrate from prisma to drizzle (#1434)
* ♻️ Migrate from prisma to drizzle * 🐛 Build issue with CalendarTile * 🚧 Temporary solution for docker container * 🐛 Drizzle not using DATABASE_URL * ♻️ Address pull request feedback * 🐛 Remove console log of env variables * 🐛 Some unit tests not working * 🐋 Revert docker tool changes * 🐛 Issue with board slug page for logged in users --------- Co-authored-by: Thomas Camlong <thomascamlong@gmail.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
import { useForm } from '@mantine/form';
|
||||
import { showNotification, updateNotification } from '@mantine/notifications';
|
||||
import { IconCheck, IconX } from '@tabler/icons-react';
|
||||
import { and, eq } from 'drizzle-orm';
|
||||
import { GetServerSideProps } from 'next';
|
||||
import { signIn } from 'next-auth/react';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
@@ -20,10 +21,11 @@ import { useRouter } from 'next/router';
|
||||
import { useState } from 'react';
|
||||
import { z } from 'zod';
|
||||
import { PasswordRequirements } from '~/components/Password/password-requirements';
|
||||
import { FloatingBackground } from '~/components/layout/Background/FloatingBackground';
|
||||
import { ThemeSchemeToggle } from '~/components/ThemeSchemeToggle/ThemeSchemeToggle';
|
||||
import { FloatingBackground } from '~/components/layout/Background/FloatingBackground';
|
||||
import { getServerAuthSession } from '~/server/auth';
|
||||
import { prisma } from '~/server/db';
|
||||
import { db } from '~/server/db';
|
||||
import { invites } from '~/server/db/schema';
|
||||
import { getServerSideTranslations } from '~/tools/server/getServerSideTranslations';
|
||||
import { api } from '~/utils/api';
|
||||
import { useI18nZodResolver } from '~/utils/i18n-zod-resolver';
|
||||
@@ -194,14 +196,14 @@ export const getServerSideProps: GetServerSideProps = async ({
|
||||
};
|
||||
}
|
||||
|
||||
const token = await prisma.invite.findUnique({
|
||||
where: {
|
||||
id: routeParams.data.inviteId,
|
||||
token: queryParams.data.token,
|
||||
},
|
||||
const dbInvite = await db.query.invites.findFirst({
|
||||
where: and(
|
||||
eq(invites.id, routeParams.data.inviteId),
|
||||
eq(invites.token, queryParams.data.token)
|
||||
),
|
||||
});
|
||||
|
||||
if (!token || token.expires < new Date()) {
|
||||
if (!dbInvite || dbInvite.expires < new Date()) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
|
||||
@@ -64,7 +64,7 @@ export const getServerSideProps: GetServerSideProps<BoardGetServerSideProps> = a
|
||||
const result = checkForSessionOrAskForLogin(
|
||||
ctx,
|
||||
session,
|
||||
() => config.settings.access.allowGuests || !session?.user
|
||||
() => config.settings.access.allowGuests || !!session?.user
|
||||
);
|
||||
if (result) {
|
||||
return result;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { GetServerSideProps, InferGetServerSidePropsType } from 'next';
|
||||
import { SSRConfig } from 'next-i18next';
|
||||
import { Dashboard } from '~/components/Dashboard/Dashboard';
|
||||
@@ -5,7 +6,9 @@ import { BoardLayout } from '~/components/layout/Templates/BoardLayout';
|
||||
import { useInitConfig } from '~/config/init';
|
||||
import { env } from '~/env';
|
||||
import { getServerAuthSession } from '~/server/auth';
|
||||
import { prisma } from '~/server/db';
|
||||
import { db } from '~/server/db';
|
||||
import { getDefaultBoardAsync } from '~/server/db/queries/userSettings';
|
||||
import { userSettings } from '~/server/db/schema';
|
||||
import { getFrontendConfig } from '~/tools/config/getFrontendConfig';
|
||||
import { getServerSideTranslations } from '~/tools/server/getServerSideTranslations';
|
||||
import { boardNamespaces } from '~/tools/server/translation-namespaces';
|
||||
@@ -32,11 +35,7 @@ type BoardGetServerSideProps = {
|
||||
|
||||
export const getServerSideProps: GetServerSideProps<BoardGetServerSideProps> = async (ctx) => {
|
||||
const session = await getServerAuthSession(ctx);
|
||||
const currentUserSettings = await prisma.userSettings.findFirst({
|
||||
where: {
|
||||
userId: session?.user?.id,
|
||||
},
|
||||
});
|
||||
const boardName = await getDefaultBoardAsync(session?.user?.id, 'default');
|
||||
|
||||
const translations = await getServerSideTranslations(
|
||||
boardNamespaces,
|
||||
@@ -44,7 +43,6 @@ export const getServerSideProps: GetServerSideProps<BoardGetServerSideProps> = a
|
||||
ctx.req,
|
||||
ctx.res
|
||||
);
|
||||
const boardName = currentUserSettings?.defaultBoard ?? 'default';
|
||||
const config = await getFrontendConfig(boardName);
|
||||
|
||||
if (!config.settings.access.allowGuests && !session?.user) {
|
||||
@@ -54,7 +52,7 @@ export const getServerSideProps: GetServerSideProps<BoardGetServerSideProps> = a
|
||||
primaryColor: config.settings.customization.colors.primary,
|
||||
secondaryColor: config.settings.customization.colors.secondary,
|
||||
primaryShade: config.settings.customization.colors.shade,
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import ContainerTable from '~/components/Manage/Tools/Docker/ContainerTable';
|
||||
import { ManageLayout } from '~/components/layout/Templates/ManageLayout';
|
||||
import { dockerRouter } from '~/server/api/routers/docker/router';
|
||||
import { getServerAuthSession } from '~/server/auth';
|
||||
import { prisma } from '~/server/db';
|
||||
import { getServerSideTranslations } from '~/tools/server/getServerSideTranslations';
|
||||
import { boardNamespaces } from '~/tools/server/translation-namespaces';
|
||||
import { api } from '~/utils/api';
|
||||
@@ -66,7 +65,6 @@ export const getServerSideProps: GetServerSideProps = async ({ locale, req, res
|
||||
const caller = dockerRouter.createCaller({
|
||||
session: session,
|
||||
cookies: req.cookies,
|
||||
prisma: prisma,
|
||||
});
|
||||
|
||||
const translations = await getServerSideTranslations(
|
||||
|
||||
@@ -148,7 +148,7 @@ const ManageUsersPage = () => {
|
||||
</tr>
|
||||
))}
|
||||
|
||||
{debouncedSearch && debouncedSearch.length > 0 && (
|
||||
{debouncedSearch && debouncedSearch.length > 0 && data.countPages === 0 && (
|
||||
<tr>
|
||||
<td colSpan={1}>
|
||||
<Box p={15}>
|
||||
|
||||
@@ -7,7 +7,8 @@ import Head from 'next/head';
|
||||
import { OnboardingSteps } from '~/components/Onboarding/onboarding-steps';
|
||||
import { ThemeSchemeToggle } from '~/components/ThemeSchemeToggle/ThemeSchemeToggle';
|
||||
import { FloatingBackground } from '~/components/layout/Background/FloatingBackground';
|
||||
import { prisma } from '~/server/db';
|
||||
import { db } from '~/server/db';
|
||||
import { getTotalUserCountAsync } from '~/server/db/queries/user';
|
||||
import { getConfig } from '~/tools/config/getConfig';
|
||||
import { getServerSideTranslations } from '~/tools/server/getServerSideTranslations';
|
||||
|
||||
@@ -32,11 +33,7 @@ export default function OnboardPage({
|
||||
<ThemeSchemeToggle pos="absolute" top={20} right={20} variant="default" />
|
||||
|
||||
<Stack h="100dvh" bg={background} spacing={0}>
|
||||
<Center
|
||||
bg={fn.linearGradient(145, colors.red[7], colors.red[5])}
|
||||
mih={150}
|
||||
h={150}
|
||||
>
|
||||
<Center bg={fn.linearGradient(145, colors.red[7], colors.red[5])} mih={150} h={150}>
|
||||
<Center bg={background} w={100} h={100} style={{ borderRadius: 64 }}>
|
||||
<Image width={70} src="/imgs/logo/logo-color.svg" alt="Homarr Logo" />
|
||||
</Center>
|
||||
@@ -72,7 +69,7 @@ export default function OnboardPage({
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const userCount = await prisma.user.count();
|
||||
const userCount = await getTotalUserCountAsync();
|
||||
if (userCount >= 1) {
|
||||
return {
|
||||
notFound: true,
|
||||
@@ -83,7 +80,12 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const configs = files.map((file) => getConfig(file));
|
||||
const configSchemaVersions = configs.map((config) => config.schemaVersion);
|
||||
|
||||
const translations = await getServerSideTranslations(['password-requirements'], ctx.locale, ctx.req, ctx.res);
|
||||
const translations = await getServerSideTranslations(
|
||||
['password-requirements'],
|
||||
ctx.locale,
|
||||
ctx.req,
|
||||
ctx.res
|
||||
);
|
||||
|
||||
return {
|
||||
props: {
|
||||
|
||||
Reference in New Issue
Block a user