From 925a380580435626e0a3d012edd3485a8151d6ac Mon Sep 17 00:00:00 2001 From: William Chong Date: Tue, 4 Jun 2024 20:42:05 +0800 Subject: [PATCH] [preprocessor/folder] enforce not null on all text columns --- preprocessor/folder/database.go | 10 +++++----- preprocessor/folder/database_schema.go | 6 +++--- preprocessor/folder/file.go | 18 +++++++++--------- preprocessor/folder/folder.go | 4 ++-- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/preprocessor/folder/database.go b/preprocessor/folder/database.go index aa74def..7a664e2 100644 --- a/preprocessor/folder/database.go +++ b/preprocessor/folder/database.go @@ -49,11 +49,11 @@ func initDbTableIfNotExists(connPool *pgxpool.Pool) error { // ProjectQueryResult represents the result of a project metadata query type ProjectQueryResult struct { - ProjectId *string - ProjectPath *string - AuthorType *string - AuthorName *string - AuthorIdentifier *string + ProjectId string + ProjectPath string + AuthorType string + AuthorName string + AuthorIdentifier string } // queryAllProjects queries all project metadata from the database diff --git a/preprocessor/folder/database_schema.go b/preprocessor/folder/database_schema.go index a4f9fc0..51b2fd4 100644 --- a/preprocessor/folder/database_schema.go +++ b/preprocessor/folder/database_schema.go @@ -19,9 +19,9 @@ var PROJECT_METADATA_TABLE = `CREATE TABLE IF NOT EXISTS project_metadata ( id BIGSERIAL PRIMARY KEY, project_id TEXT UNIQUE NOT NULL, project_path TEXT UNIQUE NOT NULL, - author_type TEXT, - author_name TEXT, - author_identifier TEXT + author_type TEXT NOT NULL DEFAULT '', + author_name TEXT NOT NULL DEFAULT '', + author_identifier TEXT NOT NULL DEFAULT '' ); CREATE INDEX IF NOT EXISTS idx_project_metadata_project_id ON project_metadata (project_id); ` diff --git a/preprocessor/folder/file.go b/preprocessor/folder/file.go index 8a7e710..04e254d 100644 --- a/preprocessor/folder/file.go +++ b/preprocessor/folder/file.go @@ -93,18 +93,18 @@ func handleNewFile(pgPool *pgxpool.Pool, filePath string, project *ProjectQueryR } if project != nil { - metadata["project_id"] = *project.ProjectId - metadata["project_path"] = *project.ProjectPath - if project.AuthorType != nil || project.AuthorName != nil || project.AuthorIdentifier != nil { + metadata["project_id"] = project.ProjectId + metadata["project_path"] = project.ProjectPath + if project.AuthorType != "" || project.AuthorName != "" || project.AuthorIdentifier != "" { author := map[string]string{} - if project.AuthorType != nil { - author["@type"] = *project.AuthorType + if project.AuthorType != "" { + author["@type"] = project.AuthorType } - if project.AuthorName != nil { - author["name"] = *project.AuthorName + if project.AuthorName != "" { + author["name"] = project.AuthorName } - if project.AuthorIdentifier != nil { - author["identifier"] = *project.AuthorIdentifier + if project.AuthorIdentifier != "" { + author["identifier"] = project.AuthorIdentifier } metadata["author"] = author } diff --git a/preprocessor/folder/folder.go b/preprocessor/folder/folder.go index 86501cb..9461ed1 100644 --- a/preprocessor/folder/folder.go +++ b/preprocessor/folder/folder.go @@ -19,7 +19,7 @@ func findProjectWithFilePath(filePath string, projects []ProjectQueryResult) *Pr syncRoot = filepath.Clean(syncRoot) filePath = filepath.Clean(strings.TrimPrefix(filePath, syncRoot)) for _, project := range projects { - projectPath := *project.ProjectPath + projectPath := project.ProjectPath projectPath = filepath.Clean(projectPath) if strings.HasPrefix(filePath, projectPath) { return &project @@ -68,7 +68,7 @@ func Run(args []string) error { } for _, project := range projects { - projectPath := *project.ProjectPath + projectPath := project.ProjectPath fileList, err := scanSyncDirectory(projectPath) if err != nil { log.Println(err)