Writing Migration Scripts with Variables
· One min read
Dubnium variables let one SQL migration adapt to development, test, and production environments without duplicating the script.
Define values in configuration
Add environment-specific values to dubnium.yml:
Variables:
SCHEMA_NAME: 'dbo'
ENV_LABEL: 'Production'
DEFAULT_ADMIN_EMAIL: 'admin@yourapp.com'
Use the configured names as tokens in a migration:
CREATE TABLE [{{SCHEMA_NAME}}].[Settings] (
[Key] NVARCHAR(100) NOT NULL,
[Value] NVARCHAR(500) NULL,
CONSTRAINT [PK_Settings] PRIMARY KEY ([Key])
);
INSERT INTO [{{SCHEMA_NAME}}].[Settings] ([Key], [Value])
VALUES ('AdminEmail', '{{DEFAULT_ADMIN_EMAIL}}');
PRINT 'Deployed to {{ENV_LABEL}}';
Dubnium resolves each token as part of the deployment workflow, keeping environment values out of version-controlled SQL.
tip
Use clear uppercase names such as SCHEMA_NAME and ENV_LABEL so variables remain easy to spot during review.