-
Notifications
You must be signed in to change notification settings - Fork 42
Add app version metadata to Project settings (fixes #167) #170
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
base: main
Are you sure you want to change the base?
Changes from all commits
a839c40
3c1f493
3bffb71
8ccf0fe
d0de098
fc2bf15
4391f9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { env } from '../env'; | ||
| import { adminProtectedProcedure } from './trpc'; | ||
|
|
||
| export const systemRoutes = { | ||
| version: adminProtectedProcedure.query(() => ({ | ||
| version: env.APP_VERSION, | ||
| commit: env.APP_COMMIT, | ||
| buildDate: env.APP_BUILD_DATE, | ||
| })), | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,9 @@ import { NewUser } from '../src/db/abstractSchema'; | |
| import { user } from '../src/db/pgSchema'; | ||
| import * as pgSchema from '../src/db/pgSchema'; | ||
|
|
||
| const db = drizzle(process.env.DB_URI!, { schema: pgSchema }); | ||
| const db = drizzle(process.env.DB_URI || '', { schema: pgSchema }); | ||
|
|
||
| describe('userTable', () => { | ||
| (process.env.DB_URI ? describe : describe.skip)('userTable', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why u need to change this. |
||
| const testUser: NewUser = { | ||
| id: 'test-user-id', | ||
| name: 'John', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { defineConfig } from 'vitest/config'; | ||
| import base from '../frontend/vite.config'; | ||
|
|
||
| const baseConfig = base as unknown as { test?: Record<string, unknown> }; | ||
|
|
||
| export default defineConfig({ | ||
| ...base, | ||
| test: { | ||
| ...(baseConfig.test ?? {}), | ||
| // Run migrations once in the main process before workers start | ||
| globalSetup: './vitest.setup.ts', | ||
| }, | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import fs from 'fs'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have a few eslint warnings. |
||
| import path from 'path'; | ||
| import Database from 'better-sqlite3'; | ||
|
|
||
| async function runMigrations() { | ||
| // Ensure a fresh sqlite DB for tests | ||
| const DB_PATH = path.resolve(process.cwd(), 'db.sqlite'); | ||
| if (fs.existsSync(DB_PATH)) { | ||
| try { | ||
| fs.unlinkSync(DB_PATH); | ||
| } catch { | ||
| // ignore | ||
| } | ||
| } | ||
|
|
||
| // Create DB file and run sqlite migrations | ||
| const db = new Database(DB_PATH); | ||
| const migrationsDir = path.resolve(process.cwd(), 'migrations-sqlite'); | ||
| if (fs.existsSync(migrationsDir)) { | ||
| const files = fs | ||
| .readdirSync(migrationsDir) | ||
| .filter((f) => f.endsWith('.sql')) | ||
| .sort(); | ||
| for (const file of files) { | ||
| const content = fs.readFileSync(path.join(migrationsDir, file), 'utf8'); | ||
| const stmts = content | ||
| .split('--> statement-breakpoint') | ||
| .map((s) => s.trim()) | ||
| .filter(Boolean); | ||
| for (const stmt of stmts) { | ||
| if (stmt) { | ||
| try { | ||
| db.exec(stmt); | ||
| } catch (err: unknown) { | ||
| let msg = ''; | ||
| if (err instanceof Error) msg = err.message; | ||
| else msg = String(err); | ||
| // Ignore "already exists" / duplicate column errors so setup is idempotent | ||
| if (/already exists|duplicate column/i.test(msg)) { | ||
| continue; | ||
| } | ||
| throw err; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| db.close(); | ||
| } | ||
|
|
||
| export default async function () { | ||
| await runMigrations(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,8 +40,11 @@ function ProjectPage() { | |
| const { tab } = Route.useSearch(); | ||
| const activeTab = tab ?? 'project'; | ||
| const project = useQuery(trpc.project.getCurrent.queryOptions()); | ||
|
|
||
| const isAdmin = project.data?.userRole === 'admin'; | ||
| const appVersion = useQuery({ | ||
| ...trpc.system.version.queryOptions(), | ||
| enabled: isAdmin, | ||
| }); | ||
|
|
||
| return ( | ||
| <div className='flex flex-row gap-6'> | ||
|
|
@@ -90,6 +93,55 @@ function ProjectPage() { | |
| <SettingsCard title='Google Credentials'> | ||
| <GoogleConfigSection isAdmin={isAdmin} /> | ||
| </SettingsCard> | ||
|
|
||
| {isAdmin && ( | ||
| <SettingsCard title='Application'> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using inputs can you make the design flatter? I know we use input for project parameters, but it's because we might make them editable, where here it does not makes sense to edit. |
||
| <div className='grid gap-4'> | ||
| <div className='grid gap-2'> | ||
| <label | ||
| htmlFor='app-version' | ||
| className='text-sm font-medium text-foreground' | ||
| > | ||
| Version | ||
| </label> | ||
| <Input | ||
| id='app-version' | ||
| value={appVersion.data?.version ?? 'unknown'} | ||
| readOnly | ||
| className='bg-muted/50 font-mono text-sm' | ||
| /> | ||
| </div> | ||
| <div className='grid gap-2'> | ||
| <label | ||
| htmlFor='app-commit' | ||
| className='text-sm font-medium text-foreground' | ||
| > | ||
| Commit | ||
| </label> | ||
| <Input | ||
| id='app-commit' | ||
| value={appVersion.data?.commit ?? 'unknown'} | ||
| readOnly | ||
| className='bg-muted/50 font-mono text-sm' | ||
| /> | ||
| </div> | ||
| <div className='grid gap-2'> | ||
| <label | ||
| htmlFor='app-build-date' | ||
| className='text-sm font-medium text-foreground' | ||
| > | ||
| Build date | ||
| </label> | ||
| <Input | ||
| id='app-build-date' | ||
| value={appVersion.data?.buildDate || 'unknown'} | ||
| readOnly | ||
| className='bg-muted/50 font-mono text-sm' | ||
| /> | ||
| </div> | ||
| </div> | ||
| </SettingsCard> | ||
| )} | ||
| </div> | ||
| )} | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this?