File size: 7,663 Bytes
af136d8
 
 
 
 
 
94aa430
af136d8
 
94aa430
 
af136d8
94aa430
 
af136d8
 
 
 
 
 
 
 
 
 
 
94aa430
af136d8
94aa430
af136d8
 
94aa430
 
 
 
af136d8
 
94aa430
af136d8
 
 
 
94aa430
af136d8
 
 
94aa430
 
 
 
 
 
 
 
 
 
 
 
 
 
 
af136d8
 
 
94aa430
af136d8
 
 
 
 
 
 
 
 
 
 
 
94aa430
 
af136d8
 
 
 
94aa430
 
af136d8
 
 
 
 
 
 
 
 
94aa430
af136d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94aa430
 
 
af136d8
 
94aa430
af136d8
 
 
 
 
 
 
 
 
 
94aa430
 
 
af136d8
94aa430
af136d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94aa430
 
af136d8
 
94aa430
 
 
 
 
 
 
 
 
 
 
 
 
af136d8
 
94aa430
 
 
af136d8
94aa430
 
af136d8
94aa430
af136d8
 
94aa430
 
 
 
 
 
 
 
 
 
 
 
af136d8
 
 
 
 
 
 
 
94aa430
 
af136d8
 
 
 
 
 
 
 
 
 
94aa430
 
 
 
af136d8
 
 
94aa430
 
 
af136d8
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
@echo off
REM ============================================================
REM  sec_fsnds - Local Docker setup
REM ============================================================
REM  This script:
REM    1. Asks the user for the values that differ per-host
REM       (sa password, port, data dir, container name, edition)
REM    2. Writes a .env file that docker compose will read
REM    3. Downloads Dockerfile + docker-compose.yaml from Hugging Face
REM    4. Downloads the 4-part 7z archive (~40 GB total) from HF
REM    5. Extracts sec_fsnds.mdf + sec_fsnds_log.ldf into the data dir
REM
REM  Requires: curl (built in on Windows 10 1803+), Docker Desktop,
REM            and 7-Zip (7z.exe) on PATH or at the default install path
REM ============================================================

setlocal EnableDelayedExpansion

echo.
echo ============================================================
echo   sec_fsnds local setup
echo ============================================================
echo.

REM -------------------------------------------------------------
REM  Hugging Face URLs
REM -------------------------------------------------------------
set "HF_REPO=https://huggingface.co/datasets/DenyTranDFW/SEC-Financial-Statements-And-Notes-Dataset/resolve/main"
set "HF_DOCKERFILE=%HF_REPO%/Dockerfile"
set "HF_COMPOSE=%HF_REPO%/docker-compose.yaml"
set "HF_VOL1=%HF_REPO%/archive/sec_fsnds_db_4vol.7z.001"
set "HF_VOL2=%HF_REPO%/archive/sec_fsnds_db_4vol.7z.002"
set "HF_VOL3=%HF_REPO%/archive/sec_fsnds_db_4vol.7z.003"
set "HF_VOL4=%HF_REPO%/archive/sec_fsnds_db_4vol.7z.004"

REM -------------------------------------------------------------
REM  Sanity checks: curl and 7z must be available
REM -------------------------------------------------------------
where curl >nul 2>nul
if errorlevel 1 (
    echo ERROR: curl.exe was not found on PATH.
    echo        curl ships with Windows 10 1803 and later.
    exit /b 1
)

set "SEVENZIP="
where 7z >nul 2>nul
if not errorlevel 1 (
    set "SEVENZIP=7z"
) else if exist "C:\Program Files\7-Zip\7z.exe" (
    set "SEVENZIP=C:\Program Files\7-Zip\7z.exe"
) else (
    echo ERROR: 7-Zip (7z.exe) was not found on PATH or at
    echo        C:\Program Files\7-Zip\7z.exe
    echo        Download from https://www.7-zip.org and install before
    echo        running this script.
    exit /b 1
)
echo Found 7-Zip: !SEVENZIP!

REM -------------------------------------------------------------
REM  Prompts
REM -------------------------------------------------------------
echo.
echo You will be asked a few questions. Press Enter to accept the
echo value shown in [brackets].
echo.

set "SA_PASSWORD="
:ask_password
set /p "SA_PASSWORD=SQL Server 'sa' password (WARNING - visible as you type): "
if "!SA_PASSWORD!"=="" (
    echo   Password cannot be empty.
    goto ask_password
)

set "HOST_PORT=1434"
set /p "HOST_PORT=Host port to expose SQL Server on [1434]: "

set "CONTAINER_NAME=mssql-sec-fsnds"
set /p "CONTAINER_NAME=Docker container name [mssql-sec-fsnds]: "

set "HOST_DATA_DIR=%CD%\data"
set /p "HOST_DATA_DIR=Host directory for database files [%CD%\data]: "

set "MSSQL_PID=Developer"
set /p "MSSQL_PID=SQL Server edition (Developer/Express/Standard/Enterprise) [Developer]: "

