-
Notifications
You must be signed in to change notification settings - Fork 0
Add organizations, billing & workspace lifecycle #47
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
Open
willwashburn
wants to merge
5
commits into
main
Choose a base branch
from
orgs-n-billing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d1bde53
Add organizations, billing & workspace lifecycle
willwashburn 3ca681c
Merge branch 'main' into orgs-n-billing
willwashburn f9751fc
Remove Stripe billing support
willwashburn d1874f8
Remove .claude/settings.local.json and ignore it
willwashburn b9517ea
Track workspace activity, auth rate limits, TTL
willwashburn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| -- Create users table | ||
| CREATE TABLE IF NOT EXISTS users ( | ||
| id TEXT PRIMARY KEY, | ||
| email TEXT NOT NULL UNIQUE, | ||
| email_verified INTEGER NOT NULL DEFAULT 0, | ||
| password_hash TEXT NOT NULL, | ||
| name TEXT NOT NULL, | ||
| created_at INTEGER NOT NULL DEFAULT (unixepoch()) | ||
| ); | ||
|
|
||
| -- Create organizations table | ||
| CREATE TABLE IF NOT EXISTS organizations ( | ||
| id TEXT PRIMARY KEY, | ||
| name TEXT NOT NULL, | ||
| plan TEXT NOT NULL DEFAULT 'free', | ||
| org_api_key_hash TEXT UNIQUE, | ||
| created_at INTEGER NOT NULL DEFAULT (unixepoch()) | ||
| ); | ||
|
|
||
| -- Create org_memberships table | ||
| CREATE TABLE IF NOT EXISTS org_memberships ( | ||
| user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE, | ||
| organization_id TEXT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE, | ||
| role TEXT NOT NULL DEFAULT 'member', | ||
| created_at INTEGER NOT NULL DEFAULT (unixepoch()), | ||
| PRIMARY KEY (user_id, organization_id) | ||
| ); | ||
| CREATE INDEX IF NOT EXISTS idx_org_memberships_org ON org_memberships(organization_id); | ||
| CREATE INDEX IF NOT EXISTS idx_org_memberships_user ON org_memberships(user_id); | ||
|
|
||
| -- Create sessions table | ||
| CREATE TABLE IF NOT EXISTS sessions ( | ||
| id TEXT PRIMARY KEY, | ||
| user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE, | ||
| active_org_id TEXT REFERENCES organizations(id), | ||
| expires_at INTEGER NOT NULL, | ||
| created_at INTEGER NOT NULL DEFAULT (unixepoch()) | ||
| ); | ||
| CREATE INDEX IF NOT EXISTS idx_sessions_user ON sessions(user_id); | ||
| CREATE INDEX IF NOT EXISTS idx_sessions_expires ON sessions(expires_at); | ||
|
|
||
| -- Create email_verifications table | ||
| CREATE TABLE IF NOT EXISTS email_verifications ( | ||
| id TEXT PRIMARY KEY, | ||
| email TEXT NOT NULL, | ||
| code TEXT NOT NULL, | ||
| user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE, | ||
| expires_at INTEGER NOT NULL, | ||
| created_at INTEGER NOT NULL DEFAULT (unixepoch()) | ||
| ); | ||
| CREATE INDEX IF NOT EXISTS idx_email_verifications_user ON email_verifications(user_id); | ||
|
|
||
| -- Add new columns to workspaces | ||
| ALTER TABLE workspaces ADD COLUMN organization_id TEXT REFERENCES organizations(id) ON DELETE CASCADE; | ||
| ALTER TABLE workspaces ADD COLUMN last_activity_at INTEGER; | ||
| ALTER TABLE workspaces ADD COLUMN deleted_at INTEGER; | ||
|
|
||
| -- Backfill: create a shadow org for each existing workspace and link them. | ||
| -- Uses the workspace id as the org id for simplicity in a one-time migration. | ||
| INSERT INTO organizations (id, name, created_at) | ||
| SELECT id, 'shadow-' || name, created_at FROM workspaces WHERE organization_id IS NULL; | ||
|
|
||
| UPDATE workspaces SET organization_id = id WHERE organization_id IS NULL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The workspace schema still has a
planfield (line 112) marked as deprecated with a comment "deprecated: read from org". However, the migration doesn't drop this column. This creates technical debt and potential confusion.Either remove the field entirely from the schema (and update all code that references it), or document clearly that it's kept for backwards compatibility but should not be written to. Currently it's still being set with a default value which is wasteful.