Portal Community

Why SQL Files, Not the Database?

The generator is a design-time tool — it runs during development, not against a live database. The SQL files in the group folder represent the canonical list of forms that will be deployed. Using the files prevents ID conflicts even when the database has not yet been refreshed from the latest scripts.

ID Selection Algorithm

// Simplified FormID selection algorithm

function findNextFormId(
  groupFolder:  string,
  rangeStart:   number,
  rangeEnd:     number
): number {
  // 1. Scan all .data.sql files in the folder
  const files = listFiles(groupFolder, '*.data.sql');

  // 2. Extract FormIDs from file names (pattern: Atlas_Forms_{id}_*.data.sql)
  const usedIds = new Set<number>();
  for (const file of files) {
    const match = file.match(/Atlas_Forms_(\d+)_/);
    if (match) usedIds.add(parseInt(match[1], 10));
  }

  // 3. Find the lowest unused ID in the group's range
  for (let id = rangeStart; id <= rangeEnd; id++) {
    if (!usedIds.has(id)) return id;
  }

  // 4. Range exhausted — abort
  throw new Error(`[AtlasForms] FormID range ${rangeStart}–${rangeEnd} is exhausted. No IDs available.`);
}

Example — GuardRails Group

// SQL files currently in the GuardRails folder:
// Atlas_Forms_13000_GuardRail_List.data.sql          → FormID 13000
// Atlas_Forms_13001_GuardRail_Edit.data.sql           → FormID 13001
// Atlas_Forms_13002_GuardRail_View.data.sql           → FormID 13002
// Atlas_Forms_13003_GuardRail_RateLimit_Edit.data.sql → FormID 13003
// Atlas_Forms_13004_GuardRail_ContentFilter_Edit.data.sql → FormID 13004
// Atlas_Forms_13005_GuardRail_TopicBlock_Edit.data.sql    → FormID 13005
// Atlas_Forms_13006_GuardRail_AccessControl_Edit.data.sql → FormID 13006
// Atlas_Forms_13007_GuardRail_Audit.data.sql          → FormID 13007

// Used IDs: { 13000, 13001, 13002, 13003, 13004, 13005, 13006, 13007 }
// Range: 13000–13099
// Next available: 13008

Range Exhaustion Warning

IDs UsedIDs RemainingAction
0–7980–100Normal — generate freely
80–8910–20Warning logged — plan range expansion
90+Less than 10Alert — request a new group or range extension before generating more
1000Error — generation aborted
Do Not Skip IDs If you delete a form (remove its SQL file), the AI will reuse that ID for the next generated form — the gap is filled. Never reserve IDs manually by creating empty placeholder files; this wastes range. If you need to reserve a range of IDs for future manual work, document this in the group's readme rather than creating files.