-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,81 @@ | ||
# atlas-go-sdk | ||
# Atlas SDK for Go | ||
|
||
An SDK for building ariga/atlas providers | ||
An SDK for building ariga/atlas providers in Go. | ||
|
||
## Installation | ||
|
||
```bash | ||
go get -u ariga.io/atlas-go-sdk | ||
``` | ||
|
||
## How to use | ||
|
||
To use the SDK, you need to create a new client with your `migrations` folder and the `atlas` binary path. | ||
|
||
```go | ||
package example | ||
|
||
import ( | ||
... | ||
"ariga.io/atlas-go-sdk/atlasexec" | ||
) | ||
|
||
func main() { | ||
// Create a new client | ||
client, err := atlasexec.NewClient("my-migration-folder", "my-atlas-cli-path") | ||
if err != nil { | ||
log.Fatalf("failed to create client: %v", err) | ||
} | ||
} | ||
``` | ||
|
||
## APIs | ||
|
||
The SDK provides the following APIs: | ||
|
||
- `Login`: Login to the [Atlas Cloud](https://atlasgo.cloud/) | ||
- `Logout`: runs the 'logout' command. | ||
- `MigratePush`: runs the "atlas migrate push" command. | ||
- `MigrateLint`: runs the "atlas migrate lint" command. | ||
- `MigrateApplySlice`: runs the "atlas migrate apply" command for multiple targets. | ||
- `MigrateApply`: runs the "atlas migrate apply" command. | ||
- `MigrateApplySlice`: runs the 'atlas migrate apply' command for multiple targets. | ||
- `MigrateDown`: runs the "atlas migrate down" command. | ||
- `MigrateStatus`: runs the "atlas migrate status" command. | ||
- `SchemaApply`: runs the "atlas schema apply" command. | ||
- `SchemaInspect`: runs the "atlas schema inspect" command. | ||
- `SchemaDiff`: runs the "atlas schema diff" command. | ||
|
||
Example with `MigratePush` API: | ||
|
||
```go | ||
|
||
func main() { | ||
// Create a new client | ||
client, err := atlasexec.NewClient("my-migration-folder", "my-atlas-cli-path") | ||
if err != nil { | ||
log.Fatalf("failed to create client: %v", err) | ||
} | ||
|
||
// Login to the Atlas Cloud | ||
ctx := context.Background() | ||
loginParams := atlasexec.LoginParams{ | ||
Token: "my-token" | ||
} | ||
err = client.Login(ctx, loginParams) | ||
if err != nil { | ||
log.Fatalf("failed to login: %v", err) | ||
} | ||
|
||
// Run the 'atlas migrate push' command | ||
migrateParams := atlasexec.MigratePushParams{ | ||
Name: "name", | ||
DirURL: "dir-url", | ||
DevURL: "dev-url", | ||
} | ||
_, err = client.MigratePush(ctx, migrateParams) | ||
if err != nil { | ||
log.Fatalf("failed to run migrate push: %v", err) | ||
} | ||
} | ||
``` |