Skip to content

Commit

Permalink
Merge pull request #153 from 0GiS0/add-sample-data
Browse files Browse the repository at this point in the history
Add sample data for dev container environment
  • Loading branch information
0GiS0 authored Jun 10, 2024
2 parents 0cfc678 + 2bb9023 commit 10e713e
Show file tree
Hide file tree
Showing 5 changed files with 323 additions and 44 deletions.
27 changes: 27 additions & 0 deletions .devcontainer/db-init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = 'heroes')
BEGIN
CREATE DATABASE heroes;
END
GO

USE heroes;
GO

IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Heroes')
BEGIN
CREATE TABLE Heroes (
Id INT PRIMARY KEY,
Name NVARCHAR(100),
AlterEgo NVARCHAR(100),
Description NVARCHAR(255)
);
END
GO

INSERT INTO Heroes (Id, Name, AlterEgo, Description) VALUES
(1, 'Batman', 'Bruce Wayne', 'A wealthy American playboy, philanthropist, and owner of Wayne Enterprises.'),
(2, 'Superman', 'Clark Kent', 'A superhero who was born on the planet Krypton and was given the name Kal-El at birth.'),
(3, 'Wonder Woman', 'Diana Prince', 'A demigoddess and warrior princess of the Amazons.'),
(4, 'Flash', 'Barry Allen', 'A superhero with the power of super speed.'),
(5, 'Green Lantern', 'Hal Jordan', 'A test pilot who was chosen to become the first human member of the Green Lantern Corps.');
GO
17 changes: 17 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,25 @@
],
"customizations": {
"vscode": {
"settings": {
"mssql.connections": [
{
"server": "db,1433",
"database": "heroes",
"authenticationType": "SqlLogin",
"user": "sa",
"password": "P@ssword",
"emptyPasswordInput": false,
"savePassword": false,
"profileName": "mssql-container",
"trustServerCertificate": true
}
]
},

"extensions": [
"ms-azuretools.vscode-docker",
"ms-mssql.mssql",
"GitHub.copilot",
"dbaeumer.vscode-eslint",
"DavidAnson.vscode-markdownlint",
Expand Down
23 changes: 22 additions & 1 deletion .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,36 @@ services:
API_URL: https://${CODESPACE_NAME}-5010.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/api/hero
command: sleep infinity
api:
depends_on:
- db
- init-db
image: ghcr.io/0gis0/tour-of-heroes-dotnet-api/tour-of-heroes-api:6b947c4
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ConnectionStrings__DefaultConnection=Server=db,1433;Initial Catalog=heroes;Persist Security Info=False;User ID=sa;Password=P@ssword;TrustServerCertificate=True;
ports:
- "5010:5000"
db:
db:
image: mcr.microsoft.com/azure-sql-edge
restart: unless-stopped
environment:
SA_PASSWORD: P@ssword
ACCEPT_EULA: Y
init-db:
image: mcr.microsoft.com/azure-sql-edge
command: >
/bin/bash -c "
while ! /opt/mssql-tools/bin/sqlcmd -S db -U sa -P 'P@ssword' -Q 'SELECT * FROM sys.databases' > /dev/null 2>&1; do
echo 'Waiting for SQL Server to become available...'
sleep 1
done;
echo 'SQL Server is now available.'
/opt/mssql-tools/bin/sqlcmd -S db -U sa -P 'P@ssword' -i /tmp/db-init.sql;
"
volumes:
- ./db-init.sql:/tmp/db-init.sql
environment:
SA_PASSWORD: P@ssword
ACCEPT_EULA: Y
restart: on-failure
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,15 @@ npm start
```

El proceso arrancará y estará disponible en esta dirección: [http://localhost:4200/](http://localhost:4200/)

## Uso de Datos de Muestra para Pruebas

Para facilitar las pruebas en el entorno de desarrollo, se ha incluido un conjunto de datos de muestra en la base de datos del contenedor de desarrollo. Estos datos permiten probar la aplicación sin necesidad de configurar una base de datos externa o realizar inserciones manuales de datos.

Para utilizar estos datos de muestra, asegúrate de que el contenedor de desarrollo esté en ejecución y sigue estos pasos:

1. Accede al contenedor de la base de datos utilizando tu herramienta de gestión de bases de datos preferida.
2. Verifica que los datos de muestra se han insertado correctamente ejecutando consultas de selección en las tablas relevantes.
3. Utiliza estos datos para realizar pruebas de funcionalidad en la aplicación.

Estos datos de muestra están diseñados para cubrir casos de uso comunes y facilitar el proceso de desarrollo y pruebas.
Loading

0 comments on commit 10e713e

Please sign in to comment.