Skip to content
Closed
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
4 changes: 1 addition & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"dev": "nodemon --exec bun run -r tsconfig-paths/register src/index.ts",
"test": "bun test",
"test:manifold": "bun test src/__tests__/manifold-project.test.ts",
"test:watch": "bun test --watch",
"generate": "drizzle-kit generate",
"migrate": "drizzle-kit migrate"
"test:watch": "bun test --watch"
},
"dependencies": {
"@anthropic-ai/sdk": "0.27.1",
Expand Down
7 changes: 0 additions & 7 deletions backend/src/db/db.ts

This file was deleted.

6 changes: 0 additions & 6 deletions backend/src/db/drizzle/0000_last_night_thrasher.sql

This file was deleted.

53 changes: 0 additions & 53 deletions backend/src/db/drizzle/meta/0000_snapshot.json

This file was deleted.

13 changes: 0 additions & 13 deletions backend/src/db/drizzle/meta/_journal.json

This file was deleted.

Binary file removed backend/src/db/mac-cloud-sql-proxy
Binary file not shown.
23 changes: 0 additions & 23 deletions backend/src/db/migrate.ts

This file was deleted.

7 changes: 0 additions & 7 deletions backend/src/db/schema.ts

This file was deleted.

Binary file modified bun.lockb
Binary file not shown.
15 changes: 13 additions & 2 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"license": "UNLICENSED",
"scripts": {
"build": "tsc && cp -R src/codemap/tree-sitter-queries dist/codemap/",
"clean": "rm -rf dist && rm tsconfig.tsbuildinfo"
"clean": "rm -rf dist && rm tsconfig.tsbuildinfo",
"db:generate": "drizzle-kit generate --config=./src/db/drizzle.config.ts",
"db:migrate": "drizzle-kit push --config=./src/db/drizzle.config.ts",
"db:start": "docker compose -f ./src/db/docker-compose.yml up -d --wait && bun run db:generate && bun run db:migrate"
},
"dependencies": {
"ignore": "5.3.2",
Expand All @@ -23,9 +26,17 @@
"tree-sitter-ruby": "0.23.0",
"tree-sitter-rust": "0.23.0",
"tree-sitter-typescript": "0.23.0",
"zod": "3.23.8"
"zod": "3.23.8",
"@auth/drizzle-adapter": "^1.5.0",
"@types/pg": "^8.11.10",
"dotenv": "^16.4.5",
"drizzle-orm": "^0.33.0",
"next": "14.2.11",
"next-auth": "^4.24.7",
"pg": "^8.13.0"
},
"peerDependencies": {
"drizzle-kit": "^0.24.2",
"@types/node": "*",
"@types/lodash": "*",
"typescript": "*"
Expand Down
16 changes: 16 additions & 0 deletions common/src/db/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: manicode
services:
db:
image: postgres:16
restart: always
ports:
- 5432:5432
environment:
POSTGRES_USER: manicode_user_local
POSTGRES_PASSWORD: secretpassword_local
POSTGRES_DB: manicode_db_local
volumes:
- db_data:/var/lib/postgresql/data
volumes:
# Store data from Postgres so they persist between Docker ups and downs
db_data:
12 changes: 12 additions & 0 deletions common/src/db/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from 'drizzle-kit'
import { env } from './env.mjs'
import path from 'path'

export default defineConfig({
dialect: 'postgresql',
schema: path.join(__dirname, 'schema.ts'),
out: path.join(__dirname, './migrations'),
dbCredentials: {
url: env.DATABASE_URL,
},
})
22 changes: 22 additions & 0 deletions common/src/db/env.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { createEnv } from '@t3-oss/env-core'
import { z } from 'zod'
import dotenv from 'dotenv'

dotenv.config({ path: '../stack.env' })
if (!process.env.ENVIRONMENT) {
console.error('ENVIRONMENT is not set, please check `stack.env`')
process.exit(1)
}

const DOTENV_PATH = process.env.ENVIRONMENT === 'local' ? '..' : '/etc/secrets'
const path = `${DOTENV_PATH}/.env.${process.env.ENVIRONMENT}`
console.log(`Using environment: ${process.env.ENVIRONMENT} (path: ${path})`)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging the environment path might expose sensitive information. Consider removing this log or handling it securely.

dotenv.config({ path })

export const env = createEnv({
server: {
ENVIRONMENT: z.string().min(1),
DATABASE_URL: z.string().min(1),
},
runtimeEnv: process.env,
})
11 changes: 11 additions & 0 deletions common/src/db/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { drizzle } from 'drizzle-orm/node-postgres'
import { Pool } from 'pg'
import { env } from './env.mjs'
import * as schema from './schema'

const pool = new Pool({
connectionString: env.DATABASE_URL,
})

const db = drizzle(pool, { schema })
export default db
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "4aec91d9-0902-42e5-97d4-eddf8a1c5f33",
"id": "fc85928a-5e41-46ac-beea-97292cd8f676",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"idx": 0,
"version": "7",
"when": 1726639583528,
"tag": "0000_funny_red_shift",
"when": 1726794860996,
"tag": "0000_overjoyed_thing",
"breakpoints": true
}
]
Expand Down
22 changes: 6 additions & 16 deletions web/db/schema.ts → common/src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
integer,
uuid,
boolean,
} from 'drizzle-orm/pg-core';
import type { AdapterAccount } from 'next-auth/adapters';
} from 'drizzle-orm/pg-core'
import type { AdapterAccount } from 'next-auth/adapters'

