mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Finish migration prisma to drizzle.
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
import { PageParams } from "@/types/next";
|
||||
import * as drizzleDb from "@/db";
|
||||
|
||||
import { Page, PageContent, PageHeader, PageTitle } from "@/features/layout/page";
|
||||
import { AdminTabs } from "@/components/wrappers/dashboard/admin/admin-tabs";
|
||||
import { currentUser } from "@/lib/auth/current-user";
|
||||
import { db } from "@/db";
|
||||
import {eq, isNotNull, isNull} from "drizzle-orm";
|
||||
|
||||
|
||||
export default async function RoutePage(props: PageParams<{}>) {
|
||||
const user = await currentUser()!;
|
||||
const user = await currentUser();
|
||||
|
||||
const users = await db.query.user.findMany({
|
||||
where: (fields, { isNull, not }) => not(isNull(fields.deletedAt)),
|
||||
where: (fields) => isNull(fields.deletedAt)
|
||||
});
|
||||
// const users = await db.query.user.findMany();
|
||||
console.log("users",users);
|
||||
|
||||
const settings = await db.query.setting.findFirst({
|
||||
where: (fields, { eq }) => eq(fields.name, "system"),
|
||||
@@ -22,7 +27,7 @@ export default async function RoutePage(props: PageParams<{}>) {
|
||||
<PageTitle>Administration Panel</PageTitle>
|
||||
</PageHeader>
|
||||
<PageContent className="mt-10">
|
||||
<AdminTabs settings={settings!} currentUser={user} users={users} />
|
||||
<AdminTabs settings={settings!} users={users} />
|
||||
</PageContent>
|
||||
</Page>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import Link from "next/link";
|
||||
import {GearIcon} from "@radix-ui/react-icons";
|
||||
import {prisma} from "@/prisma";
|
||||
import {PageParams} from "@/types/next";
|
||||
import {Page, PageContent, PageDescription, PageTitle} from "@/features/layout/page";
|
||||
import {formatDateLastContact} from "@/utils/date-formatting";
|
||||
@@ -9,38 +8,55 @@ import {Card, CardContent, CardHeader} from "@/components/ui/card";
|
||||
import {CardsWithPagination} from "@/components/wrappers/common/cards-with-pagination";
|
||||
import {DatabaseCard} from "@/components/wrappers/dashboard/projects/ProjectCard/ProjectDatabaseCard";
|
||||
import {AgentCardKey} from "@/components/wrappers/dashboard/agent/AgentCardKey/AgentCardKey";
|
||||
import { db } from "@/db";
|
||||
import * as drizzleDb from "@/db";
|
||||
import {and, eq} from "drizzle-orm";
|
||||
import {notFound} from "next/navigation";
|
||||
|
||||
|
||||
export default async function RoutePage(props: PageParams<{ agentId: string }>) {
|
||||
|
||||
const {agentId} = await props.params
|
||||
|
||||
const agent = await prisma.agent.findUnique({
|
||||
where: {
|
||||
id: agentId,
|
||||
},
|
||||
include: {
|
||||
databases: {}
|
||||
const agent = await db.query.agent.findFirst({
|
||||
where: eq(drizzleDb.schemas.agent.id, agentId),
|
||||
with: {
|
||||
databases: true
|
||||
}
|
||||
})
|
||||
//
|
||||
console.log(agent)
|
||||
|
||||
const databaseId = 'db-123';
|
||||
|
||||
const totalBackups = await prisma.backup.count({
|
||||
where: {
|
||||
databaseId: databaseId,
|
||||
},
|
||||
});
|
||||
|
||||
const successfulBackups = await prisma.backup.count({
|
||||
where: {
|
||||
databaseId: databaseId,
|
||||
status: 'success',
|
||||
},
|
||||
});
|
||||
|
||||
const successRate = totalBackups > 0 ? (successfulBackups / totalBackups) * 100 : null
|
||||
|
||||
if (!agent) {
|
||||
notFound()
|
||||
}
|
||||
//
|
||||
// const databaseId = 'db-123';
|
||||
//
|
||||
// const totalBackupsResult = await db
|
||||
// .select({ count: drizzleDb.schemas.backup.id })
|
||||
// .from(drizzleDb.schemas.backup)
|
||||
// .where(eq(drizzleDb.schemas.backup.databaseId, databaseId))
|
||||
// .execute();
|
||||
//
|
||||
// const totalBackups = totalBackupsResult.length;
|
||||
//
|
||||
// const successfulBackupsResult = await db
|
||||
// .select({ count: drizzleDb.schemas.backup.id })
|
||||
// .from(drizzleDb.schemas.backup)
|
||||
// .where(
|
||||
// and(
|
||||
// eq(drizzleDb.schemas.backup.databaseId, databaseId),
|
||||
// eq(drizzleDb.schemas.backup.status, "success")
|
||||
// )
|
||||
// )
|
||||
// .execute();
|
||||
//
|
||||
//
|
||||
// const successfulBackups = successfulBackupsResult.length;
|
||||
//
|
||||
// const successRate =
|
||||
// totalBackups > 0 ? (successfulBackups / totalBackups) * 100 : null;
|
||||
|
||||
return (
|
||||
<Page>
|
||||
@@ -73,7 +89,7 @@ export default async function RoutePage(props: PageParams<{ agentId: string }>)
|
||||
Success rate
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{successRate ?? "Unavailable for now."}
|
||||
{/*{successRate ?? "Unavailable for now."}*/}
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card className="w-full sm:w-auto flex-1">
|
||||
|
||||
@@ -6,7 +6,6 @@ import Link from "next/link";
|
||||
import { Page, PageActions, PageContent, PageHeader, PageTitle } from "@/features/layout/page";
|
||||
import { notFound } from "next/navigation";
|
||||
import { db } from "@/db";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function RoutePage(props: PageParams<{}>) {
|
||||
const agents = await db.query.agent.findMany();
|
||||
|
||||
@@ -22,7 +22,7 @@ export default async function RoutePage(props: PageParams<{ projectId: string }>
|
||||
notFound();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
const org = await db.query.organization.findFirst({
|
||||
where: eq(drizzleDb.schemas.organization.slug, "default"),
|
||||
});
|
||||
|
||||
@@ -46,7 +46,7 @@ export default async function RoutePage(props: PageParams<{
|
||||
<div className="justify-between gap-2 sm:flex">
|
||||
<PageTitle className="flex items-center">
|
||||
{proj.name}
|
||||
<Link className={buttonVariants({ variant: "outline" })} href={`/dashboard/${organization.slug}/projects/${proj.id}/edit`}>
|
||||
<Link className={buttonVariants({ variant: "outline" })} href={`/dashboard/projects/${proj.id}/edit`}>
|
||||
<GearIcon className="w-7 h-7" />
|
||||
</Link>
|
||||
</PageTitle>
|
||||
|
||||
@@ -1,26 +1,19 @@
|
||||
import {PageParams} from "@/types/next";
|
||||
import {Page, PageContent, PageHeader, PageTitle} from "@/features/layout/page";
|
||||
import {getCurrentOrganizationSlug} from "@/features/dashboard/organization-cookie";
|
||||
import {prisma} from "@/prisma";
|
||||
import {requiredCurrentUser} from "@/auth/current-user";
|
||||
import {notFound} from "next/navigation";
|
||||
import {OrganizationForm} from "@/components/wrappers/dashboard/organization/OrganizationForm/OrganizationForm";
|
||||
import {getOrganization} from "@/lib/auth/auth";
|
||||
|
||||
|
||||
export default async function RoutePage(props: PageParams<{
|
||||
slug: string;
|
||||
|
||||
}>) {
|
||||
|
||||
const {slug: organizationSlug} = await props.params;
|
||||
|
||||
const organization = await getOrganization({organizationSlug});
|
||||
const organization = await getOrganization({});
|
||||
|
||||
if (!organization) {
|
||||
notFound()
|
||||
notFound();
|
||||
}
|
||||
|
||||
|
||||
return(
|
||||
<Page>
|
||||
<PageHeader>
|
||||
|
||||
@@ -3,9 +3,6 @@ import {Page, PageActions, PageContent, PageDescription, PageHeader, PageTitle}
|
||||
import {currentUser} from "@/lib/auth/current-user";
|
||||
import {getOrganization} from "@/lib/auth/auth";
|
||||
import {notFound} from "next/navigation";
|
||||
import {requiredCurrentUser} from "@/auth/current-user";
|
||||
import {SettingsTabs} from "@/components/wrappers/dashboard/settings/SettingsTabs/SettingsTabs";
|
||||
import {getCurrentOrganizationSlug} from "@/features/dashboard/organization-cookie";
|
||||
import {
|
||||
DeleteOrganizationButton
|
||||
} from "@/components/wrappers/dashboard/organization/DeleteOrganization/DeleteOrganizationButton";
|
||||
@@ -13,50 +10,13 @@ import {EditButtonSettings} from "@/components/wrappers/dashboard/settings/EditB
|
||||
|
||||
|
||||
export default async function RoutePage(props: PageParams<{ slug: string }>) {
|
||||
const {slug: organizationSlug} = await props.params;
|
||||
|
||||
const organization = await getOrganization({});
|
||||
const user = await currentUser();
|
||||
|
||||
const organization = await getOrganization({organizationSlug});
|
||||
|
||||
if (!organization || organization?.slug !== organizationSlug) {
|
||||
if (!organization) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// const organization = await prisma.organization.findUnique({
|
||||
// where: {
|
||||
// slug: currentOrganizationSlug,
|
||||
// },
|
||||
// include: {
|
||||
// users:{
|
||||
// include:{
|
||||
// user: {}
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// const currentOrganizationUser = await prisma.userOrganization.findFirst({
|
||||
// where:{
|
||||
// userId: user.id,
|
||||
// organization:{
|
||||
// slug: currentOrganizationSlug != "" ? currentOrganizationSlug : "default",
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// if (currentOrganizationUser.role != "admin") {
|
||||
// notFound()
|
||||
// }
|
||||
//
|
||||
//
|
||||
// const settings = await prisma.settings.findUnique({
|
||||
// where: {
|
||||
// name: "system"
|
||||
// }
|
||||
// })
|
||||
|
||||
return (
|
||||
<Page>
|
||||
<PageHeader>
|
||||
@@ -76,7 +36,7 @@ export default async function RoutePage(props: PageParams<{ slug: string }>) {
|
||||
Manage your organization settings.
|
||||
</PageDescription>
|
||||
<PageContent>
|
||||
{/*<SettingsTabs settings={settings} currentUser={user} users={organization.users}/>*/}
|
||||
{/* TODO add the list of organisation members (add, remove, edit) */}
|
||||
</PageContent>
|
||||
</Page>
|
||||
)
|
||||
|
||||
@@ -8,17 +8,17 @@ import { notFound } from "next/navigation";
|
||||
import { db } from "@/db";
|
||||
import { asc, count, eq, inArray } from "drizzle-orm";
|
||||
import * as drizzleDb from "@/db";
|
||||
import {getOrganization} from "@/lib/auth/auth";
|
||||
|
||||
export default async function RoutePage(props: PageParams<{ slug: string }>) {
|
||||
const { slug: organizationSlug } = await props.params;
|
||||
export default async function RoutePage(props: PageParams<{ }>) {
|
||||
const organization = await getOrganization({});
|
||||
|
||||
const currentOrganizationSlug = await getCurrentOrganizationSlug();
|
||||
if (currentOrganizationSlug !== organizationSlug) {
|
||||
if (!organization) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const org = await db.query.organization.findFirst({
|
||||
where: eq(drizzleDb.schemas.organization.slug, currentOrganizationSlug),
|
||||
where: eq(drizzleDb.schemas.organization.slug, organization.slug),
|
||||
});
|
||||
|
||||
if (!org) notFound();
|
||||
|
||||
Reference in New Issue
Block a user