Skip to content
Merged
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 .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
]
}
}
}
}
22 changes: 15 additions & 7 deletions DbProject/dbo/Tables/DimCustomer.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
CREATE TABLE [dbo].[DimCustomer] (
[CustomerKey] INT NOT NULL PRIMARY KEY,
[FirstName] VARCHAR (50) NOT NULL,
[LastName] VARCHAR (50) NULL,
[AddressLine1] VARCHAR (200) NULL,
[City] VARCHAR (50) NULL,
[PostalCode] VARCHAR (20) NULL
CREATE TABLE [dbo].[DimCustomer]
(
[CustomerKey] INT NOT NULL PRIMARY KEY,
[FirstName] VARCHAR (50) NOT NULL,
[LastName] VARCHAR (50) NOT NULL,
[AddressLine1] VARCHAR (200) NOT NULL,
[City] VARCHAR (50) NOT NULL,
[PostalCode] VARCHAR (20) NOT NULL
);
GO

CREATE INDEX IX_DimCustomer_Name ON [dbo].[DimCustomer] ([FirstName], [LastName]);
GO
CREATE INDEX IX_DimCustomer_Address ON [dbo].[DimCustomer] ([AddressLine1], [City], [PostalCode]);
GO

ALTER TABLE [dbo].[DimCustomer]
ADD CONSTRAINT AK_DimCustomer UNIQUE ([FirstName], [LastName], [AddressLine1], [City], [PostalCode]);
GO
10 changes: 6 additions & 4 deletions DbProject/dbo/Tables/DimDate.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
CREATE TABLE [dbo].[DimDate] (
[DateKey] INT NOT NULL PRIMARY KEY,
[Date] DATE NOT NULL
CREATE TABLE [dbo].[DimDate]
(
[DateKey] INT NOT NULL PRIMARY KEY,
[Date] DATE NOT NULL
);
GO


CREATE INDEX IX_DimDate_DateKey ON [dbo].[DimDate] ([DateKey]);
GO
19 changes: 14 additions & 5 deletions DbProject/dbo/Tables/DimProduct.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
CREATE TABLE [dbo].[DimProduct] (
[ProductKey] INT NOT NULL PRIMARY KEY,
[ProductName] VARCHAR (50) NOT NULL,
[Category] VARCHAR (50) NULL,
[ListPrice] DECIMAL (18) NULL
CREATE TABLE [dbo].[DimProduct]
(
[ProductKey] INT NOT NULL PRIMARY KEY,
[ProductName] VARCHAR (50) NOT NULL,
[Category] VARCHAR (50) NOT NULL,
[ListPrice] DECIMAL (18, 2) NOT NULL
);
GO

CREATE INDEX IX_DimProduct_Name ON [dbo].[DimProduct] ([ProductName]);
GO

CREATE INDEX IX_DimProduct_Category ON [dbo].[DimProduct] ([Category]);
GO

ALTER TABLE [dbo].[DimProduct]
ADD CONSTRAINT AK_DimProduct UNIQUE ([ProductName], [Category]);
GO
13 changes: 9 additions & 4 deletions DbProject/dbo/Tables/FactSalesOrder.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
CREATE TABLE [dbo].[FactSalesOrder]
(
[SalesOrderKey] INT NOT NULL,
[SalesOrderKey] INT NOT NULL PRIMARY KEY,
[SalesOrderDateKey] INT NOT NULL,
[ProductKey] INT NOT NULL,
[CustomerKey] INT NOT NULL,
[Quantity] INT NULL,
[SalesTotal] DECIMAL (18) NULL
[Quantity] INT NOT NULL DEFAULT 0,
[SalesTotal] DECIMAL (18, 2) NOT NULL DEFAULT 0.00,

CONSTRAINT [PK_FactSalesOrder] PRIMARY KEY CLUSTERED ([SalesOrderKey] ASC),
CONSTRAINT [FK_FactSalesOrder_DimDate] FOREIGN KEY ([SalesOrderDateKey]) REFERENCES [dbo].[DimDate] ([DateKey]),
CONSTRAINT [FK_FactSalesOrder_DimProduct] FOREIGN KEY ([ProductKey]) REFERENCES [dbo].[DimProduct] ([ProductKey]),
CONSTRAINT [FK_FactSalesOrder_DimCustomer] FOREIGN KEY ([CustomerKey]) REFERENCES [dbo].[DimCustomer] ([CustomerKey])
);
GO

CREATE INDEX IX_FactSalesOrder_DateKey ON [dbo].[FactSalesOrder] ([SalesOrderDateKey]);
GO
CREATE INDEX IX_FactSalesOrder_ProductKey ON [dbo].[FactSalesOrder] ([ProductKey]);
GO
CREATE INDEX IX_FactSalesOrder_CustomerKey ON [dbo].[FactSalesOrder] ([CustomerKey]);
GO
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ build:
dotnet outdated --upgrade
dotnet build

test:
#dotnet test
./tests/test.sh

clean:
dotnet clean
docker compose down --remove-orphans --volumes
4 changes: 2 additions & 2 deletions SQL/dw-seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
MERGE INTO DimCustomer AS target
USING (VALUES
(1, 'John', 'Doe', '123 Main St', 'Springfield', '12345'),
(2, 'Jane', 'Smith', '456 Elm St', 'Springfield', '12345'),
(3, 'Bob', 'Jones', '789 Oak St', 'Springfield', '12345')
(2, 'Jane', 'Doe', '456 Elm St', 'Springfield', '12345'),
(3, 'Alice', 'Smith', '789 Oak St', 'Springfield', '12345')
) AS source (CustomerKey, FirstName, LastName, AddressLine1, City, PostalCode)
ON target.CustomerKey = source.CustomerKey
WHEN NOT MATCHED BY TARGET THEN
Expand Down
5 changes: 3 additions & 2 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ services:
- .env
environment:
ConnectionString: "Server=tcp:db,1433;Initial Catalog=demo;UID=sa;Password=${MSSQL_SA_PASSWORD};TrustServerCertificate=true;Connection Timeout=3;"
# keep the container alive for debugging
DEBUG: "${DEBUG:-}"
volumes:
- $PWD/SQL/dw-seed.sql:/seed.sql
entrypoint:
- /bin/sh
- -c
- |
./SqlClient.ConsoleApp /seed.sql
# keep the container running (for debugging)
#tail -f /dev/null
if [ -n "$DEBUG" ];then tail -f /dev/null; fi
depends_on:
sqlpackage:
condition: service_completed_successfully
Expand Down
11 changes: 6 additions & 5 deletions tests/test.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash

# select all tables and views from sql server:
set -e

QUERY="
SELECT * FROM INFORMATION_SCHEMA.TABLES
"
DB="demo"
QUERY="SELECT * FROM vSalesByCityAndCategory"

docker exec -it --env-file .env db /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$MSSQL_SA_PASSWORD" -Q "$QUERY" -b
docker exec -it --env-file .env db /opt/mssql-tools/bin/sqlcmd \
-S localhost -U sa -P "$MSSQL_SA_PASSWORD" -d "$DB" -Q "$QUERY" -b
Loading