Skip to content

Commit

Permalink
DFE-603: Adding full sql content db
Browse files Browse the repository at this point in the history
  • Loading branch information
James Cutts committed Jun 14, 2019
1 parent fb59c9f commit 6307bae
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
## Application
bin
obj
/data/
/data/ees-mssql
dfe-meta.db

## CSharp
Expand Down
19 changes: 19 additions & 0 deletions data/sql-scripts/setup-db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
IF NOT EXISTS
(
SELECT name FROM master.dbo.sysdatabases
WHERE name = N'content'
)
BEGIN
CREATE DATABASE [content]
SELECT 'content database has been created'
END;

IF NOT EXISTS
(
SELECT name FROM master.dbo.sysdatabases
WHERE name = N'statistics'
)
BEGIN
CREATE DATABASE [statistics]
SELECT 'statistics database has been created'
END;
26 changes: 6 additions & 20 deletions src/GovUk.Education.ExploreEducationStatistics.Admin/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,12 @@ public void ConfigureServices(IServiceCollection services)
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

var connectionString = Configuration.GetConnectionString("ContentDb");

if (string.IsNullOrWhiteSpace(connectionString))
{
const string connection = "Data Source=../GovUk.Education.ExploreEducationStatistics.Content.Api/dfe-meta.db";

services.AddDbContext<ApplicationDbContext>(options =>
options
.UseSqlite(connection,
builder => builder.MigrationsAssembly(typeof(Startup).Assembly.FullName))
.EnableSensitiveDataLogging()
);
}
else
{
services.AddDbContext<ApplicationDbContext>(options =>
options
.UseSqlServer(connectionString,
builder => builder.MigrationsAssembly(typeof(Startup).Assembly.FullName)));
}
services.AddDbContext<ApplicationDbContext>(options =>
options
.UseSqlServer(Configuration.GetConnectionString("ContentDb"),
builder => builder.MigrationsAssembly(typeof(Startup).Assembly.FullName))
.EnableSensitiveDataLogging()
);

// In production, the React files will be served from this directory
services.AddSpaStaticFiles(configuration =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"ConnectionStrings": {
"AzureStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;",
"NotificationService" : "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;"
"NotificationService": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;",
"ContentDb": "Server=localhost;Database=content;User=SA;Password=Your_Password123;Trusted_Connection=True;"
},
"Logging": {
"LogLevel": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup>
<ActiveDebugProfile>GovUK.Education.ExploreEducationStatistics.Meta.Api</ActiveDebugProfile>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,12 @@ public void ConfigureServices(IServiceCollection services)
options.SerializerSettings.Converters.Add(new ContentBlockConverter());
});

var connectionString = Configuration.GetConnectionString("ContentDb");

if (string.IsNullOrWhiteSpace(connectionString))
{
const string connection = "Data Source=dfe-meta.db";

services.AddDbContext<ApplicationDbContext>(options =>
options
.UseSqlite(connection,
builder => builder.MigrationsAssembly(typeof(Startup).Assembly.FullName))
.EnableSensitiveDataLogging()
);
}
else
{
services.AddDbContext<ApplicationDbContext>(options =>
options
.UseSqlServer(connectionString,
builder => builder.MigrationsAssembly(typeof(Startup).Assembly.FullName)));
}
services.AddDbContext<ApplicationDbContext>(options =>
options
.UseSqlServer(Configuration.GetConnectionString("ContentDb"),
builder => builder.MigrationsAssembly(typeof(Startup).Assembly.FullName))
.EnableSensitiveDataLogging()
);

// Adds Brotli and Gzip compressing
services.AddResponseCompression();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"ConnectionStrings": {
"AzureStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://data-storage:10000/devstoreaccount1;"
"AzureStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://data-storage:10000/devstoreaccount1;",
"ContentDb": "Server=localhost;Database=content;User=SA;Password=Your_Password123;Trusted_Connection=True;"
},
"Logging": {
"LogLevel": {
Expand Down
28 changes: 15 additions & 13 deletions src/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@ services:
ASPNETCORE_ENVIRONMENT: Development
depends_on:
- data-storage
# frontend:
# container_name: ees-frontend
# build: explore-education-statistics-frontend
# volumes:
# - './explore-education-statistics-frontend:/usr/src/app'
# - '/usr/src/app/node_modules'
# ports:
# - '3000:3000'
# environment:
# - NODE_ENV=development
# depends_on:
# - data-api
# - content-api
data-storage:
container_name: ees-storage
build:
Expand All @@ -53,6 +40,21 @@ services:
- "1433:1433"
volumes:
- ../data/ees-mssql:/var/opt/mssql/data
- ../data/sql-scripts:/scripts/
environment:
SA_PASSWORD: "Your_Password123"
ACCEPT_EULA: "Y"
command:
- /bin/bash
- -c
- |
# Launch MSSQL and send to background
/opt/mssql/bin/sqlservr &
# Wait 30 seconds for it to be available
sleep 30
# Run the setup script to create the two databases
/opt/mssql-tools/bin/sqlcmd -U sa -P $$SA_PASSWORD -l 30 -e -i /scripts/setup-db.sql
# So that the container doesn't shut down, sleep this thread
sleep infinity

0 comments on commit 6307bae

Please sign in to comment.