Skip to content

Commit

Permalink
standardize the behaviour of the Docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr D authored and iaincollins committed Aug 31, 2020
1 parent 73d21e6 commit 8f0501b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
19 changes: 7 additions & 12 deletions test/docker/mssql.yml
@@ -1,20 +1,15 @@
# @FIXME The behaviour fo the MSSQL image differs slightly from the other images
# To make it easier to setupm run tests and maintain we probably want to
# standardize the behaviour of the Docker images, but not a priority yet.
# There might be a third party image that does this out of the box
# e.g. like the one from bitnami we use for mongodb
#
# * The default username is 'sa'
# * No database is created by default
version: '2'
version: "2"

services:

mssql:
image: mcr.microsoft.com/mssql/server:2017-latest
restart: always
environment:
SA_PASSWORD: Pa55w0rd
SA_PASSWORD: Pa55w0rd # minimum password complexity
ACCEPT_EULA: Y
ports:
- "1433:1433"
- "1433:1433" # map to non-default port, to avoid conflicts ?
# WARN: command overrides, default image start sequence, start.sh starts 'sql-server'
command: '/var/setup/start.sh'
volumes:
- ./mssql:/var/setup # mount setup files
7 changes: 7 additions & 0 deletions test/docker/mssql/setup.sh
@@ -0,0 +1,7 @@
#!/usr/bin/env sh
# see https://github.com/Microsoft/mssql-docker
# no way to know when sql server is ready
until /opt/mssql-tools/bin/sqlcmd -S 127.0.01 -U sa -P Pa55w0rd -d master -i /var/setup/setup.sql
do sleep 1;
done
echo "NEXT_AUTH: setup completed"
15 changes: 15 additions & 0 deletions test/docker/mssql/setup.sql
@@ -0,0 +1,15 @@
USE master;
if not exists (select name from sys.syslogins where name = 'nextauth')
CREATE LOGIN nextauth
WITH PASSWORD = 'password',
CHECK_POLICY = OFF;
GO
if not exists (select name from sys.databases where name = 'nextauth' )
CREATE database nextauth
GO
USE nextauth;
if not exists(select [name] from sys.sysusers where name= 'nextauth')
CREATE USER nextauth FOR LOGIN nextauth
WITH DEFAULT_SCHEMA =[dbo];
GO
EXEC sp_addrolemember 'db_owner', 'nextauth'
4 changes: 4 additions & 0 deletions test/docker/mssql/start.sh
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
# launch setup on the background & start server
# otherise sqlservr won't start
/var/setup/setup.sh & /opt/mssql/bin/sqlservr
17 changes: 4 additions & 13 deletions test/mssql.js
Expand Up @@ -8,9 +8,7 @@ const Adapters = require('../adapters');
const SCHEMA_FILE = path.join(__dirname, '/fixtures/schemas/mssql.json');
const expectedSchema = JSON.parse(fs.readFileSync(SCHEMA_FILE));
const TABLES = Object.keys(expectedSchema);

const serverUrl = `mssql://sa:Pa55w0rd@127.0.0.1:1433`;
const dbName = 'nextauth';
const databaseUrl = `mssql://nextauth:password@127.0.0.1:1433/nextauth?synchronize=true`;

function printSchema() {
return new Promise(async (resolve) => {
Expand All @@ -19,19 +17,12 @@ function printSchema() {
*/
let connection;
try {
// connect to server, no db ...(it doesn't exists)
connection = await mssql.connect(serverUrl);
// create table before Adapter
await connection.query(
`if(exists(select [name] from sys.databases where name = '${dbName}'))` +
`drop database [${dbName}];` +
`create database [${dbName}];`
);
connection = await mssql.connect(databaseUrl);
// Invoke adapter to sync schema
await (Adapters.Default(`${serverUrl}/${dbName}?synchronize=true`)).getAdapter();
await (Adapters.Default(databaseUrl)).getAdapter();
// query schema
const { recordset } = await connection.query(
`use [${dbName}]; ` +
`use [nextauth]; ` +
TABLES.map(
(table) =>
`select * from INFORMATION_SCHEMA.COLUMNS` +
Expand Down

0 comments on commit 8f0501b

Please sign in to comment.