Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ jobs:
env:
NODE_OPTIONS: '--no-warnings'
NEXT_PUBLIC_APP_URL: 'https://www.sim.ai'
DATABASE_URL: 'postgresql://postgres:postgres@localhost:5432/simstudio'
ENCRYPTION_KEY: '7cf672e460e430c1fba707575c2b0e2ad5a99dddf9b7b7e3b5646e630861db1c' # dummy key for CI only
run: bun run test

- name: Build application
env:
NODE_OPTIONS: '--no-warnings'
NEXT_PUBLIC_APP_URL: 'https://www.sim.ai'
DATABASE_URL: 'postgresql://postgres:postgres@localhost:5432/simstudio'
STRIPE_SECRET_KEY: 'dummy_key_for_ci_only'
STRIPE_WEBHOOK_SECRET: 'dummy_secret_for_ci_only'
RESEND_API_KEY: 'dummy_key_for_ci_only'
Expand Down Expand Up @@ -71,7 +73,7 @@ jobs:
run: bun install

- name: Apply migrations
working-directory: ./apps/sim
working-directory: ./packages/db
env:
DATABASE_URL: ${{ github.ref == 'refs/heads/main' && secrets.DATABASE_URL || secrets.STAGING_DATABASE_URL }}
run: bunx drizzle-kit migrate
run: bunx drizzle-kit migrate --config=./drizzle.config.ts
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ Update your `.env` file with the database URL:
DATABASE_URL="postgresql://postgres:your_password@localhost:5432/simstudio"
```

4. Set up the database:
4. Set up the database (from packages/db):

```bash
bunx drizzle-kit migrate
cd packages/db
bunx drizzle-kit migrate --config=./drizzle.config.ts
```

5. Start the development servers:
Expand Down
14 changes: 7 additions & 7 deletions apps/sim/app/api/__test-utils__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export function mockExecutionDependencies() {
})),
}))

vi.mock('@/db', () => ({
vi.mock('@sim/db', () => ({
db: mockDb,
}))
}
Expand Down Expand Up @@ -395,7 +395,7 @@ export async function getMockedDependencies() {
const workflowUtilsModule = await import('@/lib/workflows/utils')
const executorModule = await import('@/executor')
const serializerModule = await import('@/serializer')
const dbModule = await import('@/db')
const dbModule = await import('@sim/db')

return {
decryptSecret: utilsModule.decryptSecret,
Expand Down Expand Up @@ -428,7 +428,7 @@ export function mockScheduleStatusDb({
schedule?: any[]
workflow?: any[]
} = {}) {
vi.doMock('@/db', () => {
vi.doMock('@sim/db', () => {
let callCount = 0

const select = vi.fn().mockImplementation(() => ({
Expand Down Expand Up @@ -469,7 +469,7 @@ export function mockScheduleExecuteDb({
workflowRecord?: any
envRecord?: any
}): void {
vi.doMock('@/db', () => {
vi.doMock('@sim/db', () => {
const select = vi.fn().mockImplementation(() => ({
from: vi.fn().mockImplementation((table: any) => {
const tbl = String(table)
Expand Down Expand Up @@ -544,7 +544,7 @@ export function mockAuth(user: MockUser = mockUser): MockAuthResult {
* Mock common schema patterns
*/
export function mockCommonSchemas() {
vi.doMock('@/db/schema', () => ({
vi.doMock('@sim/db/schema', () => ({
workflowFolder: {
id: 'id',
userId: 'userId',
Expand Down Expand Up @@ -597,7 +597,7 @@ export function mockDrizzleOrm() {
* Mock knowledge-related database schemas
*/
export function mockKnowledgeSchemas() {
vi.doMock('@/db/schema', () => ({
vi.doMock('@sim/db/schema', () => ({
knowledgeBase: {
id: 'kb_id',
userId: 'user_id',
Expand Down Expand Up @@ -1091,7 +1091,7 @@ export function createMockDatabase(options: MockDatabaseOptions = {}) {
transaction: createTransactionMock(),
}

vi.doMock('@/db', () => ({ db: mockDb }))
vi.doMock('@sim/db', () => ({ db: mockDb }))

return {
mockDb,
Expand Down
6 changes: 2 additions & 4 deletions apps/sim/app/api/auth/oauth/connections/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ describe('OAuth Connections API Route', () => {
getSession: mockGetSession,
}))

vi.doMock('@/db', () => ({
vi.doMock('@sim/db', () => ({
db: mockDb,
}))

vi.doMock('@/db/schema', () => ({
account: { userId: 'userId', providerId: 'providerId' },
user: { email: 'email', id: 'id' },
eq: vi.fn((field, value) => ({ field, value, type: 'eq' })),
}))

vi.doMock('drizzle-orm', () => ({
Expand Down
3 changes: 1 addition & 2 deletions apps/sim/app/api/auth/oauth/connections/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { account, db, user } from '@sim/db'
import { eq } from 'drizzle-orm'
import { jwtDecode } from 'jwt-decode'
import { type NextRequest, NextResponse } from 'next/server'
import { getSession } from '@/lib/auth'
import { createLogger } from '@/lib/logs/console/logger'
import { generateRequestId } from '@/lib/utils'
import { db } from '@/db'
import { account, user } from '@/db/schema'

const logger = createLogger('OAuthConnectionsAPI')

Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/auth/oauth/credentials/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ describe('OAuth Credentials API Route', () => {
parseProvider: mockParseProvider,
}))

vi.doMock('@/db', () => ({
vi.doMock('@sim/db', () => ({
db: mockDb,
}))

vi.doMock('@/db/schema', () => ({
vi.doMock('@sim/db/schema', () => ({
account: { userId: 'userId', providerId: 'providerId' },
user: { email: 'email', id: 'id' },
}))
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/auth/oauth/credentials/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { db } from '@sim/db'
import { account, user, workflow } from '@sim/db/schema'
import { and, eq } from 'drizzle-orm'
import { jwtDecode } from 'jwt-decode'
import { type NextRequest, NextResponse } from 'next/server'
Expand All @@ -7,8 +9,6 @@ import type { OAuthService } from '@/lib/oauth/oauth'
import { parseProvider } from '@/lib/oauth/oauth'
import { getUserEntityPermissions } from '@/lib/permissions/utils'
import { generateRequestId } from '@/lib/utils'
import { db } from '@/db'
import { account, user, workflow } from '@/db/schema'

export const dynamic = 'force-dynamic'

Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/auth/oauth/disconnect/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ describe('OAuth Disconnect API Route', () => {
getSession: mockGetSession,
}))

vi.doMock('@/db', () => ({
vi.doMock('@sim/db', () => ({
db: mockDb,
}))

vi.doMock('@/db/schema', () => ({
vi.doMock('@sim/db/schema', () => ({
account: { userId: 'userId', providerId: 'providerId' },
}))

Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/auth/oauth/disconnect/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { db } from '@sim/db'
import { account } from '@sim/db/schema'
import { and, eq, like, or } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { getSession } from '@/lib/auth'
import { createLogger } from '@/lib/logs/console/logger'
import { generateRequestId } from '@/lib/utils'
import { db } from '@/db'
import { account } from '@/db/schema'

export const dynamic = 'force-dynamic'

Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/auth/oauth/microsoft/file/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { db } from '@sim/db'
import { account } from '@sim/db/schema'
import { eq } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { getSession } from '@/lib/auth'
import { createLogger } from '@/lib/logs/console/logger'
import { generateRequestId } from '@/lib/utils'
import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
import { db } from '@/db'
import { account } from '@/db/schema'

export const dynamic = 'force-dynamic'

Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/auth/oauth/microsoft/files/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { db } from '@sim/db'
import { account } from '@sim/db/schema'
import { eq } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { getSession } from '@/lib/auth'
import { createLogger } from '@/lib/logs/console/logger'
import { generateRequestId } from '@/lib/utils'
import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
import { db } from '@/db'
import { account } from '@/db/schema'

export const dynamic = 'force-dynamic'

Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/auth/oauth/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('OAuth Utils', () => {
getSession: vi.fn().mockResolvedValue(mockSession),
}))

vi.doMock('@/db', () => ({
vi.doMock('@sim/db', () => ({
db: mockDb,
}))

Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/auth/oauth/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { db } from '@sim/db'
import { account, workflow } from '@sim/db/schema'
import { and, desc, eq } from 'drizzle-orm'
import { getSession } from '@/lib/auth'
import { createLogger } from '@/lib/logs/console/logger'
import { refreshOAuthToken } from '@/lib/oauth/oauth'
import { db } from '@/db'
import { account, workflow } from '@/db/schema'

const logger = createLogger('OAuthUtilsAPI')

Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/auth/oauth/wealthbox/item/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { db } from '@sim/db'
import { account } from '@sim/db/schema'
import { eq } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { getSession } from '@/lib/auth'
import { createLogger } from '@/lib/logs/console/logger'
import { generateRequestId } from '@/lib/utils'
import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
import { db } from '@/db'
import { account } from '@/db/schema'

export const dynamic = 'force-dynamic'

Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/auth/oauth/wealthbox/items/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { db } from '@sim/db'
import { account } from '@sim/db/schema'
import { eq } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { getSession } from '@/lib/auth'
import { createLogger } from '@/lib/logs/console/logger'
import { generateRequestId } from '@/lib/utils'
import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
import { db } from '@/db'
import { account } from '@/db/schema'

export const dynamic = 'force-dynamic'

Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/billing/portal/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { db } from '@sim/db'
import { subscription as subscriptionTable, user } from '@sim/db/schema'
import { and, eq } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { getSession } from '@/lib/auth'
import { requireStripeClient } from '@/lib/billing/stripe-client'
import { env } from '@/lib/env'
import { createLogger } from '@/lib/logs/console/logger'
import { db } from '@/db'
import { subscription as subscriptionTable, user } from '@/db/schema'

const logger = createLogger('BillingPortal')

Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/billing/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { db } from '@sim/db'
import { member, userStats } from '@sim/db/schema'
import { and, eq } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { getSession } from '@/lib/auth'
import { getSimplifiedBillingSummary } from '@/lib/billing/core/billing'
import { getOrganizationBillingData } from '@/lib/billing/core/organization'
import { createLogger } from '@/lib/logs/console/logger'
import { db } from '@/db'
import { member, userStats } from '@/db/schema'

const logger = createLogger('UnifiedBillingAPI')

Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/billing/update-cost/route.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { db } from '@sim/db'
import { userStats } from '@sim/db/schema'
import { eq, sql } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
import { checkInternalApiKey } from '@/lib/copilot/utils'
import { isBillingEnabled } from '@/lib/environment'
import { createLogger } from '@/lib/logs/console/logger'
import { generateRequestId } from '@/lib/utils'
import { db } from '@/db'
import { userStats } from '@/db/schema'
import { calculateCost } from '@/providers/utils'

const logger = createLogger('billing-update-cost')
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/chat/[subdomain]/otp/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { db } from '@sim/db'
import { chat } from '@sim/db/schema'
import { eq } from 'drizzle-orm'
import type { NextRequest } from 'next/server'
import { z } from 'zod'
Expand All @@ -8,8 +10,6 @@ import { getRedisClient, markMessageAsProcessed, releaseLock } from '@/lib/redis
import { generateRequestId } from '@/lib/utils'
import { addCorsHeaders, setChatAuthCookie } from '@/app/api/chat/utils'
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
import { db } from '@/db'
import { chat } from '@/db/schema'

const logger = createLogger('ChatOtpAPI')

Expand Down
8 changes: 4 additions & 4 deletions apps/sim/app/api/chat/[subdomain]/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('Chat Subdomain API Route', () => {
}),
}))

vi.doMock('@/db', () => {
vi.doMock('@sim/db', () => {
const mockSelect = vi.fn().mockImplementation((fields) => {
if (fields && fields.isDeployed !== undefined) {
return {
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('Chat Subdomain API Route', () => {
})

it('should return 404 for non-existent subdomain', async () => {
vi.doMock('@/db', () => {
vi.doMock('@sim/db', () => {
const mockLimit = vi.fn().mockReturnValue([])
const mockWhere = vi.fn().mockReturnValue({ limit: mockLimit })
const mockFrom = vi.fn().mockReturnValue({ where: mockWhere })
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('Chat Subdomain API Route', () => {
})

it('should return 403 for inactive chat', async () => {
vi.doMock('@/db', () => {
vi.doMock('@sim/db', () => {
const mockLimit = vi.fn().mockReturnValue([
{
id: 'chat-id',
Expand Down Expand Up @@ -299,7 +299,7 @@ describe('Chat Subdomain API Route', () => {

it('should return 503 when workflow is not available', async () => {
// Override the default workflow result to return non-deployed
vi.doMock('@/db', () => {
vi.doMock('@sim/db', () => {
// Track call count to return different results
let callCount = 0

Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/chat/[subdomain]/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { db } from '@sim/db'
import { chat, workflow } from '@sim/db/schema'
import { eq } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { createLogger } from '@/lib/logs/console/logger'
Expand All @@ -10,8 +12,6 @@ import {
validateChatAuth,
} from '@/app/api/chat/utils'
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
import { db } from '@/db'
import { chat, workflow } from '@/db/schema'

const logger = createLogger('ChatSubdomainAPI')

Expand Down
4 changes: 2 additions & 2 deletions apps/sim/app/api/chat/edit/[id]/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ describe('Chat Edit API Route', () => {
mockSet.mockReturnValue({ where: mockWhere })
mockDelete.mockReturnValue({ where: mockWhere })

vi.doMock('@/db', () => ({
vi.doMock('@sim/db', () => ({
db: {
select: mockSelect,
update: mockUpdate,
delete: mockDelete,
},
}))

vi.doMock('@/db/schema', () => ({
vi.doMock('@sim/db/schema', () => ({
chat: { id: 'id', subdomain: 'subdomain', userId: 'userId' },
}))

Expand Down
Loading