Skip to content

Commit e48eebf

Browse files
🔨 Support database initialization restore.
This will create the `SFADB_DEV` and `sfa_client_test` databases.
1 parent b551b05 commit e48eebf

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,15 @@ Writing code and developing in this application requires running three services:
3535
3. When the database starts the first time, the database will be empty. To load some seed data, you must obtain a database backup, and put it into `/db/backups/sfa.bak`, then run the follow commands:
3636

3737
```bash
38-
docker compose \
39-
-f docker-compose.dev.yml \
40-
exec -it db \
41-
/opt/mssql-tools/bin/sqlcmd \
42-
-U sa \
43-
-s localhost \
44-
-P Testing1122 \
45-
-Q "RESTORE DATABASE SFADB_DEV FROM DISK = N'backups/sfa.bak' WITH FILE = 1"
38+
dev up db
39+
#
40+
docker compose -f docker-compose.development.yml
4641
```
4742

4843
If you need to debug the restore, you can connect to the running SQL Server via
4944

5045
```bash
51-
docker compose -f docker-compose.dev.yml exec -it db bash
46+
docker compose -f docker-compose.development.yml exec -it db bash
5247
```
5348

5449
4. The first time you start the application, you must create a bucket named `documents` and an Access Key. Copy the access key id and secret and drop those values into the appropriate spots in the environment file. The Minio Web interface located at http://localhost:9090. Subsequent starts, it is not required to access the Minio interface.
@@ -140,7 +135,7 @@ Writing code and developing in this application requires running three services:
140135
To access the Database console directly use:
141136

142137
```bash
143-
docker compose -f docker-compose.dev.yml exec db /opt/mssql-tools/bin/sqlcmd -U sa -s localhost -P Testing1122
138+
docker compose -f docker-compose.development.yml exec db /opt/mssql-tools/bin/sqlcmd -U sa -s localhost -P Testing1122
144139
```
145140

146141
## Dev Command Usage

db/bin/configure-db.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ i=0
1111

1212
while [[ $DBSTATUS -ne 0 ]] && [[ $i -lt 60 ]] && [[ $ERRCODE -ne 0 ]]; do
1313
i=$i+1
14-
DBSTATUS=$(/opt/mssql-tools/bin/sqlcmd -h -1 -t 1 -U sa -P "$MSSQL_SA_PASSWORD" -Q "SET NOCOUNT ON; Select SUM(state) from sys.databases")
14+
DBSTATUS=$(/opt/mssql-tools/bin/sqlcmd -h -1 -t 1 -U sa -P "$MSSQL_SA_PASSWORD" -Q "SET NOCOUNT ON; Select SUM(state) from sys.databases WHERE name = 'master'")
1515
ERRCODE=$?
1616
sleep 1
1717
done
1818

1919
if [[ $DBSTATUS -ne 0 ]] || [[ $ERRCODE -ne 0 ]]; then
20-
echo "SQL Server took more than 60 seconds to start up or one or more databases are not in an ONLINE state"
20+
echo "SQL Server took more than 60 seconds to start up, master database is not in an ONLINE state"
2121
exit 1
2222
fi
2323

db/initializers/setup.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ IF NOT EXISTS (
99
FROM sys.databases
1010
WHERE name = N'SFADB_DEV'
1111
)
12-
CREATE DATABASE SFADB_DEV;
13-
GO
12+
RESTORE DATABASE SFADB_DEV FROM DISK = N'backups/sfa.bak';
1413

1514
IF NOT EXISTS (
1615
SELECT name
1716
FROM sys.databases
1817
WHERE name = N'sfa_client_test'
1918
)
20-
CREATE DATABASE sfa_client_test;
19+
RESTORE DATABASE sfa_client_test FROM DISK = N'backups/sfa.bak'
20+
WITH MOVE 'SFADB' TO '/var/opt/mssql/data/sfa_client_test.mdf',
21+
MOVE 'SFADB_log' TO '/var/opt/mssql/data/sfa_client_test_log.ldf';
2122
GO

0 commit comments

Comments
 (0)