Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ result.mmd
mermerd
coverage.html
mermerd_test.db
go.work
13 changes: 9 additions & 4 deletions Makefile
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tweaks allowed me to build/run the tests "out of the box", making it easier to just run make test-unit. At this point, it's probably reasonable to assume docker/docker-compose by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@ test-coverage:
create-mocks:
mockery --all

# https://github.com/mfridman/tparse is needed
.PHONY: test-all
test-all:
test-all: test-setup
go test $(test_target) -cover -json | tparse -all

# https://github.com/mfridman/tparse is needed
.PHONY: test-unit
test-unit:
test-unit: test-setup
go test --short $(test_target) -cover -json | tparse -all

.PHONY: test-setup
test-setup:
go install github.com/mfridman/tparse@v0.18.0
cd test && docker-compose up -d

.PHONY: test-cleanup
test-cleanup:
go clean -testcache
cd test && docker-compose stop && docker-compose rm -f
rm mermerd_test.db 2&> /dev/null || true

.PHONY: publish-package
publish-package:
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func init() {
rootCmd.Flags().Bool(config.OmitConstraintLabelsKey, false, "omit the constraint labels")
rootCmd.Flags().Bool(config.OmitAttributeKeysKey, false, "omit the attribute keys (PK, FK, UK)")
rootCmd.Flags().Bool(config.ShowSchemaPrefix, false, "show schema prefix in table name")
rootCmd.Flags().Bool(config.ShowNameBeforeType, false, "show name before type for each table")
rootCmd.Flags().BoolP(config.EncloseWithMermaidBackticksKey, "e", false, "enclose output with mermaid backticks (needed for e.g. in markdown viewer)")
rootCmd.Flags().StringP(config.ConnectionStringKey, "c", "", "connection string that should be used")
rootCmd.Flags().StringP(config.SchemaKey, "s", "", "schema that should be used")
Expand All @@ -117,6 +118,7 @@ func init() {
bindFlagToViper(config.ShowAllConstraintsKey)
bindFlagToViper(config.ShowDescriptionsKey)
bindFlagToViper(config.ShowSchemaPrefix)
bindFlagToViper(config.ShowNameBeforeType)
bindFlagToViper(config.UseAllSchemasKey)
bindFlagToViper(config.UseAllTablesKey)
}
Expand Down
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
ShowAllConstraintsKey = "showAllConstraints"
ShowDescriptionsKey = "showDescriptions"
ShowSchemaPrefix = "showSchemaPrefix"
ShowNameBeforeType = "showNameBeforeType"
UseAllSchemasKey = "useAllSchemas"
UseAllTablesKey = "useAllTables"
)
Expand All @@ -44,6 +45,7 @@ type MermerdConfig interface {
ShowSchemaPrefix() bool
UseAllSchemas() bool
UseAllTables() bool
ShowNameBeforeType() bool
}

func NewConfig() MermerdConfig {
Expand Down Expand Up @@ -122,3 +124,7 @@ func (c config) SchemaPrefixSeparator() string {
func (c config) OutputMode() OutputModeType {
return OutputModeType(viper.GetString(OutputMode))
}

func (c config) ShowNameBeforeType() bool {
return viper.GetBool(ShowNameBeforeType)
}
2 changes: 2 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ relationshipLabels:
useAllSchemas: true
showSchemaPrefix: true
schemaPrefixSeparator: "_"
showNameBeforeType: true
ignoreTables:
- city
- customer
Expand Down Expand Up @@ -71,6 +72,7 @@ connectionStringSuggestions:
assert.True(t, config.UseAllSchemas())
assert.True(t, config.ShowSchemaPrefix())
assert.Equal(t, "_", config.SchemaPrefixSeparator())
assert.Equal(t, true, config.ShowNameBeforeType())
assert.ElementsMatch(t,
config.RelationshipLabels(),
[]RelationshipLabel{
Expand Down
1 change: 1 addition & 0 deletions diagram/diagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (d diagram) Create(wr io.Writer, result *database.Result) error {

diagramData := ErdDiagramData{
EncloseWithMermaidBackticks: d.config.EncloseWithMermaidBackticks(),
ShowNameBeforeType: d.config.ShowNameBeforeType(),
Tables: tableData,
Constraints: constraints,
}
Expand Down
1 change: 1 addition & 0 deletions diagram/diagram_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type ErdDiagramData struct {
EncloseWithMermaidBackticks bool
Tables []ErdTableData
Constraints []ErdConstraintData
ShowNameBeforeType bool
}

type ErdTableData struct {
Expand Down
3 changes: 2 additions & 1 deletion diagram/erd_template.gommd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ erDiagram
{{- range .Tables}}
{{.Name}} {
{{- range .Columns}}
{{.DataType}} {{.Name}} {{- if .AttributeKeys}} {{range $index, $attributeKey := .AttributeKeys}}
{{if $.ShowNameBeforeType}}{{.Name}} {{.DataType}}{{else}}{{.DataType}} {{.Name}} {{end -}}
{{- if .AttributeKeys}} {{range $index, $attributeKey := .AttributeKeys}}
{{- if $index}},{{end -}}
{{$attributeKey}}
{{- end}}{{end}} {{if .Description -}}
Expand Down
16 changes: 16 additions & 0 deletions mocks/MermerdConfig.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ services:
- ./mysql/mysql-multiple-databases.sql:/docker-entrypoint-initdb.d/3.sql
mermerd-mssql-test-db:
image: mcr.microsoft.com/mssql/server:2019-latest
platform: linux/amd64
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silences warning on macos

environment:
ACCEPT_EULA: "Y"
SA_PASSWORD: "securePassword1!"
Expand Down