!124 一些更新和bug

* fix: 代码合并
* feat:支持数据库版本兼容,目前兼容了oracle11g部分特性
* fix: 修改数据同步bug,数据sql里指定修改字段别,导致未正确记录修改字段值
* feat: 数据库迁移支持定时迁移和迁移到sql文件
This commit is contained in:
zongyangleo
2024-10-20 03:52:23 +00:00
committed by Coder慌
parent 6837a9c867
commit 6343173cf8
68 changed files with 3319 additions and 1587 deletions

View File

@@ -0,0 +1,51 @@
package writer
import (
"io"
"os"
"path/filepath"
)
type FileWriter struct {
tryFlushCount int
writer *os.File
aborted bool
}
func NewFileWriter(filePath string) *FileWriter {
if filePath == "" {
panic("filePath is empty")
}
// 使用filepath.Dir函数提取文件夹路径
dir := filepath.Dir(filePath)
if dir != "" {
// 检查文件夹路径,不存在则创建
if _, err := os.Stat(dir); os.IsNotExist(err) {
err = os.MkdirAll(dir, os.ModePerm)
if err != nil {
panic(err)
}
}
}
fw, err := os.Create(filePath)
if err != nil {
panic(err)
}
return &FileWriter{writer: fw}
}
func (f *FileWriter) Close() {
f.writer.Close()
}
func (f *FileWriter) TryFlush() {
}
func (f *FileWriter) Write(b []byte) (n int, err error) {
return f.writer.Write(b)
}
func (f *FileWriter) WriteString(data string) {
io.WriteString(f.writer, data)
}

View File

@@ -0,0 +1,50 @@
package writer
import (
"compress/gzip"
"io"
"mayfly-go/pkg/biz"
)
type GzipWriter struct {
tryFlushCount int
writer *gzip.Writer
aborted bool
}
func NewGzipWriter(writer io.Writer) *GzipWriter {
return &GzipWriter{writer: gzip.NewWriter(writer)}
}
func (g *GzipWriter) WriteString(data string) {
if g.aborted {
return
}
if _, err := g.writer.Write([]byte(data)); err != nil {
g.aborted = true
biz.IsTrue(false, "数据库导出失败:%s", err)
}
}
func (g *GzipWriter) Write(p []byte) (n int, err error) {
if g.aborted {
return
}
if _, err := g.writer.Write(p); err != nil {
g.aborted = true
biz.IsTrue(false, "数据库导出失败:%s", err)
}
return
}
func (g *GzipWriter) Close() {
g.writer.Close()
}
func (g *GzipWriter) TryFlush() {
if g.tryFlushCount%1000 == 0 {
g.writer.Flush()
}
g.tryFlushCount += 1
}

View File

@@ -0,0 +1,10 @@
package writer
import "io"
type CustomWriter interface {
io.Writer
WriteString(data string)
Close()
TryFlush()
}