export const users = pgTable('user', {
id: text('id')
Expand All @@ -20,7 +20,7 @@ export const users = pgTable('user', {
image: text('image'),
isActive: boolean('isActive').notNull().default(false),
stripeCustomerId: text('stripeCustomerId').unique(),
});
})

export const accounts = pgTable(
'account',
Expand All @@ -44,15 +44,15 @@ export const accounts = pgTable(
columns: [account.provider, account.providerAccountId],
}),
})
);
)

export const sessions = pgTable('session', {
sessionToken: text('sessionToken').notNull().primaryKey(),
userId: text('userId')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
expires: timestamp('expires', { mode: 'date' }).notNull(),
});
})

export const verificationTokens = pgTable(
'verificationToken',
Expand All @@ -64,14 +64,4 @@ export const verificationTokens = pgTable(
(vt) => ({
compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
})
);

// const models = {
// users,
// accounts,
// sessions,
// verificationTokens,
// };
// type models = typeof models;

// export default models;
)
1 change: 1 addition & 0 deletions common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"composite": true,
"allowJs": true,
"module": "CommonJS",
"moduleResolution": "node",
"esModuleInterop": true,
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
"workspaces": [
"common",
"backend",
"npm-app"
"npm-app",
"web"
],
"scripts": {
"start-client": "bun --cwd npm-app start",
"start-web": "bun --cwd web dev",
"start-server": "bun --cwd backend start",
"start-db": "bun --cwd common db:start",
"start-web": "bun run start-db && bun --cwd web dev",
"start-server": "bun run start-db && bun --cwd backend start",
"start-manifold": "bun --cwd npm-app start-manifold",
"start-litestar": "bun --cwd npm-app start-litestar",
"start-jpcsp": "bun --cwd npm-app start-jpcsp",
Expand Down
8 changes: 4 additions & 4 deletions test/__src__/setup.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { beforeAll } from 'bun:test'
import dotenv from 'dotenv'
import path from 'path'
// import dotenv from 'dotenv'
import { env } from './env.mjs'

beforeAll(() => {
dotenv.config({
processEnv: env,
})
// dotenv.config({
// processEnv: env,
// })
})
5 changes: 0 additions & 5 deletions web/.vscode/extensions.json

This file was deleted.

11 changes: 0 additions & 11 deletions web/db/drizzle.config.ts

This file was deleted.

10 changes: 0 additions & 10 deletions web/db/index.ts

This file was deleted.

4 changes: 1 addition & 3 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "next dev --turbo",
"dev": "next dev",
"build": "next build",
"db:generate": "drizzle-kit generate --config=./db/drizzle.config.ts",
"db:migrate": "bun run drizzle-kit push --config=./db/drizzle.config.ts",
"start": "next start",
"preview": "next build && next start",
"lint": "next lint",
Expand Down
4 changes: 2 additions & 2 deletions web/src/app/api/auth/[...nextauth]/auth-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { DrizzleAdapter } from '@auth/drizzle-adapter';

import { env } from '@/env.mjs';
import { stripeServer } from '@/lib/stripe';
import { db } from '@@/db';
import * as models from '@@/db/schema';
import db from 'common/src/db';
import * as models from 'common/db/schema';
import { eq } from 'drizzle-orm';
import { Adapter } from 'next-auth/adapters';

Expand Down
Loading