Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion distributions/teamcity/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ project.tasks.register("distribution", ModuleDistribution) {
dist.extraFileIdentifier = '-test'
dist.versionPrefix = 'Test'

dist.extraProperties = [supportedDatabases: "pgsql, mssql"]
dist.extraProperties = [supportedDatabases: "pgsql"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be able to remove this line. Then we can remove support for the "supportedDatabases" property in the product.

}


Expand Down
1 change: 0 additions & 1 deletion modules/ETLtest/module.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Name: ETLtest
SchemaVersion: 26.001
SupportedDatabases: mssql, pgsql
ManageVersion: true
29 changes: 29 additions & 0 deletions modules/ETLtest/resources/externalFixtures/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# External SQL Server fixtures

SQL Server is no longer supported as LabKey's primary database, but it **is** still supported as an external data source, including running stored procedures through the DataIntegration `StoredProcedureStep`. These scripts are the SQL Server dialect fixtures for that feature, preserved when the primary-DB SQL Server dbscripts were removed.

They are deliberately **not** under `schemas/dbscripts/`. The module upgrade scanner only reads `schemas/dbscripts/<dialect>/`, so nothing here can ever execute against the primary database. Apply them by hand to an external SQL Server database.

| Script | Contents |
|---|---|
| `sqlserver/etltest-procs.sql` | `etltest` schema, the `source` table, and the `etlTest` / `etlTestResultSet` procedures covering the nine test modes (return codes, raised errors, in/out parameter persistence, run and modified-since filter strategies, result sets) |
| `sqlserver/etltest-specialchars.sql` | `"etl test!schema"."etl""test proc!"` — identifier quoting/escaping for schema and procedure names containing spaces, `!`, and an embedded double-quote. Driven by `../ETLs/SProcSpecialCharacters.xml` |

## Porting notes

These were lifted from the deleted `schemas/dbscripts/sqlserver/` scripts and adjusted for a database that is not a LabKey primary DB:

- `entityid` is a LabKey alias type defined by `core`; replaced with `UNIQUEIDENTIFIER`.
- The `container` foreign key to `core.containers` was dropped — that table does not exist in an external database.
- `EXEC core.fn_dropifexists` calls were dropped for the same reason. Scripts assume a clean schema.
- The procedures are the final state, not the `CREATE` plus `ALTER` chain the versioned dbscripts carried.

The trap worth knowing before editing `etltest-specialchars.sql`: LabKey's `SqlScanner` does not understand `[bracket]` quoting and will misread a double-quote inside brackets as the start of a string literal. Use `"..."` with the interior quote doubled as `""`, and keep `SET QUOTED_IDENTIFIER ON`.

## Not wired up in TeamCity

There is no automated coverage for this path yet, and `test.properties.template` has no external-datasource keys at all — that absence, not a missing fixture, is the gap. Wiring it up needs, at minimum:

- external SQL Server datasource properties in `test.properties.template` and the TeamCity build configuration
- a way to apply these scripts to that database during test setup
- a skip gate for "an external SQL Server datasource is configured". Note this is **not** `SqlserverOnlyTest`, which means "the primary database is SQL Server" and is now permanently false.
203 changes: 203 additions & 0 deletions modules/ETLtest/resources/externalFixtures/sqlserver/etltest-procs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
/*
* Copyright (c) 2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

-- SQL Server fixture for the DataIntegration StoredProcedureStep. Apply by hand to an external SQL Server
-- database; see ../README.md. Not a module dbscript: it is deliberately outside schemas/dbscripts/ so the
-- module upgrade scanner never runs it against the primary database.

-- entityid is a LabKey alias type defined by core, and core.containers does not exist in an external
-- database, so container is a bare UNIQUEIDENTIFIER here with no foreign key. The primary-DB Postgres
-- script keeps both.
CREATE SCHEMA etltest;
GO

CREATE TABLE etltest.source(
RowId INT IDENTITY(1,1),
container UNIQUEIDENTIFIER,
created DATETIME,
modified DATETIME,
id VARCHAR(9),
name VARCHAR(100),
TransformRun INT,
rowversion rowversion,

CONSTRAINT PK_etlsource PRIMARY KEY (rowid),
CONSTRAINT AK_etlsource UNIQUE (container,id)
);
GO

CREATE PROCEDURE etltest.etlTest
@transformRunId int,
@containerId UNIQUEIDENTIFIER = NULL OUTPUT,
@rowsInserted int = 0 OUTPUT,
@rowsDeleted int = 0 OUTPUT,
@rowsModified int = 0 OUTPUT,
@returnMsg varchar(100) = 'default message' OUTPUT,
@debug varchar(1000) = '',
@filterRunId int = null,
@filterStartTimeStamp datetime = null OUTPUT,
@filterEndTimeStamp datetime = null OUTPUT,
@testMode int,
@testInOutParam varchar(10) = null OUTPUT,
@runCount int = 1 OUTPUT,
@previousFilterRunId int = -1 OUTPUT,
@previousFilterStartTimeStamp datetime = null OUTPUT,
@previousFilterEndTimeStamp datetime = null OUTPUT
AS
BEGIN

/*
Test modes
1 normal operation
2 return code > 0
3 raise error
4 input/output parameter persistence
5 override of persisted input/output parameter
6 Run filter strategy, require filterRunId. Test persistence.
7 Modified since filter strategy, no source, require filterStartTimeStamp & filterEndTimeStamp,
populated from output of previous run
8 Modified since filter strategy with source, require filterStartTimeStamp & filterEndTimeStamp
populated from the filter strategy IncrementalStartTime & IncrementalEndTime
9 Sleep for 2 minutes before finishing
*/

IF @testMode IS NULL
BEGIN
SET @returnMsg = 'No testMode set'
RETURN 1
END

IF @runCount IS NULL
SET @runCount = 1;
ELSE
SET @runCount = @runCount + 1;

IF @testMode = 1
BEGIN
print 'Test print statement logging'
SET @rowsInserted = 1
SET @rowsDeleted = 2
SET @rowsModified = 4
SET @returnMsg = 'Test returnMsg logging'
RETURN 0
END

IF @testMode = 2 RETURN 1

IF @testMode = 3
BEGIN
SET @returnMsg = 'Intentional SQL Exception From Inside Proc'
RAISERROR(@returnMsg, 11, 1)
END

IF @testMode = 4 AND @testInOutParam != 'after' AND @runCount > 1
BEGIN
SET @returnMsg = 'Expected value "after" for @testInOutParam on run count = ' + convert(varchar, @runCount) + ', but was ' + @testInOutParam
RETURN 1
END

IF @testMode = 5 AND @testInOutParam != 'before' AND @runCount > 1
BEGIN
SET @returnMsg = 'Expected value "before" for @testInOutParam on run count = ' + convert(varchar, @runCount) + ', but was ' + @testInOutParam
RETURN 1
END

IF @testMode = 6
BEGIN
IF @filterRunId IS NULL
BEGIN
SET @returnMsg = 'Required @filterRunId value not supplied'
RETURN 1
END
IF @runCount > 1 AND (@previousFilterRunId IS NULL OR @previousFilterRunId >= @filterRunId)
BEGIN
SET @returnMsg = 'Required @filterRunId was not persisted from previous run.'
RETURN 1
END
SET @previousFilterRunId = @filterRunId
END

IF @testMode = 7
BEGIN
IF @runCount > 1 AND (@filterStartTimeStamp IS NULL AND @filterEndTimeStamp IS NULL)
BEGIN
SET @returnMsg = 'Required filterStartTimeStamp or filterEndTimeStamp were not persisted from previous run.';
RETURN 1;
END;
SET @filterStartTimeStamp = CURRENT_TIMESTAMP;
SET @filterEndTimeStamp = CURRENT_TIMESTAMP;
END;

IF @testMode = 8

BEGIN
IF @runCount > 1 AND ((@previousFilterStartTimeStamp IS NULL AND @previousFilterEndTimeStamp IS NULL)
OR (@filterStartTimeStamp IS NULL AND @filterEndTimeStamp IS NULL))
BEGIN
SET @returnMsg = 'Required filterStartTimeStamp or filterEndTimeStamp were not persisted from previous run.';
RETURN 1;
END;
SET @previousFilterStartTimeStamp = coalesce(@filterStartTimeStamp, CURRENT_TIMESTAMP);
SET @previousFilterEndTimeStamp = coalesce(@filterEndTimeStamp, CURRENT_TIMESTAMP);
END;

IF @testMode = 9
BEGIN
-- Sleep for 30 seconds
WAITFOR DELAY '00:00:30'
RETURN 1;
END;

-- set value for persistence tests
IF @testInOutParam IS NOT NULL AND @testInOutParam != '' SET @testInOutParam = 'after'

RETURN 0

END
GO

-- testMode 9 returns a result set rather than only output parameters, exercising the step's result-set handling.
CREATE PROCEDURE etltest.etlTestResultSet
@transformRunId int,
@containerId varchar(100) = NULL OUTPUT,
@rowsInserted int = 0 OUTPUT,
@rowsDeleted int = 0 OUTPUT,
@rowsModified int = 0 OUTPUT,
@returnMsg varchar(100) = 'default message' OUTPUT,
@debug varchar(1000) = '',
@filterRunId int = null,
@filterStartTimeStamp datetime = null OUTPUT,
@filterEndTimeStamp datetime = null OUTPUT,
@testMode int,
@testInOutParam varchar(10) = null OUTPUT,
@runCount int = 1 OUTPUT,
@previousFilterRunId int = null OUTPUT,
@previousFilterStartTimeStamp datetime = null OUTPUT,
@previousFilterEndTimeStamp datetime = null OUTPUT
AS
BEGIN

IF @testMode = 9
BEGIN
SELECT * FROM etltest.source WHERE container = @containerId
END

IF @testInOutParam IS NOT NULL SET @testInOutParam = 'after'

RETURN 0

END
GO
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
* limitations under the License.
*/

-- Create a schema and stored procedure whose names contain special characters (spaces, exclamation point, and an
-- SQL Server fixture for the DataIntegration StoredProcedureStep. Apply by hand to an external SQL Server
-- database; see ../README.md. Not a module dbscript: it is deliberately outside schemas/dbscripts/ so the
-- module upgrade scanner never runs it against the primary database.

-- Creates a schema and stored procedure whose names contain special characters (spaces, exclamation point, and an
-- embedded double-quote in the procedure name). These exercise the identifier quoting/escaping that SqlDialect
-- applies when building the CALL statement for the DataIntegration StoredProcedureStep. The schema is registered
-- with the module via the matching schema metadata file; it is created here because the module dbscript filename
-- convention only permits word-character schema names.
-- applies when building the CALL statement for the StoredProcedureStep. Driven by ETLs/SProcSpecialCharacters.xml.

-- Use double-quote delimited identifiers (with the interior quote doubled as "") rather than [bracket] identifiers.
-- LabKey's SqlScanner, which splits scripts into statements, does not understand bracket quoting and would misread a
Expand Down
Loading