Skip to content

Commit

Permalink
support clickhouse and mssql (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronenlu authored Feb 22, 2024
1 parent 5275927 commit 728aa2f
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 6 deletions.
9 changes: 5 additions & 4 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"embed"
_ "embed"
"fmt"
"slices"
"text/template"
)

Expand All @@ -23,13 +24,13 @@ type (
}
)

var Drivers = []string{"mysql", "postgres", "mariadb", "sqlite", "mssql", "clickhouse"}

func validateDriver(s string) error {
switch s {
case "postgres", "mysql", "mariadb", "sqlite":
return nil
default:
if !slices.Contains(Drivers, s) {
return fmt.Errorf("unknown driver %q", s)
}
return nil
}

var (
Expand Down
37 changes: 37 additions & 0 deletions gen/services.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,39 @@
--health-start-period 10s
--health-timeout 5s
--health-retries 10
{{- else if eq .Driver "clickhouse" }}
services:
# Spin up a clickhouse:23.10 container to be used as the dev-database for analysis.
clickhouse:
image: clickhouse/clickhouse-server:23.10
env:
CLICKHOUSE_DB: test
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
CLICKHOUSE_PASSWORD: pass
CLICKHOUSE_USER: root
ports:
- 9000:9000
options: >-
--health-cmd "clickhouse-client --host localhost --query 'SELECT 1'"
--health-interval 10s
--health-timeout 5s
--health-retries 5
{{- else if eq .Driver "mssql" }}
services:
# Spin up a mcr.microsoft.com/mssql/server:2022-latest container to be used as the dev-database for analysis.
sqlserver:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
ACCEPT_EULA: Y
MSSQL_PID: Developer
MSSQL_SA_PASSWORD: P@ssw0rd0995
ports:
- 1433:1433
options: >-
--health-cmd "/opt/mssql-tools/bin/sqlcmd -U sa -P P@ssw0rd0995 -Q \"SELECT 1\""
--health-interval 10s
--health-timeout 5s
--health-retries 5
{{- end }}
{{- end }}

Expand All @@ -59,5 +92,9 @@
dev-url: 'maria://root:pass@localhost:3306/dev'
{{- else if eq .Driver "sqlite" -}}
dev-url: 'sqlite://dev?mode=memory'
{{- else if eq .Driver "clickhouse" -}}
dev-url: 'clickhouse://root:pass@localhost:9000/test'
{{- else if eq .Driver "mssql" -}}
dev-url: 'sqlserver://sa:P@ssw0rd0995@localhost:1433/test'
{{- end -}}
{{- end -}}
54 changes: 54 additions & 0 deletions gen/testdata/clickhouse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Atlas
on:
push:
branches:
- master
paths:
- .github/workflows/ci-atlas.yaml
- 'migrations/*'
pull_request:
paths:
- 'migrations/*'
# Permissions to write comments on the pull request.
permissions:
contents: read
pull-requests: write
jobs:
atlas:
services:
# Spin up a clickhouse:23.10 container to be used as the dev-database for analysis.
clickhouse:
image: clickhouse/clickhouse-server:23.10
env:
CLICKHOUSE_DB: test
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
CLICKHOUSE_PASSWORD: pass
CLICKHOUSE_USER: root
ports:
- 9000:9000
options: >-
--health-cmd "clickhouse-client --host localhost --query 'SELECT 1'"
--health-interval 10s
--health-timeout 5s
--health-retries 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }}
- uses: ariga/atlas-action/migrate/lint@v1
with:
dir: 'file://migrations'
dir-name: 'name'
dev-url: 'clickhouse://root:pass@localhost:9000/test'
env:
GITHUB_TOKEN: ${{ github.token }}
- uses: ariga/atlas-action/migrate/push@v1
if: github.ref == 'refs/heads/master'
with:
dir: 'file://migrations'
dir-name: 'name'
dev-url: 'clickhouse://root:pass@localhost:9000/test'
53 changes: 53 additions & 0 deletions gen/testdata/mssql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Atlas
on:
push:
branches:
- master
paths:
- .github/workflows/ci-atlas.yaml
- 'migrations/*'
pull_request:
paths:
- 'migrations/*'
# Permissions to write comments on the pull request.
permissions:
contents: read
pull-requests: write
jobs:
atlas:
services:
# Spin up a mcr.microsoft.com/mssql/server:2022-latest container to be used as the dev-database for analysis.
sqlserver:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
ACCEPT_EULA: Y
MSSQL_PID: Developer
MSSQL_SA_PASSWORD: P@ssw0rd0995
ports:
- 1433:1433
options: >-
--health-cmd "/opt/mssql-tools/bin/sqlcmd -U sa -P P@ssw0rd0995 -Q \"SELECT 1\""
--health-interval 10s
--health-timeout 5s
--health-retries 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }}
- uses: ariga/atlas-action/migrate/lint@v1
with:
dir: 'file://migrations'
dir-name: 'name'
dev-url: 'sqlserver://sa:P@ssw0rd0995@localhost:1433/test'
env:
GITHUB_TOKEN: ${{ github.token }}
- uses: ariga/atlas-action/migrate/push@v1
if: github.ref == 'refs/heads/master'
with:
dir: 'file://migrations'
dir-name: 'name'
dev-url: 'sqlserver://sa:P@ssw0rd0995@localhost:1433/test'
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var cli struct {
// InitActionCmd is the command for initializing a new Atlas CI workflow.
type InitActionCmd struct {
DirPath string `arg:"" optional:"" type:"-path" help:"Path inside repository containing the migration files."`
Driver string `enum:"mysql,postgres,mariadb,sqlite" default:"mysql" help:"Driver of the migration directory (mysql,postgres,mariadb,sqlite)."`
Driver string `enum:"mysql,postgres,mariadb,sqlite,mssql,clickhouse" default:"mysql" help:"Driver of the migration directory (mysql,postgres,mariadb,sqlite,mssql,clickhouse)."`
Token string `short:"t" help:"Atlas authentication token."`
Repo string `short:"R" help:"GitHub repository owner/name, defaults to the current repository."`
ConfigPath string `optional:"" help:"Path to atlas.hcl configuration file."`
Expand Down
3 changes: 2 additions & 1 deletion prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"strings"

"ariga.io/gh-atlas/gen"
"github.com/1lann/promptui"
"github.com/hashicorp/hcl/v2/hclparse"
"github.com/hashicorp/hcl/v2/hclsyntax"
Expand All @@ -25,7 +26,7 @@ func (i *InitActionCmd) setParams(ctx context.Context, repo *Repository) error {
prompt := promptui.Select{
Label: "Choose driver",
HideHelp: true,
Items: []string{"mysql", "postgres", "mariadb", "sqlite"},
Items: gen.Drivers,
Stdin: i.stdin,
}
if _, i.Driver, err = prompt.Run(); err != nil {
Expand Down

0 comments on commit 728aa2f

Please sign in to comment.