Skip to content

Commit 8581087

Browse files
Merge pull request #11 from Ritik574-coder/dbt_branch
adding and edating staging models and writing documentition
2 parents b7cf601 + b41c3b7 commit 8581087

11 files changed

Lines changed: 1132 additions & 444 deletions

File tree

.github/workflows/dbt-ci.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ env:
1414
DBT_PROFILES_DIR: .github/profiles
1515
DBT_SQLSERVER_HOST: localhost
1616
DBT_SQLSERVER_PORT: 1433
17-
DBT_SQLSERVER_DATABASE: retail_analytics
17+
DBT_SQLSERVER_DATABASE: RetailDB
1818
DBT_SQLSERVER_SCHEMA: dbt_ci
1919
DBT_SQLSERVER_USER: sa
2020
DBT_SQLSERVER_PASSWORD: TestPassword123!
@@ -35,6 +35,20 @@ jobs:
3535
cache: pip
3636
cache-dependency-path: requirements.txt
3737

38+
- name: Install ODBC Driver 18
39+
run: |
40+
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc \
41+
| sudo gpg --dearmor --batch --yes \
42+
-o /usr/share/keyrings/microsoft-prod.gpg
43+
44+
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/ubuntu/22.04/prod jammy main" \
45+
| sudo tee /etc/apt/sources.list.d/microsoft-prod.list
46+
47+
sudo apt-get update
48+
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 mssql-tools18 unixodbc-dev
49+
50+
echo "/opt/mssql-tools18/bin" >> "$GITHUB_PATH"
51+
3852
- name: Install dependencies
3953
run: pip install -r requirements.txt
4054

@@ -61,7 +75,7 @@ jobs:
6175
- name: Lint SQL (when models exist)
6276
run: |
6377
if find models -name '*.sql' -print -quit | grep -q .; then
64-
sqlfluff lint models
78+
sqlfluff lint models --ignore=templating
6579
else
6680
echo "No SQL models found — skipping sqlfluff."
6781
fi
@@ -116,10 +130,17 @@ jobs:
116130
- name: Wait for SQL Server
117131
run: bash scripts/wait_for_sqlserver.sh
118132

119-
- name: Initialize CI database
133+
- name: Create Bronze Tables
120134
run: |
121135
sqlcmd -S localhost,1433 -U sa -P "$DBT_SQLSERVER_PASSWORD" -C -i scripts/ci-init-db.sql
122136
137+
- name: Create Bronze Tables
138+
run: |
139+
sqlcmd -S localhost,1433 -U sa -P "$DBT_SQLSERVER_PASSWORD" -C -i scripts/loading/ddl_bronze.sql
140+
141+
- name: Load Bronze Data
142+
run: python scripts/loading/python_load.py
143+
123144
- name: Install dbt packages
124145
run: dbt deps
125146

.github/workflows/dbt-docs.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ env:
1515
DBT_PROFILES_DIR: .github/profiles
1616
DBT_SQLSERVER_HOST: localhost
1717
DBT_SQLSERVER_PORT: 1433
18-
DBT_SQLSERVER_DATABASE: retail_analytics
18+
DBT_SQLSERVER_DATABASE: RetailDB
1919
DBT_SQLSERVER_SCHEMA: dbt_ci
2020
DBT_SQLSERVER_USER: sa
2121
DBT_SQLSERVER_PASSWORD: TestPassword123!
@@ -79,6 +79,14 @@ jobs:
7979
run: |
8080
sqlcmd -S localhost,1433 -U sa -P "$DBT_SQLSERVER_PASSWORD" -C -i scripts/ci-init-db.sql
8181
82+
- name: Create Bronze Tables
83+
run: |
84+
sqlcmd -S localhost,1433 -U sa -P "$DBT_SQLSERVER_PASSWORD" -C -i scripts/loading/ddl_bronze.sql
85+
86+
- name: Load Bronze Data
87+
run: |
88+
python scripts/loading/python_load.py
89+
8290
- name: Generate dbt docs
8391
run: |
8492
dbt deps

.sqlfluff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ exclude_rules = layout.long_lines
66

77
[sqlfluff:templater:dbt]
88
project_dir = .
9-
profiles_dir = .
9+
profiles_dir = .github/profiles
1010
profile = dbt_analytics_engineering
11-
target = dev
11+
target = ci
1212

1313
[sqlfluff:indentation]
1414
tab_space_size = 4

