Skip to main content

Schema Definition

The projects table stores information about code projects in Polaris.

Fields

_id
Id<'projects'>
required
Unique project identifier
name
string
required
Project name
ownerId
string
required
User ID of the project owner
updatedAt
number
required
Unix timestamp (in milliseconds) of last update
importStatus
string
Status of project import operation
exportStatus
string
Status of project export operation
exportRepoUrl
string
URL of the exported repository (set after successful export)
settings
object
Project configuration settings

Indexes

by_owner
index
Index on ownerId field for efficient user project queriesFields: ["ownerId"]

Queries

get

Retrieve all projects owned by the authenticated user.
import { api } from "@/convex/_generated/api";
import { useQuery } from "convex/react";

function MyProjects() {
  const projects = useQuery(api.projects.get);
  return projects?.map(p => <div key={p._id}>{p.name}</div>);
}
Returns: Array of all user’s projects, ordered by most recent first

getPartial

Retrieve a limited number of projects owned by the authenticated user.
limit
number
required
Maximum number of projects to return
import { api } from "@/convex/_generated/api";
import { useQuery } from "convex/react";

function RecentProjects() {
  const projects = useQuery(api.projects.getPartial, { limit: 5 });
  return projects?.map(p => <div key={p._id}>{p.name}</div>);
}
Returns: Array of projects (up to limit), ordered by most recent first

getById

Retrieve a specific project by ID.
id
Id<'projects'>
required
Project identifier
import { api } from "@/convex/_generated/api";
import { useQuery } from "convex/react";

function ProjectDetails({ projectId }) {
  const project = useQuery(api.projects.getById, { id: projectId });
  return <h1>{project?.name}</h1>;
}
Returns: Project object Errors:
  • "Project not found" - Project doesn’t exist
  • "Unauthorized access to this project" - User is not the owner

Mutations

create

Create a new project.
name
string
required
Name for the new project
import { api } from "@/convex/_generated/api";
import { useMutation } from "convex/react";

function CreateProject() {
  const createProject = useMutation(api.projects.create);
  
  const handleCreate = async () => {
    const projectId = await createProject({ name: "My New Project" });
    console.log("Created project:", projectId);
  };
  
  return <button onClick={handleCreate}>Create Project</button>;
}
Returns: Id<'projects'> - ID of the newly created project

rename

Rename an existing project.
id
Id<'projects'>
required
Project identifier
name
string
required
New name for the project
import { api } from "@/convex/_generated/api";
import { useMutation } from "convex/react";

function RenameProject({ projectId }) {
  const renameProject = useMutation(api.projects.rename);
  
  const handleRename = async () => {
    await renameProject({ 
      id: projectId, 
      name: "Updated Project Name" 
    });
  };
  
  return <button onClick={handleRename}>Rename</button>;
}
Errors:
  • "Project not found" - Project doesn’t exist
  • "Unauthorized access to this project" - User is not the owner

updateSettings

Update project configuration settings.
id
Id<'projects'>
required
Project identifier
settings
object
required
Project settings object
import { api } from "@/convex/_generated/api";
import { useMutation } from "convex/react";

function ProjectSettings({ projectId }) {
  const updateSettings = useMutation(api.projects.updateSettings);
  
  const handleUpdate = async () => {
    await updateSettings({
      id: projectId,
      settings: {
        installCommand: "npm install",
        devCommand: "npm run dev"
      }
    });
  };
  
  return <button onClick={handleUpdate}>Save Settings</button>;
}
Errors:
  • "Project not found" - Project doesn’t exist
  • "Unauthorized to update this project" - User is not the owner

Source Reference

  • Schema definition: convex/schema.ts:5-31
  • Queries and mutations: convex/projects.ts

Build docs developers (and LLMs) love