Portal Community

File Naming Convention

-- Pattern:
Atlas_Forms_{FormID}_{FormCode}.data.sql

-- Examples:
Atlas_Forms_13008_GuardRail_IpAllowlist_Edit.data.sql
Atlas_Forms_15001_WorkDesk_Task_Edit.data.sql
Atlas_Forms_20003_AppStudio_Widget_View.data.sql

Full File Template

-- Atlas_Forms_{FormID}_{FormCode}.data.sql
-- Generated by AI Form Generator on {date}
-- Group: {GroupName} (FormCategoryID {categoryId})

SET IDENTITY_INSERT [dbo].[Atlas_Forms] ON;

IF NOT EXISTS (
    SELECT 1
    FROM   [dbo].[Atlas_Forms]
    WHERE  [FormID] = {FormID}
)
BEGIN
    INSERT INTO [dbo].[Atlas_Forms]
    (
        [FormID],
        [FormCode],
        [FormCategoryID],
        [FormTypeID],
        [PrimaryUsage],
        [NodeUsage],
        [TenantID],
        [IsActive],
        [SchemaJson]
    )
    VALUES
    (
        {FormID},
        '{FormCode}',
        {FormCategoryID},
        {FormTypeID},        -- 1=List, 2=Property, 3=Wizard, 4=Dashboard
        '{PrimaryUsage}',
        {NodeUsage},         -- NULL or '{nodeUsage}'
        NULL,                -- Base form: TenantID always NULL
        1,                   -- IsActive
        N'{escaped-schema-json}'
    );
END

SET IDENTITY_INSERT [dbo].[Atlas_Forms] OFF;

Why IDENTITY_INSERT?

The FormID column uses SQL Server's IDENTITY mechanism. To insert a specific pre-determined ID (rather than letting SQL Server auto-assign), IDENTITY_INSERT must be temporarily enabled for the session. The AI generator always wraps the INSERT with the correct ON/OFF pair.

Why IF NOT EXISTS?

The deploy scripts are run idempotently — they may be executed many times (on environment refreshes, CI pipelines, local developer setups). The IF NOT EXISTS guard keyed on FormID ensures the INSERT only runs once even when the script is re-run. Without the guard, the second run would fail with a primary key violation.

SchemaJson Escaping

The JSON schema is stored in an NVARCHAR(MAX) column with the N'' prefix (Unicode string). Single quotes inside the JSON must be escaped as double single quotes (''):

-- Correct: single quotes in JSON escaped as ''
N'{ "metadata": { "title": "It''s a Test Form" } }'

-- Wrong: unescaped single quote breaks the SQL string
N'{ "metadata": { "title": "It's a Test Form" } }'

Pattern Comparison: Manual vs AI-Generated

ConcernManual FileAI-Generated File
IDENTITY_INSERT blocksOften forgottenAlways present
IF NOT EXISTS guardSometimes omittedAlways present
Quote escaping in JSONFrequent source of errorsCorrectly escaped
File namingInconsistentStrict convention followed
Header commentVariableStandardised with date and group
Validate the JSON Before Committing Even AI-generated JSON can contain errors if the schema is complex. Before committing the SQL file, copy the SchemaJson value out of the file and validate it with parseSchema() in a test. See the next page for the full validation checklist.