issues.txt

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
================================================================================
2+
DBT ANALYTICS ENGINEERING — CI/CD PIPELINE FAILURE ANALYSIS
3+
================================================================================
4+
Generated: 2026-06-20
5+
Repository: Ritik574-coder/dbt-analytics-engineering
6+
Branch with failures: dbt_branch (PR to main)
7+
8+
SUMMARY
9+
-------
10+
All three GitHub Actions workflows are currently failing:
11+
12+
Workflow Latest failed run Failing job/step
13+
---------------- ------------------ ------------------------------------------
14+
dbt CI 27859117241 dbt integration → Load Bronze Data
15+
dbt Docs 27859117248 Generate documentation → Generate dbt docs
16+
dbt CD 27839146670 Deploy (prod) → dbt debug
17+
18+
The "Lint & parse" CI job passes. Failures are in database connectivity / setup.
19+
20+
21+
================================================================================
22+
ISSUE 1 — DATABASE NAME MISMATCH (CI + DOCS) — PRIMARY BLOCKER
23+
================================================================================
24+
25+
SEVERITY: Critical (blocks CI and Docs right now)
26+
27+
EXACT REASON:
28+
GitHub Actions workflows set:
29+
DBT_SQLSERVER_DATABASE: retail_analytics
30+
31+
But the database initialization script creates a different database:
32+
scripts/ci-init-db.sql → CREATE DATABASE RetailDB
33+
34+
When python_load.py and dbt connect, they use the env var
35+
DBT_SQLSERVER_DATABASE=retail_analytics. That database does NOT exist
36+
on the CI SQL Server container. SQL Server returns error 4060:
37+
38+
Cannot open database "retail_analytics" requested by the login.
39+
The login failed. (4060)
40+
41+
Evidence from latest CI run (27859117241), step "Load Bronze Data":
42+
- ci-init-db.sql succeeded: "Changed database context to 'RetailDB'."
43+
- python_load.py failed immediately trying to connect to retail_analytics
44+
45+
Same error in dbt Docs run (27859117248), step "Generate dbt docs":
46+
dbt docs generate cannot connect because retail_analytics does not exist.
47+
48+
AFFECTED FILES:
49+
- .github/workflows/dbt-ci.yml (remote/pushed version still has retail_analytics)
50+
- .github/workflows/dbt-docs.yml (still has retail_analytics)
51+
- scripts/ci-init-db.sql (creates RetailDB)
52+
- scripts/loading/python_load.py (defaults to RetailDB, but CI env overrides it)
53+
- models/staging/_retail__sources.yml (correctly references database: RetailDB)
54+
- profiles.example.yml / .env.example (default to retail_analytics — confusing)
55+
56+
NOTE:
57+
You have a LOCAL uncommitted fix in dbt-ci.yml changing retail_analytics → RetailDB,
58+
but it is NOT pushed to GitHub yet, and dbt-docs.yml was NOT updated.
59+
60+
HOW TO FIX:
61+
1. Use ONE database name everywhere. Recommended: RetailDB (matches init script,
62+
DDL, sources, and bronze load scripts).
63+
64+
2. Update workflow env vars:
65+
.github/workflows/dbt-ci.yml:
66+
DBT_SQLSERVER_DATABASE: RetailDB
67+
68+
.github/workflows/dbt-docs.yml:
69+
DBT_SQLSERVER_DATABASE: RetailDB
70+
71+
3. Commit and push both workflow changes to dbt_branch.
72+
73+
4. Optionally align defaults for local dev consistency:
74+
.env.example → DBT_SQLSERVER_DATABASE=RetailDB
75+
profiles.example.yml → default 'RetailDB' instead of 'retail_analytics'
76+
77+
5. Re-run CI after push. Bronze load + dbt run should proceed past current failure.
78+
79+
80+
================================================================================
81+
ISSUE 2 — BRONZE TABLES NOT LOADED (CI — secondary failure after Issue 1)
82+
================================================================================
83+
84+
SEVERITY: High (appeared in earlier CI runs once DB connection partially worked)
85+
86+
EXACT REASON:
87+
In CI run 27840802070, dbt run reached execution but all 8 staging models failed:
88+
89+
Invalid object name 'RetailDB.bronze.customers'. (208)
90+
Invalid object name 'RetailDB.bronze.employees'. (208)
91+
... (same for all bronze source tables)
92+
93+
This means dbt connected, but bronze tables were missing or empty.
94+
Root cause chain:
95+
a) python_load.py never loaded data (database name mismatch), OR
96+
b) ddl_bronze.sql was not run before dbt run, OR
97+
c) Load step was missing from an older workflow version
98+
99+
Current workflow (dbt-ci.yml) does have the correct sequence:
100+
1. ci-init-db.sql → create RetailDB + schemas
101+
2. ddl_bronze.sql → create bronze tables
102+
3. python_load.py → load CSV data into bronze.*
103+
4. dbt run → build staging/intermediate models
104+
105+
Fixing Issue 1 should allow steps 1–3 to complete and prevent this error.
106+
107+
HOW TO FIX:
108+
1. Fix Issue 1 first (RetailDB name alignment).
109+
2. Verify CI log shows after python_load.py:
110+
"Loaded N rows into bronze.customers" (for each table)
111+
3. If tables still missing, confirm CSV files exist in repo:
112+
scripts/raw_dataset/csv_data_file/*.csv (all 8 files present ✓)
113+
4. Confirm ddl_bronze.sql runs without error before python_load.py.
114+
115+
116+
================================================================================
117+
ISSUE 3 — CD PIPELINE CANNOT REACH PRODUCTION SQL SERVER
118+
================================================================================
119+
120+
SEVERITY: Critical (blocks all CD deployments)
121+
122+
EXACT REASON:
123+
CD workflow (dbt-cd.yml) fails at "dbt debug" with:
124+
125+
Login timeout expired (HYT00)
126+
Connection test: [ERROR]
127+
128+
This means the GitHub Actions runner waited ~60+ seconds and could NOT
129+
establish a TCP connection to the SQL Server defined in GitHub Secrets.
130+
131+
CD does NOT use a local SQL Server container. It connects to a real server
132+
via repository/environment secrets:
133+
DBT_SQLSERVER_HOST
134+
DBT_SQLSERVER_PORT
135+
DBT_SQLSERVER_DATABASE
136+
DBT_SQLSERVER_SCHEMA
137+
DBT_SQLSERVER_USER
138+
DBT_SQLSERVER_PASSWORD
139+
140+
Login timeout (not "login failed") typically means:
141+
- Host is unreachable (wrong IP/hostname, localhost, private network)
142+
- Firewall blocks GitHub Actions runner IP ranges
143+
- SQL Server not listening on the configured port
144+
- Azure SQL / cloud DB requires firewall rule for GitHub Actions
145+
- Secrets not configured in the "production" GitHub Environment
146+
147+
All recent CD runs fail the same way (runs: 27839146670, 27750986715,
148+
27735843782, 27623198237).
149+
150+
HOW TO FIX:
151+
1. In GitHub → Settings → Environments → production → verify ALL 6
152+
DBT_SQLSERVER_* secrets are set (not empty, not localhost).
153+
154+
2. DBT_SQLSERVER_HOST must be a publicly reachable hostname/IP
155+
(e.g. your Azure SQL server: myserver.database.windows.net).
156+
localhost / 127.0.0.1 will ALWAYS fail in GitHub Actions.
157+
158+
3. Open firewall for GitHub Actions:
159+
- Azure SQL: enable "Allow Azure services" OR add GitHub IP ranges
160+
- On-prem SQL Server: allow inbound TCP 1433 from GitHub Actions IPs
161+
(or use a self-hosted runner inside your network)
162+
163+
4. Verify SQL Server accepts SQL authentication (not Windows-only auth).
164+
165+
5. Test connectivity manually from outside your network:
166+
sqlcmd -S <host>,<port> -U <user> -P <password> -C -Q "SELECT 1"
167+
168+
6. Ensure ODBC Driver 18 settings match your server (trust_cert: true is
169+
already set in profiles.example.yml).
170+
171+
7. Re-run CD via Actions → dbt CD → Run workflow.
172+
173+
174+
================================================================================
175+
ISSUE 4 — INCONSISTENT DATABASE NAMING ACROSS PROJECT
176+
================================================================================
177+
178+
SEVERITY: Medium (causes confusion and repeat failures)
179+
180+
EXACT REASON:
181+
The project uses two different database names:
182+
- RetailDB → ci-init-db.sql, ddl_bronze.sql, sources.yml, proc scripts
183+
- retail_analytics → workflows, .env.example, profiles.example.yml
184+
185+
dbt profile connects to one database (from env var), while source() macros
186+
hardcode database: RetailDB in _retail__sources.yml. This can work in SQL
187+
Server (cross-database queries) ONLY if both databases exist. In CI, only
188+
RetailDB is created — retail_analytics never exists.
189+
190+
HOW TO FIX:
191+
Standardize on RetailDB everywhere, OR rename ci-init-db.sql to create
192+
retail_analytics instead. Pick one name and update all references.
193+
194+
195+
================================================================================
196+
ISSUE 5 — DOCS WORKFLOW MISSING BRONZE SETUP (minor / future)
197+
================================================================================
198+
199+
SEVERITY: Low (docs generate may work without bronze data, but DB must exist)
200+
201+
EXACT REASON:
202+
dbt-docs.yml only runs ci-init-db.sql, then dbt docs generate.
203+
It does NOT run ddl_bronze.sql or python_load.py.
204+
205+
dbt docs generate needs a valid DB connection but does not require bronze
206+
data. Fixing the database name (Issue 1) should be enough for Docs to pass.
207+
208+
HOW TO FIX:
209+
1. Fix DBT_SQLSERVER_DATABASE in dbt-docs.yml → RetailDB.
210+
2. No bronze load needed unless you add compile/run steps that query sources.
211+
212+
213+
================================================================================
214+
ISSUE 6 — WORKFLOW HYGIENE (non-blocking but worth fixing)
215+
================================================================================
216+
217+
SEVERITY: Low
218+
219+
EXACT REASON:
220+
a) dbt-ci.yml has two steps both named "Create Bronze Tables" (lines 133–139).
221+
Makes debugging CI logs harder.
222+
223+
b) SQL Server service health check uses:
224+
/opt/mssql-tools18/bin/sqlcmd
225+
inside the mcr.microsoft.com/mssql/server:2022-latest container.
226+
The container image may ship sqlcmd at a different path. CI currently
227+
works (sqlcmd on the runner host is used for steps), but the service
228+
health check path may be unreliable.
229+
230+
c) dbt_project.yml has unused config paths (marts, seeds, snapshots) —
231+
warnings only, not causing failures.
232+
233+
HOW TO FIX:
234+
a) Rename steps: "Initialize CI database" and "Create bronze DDL tables".
235+
b) Change health-cmd to use runner-side check or correct container path:
236+
/opt/mssql-tools18/bin/sqlcmd OR /opt/mssql-tools/bin/sqlcmd
237+
c) Add marts/seeds/snapshots content or remove unused config blocks.
238+
239+
240+
================================================================================
241+
RECOMMENDED FIX ORDER
242+
================================================================================
243+
244+
Step Action Expected result
245+
---- -------------------------------------------------- -------------------------
246+
1 Push RetailDB fix to dbt-ci.yml AND dbt-docs.yml CI + Docs pass DB connect
247+
2 Verify bronze load + dbt run/test in CI logs Full CI green
248+
3 Fix CD secrets + firewall for production SQL Server CD deploys succeed
249+
4 Align .env.example / profiles.example.yml Local dev matches CI
250+
251+
252+
================================================================================
253+
WHAT IS ALREADY WORKING
254+
================================================================================
255+
256+
✓ Lint & parse job (YAML validation, dbt parse, sqlfluff) — passes
257+
✓ Python dependencies install (dbt-core, pandas, sqlalchemy, pyodbc)
258+
✓ ODBC Driver 18 install on Ubuntu runner
259+
✓ SQL Server container starts and accepts sqlcmd from runner
260+
✓ ci-init-db.sql creates RetailDB + bronze + dbt_ci schemas
261+
✓ ddl_bronze.sql creates bronze tables (when run against RetailDB)
262+
✓ CSV seed files exist in scripts/raw_dataset/csv_data_file/
263+
✓ dbt models compile (35 models found in latest parse)
264+
265+
266+
================================================================================
267+
QUICK REFERENCE — EXACT ERROR MESSAGES FROM GITHUB ACTIONS
268+
================================================================================
269+
270+
CI (latest):
271+
sqlalchemy.exc.ProgrammingError: Cannot open database "retail_analytics"
272+
requested by the login. The login failed. (4060)
273+
274+
Docs (latest):
275+
Database Error: Cannot open database "retail_analytics" requested by the
276+
login. The login failed. (4060)
277+
278+
CI (earlier, after partial progress):
279+
Invalid object name 'RetailDB.bronze.customers'. (208)
280+
281+
CD (all recent runs):
282+
Login timeout expired (HYT00) — Connection test: [ERROR]
283+
284+
================================================================================
285+
END OF REPORT
286+
================================================================================

0 commit comments

Comments
 (0)