|
1 | | -# EF Core Code-First Example with TimescaleDB |
| 1 | +# EF Core Code-First Example with TimescaleDB |
2 | 2 |
|
3 | 3 | This project demonstrates how to use the **Code-First** approach with [TimescaleDB](https://www.timescale.com/) using the `CmdScale.EntityFrameworkCore.TimescaleDB` package. |
4 | 4 |
|
5 | 5 | --- |
6 | 6 |
|
7 | | -## 🚀 Migrations and Database Management |
| 7 | +## Migrations and Database Management |
8 | 8 |
|
9 | 9 | Use the following commands to manage your EF Core migrations and database updates. |
10 | 10 |
|
11 | | -### 📌 Add a new migration |
| 11 | +> **Note:** Run all commands from the repository root directory. |
| 12 | +
|
| 13 | +### Add a new migration |
12 | 14 |
|
13 | 15 | ```bash |
14 | | -dotnet ef migrations add --project CmdScale.EntityFrameworkCore.TimescaleDB.Example.DataAccess --startup-project CmdScale.EntityFrameworkCore.TimescaleDB.Example <MigrationName> |
| 16 | +dotnet ef migrations add <MigrationName> --project samples/Eftdb.Samples.Shared --startup-project samples/Eftdb.Samples.CodeFirst |
15 | 17 | ``` |
16 | 18 |
|
17 | | -### ✅ Apply migrations to the database |
| 19 | +### Apply migrations to the database |
18 | 20 |
|
19 | 21 | ```bash |
20 | | -dotnet ef database update --project CmdScale.EntityFrameworkCore.TimescaleDB.Example.DataAccess --startup-project CmdScale.EntityFrameworkCore.TimescaleDB.Example |
| 22 | +dotnet ef database update --project samples/Eftdb.Samples.Shared --startup-project samples/Eftdb.Samples.CodeFirst |
21 | 23 | ``` |
22 | 24 |
|
23 | | -### ❌ Remove last migration (if not applied to the database, yet) |
24 | | -``` |
25 | | - dotnet ef migrations remove --project CmdScale.EntityFrameworkCore.TimescaleDB.Example.DataAccess --startup-project CmdScale.EntityFrameworkCore.TimescaleDB.Example |
| 25 | +### Remove last migration (if not applied to the database yet) |
| 26 | + |
| 27 | +```bash |
| 28 | +dotnet ef migrations remove --project samples/Eftdb.Samples.Shared --startup-project samples/Eftdb.Samples.CodeFirst |
26 | 29 | ``` |
27 | 30 |
|
28 | | -### 🧹 Reset all migrations (rollback to initial state) |
| 31 | +### Reset all migrations (rollback to initial state) |
29 | 32 |
|
30 | 33 | ```bash |
31 | | -dotnet ef database update 0 --project CmdScale.EntityFrameworkCore.TimescaleDB.Example.DataAccess --startup-project CmdScale.EntityFrameworkCore.TimescaleDB.Example |
| 34 | +dotnet ef database update 0 --project samples/Eftdb.Samples.Shared --startup-project samples/Eftdb.Samples.CodeFirst |
32 | 35 | ``` |
33 | 36 |
|
34 | 37 | --- |
35 | 38 |
|
36 | | -## 📁 Project Structure |
| 39 | +## Project Structure |
37 | 40 |
|
38 | 41 | ```text |
39 | | -CmdScale.EntityFrameworkCore.TimescaleDB.Example/ |
40 | | -│ |
41 | | -├── CmdScale.EntityFrameworkCore.TimescaleDB.Example/ # Startup project |
42 | | -├── CmdScale.EntityFrameworkCore.TimescaleDB.Example.DataAccess/ # Contains DbContext and migrations |
43 | | -└── docker-compose.yml # Sets up TimescaleDB container (in Solution Items) |
| 42 | +samples/ |
| 43 | +├── Eftdb.Samples.CodeFirst/ # Startup project (contains Program.cs and design-time services) |
| 44 | +├── Eftdb.Samples.Shared/ # Contains DbContext, entities, and migrations |
| 45 | +└── Eftdb.Samples.DatabaseFirst/ # Database-first scaffolding example |
44 | 46 | ``` |
45 | 47 |
|
46 | 48 | --- |
47 | 49 |
|
48 | | -## 🐳 Docker |
49 | | -- This project assumes you have an existing TimescaleDB-compatible PostgreSQL database. |
50 | | -- A `docker-compose.yml` file is included in the **Solution Items** folder to spin up a TimescaleDB container for local development and testing. |
| 50 | +## Docker |
| 51 | + |
| 52 | +This project assumes you have an existing TimescaleDB-compatible PostgreSQL database. A `docker-compose.yml` file is included in the repository root to spin up a TimescaleDB container for local development and testing. |
51 | 53 |
|
52 | | - To start the container, run: |
| 54 | +To start the container, run from the repository root: |
53 | 55 |
|
54 | | - ```bash |
55 | | - docker-compose up -d |
56 | | - ``` |
| 56 | +```bash |
| 57 | +docker-compose up -d |
| 58 | +``` |
| 59 | + |
| 60 | +To stop and reset the database: |
| 61 | + |
| 62 | +```bash |
| 63 | +docker-compose down -v |
| 64 | +``` |
57 | 65 |
|
58 | | -- Connection string settings should match the configuration in your `docker-compose.yml`. |
| 66 | +Connection string settings should match the configuration in your `docker-compose.yml`. |
59 | 67 |
|
60 | 68 | --- |
61 | 69 |
|
62 | | -## 🧠 Notes |
63 | | -- Depending on if you're using project- or package-references you might to (un)comment adding the services in `TimescaleDBDesignTimeService.cs` |
| 70 | +## Notes |
64 | 71 |
|
| 72 | +- Depending on if you're using project- or package-references you might need to (un)comment adding the services in `TimescaleDBDesignTimeService.cs` |
| 73 | +- The `Eftdb.Samples.Shared` project contains the `TimescaleContext` and entity models shared between samples |
65 | 74 |
|
66 | | -## 📚 Resources |
| 75 | +## Resources |
67 | 76 |
|
68 | 77 | - [Entity Framework Core Documentation](https://learn.microsoft.com/en-us/ef/core/) |
69 | 78 | - [TimescaleDB Documentation](https://docs.timescale.com/) |
|
0 commit comments