Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add README.md #12

Merged
merged 10 commits into from
Aug 1, 2024
112 changes: 110 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,111 @@
Atlas Provider for Entity Framework Core
=======================================
# Atlas Provider for Entity Framework Core

Load [Entity Framework](https://learn.microsoft.com/en-us/ef/) schemas into an [Atlas](https://atlasgo.io) project.

## Use-cases

1. **Declarative migrations** - use a Terraform-like `atlas schema apply --env ef` to apply your EF schema to the database.
2. **Automatic migration planning** - use `atlas migrate diff --env ef` to automatically plan a migration from
luantranminh marked this conversation as resolved.
Show resolved Hide resolved
the current database version to the EF schema.

luantranminh marked this conversation as resolved.
Show resolved Hide resolved
## Installation

Install Atlas from macOS or Linux by running:
```bash
luantranminh marked this conversation as resolved.
Show resolved Hide resolved
curl -sSf https://atlasgo.sh | sh
```

See [atlasgo.io](https://atlasgo.io/getting-started#installation) for more installation options.

### AtlasEF Package

Make sure to have a tool manifest available in your repository or create one using the following command:

luantranminh marked this conversation as resolved.
Show resolved Hide resolved
```bash
dotnet new tool-manifest
```

Install the `AtlasEF` package from the command line:

```bash
dotnet tool install atlas-ef --version 0.0.1
```
luantranminh marked this conversation as resolved.
Show resolved Hide resolved
luantranminh marked this conversation as resolved.
Show resolved Hide resolved

Let's check if the tool is installed correctly:

```bash
dotnet atlas-ef --version
```

## Configuration

By default, this tool will scan for implementation of the **DbContext** class in the current project and generate a database schema based on them.

luantranminh marked this conversation as resolved.
Show resolved Hide resolved
This tool does not require a database connection, but it does need [Database Providers](https://learn.microsoft.com/en-us/ef/core/providers/?tabs=dotnet-core-cli) restored.

luantranminh marked this conversation as resolved.
Show resolved Hide resolved
### Setup Atlas

In your project directory, create a new file named `atlas.hcl` with the following contents:

```hcl
data "external_schema" "ef" {
program = [
"dotnet",
"atlas-ef",
]
}

env "ef" {
src = data.external_schema.ef.url
dev = "docker://mysql/8/dev" # list of dev dbs can be found here: https://atlasgo.io/concepts/dev-database
luantranminh marked this conversation as resolved.
Show resolved Hide resolved
migration {
dir = "file://atlas-migrations"
}
luantranminh marked this conversation as resolved.
Show resolved Hide resolved
format {
migrate {
diff = "{{ sql . \" \" }}"
}
}
}
```

### Usage

Once you have the provider tool and Atlas configured, you can use them to manage your database schema.

#### Apply

You can use the `atlas schema apply` command to plan and apply a migration of your database to
your current EF schema. This works by inspecting the target database and comparing it to the
luantranminh marked this conversation as resolved.
Show resolved Hide resolved
EF schema and creating a migration plan. Atlas will prompt you to confirm the migration plan
luantranminh marked this conversation as resolved.
Show resolved Hide resolved
before applying it to the database.
luantranminh marked this conversation as resolved.
Show resolved Hide resolved

```bash
atlas schema apply --env ef -u "mysql://root:password@localhost:3306/mydb"
```

Where the `-u` flag accepts the [URL](https://atlasgo.io/concepts/url) to the
target database.
luantranminh marked this conversation as resolved.
Show resolved Hide resolved

#### Diff

Atlas supports a [versioned migration](https://atlasgo.io/concepts/declarative-vs-versioned#versioned-migrations)
workflow, where each change to the database is versioned and recorded in a migration file. You can use the
`atlas migrate diff` command to automatically generate a migration file that will migrate the database
from its latest revision to the current EF schema.

```bash
atlas migrate diff --env ef
```

### Supported Databases

The provider supports the following databases:
* SQL Server
* MySQL
* PostgreSQL
* SQLite

### License

This project is licensed under the [Apache License 2.0](LICENSE).
Loading