The SQL File Pattern
Every form data SQL file follows a strict three-part pattern: IDENTITY_INSERT ON, an IF NOT EXISTS guarded INSERT, then IDENTITY_INSERT OFF. This makes every file safely idempotent and deployable to any environment in any order.
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
| Concern | Manual File | AI-Generated File |
|---|---|---|
| IDENTITY_INSERT blocks | Often forgotten | Always present |
| IF NOT EXISTS guard | Sometimes omitted | Always present |
| Quote escaping in JSON | Frequent source of errors | Correctly escaped |
| File naming | Inconsistent | Strict convention followed |
| Header comment | Variable | Standardised with date and group |
SchemaJson value out of the file and validate it with parseSchema() in a test. See the next page for the full validation checklist.