Skip to content

Commit

Permalink
chore: Update database initialization script and devcontainer configu…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
0GiS0 committed Jun 10, 2024
1 parent 9f1adc5 commit 8c8b97e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
32 changes: 17 additions & 15 deletions .devcontainer/db-init.sql
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
CREATE DATABASE heroes;
GO;

IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = 'heroes')
BEGIN
CREATE DATABASE heroes;
END
GO

USE heroes;
GO;

GO

CREATE TABLE Heroes (
Id INT PRIMARY KEY,
Name NVARCHAR(100),
AlterEgo NVARCHAR(100),
Description NVARCHAR(255)
);

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;
GO
21 changes: 11 additions & 10 deletions .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ services:
ACCEPT_EULA: Y
init-db:
image: mcr.microsoft.com/azure-sql-edge
command: >
/bin/bash -c "
# Comando para esperar a que SQL esté listo (pseudocódigo)
while ! sqlcmd -U sa -P P@ssword -Q 'SELECT 1'; do
sleep 1
done;
# Comando para inicializar la base de datos, reemplazar con tu script real
sqlcmd -U sa -P P@ssword -i /init/db-init.sql;
"
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:/init/db-init.sql
- ./db-init.sql:/tmp/db-init.sql
environment:
SA_PASSWORD: P@ssword
ACCEPT_EULA: Y
Expand Down

0 comments on commit 8c8b97e

Please sign in to comment.