Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ added prisma schema for db creation #109

Merged
merged 4 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
auto-install-peers = true
enable-pre-post-scripts=true # Enable pre/post scripts (for postui:add)
enable-pre-post-scripts=true
2 changes: 1 addition & 1 deletion apps/web/app/(app)/loading/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@ultra-reporter/utils/xml-parser';
import { Bug, MoveLeft } from 'lucide-react';
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';
import { JSX, useEffect, useState } from 'react';

const LoadingPage = (): JSX.Element => {
const [progress, setProgress] = useState(0);
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/(app)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { HowItWorks } from '@ultra-reporter/ui/home/how-it-works';
import { NavBar } from '@ultra-reporter/ui/home/nav-bar';
import { OpenSource } from '@ultra-reporter/ui/home/open-source';
import { Sponsor } from '@ultra-reporter/ui/home/sponsor';
import { JSX } from 'react';

const LandingPage = (): JSX.Element => {
return (
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/(app)/results/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { columns } from '@ultra-reporter/ui/data-table/table/columns';
import { NavBar } from '@ultra-reporter/ui/home/nav-bar';
import { cn } from '@ultra-reporter/utils/cn';
import { FormattedData } from '@ultra-reporter/utils/types';
import { useEffect, useState } from 'react';
import { JSX, useEffect, useState } from 'react';

const chartConfig: ChartConfig = {
total: {
Expand Down
9 changes: 6 additions & 3 deletions apps/web/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { Button } from '@ultra-reporter/ui/components/button';
import { FileQuestion } from 'lucide-react';
import Link from 'next/link';
import { JSX } from 'react';

export default function NotFound() {
const NotFound = (): JSX.Element => {
return (
<div className='bg-background text-foreground flex min-h-screen flex-col items-center justify-center'>
<FileQuestion className='text-primary mb-8 h-24 w-24' />
<h1 className='mb-4 text-4xl font-bold'>404 - Page Not Found</h1>
<p className='mb-8 max-w-md text-center text-xl'>
Oops! It seems what you're looking for has gone missing in our data
Oops! It seems what you&apos;re looking for has gone missing in our data
center.
</p>
<Button asChild>
<Link href='/'>Return to Homepage</Link>
</Button>
</div>
);
}
};

export default NotFound;
18 changes: 9 additions & 9 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@
"start": "next start"
},
"peerDependencies": {
"react": "^18.0",
"react-dom": "^18.0"
"react": "^19.0",
"react-dom": "^19.0"
},
"dependencies": {
"@next/third-parties": "^15.0.3",
"@tanstack/react-table": "^8.20.5",
"@next/third-parties": "^15.1.2",
"@tanstack/react-table": "^8.20.6",
"@ultra-reporter/analytics": "workspace:*",
"@ultra-reporter/feature-toggle": "workspace:*",
"@ultra-reporter/ui": "workspace:*",
"@ultra-reporter/utils": "workspace:*",
"lucide-react": "^0.462.0",
"next": "15.0.3"
"lucide-react": "^0.469.0",
"next": "15.1.2"
},
"devDependencies": {
"@types/react": "^18.3.12",
"@types/react-dom": "^18",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@ultra-reporter/typescript-config": "workspace:*",
"postcss": "^8.4.49",
"tailwindcss": "^3.4.15"
"tailwindcss": "^3.4.17"
}
}
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "ultra-reporter-app",
"version": "0.6.0",
"private": true,
"license": "AGPL-3.0-or-later",
"workspaces": [
"packages/*",
"apps/*"
Expand All @@ -24,33 +25,33 @@
"release:prepatch": "pnpm beta prepatch"
},
"devDependencies": {
"@eslint/compat": "^1.2.3",
"@next/eslint-plugin-next": "^15.0.3",
"@eslint/compat": "^1.2.4",
"@next/eslint-plugin-next": "^15.1.2",
"@release-it-plugins/lerna-changelog": "^7.0.0",
"@stylistic/eslint-plugin-js": "^2.11.0",
"@stylistic/eslint-plugin-ts": "^2.11.0",
"@types/node": "^22.10.1",
"@typescript-eslint/eslint-plugin": "^8.16.0",
"@typescript-eslint/parser": "^8.16.0",
"@stylistic/eslint-plugin-js": "^2.12.1",
"@stylistic/eslint-plugin-ts": "^2.12.1",
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"@vercel/style-guide": "^6.0.0",
"eslint": "^9.16.0",
"eslint-config-next": "15.0.3",
"eslint": "^9.17.0",
"eslint-config-next": "15.1.2",
"eslint-config-prettier": "^9.1.0",
"eslint-config-turbo": "2.3.3",
"eslint-plugin-only-warn": "^1.1.0",
"eslint-plugin-prettier": "^5.2.1",
"globals": "^15.12.0",
"globals": "^15.14.0",
"husky": "^9.1.7",
"lerna-changelog": "^2.2.0",
"lint-staged": "^15.2.10",
"prettier": "^3.4.1",
"lint-staged": "^15.2.11",
"prettier": "^3.4.2",
"prettier-plugin-organize-imports": "^4.1.0",
"prettier-plugin-tailwindcss": "^0.6.9",
"release-it": "^17.10.0",
"release-it-pnpm": "^4.6.3",
"turbo": "^2.3.3",
"typescript": "^5.7.2",
"typescript-eslint": "^8.16.0"
"typescript-eslint": "^8.18.1"
},
"lint-staged": {
"**/*.{ts,tsx}": [
Expand All @@ -63,7 +64,7 @@
]
},
"engines": {
"node": ">=18"
"node": ">=20"
},
"packageManager": "pnpm@9.12.2"
"packageManager": "pnpm@9.15.0"
}
6 changes: 3 additions & 3 deletions packages/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"./client": "./src/client.tsx"
},
"dependencies": {
"@openpanel/nextjs": "^1.0.6",
"@openpanel/nextjs": "^1.0.7",
"@ultra-reporter/utils": "workspace:*",
"@vercel/functions": "^1.5.1"
"@vercel/functions": "^1.5.2"
},
"devDependencies": {
"@types/react": "^18.3.12",
"@types/react": "^19.0.2",
"@ultra-reporter/logger": "workspace:*",
"@ultra-reporter/typescript-config": "workspace:*"
}
Expand Down
22 changes: 22 additions & 0 deletions packages/db/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@ultra-reporter/db",
"description": "Ultra Reporter database schema handling",
"version": "0.6.0",
"private": true,
"scripts": {
"lint": "eslint . --max-warnings 0",
"db:generate": "prisma generate --schema=./src/schema",
"db:push": "prisma db push --schema=./src/schema --skip-generate",
"db:studio": "prisma studio --schema=./src/schema --browser none"
},
"exports": {
".": "./src/index.ts"
},
"dependencies": {
"@prisma/client": "^6.1.0"
},
"devDependencies": {
"@ultra-reporter/typescript-config": "workspace:*",
"prisma": "^6.1.0"
}
}
12 changes: 12 additions & 0 deletions packages/db/src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { PrismaClient } from '@prisma/client';

