This repository has been archived by the owner on Apr 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#605 - Components for Docker database
- Loading branch information
1 parent
31db5cc
commit 2686fe2
Showing
12 changed files
with
160 additions
and
43 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: '2' | ||
|
||
services: | ||
mssql: | ||
image: mcr.microsoft.com/mssql/server:latest | ||
ports: | ||
- 1433:1433 | ||
environment: | ||
- ACCEPT_EULA=Y | ||
- SA_PASSWORD=magenicMAQS2 | ||
- MSSQL_PID=Developer | ||
expose: | ||
- 1433 | ||
volumes: | ||
# Mount the current directory onto /mnt/host on the image. | ||
- ./:/mnt/host/ | ||
# Run a custom bash script that bootstraps the database after it is started. | ||
command: ['/bin/bash', '/mnt/host/initialize_and_start_sqlserver.sh'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
{ | ||
# Wait for SQL Server to start up | ||
# Check if the server is ready | ||
not_ready=1 | ||
while [ $not_ready != 0 ] | ||
do | ||
# Wait for the return code of the following statement to be zero | ||
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P magenicMAQS2 -d master -Q "SELECT TOP 1 message_id FROM sys.messages" | ||
not_ready=$? | ||
|
||
if [ $not_ready != 0 ] | ||
then | ||
echo "Could not contact sql server, will try again in 5 seconds." | ||
sleep 5s | ||
fi | ||
done | ||
|
||
echo "Started initializing database" | ||
# Set up the schema and stored procedures | ||
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P magenicMAQS2 -d master -i `dirname $0`/schema.sql | ||
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P magenicMAQS2 -d master -i `dirname $0`/stored_procedures.sql | ||
# Use BCP to import test data | ||
/opt/mssql-tools/bin/bcp MagenicAutomation.dbo.States in "`dirname $0`/SeedData/MagenicAutomation/States.bcp" \ | ||
-n -S localhost -U sa -P magenicMAQS2 | ||
/opt/mssql-tools/bin/bcp MagenicAutomation.dbo.Cities in "`dirname $0`/SeedData/MagenicAutomation/Cities.bcp" \ | ||
-n -S localhost -U sa -P magenicMAQS2 | ||
/opt/mssql-tools/bin/bcp MagenicAutomation.dbo.Datatype in "`dirname $0`/SeedData/MagenicAutomation/Datatype.bcp" \ | ||
-n -S localhost -U sa -P magenicMAQS2 | ||
echo "Finished initializing database" | ||
}& | ||
|
||
# Start SQL server | ||
exec /opt/mssql/bin/sqlservr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
CREATE DATABASE MagenicAutomation; | ||
GO | ||
USE MagenicAutomation; | ||
GO | ||
CREATE TABLE [dbo].[States]( | ||
[StateID] [int] PRIMARY KEY IDENTITY(1,1) NOT NULL, | ||
[StateName] [nvarchar](max) NOT NULL, | ||
[StateAbbreviation] [nvarchar](2) NULL | ||
); | ||
GO | ||
CREATE TABLE [dbo].[Cities]( | ||
[CityID] [int] PRIMARY KEY IDENTITY(1,1) NOT NULL, | ||
[CityName] [nvarchar](max) NOT NULL, | ||
[CityPopulation] [decimal](18, 2) | ||
); | ||
GO | ||
CREATE TABLE [dbo].[Datatype]( | ||
[bitintType] [bigint] NULL, | ||
[bitType] [bit] NULL, | ||
[char10Type] [char](10) NULL, | ||
[dateType] [date] NULL, | ||
[dateTimeType] [datetime] NULL, | ||
[floatType] [float] NULL, | ||
[intType] [int] NULL, | ||
[ncharType] [nchar](10) NULL, | ||
[nvarcharType] [nvarchar](50) NULL, | ||
[varcharType] [varchar](50) NULL, | ||
[decimalType] [decimal](18, 2) NULL, | ||
[xmlType] [xml] NULL | ||
); | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
USE MagenicAutomation; | ||
GO | ||
CREATE PROCEDURE [dbo].[getStateAbbrevMatch] | ||
@StateAbbreviation VARCHAR(2) | ||
AS BEGIN | ||
SELECT StateAbbreviation FROM States | ||
WHERE StateAbbreviation = @StateAbbreviation | ||
END | ||
GO | ||
CREATE PROCEDURE [dbo].[setStateAbbrevToSelf] | ||
@StateAbbreviation VARCHAR(2) | ||
AS BEGIN | ||
UPDATE States | ||
SET StateAbbreviation = @StateAbbreviation | ||
WHERE StateAbbreviation = @StateAbbreviation | ||
END | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters