Skip to main content

Schema & Migrations

Tables (D1):

  • tenants(id TEXT PRIMARY KEY, name TEXT NOT NULL, slug TEXT UNIQUE, created_at TIMESTAMP)
  • projects(id TEXT PRIMARY KEY, tenant_id TEXT NOT NULL, name TEXT NOT NULL, description TEXT, repo_url TEXT, status TEXT DEFAULT 'active', created_at TIMESTAMP, updated_at TIMESTAMP)
  • chats(id TEXT PRIMARY KEY, project_id TEXT NOT NULL, title TEXT, created_at TIMESTAMP, updated_at TIMESTAMP)
  • logs(id INTEGER PRIMARY KEY AUTOINCREMENT, project_id TEXT, chat_id TEXT, level TEXT, message TEXT, payload TEXT, created_at TIMESTAMP)

Indexes:

  • idx_projects_tenant(tenant_id), idx_projects_status(status)
  • idx_chats_project(project_id)
  • idx_logs_project(project_id), idx_logs_chat(chat_id)
  • idx_tenants_slug(slug)

Migrations:

  • db/migrations/0001_init.sql → create base tables & indexes
  • db/migrations/0002_add_slug.sql → add tenants.slug + unique index
  • db/migrations/0003_seed.sql → seed default tenant and demo project

Apply migrations:

npx wrangler d1 migrations apply chyperai_db --remote

Verify schema:

npx wrangler d1 execute chyperai_db --remote --command "SELECT name FROM sqlite_master WHERE type='table';"