utils

package
v1.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Copyright (c) YugabyteDB, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) YugabyteDB, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) YugabyteDB, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) YugabyteDB, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) YugabyteDB, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	TABLE_MIGRATION_NOT_STARTED = iota
	TABLE_MIGRATION_IN_PROGRESS
	TABLE_MIGRATION_DONE
	TABLE_MIGRATION_COMPLETED
	YB_VOYAGER_NULL_STRING = "__YBV_NULL__"
)
View Source
const (
	SNAPSHOT_ONLY        = "snapshot-only"
	SNAPSHOT_AND_CHANGES = "snapshot-and-changes"
	CHANGES_ONLY         = "changes-only"
)
View Source
const (
	// This constant must be updated on every release.
	YB_VOYAGER_VERSION = "1.6.5"

	// @Refer: https://icinga.com/blog/2022/05/25/embedding-git-commit-information-in-go-binaries/
	GIT_COMMIT_HASH = "$Format:%H$"
)

Variables

View Source
var DoNotPrompt bool
View Source
var TableMetadataStatusMap = map[int]string{
	0: "NOT-STARTED",
	1: "EXPORTING",
	2: "DONE",
	3: "DONE",
}
View Source
var WaitChannel = make(chan int)
View Source
var WaitGroup sync.WaitGroup

Functions

func AskPrompt

func AskPrompt(args ...string) bool

func CleanDir

func CleanDir(dir string)

func ContainsAnySubstringFromSlice added in v1.6.2

func ContainsAnySubstringFromSlice(slice []string, s string) bool

func ContainsString added in v1.6.0

func ContainsString(list []string, str string) bool

func CsvStringToSlice

func CsvStringToSlice(str string) []string

func ErrExit

func ErrExit(formatString string, args ...interface{})

func FileOrFolderExists

func FileOrFolderExists(path string) bool

func FileOrFolderExistsWithGlobPattern added in v1.6.0

func FileOrFolderExistsWithGlobPattern(path string) bool

func ForEachLineInFile added in v1.5.0

func ForEachLineInFile(filePath string, callback func(line string) bool) error

func ForEachMatchingLineInFile added in v1.5.0

func ForEachMatchingLineInFile(filePath string, re *regexp.Regexp, callback func(matches []string) bool) error

func GenerateRandomString added in v1.4.0

func GenerateRandomString(length int) string

https://yourbasic.org/golang/generate-random-string/

func GetEnvAsInt added in v1.5.0

func GetEnvAsInt(key string, fallback int) int

func GetExportSchemaObjectList added in v1.6.0

func GetExportSchemaObjectList(sourceDBType string) []string

func GetFSUtilizationPercentage added in v1.5.0

func GetFSUtilizationPercentage(path string) (int, error)

func GetMapKeysSorted added in v1.5.0

func GetMapKeysSorted(m map[string]*string) []string

func GetObjectDirPath

func GetObjectDirPath(schemaDirPath string, objType string) string

func GetObjectFileName

func GetObjectFileName(schemaDirPath string, objType string) string

func GetObjectFilePath

func GetObjectFilePath(schemaDirPath string, objType string) string

func GetObjectNameListFromReport

func GetObjectNameListFromReport(report Report, objType string) []string

func GetRedactedURLs added in v0.81.0

func GetRedactedURLs(urlList []string) []string

func GetSchemaObjectList

func GetSchemaObjectList(sourceDBType string) []string

func GetSortedKeys

func GetSortedKeys(tablesProgressMetadata map[string]*TableProgressMetadata) []string

func GetSqlStmtToPrint added in v0.83.0

func GetSqlStmtToPrint(stmt string) string

func GitCommitHash

func GitCommitHash() string

func HumanReadableByteCount added in v1.4.0

func HumanReadableByteCount(bytes int64) string

func IsDirectoryEmpty

func IsDirectoryEmpty(pathPattern string) bool

