Skip to content

Commit c4a63f4

Browse files
Create README.md
Create a README.md file that explains what the database project is for
1 parent ef70ec5 commit c4a63f4

1 file changed

Lines changed: 145 additions & 0 deletions

File tree

src/Database/README.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# CATS Database Repository
2+
3+
This repository contains the database definition, deployment tooling, and supporting utilities for the **CATS database** using a modern **.NET SQL Project (DbProj, .NET 10)** approach.
4+
5+
---
6+
7+
## 📦 Repository Structure
8+
9+
```
10+
/ (root)
11+
12+
├── /src/Database/CatsDb # SQL Project (database schema)
13+
├── /src/DatabaseSeeding # Data seeding & migration project
14+
```
15+
16+
---
17+
18+
## 🧱 SQL Project (CatsDb)
19+
20+
### What is a SQL Project?
21+
22+
The SQL Project is a **schema-first database project** built using the .NET SQL SDK. It represents the full structure of the CATS database as source-controlled code.
23+
24+
This includes:
25+
26+
- Tables
27+
- Views
28+
- Stored Procedures
29+
- Functions
30+
- Schemas
31+
- Constraints & indexes
32+
- Security objects
33+
34+
### Key Concepts
35+
36+
- Declarative model – define the desired state, not the steps
37+
- Source-controlled schema
38+
- Repeatable builds
39+
- Drift detection
40+
41+
---
42+
43+
## 🚀 Deployment Process (sqlpackage)
44+
45+
The SQL project builds into a `.dacpac` file:
46+
47+
```
48+
CatsDb.dacpac
49+
```
50+
51+
### Build
52+
53+
```
54+
dotnet build
55+
```
56+
57+
---
58+
59+
### Deploy
60+
61+
```
62+
sqlpackage /Action:Publish /SourceFile:CatsDb.dacpac /TargetConnectionString:"<connection-string>" /p:BlockOnPossibleDataLoss=false
63+
```
64+
65+
### How it Works
66+
67+
- Compares `.dacpac` with target database
68+
- Generates deployment plan
69+
- Applies only schema differences
70+
71+
---
72+
73+
### Notes
74+
75+
- Avoid manual DB changes (they can be overwritten)
76+
- Use PRs for all schema updates
77+
78+
---
79+
80+
## 🌱 Database Seeding Project
81+
82+
### Location
83+
84+
```
85+
/src/DatabaseSeeding
86+
```
87+
88+
### Purpose
89+
90+
This project handles **data**, not schema:
91+
92+
- Test data setup
93+
- Data migrations
94+
- Backfilling and transformation
95+
96+
### Why Separate?
97+
98+
The SQL Project is schema-only. This project handles:
99+
100+
- Data insertion
101+
- Data transformation
102+
103+
Keeping them separate ensures clean deployments and clear responsibility.
104+
105+
---
106+
107+
### Execution
108+
109+
```
110+
dotnet run --project DatabaseSeeding
111+
```
112+
113+
---
114+
115+
### Best Practices
116+
117+
- Make scripts idempotent
118+
- Keep migrations small
119+
- Log changes clearly
120+
121+
---
122+
123+
## 🔄 Workflow
124+
125+
1. Update schema in SQL project
126+
2. Build to `CatsDb.dacpac`
127+
3. Deploy via `sqlpackage`
128+
4. Run DatabaseSeeding
129+
130+
---
131+
132+
## ✅ Summary
133+
134+
- SQL Project → Schema definition
135+
- sqlpackage → Deployment
136+
- DatabaseSeeding → Data setup & migration
137+
138+
---
139+
140+
## 🛠️ Requirements
141+
142+
- .NET 10 SDK
143+
- sqlpackage CLI
144+
- SQL Server access
145+

0 commit comments

Comments
 (0)