diff --git a/.github/workflows/release_build.yml b/.github/workflows/release_build.yml index 2ac2c91..7762d1f 100644 --- a/.github/workflows/release_build.yml +++ b/.github/workflows/release_build.yml @@ -23,3 +23,5 @@ jobs: args: release --rm-dist env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Publish module + run: make publish-package diff --git a/Makefile b/Makefile index 4de40dd..8cbd2b4 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +GIT_TAG := $(shell git describe --tags `git rev-list --tags --max-count=1`) test_target := "./..." .PHONY: test-coverage @@ -19,3 +20,6 @@ test-all: test-unit: go test --short $(test_target) -cover -json | tparse -all +.PHONY: publish-package +publish-package: + echo GOPROXY=proxy.golang.org go list -m github.com/KarnerTh/mermerd@$(GIT_TAG) \ No newline at end of file diff --git a/analyzer/analyzer.go b/analyzer/analyzer.go index db59ddc..8550770 100644 --- a/analyzer/analyzer.go +++ b/analyzer/analyzer.go @@ -2,9 +2,10 @@ package analyzer import ( "errors" - "mermerd/config" - "mermerd/database" - "mermerd/util" + + "github.com/KarnerTh/mermerd/config" + "github.com/KarnerTh/mermerd/database" + "github.com/KarnerTh/mermerd/util" ) type analyzer struct { diff --git a/analyzer/analyzer_test.go b/analyzer/analyzer_test.go index c5969c7..4b4925b 100644 --- a/analyzer/analyzer_test.go +++ b/analyzer/analyzer_test.go @@ -1,10 +1,11 @@ package analyzer import ( - "github.com/stretchr/testify/assert" - "mermerd/database" - "mermerd/mocks" "testing" + + "github.com/KarnerTh/mermerd/database" + "github.com/KarnerTh/mermerd/mocks" + "github.com/stretchr/testify/assert" ) func getAnalyzerWithMocks() (Analyzer, *mocks.MermerdConfig, *mocks.ConnectorFactory, *mocks.Questioner) { diff --git a/changelog.md b/changelog.md index 870e365..6de0c31 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) (after version 0.0.5). +## [0.1.0] - 2022-04-15 +### Added +- Mermerd is available via the go tools + +### Changed +- go 1.18 is now used + +### Fixed +- MySQL query fix for constraints ([Issue #7](https://github.com/KarnerTh/mermerd/issues/7)) + ## [0.0.5] - 2022-03-17 ### Added - New config: allow surrounding output with mermerd backticks ([PR #4](https://github.com/KarnerTh/mermerd/pull/4)) @@ -45,6 +55,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) (after version 0.0 ### Added - Initial release of mermerd +[0.1.0]: https://github.com/KarnerTh/mermerd/releases/tag/v0.1.0 + [0.0.5]: https://github.com/KarnerTh/mermerd/releases/tag/v0.0.5 [0.0.4]: https://github.com/KarnerTh/mermerd/releases/tag/v0.0.4 diff --git a/cmd/root.go b/cmd/root.go index 436a0b4..4b841ef 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -2,16 +2,17 @@ package cmd import ( "fmt" - "github.com/fatih/color" - "mermerd/analyzer" - "mermerd/config" - "mermerd/database" - "mermerd/diagram" - "mermerd/util" "os" + "github.com/fatih/color" "github.com/spf13/cobra" "github.com/spf13/viper" + + "github.com/KarnerTh/mermerd/analyzer" + "github.com/KarnerTh/mermerd/config" + "github.com/KarnerTh/mermerd/database" + "github.com/KarnerTh/mermerd/diagram" + "github.com/KarnerTh/mermerd/util" ) var runConfig string diff --git a/cmd/version.go b/cmd/version.go index 8bd243a..7c8766a 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -2,9 +2,9 @@ package cmd import ( "fmt" - "github.com/spf13/viper" "github.com/spf13/cobra" + "github.com/spf13/viper" ) var versionCmd = &cobra.Command{ diff --git a/database/connector.go b/database/connector.go index 16933ce..43d60cc 100644 --- a/database/connector.go +++ b/database/connector.go @@ -1,8 +1,6 @@ package database -import ( - "database/sql" -) +import "database/sql" type baseConnector struct { dbType DbType diff --git a/database/connector_factory_test.go b/database/connector_factory_test.go index af40858..d16e329 100644 --- a/database/connector_factory_test.go +++ b/database/connector_factory_test.go @@ -2,8 +2,9 @@ package database import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestNewConnector(t *testing.T) { diff --git a/database/database_integration_test.go b/database/database_integration_test.go index 0e7e487..2311fe5 100644 --- a/database/database_integration_test.go +++ b/database/database_integration_test.go @@ -2,8 +2,9 @@ package database import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestDatabaseIntegrations(t *testing.T) { diff --git a/database/mysql.go b/database/mysql.go index 7ff4699..b873c2c 100644 --- a/database/mysql.go +++ b/database/mysql.go @@ -3,6 +3,7 @@ package database import ( "database/sql" "fmt" + _ "github.com/go-sql-driver/mysql" ) diff --git a/database/postgres.go b/database/postgres.go index f9a1245..b3f8b81 100644 --- a/database/postgres.go +++ b/database/postgres.go @@ -3,6 +3,7 @@ package database import ( "database/sql" "fmt" + _ "github.com/jackc/pgx/v4/stdlib" ) diff --git a/database/result_test.go b/database/result_test.go index 62193fe..4822d87 100644 --- a/database/result_test.go +++ b/database/result_test.go @@ -1,8 +1,9 @@ package database import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestConstraintResultList_AppendIfNotExists(t *testing.T) { diff --git a/database/type_test.go b/database/type_test.go index a703902..13d1245 100644 --- a/database/type_test.go +++ b/database/type_test.go @@ -2,8 +2,9 @@ package database import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestDbType_String(t *testing.T) { diff --git a/database/value_sanitizer_test.go b/database/value_sanitizer_test.go index a09feac..9a7ab35 100644 --- a/database/value_sanitizer_test.go +++ b/database/value_sanitizer_test.go @@ -2,8 +2,9 @@ package database import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestSanitizeValue(t *testing.T) { diff --git a/diagram/diagram.go b/diagram/diagram.go index 351b75d..7c57e66 100644 --- a/diagram/diagram.go +++ b/diagram/diagram.go @@ -3,10 +3,11 @@ package diagram import ( "bufio" "fmt" - "mermerd/config" - "mermerd/database" "os" "strings" + + "github.com/KarnerTh/mermerd/config" + "github.com/KarnerTh/mermerd/database" ) const ( diff --git a/diagram/diagram_test.go b/diagram/diagram_test.go index 2822298..3fca0cf 100644 --- a/diagram/diagram_test.go +++ b/diagram/diagram_test.go @@ -2,9 +2,11 @@ package diagram import ( "fmt" - "github.com/stretchr/testify/assert" - "mermerd/database" "testing" + + "github.com/stretchr/testify/assert" + + "github.com/KarnerTh/mermerd/database" ) func TestGetRelation(t *testing.T) { diff --git a/go.mod b/go.mod index f9d7349..515070c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ -module mermerd +module github.com/KarnerTh/mermerd -go 1.17 +go 1.18 require ( github.com/AlecAivazis/survey/v2 v2.3.2 diff --git a/main.go b/main.go index 2f4baa7..0e25727 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,8 @@ package main import ( "github.com/spf13/viper" - "mermerd/cmd" + + "github.com/KarnerTh/mermerd/cmd" ) // ldflags flags from goreleaser diff --git a/mocks/Analyzer.go b/mocks/Analyzer.go index 170f116..e507b94 100644 --- a/mocks/Analyzer.go +++ b/mocks/Analyzer.go @@ -1,10 +1,9 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.10.6. DO NOT EDIT. package mocks import ( - database "mermerd/database" - + database "github.com/KarnerTh/mermerd/database" mock "github.com/stretchr/testify/mock" ) @@ -35,3 +34,91 @@ func (_m *Analyzer) Analyze() (*database.Result, error) { return r0, r1 } + +// GetColumnsAndConstraints provides a mock function with given fields: db, selectedTables +func (_m *Analyzer) GetColumnsAndConstraints(db database.Connector, selectedTables []string) ([]database.TableResult, error) { + ret := _m.Called(db, selectedTables) + + var r0 []database.TableResult + if rf, ok := ret.Get(0).(func(database.Connector, []string) []database.TableResult); ok { + r0 = rf(db, selectedTables) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.TableResult) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(database.Connector, []string) error); ok { + r1 = rf(db, selectedTables) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetConnectionString provides a mock function with given fields: +func (_m *Analyzer) GetConnectionString() (string, error) { + ret := _m.Called() + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetSchema provides a mock function with given fields: db +func (_m *Analyzer) GetSchema(db database.Connector) (string, error) { + ret := _m.Called(db) + + var r0 string + if rf, ok := ret.Get(0).(func(database.Connector) string); ok { + r0 = rf(db) + } else { + r0 = ret.Get(0).(string) + } + + var r1 error + if rf, ok := ret.Get(1).(func(database.Connector) error); ok { + r1 = rf(db) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetTables provides a mock function with given fields: db, selectedSchema +func (_m *Analyzer) GetTables(db database.Connector, selectedSchema string) ([]string, error) { + ret := _m.Called(db, selectedSchema) + + var r0 []string + if rf, ok := ret.Get(0).(func(database.Connector, string) []string); ok { + r0 = rf(db, selectedSchema) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(database.Connector, string) error); ok { + r1 = rf(db, selectedSchema) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} diff --git a/mocks/Connector.go b/mocks/Connector.go index d0b0840..a49da9e 100644 --- a/mocks/Connector.go +++ b/mocks/Connector.go @@ -1,10 +1,9 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.10.6. DO NOT EDIT. package mocks import ( - database "mermerd/database" - + database "github.com/KarnerTh/mermerd/database" mock "github.com/stretchr/testify/mock" ) diff --git a/mocks/ConnectorFactory.go b/mocks/ConnectorFactory.go index ba0c1fc..c22efa3 100644 --- a/mocks/ConnectorFactory.go +++ b/mocks/ConnectorFactory.go @@ -1,10 +1,9 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.10.6. DO NOT EDIT. package mocks import ( - database "mermerd/database" - + database "github.com/KarnerTh/mermerd/database" mock "github.com/stretchr/testify/mock" ) diff --git a/mocks/Diagram.go b/mocks/Diagram.go index 472f24d..62aee17 100644 --- a/mocks/Diagram.go +++ b/mocks/Diagram.go @@ -1,9 +1,9 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.10.6. DO NOT EDIT. package mocks import ( - database "mermerd/database" + database "github.com/KarnerTh/mermerd/database" mock "github.com/stretchr/testify/mock" ) diff --git a/mocks/LoadingSpinner.go b/mocks/LoadingSpinner.go index a8d1c35..ac7fbd3 100644 --- a/mocks/LoadingSpinner.go +++ b/mocks/LoadingSpinner.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.10.6. DO NOT EDIT. package mocks diff --git a/mocks/MermerdConfig.go b/mocks/MermerdConfig.go index 9d72a46..776568b 100644 --- a/mocks/MermerdConfig.go +++ b/mocks/MermerdConfig.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.10.6. DO NOT EDIT. package mocks diff --git a/mocks/Questioner.go b/mocks/Questioner.go index 8fdaeb0..31a35a1 100644 --- a/mocks/Questioner.go +++ b/mocks/Questioner.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.10.0. DO NOT EDIT. +// Code generated by mockery v2.10.6. DO NOT EDIT. package mocks diff --git a/util/intro.go b/util/intro.go index 6cb520f..1707c2e 100644 --- a/util/intro.go +++ b/util/intro.go @@ -2,6 +2,7 @@ package util import ( "fmt" + "github.com/fatih/color" "github.com/spf13/viper" ) diff --git a/util/loading_spinner.go b/util/loading_spinner.go index 3e3b581..7cb2628 100644 --- a/util/loading_spinner.go +++ b/util/loading_spinner.go @@ -1,8 +1,9 @@ package util import ( - "github.com/briandowns/spinner" "time" + + "github.com/briandowns/spinner" ) type LoadingSpinner interface { diff --git a/util/outro.go b/util/outro.go index f81ccc8..2eb7b59 100644 --- a/util/outro.go +++ b/util/outro.go @@ -2,6 +2,7 @@ package util import ( "fmt" + "github.com/fatih/color" )