경로 통일

This commit is contained in:
Lectom C Han
2025-12-10 10:46:21 +09:00
parent b1a9204e22
commit 199bc29115
11 changed files with 612 additions and 359 deletions

View File

@@ -20,7 +20,7 @@ import (
const (
defaultSchema = "public"
replicaTable = "user_program_info_replica"
ReplicaTable = "user_program_info_replica"
)
var (
@@ -63,7 +63,7 @@ func EnsureUserProgramReplica(ctx context.Context, conn *pgx.Conn, csvPath, sche
logDir = "log"
}
if err := createReplicaTable(ctx, conn, schema, replicaTable); err != nil {
if err := createReplicaTable(ctx, conn, schema, ReplicaTable); err != nil {
return err
}
@@ -97,38 +97,10 @@ func ImportUserProgramUpdates(ctx context.Context, conn *pgx.Conn, updateDir, sc
return nil
}
latestDate, err := latestCreatedDate(ctx, conn, schema, replicaTable)
if err != nil {
return err
}
for _, file := range files {
fileDate, err := dateFromFilename(file)
if err != nil {
_ = writeImportLog(logDir, importLog{
StartedAt: time.Now(),
CSVPath: file,
Status: "skipped",
Error: fmt.Sprintf("cannot parse date from filename: %v", err),
LatestDate: latestDate,
})
continue
}
if !fileDate.After(latestDate) {
_ = writeImportLog(logDir, importLog{
StartedAt: time.Now(),
CSVPath: file,
Status: "skipped",
Error: fmt.Sprintf("file date %s not after latest date %s", fileDate.Format("2006-01-02"), latestDate.Format("2006-01-02")),
LatestDate: latestDate,
})
continue
}
if err := importSingle(ctx, conn, file, schema, logDir); err != nil {
return err
}
latestDate = fileDate
}
return nil
}
@@ -362,7 +334,7 @@ func nullOrString(val string) any {
func importSingle(ctx context.Context, conn *pgx.Conn, csvPath, schema, logDir string) error {
startedAt := time.Now()
res, err := copyAndUpsertCSV(ctx, conn, csvPath, schema, replicaTable)
res, err := copyAndUpsertCSV(ctx, conn, csvPath, schema, ReplicaTable)
logStatus := "succeeded"
logErrMsg := ""
if err != nil {
@@ -479,7 +451,7 @@ func quoteColumns(cols []string) []string {
return out
}
func latestCreatedDate(ctx context.Context, conn *pgx.Conn, schema, table string) (time.Time, error) {
func LatestCreatedDate(ctx context.Context, conn *pgx.Conn, schema, table string) (time.Time, error) {
var ts sql.NullTime
query := fmt.Sprintf("SELECT MAX(created_at) FROM %s", pgx.Identifier{schema, table}.Sanitize())
if err := conn.QueryRow(ctx, query).Scan(&ts); err != nil {