Skip to content

Commit

Permalink
Merge commit '9d9c333b15068df7709baf722dd2e1e27787b2d0'
Browse files Browse the repository at this point in the history
Update subtree
  • Loading branch information
segovoni committed Sep 30, 2022
2 parents d1af589 + 9d9c333 commit 97eb5a5
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 20 deletions.
85 changes: 85 additions & 0 deletions Libraries/sp_alter_column/.github/workflows/unit-test-runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# This workflow installs tSQLt and runs the test units

name: tSQLt installer and unit testing runner

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "master" branch
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
windows-auth-tsqlt:
name: Installting tSQLt with SQL Auth
# The type of runner that the job will run on
runs-on: ubuntu-latest

services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2022-latest
ports:
- 1433:1433
env:
ACCEPT_EULA: Y
SA_PASSWORD: 3uuiCaKxfbForrK

steps:
- uses: actions/checkout@v2

- name: Install tSQLt with SQL auth
uses: lowlydba/tsqlt-installer@v1
with:
sql-instance: localhost
database: tempdb
version: latest
user: sa
password: 3uuiCaKxfbForrK

#- name: Get the containers list unformatted
# run: docker ps

#- name: Get the containers list formatted
# run: docker ps --all --filter status=running --no-trunc --format "{{.ID}}"

#- name: Set the container ID
# run: echo '::set-output name=CONTAINER_ID::$(docker ps --all --filter status=running --no-trunc --format "{{.ID}}")'
# id: ContainerID

#- name: Get container ID
# run: echo "The container ID is ${{ steps.ContainerID.outputs.CONTAINER_ID }}"

- name: Set environment variable ENV_CONTAINER_ID
run: echo "ENV_CONTAINER_ID=$(docker ps --all --filter status=running --no-trunc --format "{{.ID}}")" >> $GITHUB_ENV

- name: Test environment variable ENV_CONTAINER_ID
run: echo $ENV_CONTAINER_ID

#- name: Print environment variables
# run: env

- name: Get the database list
run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -Q "SELECT Name FROM sys.databases"

- name: Copy file sp-alter-column.sql into ENV_CONTAINER_ID
run: docker cp ./source/sp-alter-column.sql $ENV_CONTAINER_ID:/

- name: Create the system under test (SUT) sp_alter_column
run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -d tempdb < ./source/sp-alter-column.sql

#- name: Get the stored procedures list
# run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -d tempdb -Q "SELECT Name FROM sys.procedures"

- name: Create tSQLt test class for sp_alter_column
run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -d tempdb -Q "EXEC tSQLt.NewTestClass 'UnitTestAlterColumn'"

- name: Create and run unit test [test alter column with PK]
run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -d tempdb < ./unit-test/sp-alter-column-unit-test-30-test-alter-column-with-PK.sql

- name: Create and run unit test [test alter column with FK]
run: docker exec -i $ENV_CONTAINER_ID /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "3uuiCaKxfbForrK" -d tempdb < ./unit-test/sp-alter-column-unit-test-31-test-alter-column-with-FK.sql

4 changes: 3 additions & 1 deletion Libraries/sp_alter_column/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# SQL Server sp_alter_column stored procedure!
[![tSQLt installer and unit testing runner](https://github.com/segovoni/sp_alter_column/actions/workflows/unit-test-runner.yml/badge.svg)](https://github.com/segovoni/sp_alter_column/actions/workflows/unit-test-runner.yml)

# sp_alter_column stored procedure for SQL Server!

The *sp_alter_column* stored procedure is able to alter a column with dependencies in your SQL Server database!

Expand Down
8 changes: 4 additions & 4 deletions Libraries/sp_alter_column/source/sp-alter-column.sql
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,8 @@ AS BEGIN
,sqltext
)
SELECT
Stat.schemaname
,Stat.tablename
Stat.SchemaName
,Stat.TableName
,'STATS' AS objecttype
,'C' AS operationtype
,Stat.SQLStr + ')'
Expand Down Expand Up @@ -740,7 +740,7 @@ AS BEGIN
JOIN
sys.objects AS O ON (O.object_id=Create_Indexes.object_id)
WHERE
(Create_Indexes.RowType='R')
(Create_Indexes.rowtype='R')
GROUP BY
Create_Indexes.object_id
,Create_Indexes.index_id
Expand Down Expand Up @@ -1081,4 +1081,4 @@ AS BEGIN
RAISERROR(@ErrorMessage, @ErrorSeverity, @ErrorState);
END CATCH
END;
GO
GO
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ USE [master];
GO

-- Drop database if exists
IF (DB_ID('Alter_Column_DB') IS NOT NULL)
IF (DB_ID('sp_alter_column_devtest') IS NOT NULL)
BEGIN
ALTER DATABASE [Alter_Column_DB]
ALTER DATABASE [sp_alter_column_devtest]
SET SINGLE_USER WITH ROLLBACK IMMEDIATE;

DROP DATABASE [Alter_Column_DB];
DROP DATABASE [sp_alter_column_devtest];
END;
GO

-- Create database
CREATE DATABASE [Alter_Column_DB];
CREATE DATABASE [sp_alter_column_devtest];
GO

/*
USE [Alter_Column_DB];
USE [sp_alter_column_devtest];
GO
IF OBJECT_ID('dbo.Tab2', 'U') IS NOT NULL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ EXEC sp_configure 'clr enabled';
GO


USE [Alter_Column_DB];
USE [sp_alter_column_devtest];
GO

-- Enable TRUSTWORTHY property at the database level
-- in each database you want to install tSQLt framework
ALTER DATABASE [Alter_Column_DB] SET TRUSTWORTHY ON;
ALTER DATABASE [sp_alter_column_devtest] SET TRUSTWORTHY ON;
GO


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
-- Notes: -- -
------------------------------------------------------------------------

USE [Alter_Column_DB];
USE [sp_alter_column_devtest];
GO


/*
1. Download sp_alter_column from https://github.com/segovoni/sp_alter_column
2. Execute sp-alter-column.sql in the database you have just installed
tSQLt framework (Alter_Column_DB for this example)
tSQLt framework (sp_alter_column_devtest for this example)
*/
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
-- Notes: -- -
------------------------------------------------------------------------

USE [Alter_Column_DB];
GO

CREATE OR ALTER PROCEDURE UnitTestAlterColumn.[test alter column with PK]
AS
Expand Down Expand Up @@ -103,7 +101,7 @@ END;
GO


EXEC tSQLt.Run'UnitTestAlterColumn.[test alter column with PK]';
EXEC tSQLt.Run 'UnitTestAlterColumn.[test alter column with PK]';
GO


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
-- Notes: -- -
------------------------------------------------------------------------

USE [Alter_Column_DB];
GO


CREATE OR ALTER PROCEDURE UnitTestAlterColumn.[test alter column with FK]
AS
Expand Down

0 comments on commit 97eb5a5

Please sign in to comment.