-
Notifications
You must be signed in to change notification settings - Fork 261
lighthouse #1109
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: v5
Are you sure you want to change the base?
lighthouse #1109
Changes from all commits
33291b8
dea5249
50914b3
478c4c9
52dab4f
c99b3d0
abe2158
949634f
26dce02
420d441
12f7507
409b881
50f7fbd
37317e0
fdf0256
cf6aeaf
41967e1
f80a11d
cae073d
201f0b2
74dd139
6758ced
1dbb9a7
cf88304
f738aff
e8cc9be
3efe8e1
3af6374
9c2b28b
a7ec2ef
9760419
de8d57d
dad1dac
d5365ae
c725e3a
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 |
|---|---|---|
|
|
@@ -1025,8 +1025,7 @@ | |
| "type": "string", | ||
| "enum": [ | ||
| "OWNER", | ||
| "MEMBER", | ||
| "GUEST" | ||
| "MEMBER" | ||
| ] | ||
| }, | ||
| "createdAt": { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| --- | ||
| title: Billing | ||
| sidebarTitle: Billing | ||
| --- | ||
|
|
||
| Sourcebot Enterprise is available on monthly and yearly plans. Both are seat-based. This page explains how seats are billed, how changes mid-term are handled, and what happens at renewal. | ||
|
|
||
| ## Seat count | ||
| Your seat count is the number of active users in your Sourcebot instance. Seat usage is reported to Sourcebot on a daily interval, and your subscription quantity is kept in sync with that number. | ||
|
|
||
| ## Monthly plans | ||
| Monthly subscriptions are billed at the start of each billing cycle. Users added mid-cycle are prorated across the remaining days and appear on your next invoice. Users removed mid-cycle take effect at the next cycle. There is no refund for the remainder of the current one. | ||
|
|
||
| In short: you can scale up at any time and pay the prorated difference. Scaling down is effectively free until the cycle rolls over. | ||
|
|
||
| ## Yearly plans | ||
|
|
||
| Yearly subscriptions are billed upfront for a committed seat count. As users are added during the term, the seat count rises but you aren't charged immediately. Every three months we reconcile. Any seats added that quarter are billed, prorated across the quarters remaining in the term. | ||
|
|
||
| Seats only move upward during the term. Shrinking the user count does not refund, and does not reduce the seat count until renewal. At renewal, you're invoiced at your current seat count, and that number becomes the committed baseline for the next year. | ||
|
|
||
| ### Example | ||
|
|
||
| Suppose you start a yearly plan in January with 100 seats. | ||
|
|
||
| - In Q1, your user count grows to 110. At the end of Q1, you're invoiced for 10 seats prorated across the 3 remaining quarters. | ||
| - In Q2, your user count stays at 110. No reconciliation invoice is generated. | ||
| - In Q3, your user count grows to 120. At the end of Q3, you're invoiced for 10 seats prorated across the 1 remaining quarter. | ||
| - In Q4, reconciliation does not generate a charge (there are no remaining quarters to prorate across). | ||
| - At renewal in January, you're invoiced at 120 seats for the next year. 120 becomes the new committed baseline. | ||
|
|
||
| ## Cancellation | ||
|
|
||
| Cancelling a subscription takes effect at the end of the current billing cycle (monthly) or term (yearly). You retain access to Sourcebot Enterprise features until that point. | ||
|
|
||
| ## Questions? | ||
|
|
||
| For billing questions, [contact us](mailto:support@sourcebot.dev). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { vi } from 'vitest'; | ||
|
|
||
| export const prisma = { | ||
| license: { | ||
| findUnique: vi.fn().mockResolvedValue(null), | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { | ||
| Entitlement, | ||
| _hasEntitlement, | ||
| _getEntitlements, | ||
| } from "@sourcebot/shared"; | ||
| import { prisma } from "./prisma.js"; | ||
| import { SINGLE_TENANT_ORG_ID } from "./constants.js"; | ||
|
|
||
| const getLicense = async () => { | ||
| return prisma.license.findUnique({ | ||
| where: { orgId: SINGLE_TENANT_ORG_ID }, | ||
| }); | ||
| } | ||
|
|
||
| export const hasEntitlement = async (entitlement: Entitlement): Promise<boolean> => { | ||
| const license = await getLicense(); | ||
| return _hasEntitlement(entitlement, license); | ||
| } | ||
|
|
||
| export const getEntitlements = async (): Promise<Entitlement[]> => { | ||
| const license = await getLicense(); | ||
| return _getEntitlements(license); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { PrismaClient } from "@sourcebot/db"; | ||
| import { getDBConnectionString } from "@sourcebot/shared"; | ||
|
|
||
| export const prisma = new PrismaClient({ | ||
| datasources: { | ||
| db: { | ||
| url: getDBConnectionString(), | ||
| }, | ||
| }, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,15 @@ | ||
| import { defineConfig } from 'vitest/config'; | ||
| import path from 'path'; | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| environment: 'node', | ||
| watch: false, | ||
| env: { | ||
| DATA_CACHE_DIR: 'test-data' | ||
| } | ||
| }, | ||
| alias: { | ||
| './prisma.js': path.resolve(__dirname, 'src/__mocks__/prisma.ts'), | ||
| }, | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| -- CreateTable | ||
| CREATE TABLE "License" ( | ||
| "id" TEXT NOT NULL, | ||
| "orgId" INTEGER NOT NULL, | ||
| "activationCode" TEXT NOT NULL, | ||
| "entitlements" TEXT[], | ||
| "seats" INTEGER, | ||
| "status" TEXT, | ||
| "lastSyncAt" TIMESTAMP(3), | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
|
||
| CONSTRAINT "License_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "License_orgId_key" ON "License"("orgId"); | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "License" ADD CONSTRAINT "License_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "Org"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| Warnings: | ||
|
|
||
| - The values [GUEST] on the enum `OrgRole` will be removed. If these variants are still used in the database, this will fail. | ||
|
|
||
| */ | ||
|
|
||
| -- Remove the guest user and its membership (only holder of GUEST role) | ||
| DELETE FROM "UserToOrg" WHERE "role" = 'GUEST'; | ||
| DELETE FROM "User" WHERE id = '1'; | ||
|
Comment on lines
+8
to
+10
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. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify guest-user conventions and FK relationships that reference User.
set -euo pipefail
echo "=== Where is the guest User with id='1' created/seeded? ==="
rg -nP -C3 $'\bid:\s*["\']1["\']' --type=ts --type=sql --type=prisma || true
rg -nPU -C3 "(?s)guest[^\n]*user[^\n]*id" --type=ts || true
echo
echo "=== Prisma schema: User model and anything referencing it ==="
fd -t f schema.prisma --exec rg -nP -C3 'model\s+User\b|userId|createdById|actorId' {} \;
echo
echo "=== All tables with onDelete semantics on userId/createdById ==="
fd -t f schema.prisma --exec rg -nP -C1 'onDelete' {} \;
echo
echo "=== Other migrations touching 'GUEST' or User id='1' ==="
fd -t f -e sql --exec rg -nP -C2 "GUEST|WHERE id = '1'|WHERE \"id\" = '1'" {} \;Repository: sourcebot-dev/sourcebot Length of output: 8832 🏁 Script executed: #!/bin/bash
# Find seed files, database initialization, and when GUEST role was introduced
echo "=== Search for seed/seeding files ==="
fd -t f \( -name "*seed*" -o -name "*init*" -o -name "*fixture*" \) | head -20
echo
echo "=== List all migrations in order ==="
fd -t f -e sql -path "*/migrations/*" | sort
echo
echo "=== Look for GUEST role introduction in migrations ==="
fd -t f -e sql -path "*/migrations/*" | xargs rg -l "GUEST" | sort
echo
echo "=== Check early migrations for GUEST role ==="
fd -t f -e sql -path "*/migrations/*" | sort | head -5 | xargs -I {} bash -c "echo '=== {} ===' && head -20 {}"
echo
echo "=== Search for 'guest' user references in TypeScript code ==="
rg -i "guest.*user|user.*guest" --type=ts -C2 | head -40Repository: sourcebot-dev/sourcebot Length of output: 3966 🏁 Script executed: #!/bin/bash
# Read the migration that introduced GUEST role
echo "=== GUEST role introduction migration ==="
cat "packages/db/prisma/migrations/20250520182630_add_guest_role/migration.sql"
echo
echo "=== Current migration being reviewed ==="
cat "packages/db/prisma/migrations/20260417224042_remove_guest_org_role/migration.sql"
echo
echo "=== Check for any user creation or seeding in migrations ==="
fd -type f -path "*/migrations/*" -name "*.sql" | xargs rg -l "INSERT INTO.*User|SELECT.*FROM.*User" | head -5
echo
echo "=== Look for initialization or setup code ==="
rg -i "seed|init" packages/db --type=ts --type=sql | head -20Repository: sourcebot-dev/sourcebot Length of output: 2274 🏁 Script executed: #!/bin/bash
# Search more carefully for how id='1' was used or created
echo "=== All migrations sorted chronologically ==="
ls -la packages/db/prisma/migrations/ | tail -15
echo
echo "=== Migrations between GUEST introduction and removal ==="
ls packages/db/prisma/migrations/ | sort | awk '/20250520182630/,/20260417224042/'
echo
echo "=== Search for explicit '1' in migration context (not regex) ==="
rg "WHERE id = '1'|WHERE \"id\" = '1'|userId.*=.*'1'|user.*id.*'1'" packages/db/prisma/migrations/
echo
echo "=== Search for all migrations that touch UserToOrg ==="
fd -type f -path "*/migrations/*" -name "*.sql" | xargs rg -l "UserToOrg" | sort
echo
echo "=== Look for git log or comments about guest user ==="
rg -i "guest" packages/db/prisma --type=sql -B2 -A2Repository: sourcebot-dev/sourcebot Length of output: 5985 Hard-coded guest user id='1' is brittle and relies on an established but fragile convention. While the codebase does establish Additionally, the Prisma schema shows all User foreign key references use Prefer deriving the guest user from the GUEST role membership rather than a hard-coded id, or add an explicit marker/flag to identify the guest user unambiguously. Safer approach-- Remove the guest user and its membership (only holder of GUEST role)
-DELETE FROM "UserToOrg" WHERE "role" = 'GUEST';
-DELETE FROM "User" WHERE id = '1';
+-- Identify and delete the guest user through GUEST role membership
+DELETE FROM "User"
+WHERE id IN (
+ SELECT DISTINCT "userId" FROM "UserToOrg" WHERE "role" = 'GUEST'
+);
+DELETE FROM "UserToOrg" WHERE "role" = 'GUEST';🤖 Prompt for AI Agents |
||
|
|
||
| -- AlterEnum | ||
| BEGIN; | ||
| CREATE TYPE "OrgRole_new" AS ENUM ('OWNER', 'MEMBER'); | ||
| ALTER TABLE "UserToOrg" ALTER COLUMN "role" DROP DEFAULT; | ||
| ALTER TABLE "UserToOrg" ALTER COLUMN "role" TYPE "OrgRole_new" USING ("role"::text::"OrgRole_new"); | ||
| ALTER TYPE "OrgRole" RENAME TO "OrgRole_old"; | ||
| ALTER TYPE "OrgRole_new" RENAME TO "OrgRole"; | ||
| DROP TYPE "OrgRole_old"; | ||
| ALTER TABLE "UserToOrg" ALTER COLUMN "role" SET DEFAULT 'MEMBER'; | ||
| COMMIT; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "License" ADD COLUMN "currency" TEXT, | ||
| ADD COLUMN "interval" TEXT, | ||
| ADD COLUMN "intervalCount" INTEGER, | ||
| ADD COLUMN "nextRenewalAmount" INTEGER, | ||
| ADD COLUMN "nextRenewalAt" TIMESTAMP(3), | ||
| ADD COLUMN "planName" TEXT, | ||
| ADD COLUMN "unitAmount" INTEGER; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "License" ADD COLUMN "cancelAt" TIMESTAMP(3); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "License" ADD COLUMN "trialEnd" TIMESTAMP(3); | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "Org" ADD COLUMN "trialUsedAt" TIMESTAMP(3); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "License" ADD COLUMN "hasPaymentMethod" BOOLEAN; |
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.
🧩 Analysis chain
🏁 Script executed:
Repository: sourcebot-dev/sourcebot
Length of output: 559
🏁 Script executed:
Repository: sourcebot-dev/sourcebot
Length of output: 916
🏁 Script executed:
Repository: sourcebot-dev/sourcebot
Length of output: 3390
🏁 Script executed:
Repository: sourcebot-dev/sourcebot
Length of output: 177
🏁 Script executed:
Repository: sourcebot-dev/sourcebot
Length of output: 9457
🏁 Script executed:
Repository: sourcebot-dev/sourcebot
Length of output: 559
Async
startScheduler()calls may produce unhandled rejections at call sites.The
startScheduler()methods onrepoPermissionSyncer(line 69) andaccountPermissionSyncer(line 71) inpackages/backend/src/index.tsare async and throw errors internally, but are invoked withoutawait. If either method's Promise rejects, the error will be swallowed as an unhandled rejection instead of crashing the application during startup. Both calls must be awaited to properly handle errors.🤖 Prompt for AI Agents