echo.
echo --- Summary ---
echo   sa password  : (hidden)
echo   host port    : !HOST_PORT!
echo   container    : !CONTAINER_NAME!
echo   data dir     : !HOST_DATA_DIR!
echo   edition      : !MSSQL_PID!
echo.

set "CONFIRM=Y"
set /p "CONFIRM=Proceed with these values? [Y/n]: "
if /i "!CONFIRM!"=="N" (
    echo Aborted by user.
    exit /b 1
)

REM -------------------------------------------------------------
REM  Write .env
REM -------------------------------------------------------------
echo.
echo --- Writing .env ---
(
    echo # Generated by sec_fsnds_setup.cmd - do not commit this file
    echo ACCEPT_EULA=Y
    echo MSSQL_SA_PASSWORD=!SA_PASSWORD!
    echo MSSQL_PID=!MSSQL_PID!
    echo HOST_PORT=!HOST_PORT!
    echo CONTAINER_NAME=!CONTAINER_NAME!
    echo HOST_DATA_DIR=!HOST_DATA_DIR!
) > .env
if errorlevel 1 (
    echo ERROR: could not write .env
    exit /b 1
)
echo Wrote .env

REM -------------------------------------------------------------
REM  Create data directory
REM -------------------------------------------------------------
if not exist "!HOST_DATA_DIR!" (
    echo --- Creating data directory !HOST_DATA_DIR! ---
    mkdir "!HOST_DATA_DIR!"
    if errorlevel 1 (
        echo ERROR: could not create !HOST_DATA_DIR!
        exit /b 1
    )
)

REM -------------------------------------------------------------
REM  Download Dockerfile + compose
REM -------------------------------------------------------------
echo.
echo --- Downloading Dockerfile ---
curl -L --fail --retry 3 -C - -o "Dockerfile" "%HF_DOCKERFILE%"
if errorlevel 1 (
    echo ERROR: Dockerfile download failed.
    exit /b 1
)

echo.
echo --- Downloading docker-compose.yaml ---
curl -L --fail --retry 3 -C - -o "docker-compose.yaml" "%HF_COMPOSE%"
if errorlevel 1 (
    echo ERROR: docker-compose.yaml download failed.
    exit /b 1
)

REM -------------------------------------------------------------
REM  Download database archive volumes (~10 GB each, ~40 GB total)
REM  curl -C - enables resume if a download is interrupted.
REM -------------------------------------------------------------
echo.
echo --- Downloading database archive (4 volumes, ~40 GB total) ---
echo     This will take a while. If interrupted, re-run the script
echo     and curl will resume where it left off.
echo.

for %%V in (001 002 003 004) do (
    echo --- Downloading sec_fsnds_db_4vol.7z.%%V ---
    curl -L --fail --retry 5 -C - -o "!HOST_DATA_DIR!\sec_fsnds_db_4vol.7z.%%V" "!HF_REPO!/archive/sec_fsnds_db_4vol.7z.%%V"
    if errorlevel 1 (
        echo ERROR: sec_fsnds_db_4vol.7z.%%V download failed.
        echo        Re-run this script to resume.
        exit /b 1
    )
)

REM -------------------------------------------------------------
REM  Extract the archive
REM -------------------------------------------------------------
echo.
echo --- Extracting database files (293 GB, may take 10-20 min) ---
"!SEVENZIP!" x -o"!HOST_DATA_DIR!" "!HOST_DATA_DIR!\sec_fsnds_db_4vol.7z.001" -y
if errorlevel 1 (
    echo ERROR: 7z extraction failed.
    exit /b 1
)
echo Extraction complete.

REM  Verify the extracted files exist
if not exist "!HOST_DATA_DIR!\sec_fsnds.mdf" (
    echo ERROR: sec_fsnds.mdf not found after extraction.
    exit /b 1
)
if not exist "!HOST_DATA_DIR!\sec_fsnds_log.ldf" (
    echo ERROR: sec_fsnds_log.ldf not found after extraction.
    exit /b 1
)
echo Verified: sec_fsnds.mdf and sec_fsnds_log.ldf present.

echo.
echo ============================================================
echo   Setup complete
echo ============================================================
echo.
echo Next steps:
echo.
echo   1. Build and start the container:
echo        docker compose up -d --build
echo.
echo   2. Watch the logs until "SQL Server is now ready":
echo        docker compose logs -f
echo.
echo   3. Connect:
echo        Server   : localhost,!HOST_PORT!
echo        User     : sa
echo        Password : (what you entered)
echo        Database : sec_fsnds
echo.
echo   4. (Optional) Install stored procedures:
echo        Download the sql/ folder from the Hugging Face repo
echo        and run each .sql file with sqlcmd -i
echo.
echo Your .env file holds the values above. Keep it out of source
echo control -- it contains the sa password in plaintext.
echo.
echo You can safely delete the .7z archive volumes from !HOST_DATA_DIR!
echo after verifying the database starts correctly.
echo.

endlocal