declare global {
// eslint-disable-next-line no-var
var prisma: PrismaClient | undefined;
}

export const db = globalThis.prisma || new PrismaClient();

if (process.env.NODE_ENV !== 'production') {
globalThis.prisma = db;
}
3 changes: 3 additions & 0 deletions packages/db/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// export * from '@prisma/client';
export * from './client';
export * from './users';
33 changes: 33 additions & 0 deletions packages/db/src/schema/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["prismaSchemaFolder"]
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id String @id @default(cuid())
user_name String
email String
provider String

created_at DateTime @default(now())
updated_at DateTime @updatedAt

LoginSession LoginSession[]
}

model LoginSession {
id String @id @default(cuid())
user_id String
last_login_at DateTime @default(now())
created_at DateTime @default(now())
updated_at DateTime @updatedAt

user User @relation(fields: [user_id], references: [id])

@@index([user_id])
}
80 changes: 80 additions & 0 deletions packages/db/src/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { db } from './client';

interface User {
id?: string;
userName: string;
email: string;
provider: string;
}

interface UserResponse {
data?: any;
error?: unknown;
}

const updateUser = async ({
id,
userName,
email,
provider,
}: User): Promise<UserResponse> => {
try {
const user = await db.user.update({
where: { id },
data: {
user_name: userName,
email,
provider,
},
});
return {
data: user,
};
} catch (error) {
return { error };
}
};

const createUser = async ({
userName,
email,
provider,
}: User): Promise<UserResponse> => {
try {
const user = await db.user.create({
data: {
user_name: userName,
email,
provider,
},
});
return { data: user };
} catch (error) {
return { error };
}
};

const getUser = async (id: string): Promise<UserResponse> => {
try {
const user = await db.user.findUnique({
where: { id },
});
return { data: user };
} catch (error) {
return { error };
}
};

const deleteUser = async (id: string): Promise<UserResponse> => {
try {
const user = await db.user.delete({
where: { id },
});
return { data: user };
} catch (error) {
return { error };
}
};

export { createUser, deleteUser, getUser, updateUser };
11 changes: 11 additions & 0 deletions packages/db/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "@ultra-reporter/typescript-config/react-library.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["src"],
"exclude": ["node_modules"]
}
10 changes: 5 additions & 5 deletions packages/feature-toggle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
"./provider": "./src/provider.tsx"
},
"devDependencies": {
"@types/react": "^18.3.12",
"@types/react-dom": "^18",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@ultra-reporter/typescript-config": "workspace:*"
},
"peerDependencies": {
"react": "^18.0",
"react-dom": "^18.0"
"react": "^19.0",
"react-dom": "^19.0"
},
"dependencies": {
"flagsmith": "^7.0.2"
"flagsmith": "^8.0.1"
}
}
2 changes: 1 addition & 1 deletion packages/feature-toggle/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { createFlagsmithInstance } from 'flagsmith/isomorphic';
import { FlagsmithProvider, useFlags } from 'flagsmith/react';
import { IFlagsmithFeature, IFlagsmithTrait, IState } from 'flagsmith/types';
import { useRef } from 'react';
import { JSX, useRef } from 'react';
import { Flags } from './flag-list';

interface FeatureProviderProps {
Expand Down
Loading
Loading