Skip to content

Commit 199c7d7

Browse files
committed
Seed data
1 parent 01459d7 commit 199c7d7

File tree

13 files changed

+212
-40
lines changed

13 files changed

+212
-40
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,4 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v4
1212
- name: Build the stack
13-
run: docker compose up -d
14-
- name: Test
15-
run: docker compose logs sqlpackage
16-
- name: Stats
17-
run: docker compose stats --no-stream
18-
- name: Stop the stack
19-
run: docker compose down -v
13+
run: docker compose up --quiet-pull --no-color --remove-orphans --abort-on-container-failure --exit-code-from seed

DbProject/dbo/Tables/DimCustomer.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
CREATE TABLE [dbo].[DimCustomer] (
22
[CustomerKey] INT NOT NULL PRIMARY KEY,
3-
[CustomerAltKey] VARCHAR (50) NULL,
4-
[Title] VARCHAR (5) NULL,
53
[FirstName] VARCHAR (50) NOT NULL,
64
[LastName] VARCHAR (50) NULL,
75
[AddressLine1] VARCHAR (200) NULL,
86
[City] VARCHAR (50) NULL,
9-
[StateProvince] VARCHAR (50) NULL,
10-
[CountryRegion] VARCHAR (50) NULL,
117
[PostalCode] VARCHAR (20) NULL
128
);
139

DbProject/dbo/Tables/DimDate.sql

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
CREATE TABLE [dbo].[DimDate] (
22
[DateKey] INT NOT NULL PRIMARY KEY,
3-
[DateAltKey] DATE NOT NULL,
4-
[DayOfWeek] INT NOT NULL,
5-
[WeekDayName] VARCHAR (10) NULL,
6-
[DayOfMonth] INT NOT NULL,
7-
[Month] INT NOT NULL,
8-
[MonthName] VARCHAR (12) NULL,
9-
[Year] INT NOT NULL
3+
[Date] DATE NOT NULL
104
);
115

126