func IsQuotedString

func IsQuotedString(str string) bool

func LookupIP

func LookupIP(name string) []string

func PrettifyHtmlString

func PrettifyHtmlString(htmlStr string) string

func PrettifyJsonString

func PrettifyJsonString(jsonStr string) string

func PrintAndLog

func PrintAndLog(formatString string, args ...interface{})

func PrintIfTrue

func PrintIfTrue(message string, args ...bool)

func PrintSqlStmtIfDDL added in v0.83.0

func PrintSqlStmtIfDDL(stmt string, fileName string)

func ReadTableNameListFromFile added in v1.6.0

func ReadTableNameListFromFile(filePath string) ([]string, error)

read the file and return slice of csv

func Readline

func Readline(r *bufio.Reader) (string, error)

func SetDifference added in v0.81.0

func SetDifference(includeList []string, excludeList []string) []string

func ToCaseInsensitiveNames added in v0.81.0

func ToCaseInsensitiveNames(names []string) []string

func Wait

func Wait(args ...string)

Types

type BoolStr added in v1.6.0

type BoolStr bool

func (*BoolStr) Set added in v1.6.0

func (b *BoolStr) Set(s string) error

func (*BoolStr) String added in v1.6.0

func (b *BoolStr) String() string

func (*BoolStr) Type added in v1.6.0

func (b *BoolStr) Type() string

type DBObject

type DBObject struct {
	ObjectType   string `json:"objectType"`
	TotalCount   int    `json:"totalCount"`
	InvalidCount int    `json:"invalidCount"`
	ObjectNames  string `json:"objectNames"`
	Details      string `json:"details"`
}

type IndexInfo added in v1.6.0

type IndexInfo struct {
	IndexName string   `json:"IndexName"`
	IndexType string   `json:"IndexType"`
	TableName string   `json:"TableName"`
	Columns   []string `json:"Columns"`
}

type Issue

type Issue struct {
	ObjectType   string `json:"objectType"`
	ObjectName   string `json:"objectName"`
	Reason       string `json:"reason"`
	SqlStatement string `json:"sqlStatement,omitempty"`
	FilePath     string `json:"filePath"`
	Suggestion   string `json:"suggestion"`
	GH           string `json:"GH"`
}

type Report

type Report struct {
	Summary Summary `json:"summary"`
	Issues  []Issue `json:"issues"`
}

report.json format

func ParseJsonFromString

func ParseJsonFromString(jsonString string) Report

type Segment added in v1.6.0

type Segment struct {
	Num      int
	FilePath string
}

type Summary

type Summary struct {
	DBName     string     `json:"dbName"`
	SchemaName string     `json:"schemaName"`
	DBVersion  string     `json:"dbVersion"`
	Notes      []string   `json:"notes"`
	DBObjects  []DBObject `json:"databaseObjects"`
}

type TableProgressMetadata

type TableProgressMetadata struct {
	TableName            *sqlname.SourceName
	InProgressFilePath   string
	FinalFilePath        string
	Status               int //(0: NOT-STARTED, 1: IN-PROGRESS, 2: DONE, 3: COMPLETED)
	CountLiveRows        int64
	CountTotalRows       int64
	FileOffsetToContinue int64 // This might be removed later
	IsPartition          bool
	ParentTable          string
}

type TailReader added in v1.2.0

type TailReader struct {
	// contains filtered or unexported fields
}

func NewTailReader added in v1.2.0

func NewTailReader(r io.Reader, getLastValidOffsetFn func() (int64, error)) *TailReader

func (*TailReader) Read added in v1.2.0

func (t *TailReader) Read(p []byte) (n int, err error)

Read the underlying io.Reader and return the contents. If the underlying reader returns io.EOF, keep on retrying until some data is available.

Directories

Path Synopsis
Package csv reads and writes comma-separated values (CSV) files.
Package csv reads and writes comma-separated values (CSV) files.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL