Skip to content

Database Schema (MySQL)

The schema for the backend lives in server/database/schema.sql. It defines the core entities for datasets, labeling, models, predictions, and billing.

Schema management

  • server/database/schema.sql is the source of truth for table definitions.
  • server/database/init_db_dev.py and server/database/init_db_prod.py load the schema into MySQL.

If you add or modify tables, update server/database/schema.sql and keep related queries in server/database/db.py and server/database/db_auth.py in sync.

Example schema snippet

This small example demonstrates how a simple user + dataset + document setup could look.

CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  email VARCHAR(255) UNIQUE NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE datasets (
  id INT AUTO_INCREMENT PRIMARY KEY,
  user_id INT NOT NULL,
  name VARCHAR(255) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (user_id) REFERENCES users(id)
);

CREATE TABLE documents (
  id INT AUTO_INCREMENT PRIMARY KEY,
  dataset_id INT NOT NULL,
  storage_url TEXT,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (dataset_id) REFERENCES datasets(id)
);
Note how the datasets references users, and the documents references datasets.