DbProject/dbo/Tables/DimProduct.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
CREATE TABLE [dbo].[DimProduct] (
2-
-- Update comment
32
[ProductKey] INT NOT NULL PRIMARY KEY,
4-
[ProductAltKey] VARCHAR (25) NULL,
53
[ProductName] VARCHAR (50) NOT NULL,
64
[Category] VARCHAR (50) NULL,
75
[ListPrice] DECIMAL (18) NULL
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
CREATE VIEW vSalesByCityAndCategory
3+
AS
4+
SELECT
5+
c.City,
6+
p.Category,
7+
SUM(f.Quantity) AS TotalQuantity,
8+
SUM(f.SalesTotal) AS TotalSales
9+
FROM
10+
dbo.FactSalesOrder f
11+
INNER JOIN dbo.DimCustomer c ON f.CustomerKey = c.CustomerKey
12+
INNER JOIN dbo.DimProduct p ON f.ProductKey = p.ProductKey
13+
GROUP BY
14+
c.City,
15+
p.Category
16+
17+
GO

DbProject/dbo/Views/vSalesByRegion.sql

Lines changed: 0 additions & 18 deletions
This file was deleted.

SQL/dw-seed.sql

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
-- Insert sample data into the Customers table
2+
MERGE INTO DimCustomer AS target
3+
USING (VALUES
4+
(1, 'John', 'Doe', '123 Main St', 'Springfield', '12345'),
5+
(2, 'Jane', 'Smith', '456 Elm St', 'Springfield', '12345'),
6+
(3, 'Bob', 'Jones', '789 Oak St', 'Springfield', '12345')
7+
) AS source (CustomerKey, FirstName, LastName, AddressLine1, City, PostalCode)
8+
ON target.CustomerKey = source.CustomerKey
9+
WHEN NOT MATCHED BY TARGET THEN
10+
INSERT (CustomerKey, FirstName, LastName, AddressLine1, City, PostalCode)
11+
VALUES (source.CustomerKey, source.FirstName, source.LastName, source.AddressLine1, source.City, source.PostalCode);
12+
13+
-- Insert sample data into the DimProducts table
14+
MERGE INTO DimProduct AS target
15+
USING (VALUES
16+
(1, 'Bike', 'BK-001', 1000.00),
17+
(2, 'Car', 'CR-001', 2000.00),
18+
(3, 'Truck', 'TR-001', 3000.00)
19+
) AS source (ProductKey, ProductName, Category, ListPrice)
20+
ON target.ProductKey = source.ProductKey
21+
WHEN NOT MATCHED BY TARGET THEN
22+
INSERT (ProductKey, ProductName, Category, ListPrice)
23+
VALUES (source.ProductKey, source.ProductName, source.Category, source.ListPrice);
24+
25+
-- Insert sample data into the DimDate table
26+
MERGE INTO DimDate AS target
27+
USING (VALUES
28+
(1, '2020-01-01'),
29+
(2, '2020-01-02'),
30+
(3, '2020-01-03')
31+
) AS source (DateKey, Date)
32+
ON target.DateKey = source.DateKey
33+
WHEN NOT MATCHED BY TARGET THEN
34+
INSERT (DateKey, Date)
35+
VALUES (source.DateKey, source.Date);
36+
37+
-- Insert sample data into the FactSales table
38+
MERGE INTO FactSalesOrder AS target
39+
USING (VALUES
40+
(1, 1, 1, 1, 1, 1000.00),
41+
(2, 2, 2, 2, 2, 4000.00),
42+
(3, 3, 3, 3, 3, 9000.00)
43+
) AS source (SalesOrderKey, SalesOrderDateKey, ProductKey, CustomerKey, Quantity, SalesTotal)
44+
ON target.SalesOrderKey = source.SalesOrderKey
45+
WHEN NOT MATCHED BY TARGET THEN
46+
INSERT (SalesOrderKey, SalesOrderDateKey, ProductKey, CustomerKey, Quantity, SalesTotal)
47+
VALUES (source.SalesOrderKey, source.SalesOrderDateKey, source.ProductKey, source.CustomerKey, source.Quantity, source.SalesTotal);

azure-sql-deploy-dacpac.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbProject", "DbProject\DbProject.sqlproj", "{0DA6EF13-79FA-455F-85E0-C6A54842EED0}"
77
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A1AF7517-E017-4C34-A844-B6A2A78D141A}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlClient.ConsoleApp", "src\SqlClient.ConsoleApp\SqlClient.ConsoleApp.csproj", "{405F855C-1D92-41FF-9E1A-EDDCE4305170}"
11+
EndProject
812
Global
913
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1014
Debug|Any CPU = Debug|Any CPU
@@ -18,5 +22,12 @@ Global
1822
{0DA6EF13-79FA-455F-85E0-C6A54842EED0}.Debug|Any CPU.Build.0 = Debug|Any CPU
1923
{0DA6EF13-79FA-455F-85E0-C6A54842EED0}.Release|Any CPU.ActiveCfg = Release|Any CPU
2024
{0DA6EF13-79FA-455F-85E0-C6A54842EED0}.Release|Any CPU.Build.0 = Release|Any CPU
25+
{405F855C-1D92-41FF-9E1A-EDDCE4305170}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{405F855C-1D92-41FF-9E1A-EDDCE4305170}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{405F855C-1D92-41FF-9E1A-EDDCE4305170}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{405F855C-1D92-41FF-9E1A-EDDCE4305170}.Release|Any CPU.Build.0 = Release|Any CPU
29+
EndGlobalSection
30+
GlobalSection(NestedProjects) = preSolution
31+
{405F855C-1D92-41FF-9E1A-EDDCE4305170} = {A1AF7517-E017-4C34-A844-B6A2A78D141A}
2132
EndGlobalSection
2233
EndGlobal

compose.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
services:
2+
seed:
3+
build:
4+
context: ./src/SqlClient.ConsoleApp
5+
tty: true
6+
container_name: seed
7+
working_dir: /app
8+
env_file:
9+
- .env
10+
environment:
11+
ConnectionString: "Server=tcp:db,1433;Initial Catalog=demo;UID=sa;Password=${MSSQL_SA_PASSWORD};TrustServerCertificate=true;Connection Timeout=3;"
12+
volumes:
13+
- $PWD/SQL/dw-seed.sql:/seed.sql
14+
entrypoint:
15+
- /bin/sh
16+
- -c
17+
- |
18+
./SqlClient.ConsoleApp /seed.sql
19+
# keep the container running (for debugging)
20+
#tail -f /dev/null
21+
depends_on:
22+
sqlpackage:
23+
condition: service_completed_successfully
24+
required: true
25+
226
sqlpackage:
327
build:
428
context: ./docker/sqlpackage
@@ -19,8 +43,6 @@ services:
1943
- -c
2044
- |
2145
/scripts/deploy.sh
22-
# keep the container running (for debugging)
23-
tail -f /dev/null
2446
depends_on:
2547
db:
2648
condition: service_healthy
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# directories
2+
**/bin/
3+
**/obj/
4+
**/out/
5+
6+
# files
7+
Dockerfile*
8+
**/*.md

0 commit comments

Comments
 (0)