Skip to content

Commit

Permalink
fix: alteração em docker-compose para criação de intancia com banco d…
Browse files Browse the repository at this point in the history
…e dados

Estava ocorrendo um erro de conexão pois o Nhibernate no Progra.cs procurava uma conexão com o banco MercadoLivreClone. Porém, o BD ainda não existia.

A solução foi criar o BD pelo Docker conforme a sugestão em:
microsoft/mssql-docker#2 (comment)
  • Loading branch information
hd1fernando committed Jun 5, 2022
1 parent 97653f4 commit ebf841f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 6 deletions.
2 changes: 2 additions & 0 deletions data/Entropy.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
���[�dlY��^k�醖�$�/V>����!s�kw�MȠ���𠖵����0��j� ��0����)�~Do(�x�Ҍ9F�:W�}�������+�~/Ǖ�*JuU��L�1B�\ۍ�AG�Q]��u@���@2�J��!f�����-�'k>ߒ��Xr�\M�`i0���@i�Ɛ�=��w�!;����a
\8�ba΂줉���Z�}��� ���t�"9]m��~��&�a,���j��l���t {
Expand Down
6 changes: 6 additions & 0 deletions data/db-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#wait for the SQL Server to come up
sleep 30s

echo "running set up script"
#run the setup script to create the DB and the schema in the DB
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P P@ssword42 -d master -i db-init.sql
11 changes: 11 additions & 0 deletions data/db-init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
USE [master]
GO

IF DB_ID('MercadoLivreClone') IS NOT NULL
set noexec on -- prevent creation when already exists

CREATE DATABASE [MercadoLivreClone];
GO

USE [MercadoLivre]
GO
2 changes: 2 additions & 0 deletions data/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#start SQL Server, start the script to create/setup the DB
/db-init.sh & /opt/mssql/bin/sqlservr
15 changes: 11 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ version: '3'
services:
db:
image: "mcr.microsoft.com/mssql/server:2019-latest"
environment:
SA_PASSWORD: P@ssword42
ACCEPT_EULA: "Y"
container_name: mssql
command: /bin/bash ./entrypoint.sh
ports:
- 1433:1433
- 1433:1433
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=P@ssword42
volumes:
- ./data:/var/opt/mssql/data
- ./data/entrypoint.sh:/entrypoint.sh
- ./data/db-init.sh:/db-init.sh
- ./data/db-init.sql:/db-init.sql
2 changes: 1 addition & 1 deletion src/MercadoLivre.Clone.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
},
"ConnectionStrings": {
"DefaultConnection": "Server=localhost,1433;DataBase=CasaDoCodigoClone;User Id=sa;Password=P@ssword42;Trusted_Connection=false"
"DefaultConnection": "Server=localhost,1433;DataBase=MercadoLivreClone;User Id=sa;Password=P@ssword42;Trusted_Connection=false"
},
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FluentMigrator;


namespace MercadoLivre.Clone.Data.Migrations
{
[Migration(2022202442, "Criação da tabela Categoria")]
Expand All @@ -21,4 +22,4 @@ public override void Up()
}
}
}
// dotnet-fm migrate -a .\MercadoLivre.Clone.Data.Migrations.dll -p SqlServer2016 -o -t local -c "Server=localhost,1433;DataBase=CasaDoCodigoClone;User Id=sa;Password=P@ssword42;Trusted_Connection=false" --allowDirtyAssemblies
// dotnet-fm migrate -a .\MercadoLivre.Clone.Data.Migrations.dll -p SqlServer2016 -o -t local -c "Server=localhost,1433;DataBase=MercadoLivreClone;User Id=sa;Password=P@ssword42;Trusted_Connection=false" --allowDirtyAssemblies

0 comments on commit ebf841f

Please sign in to comment.