LiveGobe Wiki

Database Schema

Overview

This page documents the internal Wiki and WikiPage schemas used by the LiveGobe Wiki System backend.

These Mongoose schemas define the structure, validation, and relationships between wiki instances and their content pages.

Wiki Schema

The Wiki schema represents an individual wiki site — including its configuration, language, and creation metadata.

const WikiSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
    unique: true,
    match: /^[a-z0-9-]+$/,  // Only lowercase letters, numbers, hyphens
    trim: true
  },
  language: {
    type: String,
    required: true,
    default: "en"
  },
  title: {
    type: String,
    required: true,
    trim: true
  },
  description: {
    type: String,
    trim: true
  },
  settings: {
    theme: { type: String, default: "default" },
    allowAnonymousRead: { type: Boolean, default: true },
    allowAnonymousEdit: { type: Boolean, default: true },
    defaultLayout: { type: String, default: "default" }
  },
  createdAt: { type: Date, default: Date.now },
  updatedAt: { type: Date, default: Date.now }
});
Wiki Schema Fields
FieldTypeDescription
nameStringUnique lowercase ID of the wiki (e.g. my-wiki).
languageStringDefault language code for this wiki.
titleStringDisplay title shown in the header and metadata.
descriptionStringOptional text shown on main or about pages.
settings.themeStringTheme name (Currently unused).
settings.allowAnonymousReadBooleanAllows public viewing if true.
settings.allowAnonymousEditBooleanAllows all registered users to edit the pages if true.
settings.defaultLayoutStringDefault page layout template (Currently unused).
createdAtDateCreation timestamp.
updatedAtDateLast modification timestamp.

WikiPage Schema

The WikiPage schema defines all content pages stored within a wiki.

Each page includes version tracking, categorization, and relationships with templates and categories.

const RevisionSchema = new mongoose.Schema({
  content: { type: String, required: true },
  comment: { type: String, default: "" },
  author: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
  timestamp: { type: Date, default: Date.now },
  minor: { type: Boolean, default: false }
});

const WikiPageSchema = new mongoose.Schema({
  wiki: { type: mongoose.Schema.Types.ObjectId, ref: 'Wiki', required: true, index: true },
  title: { type: String, required: true, trim: true },
  namespace: { type: String, required: true, default: "Main", enum: utils.getSupportedNamespaces(), index: true },
  path: { type: String, required: true, trim: true },
  content: { type: String, required: true, default: "" },
  html: { type: String },
  revisions: [RevisionSchema],
  createdAt: { type: Date, default: Date.now },
  createdBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
  lastModifiedAt: { type: Date, default: Date.now },
  lastModifiedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
  categories: [{ type: String, ref: 'WikiPage', index: true }],
  tags: [{ type: String, index: true }],
  templateUsedBy: [{ type: mongoose.Schema.Types.ObjectId, ref: 'WikiPage' }],
  templatesUsed: [{ type: mongoose.Schema.Types.ObjectId, ref: 'WikiPage' }],
  protected: { type: String, enum: ["none", "edit", "move", "full"], default: "none" },
  isPurging: { type: Boolean, default: false, select: false },
  pagesUsingCategory: [{ type: mongoose.Schema.Types.ObjectId, ref: 'WikiPage' }]
});
WikiPage Schema Fields
FieldTypeDescription
wikiObjectId (Wiki)Reference to the parent wiki.
titleStringPage title, unique per namespace.
namespaceStringPage namespace (e.g. Main, Template, Module).
pathStringFull hierarchical path (e.g. Parent/Child/Subpage).
contentStringRaw source text of the page.
htmlStringRendered HTML output.
revisionsArray of RevisionHistory of content edits.
createdBy / lastModifiedByObjectId (User)References to authors.
categories[String]List of categories the page belongs to.
tags[String]Custom tags for filtering and search.
templateUsedBy[ObjectId]Pages that use this as a template.
templatesUsed[ObjectId]Templates used by this page.
protectedString (enum)Restriction level: "none", "edit", "move", "full".
isPurgingBooleanTemporary flag for purge operations (hidden by default).
pagesUsingCategory[ObjectId]Currently unused.

Revision Schema

Each revision records a single saved version of a page.

FieldTypeDescription
contentStringSnapshot of the page content.
commentStringEdit summary.
authorObjectId (User)Author reference.
timestampDateWhen the revision was created.
minorBooleanWhether the edit was marked as minor.

Relationships

Wiki Data Relationships
FromToTypeDescription
WikiWikiPageOne-to-ManyEach wiki contains multiple pages.
WikiPageRevisionOne-to-ManyA page has multiple content revisions.
WikiPageWikiPage (Template)Many-to-ManyPages may use other pages as templates.
WikiPageWikiPage (Category)Many-to-ManyCategory pages can list other pages.

Notes

  • Pages with protected set to "full" can only be edited by admins.
  • The field isPurging is hidden from normal queries to avoid interference during cleanup.
  • Categories and templates are dynamically updated through backend hooks.

See Also

Last Edited by LiveGobe on 11/8/2025, 10:00:02 AM

This page categories: