Skip to content

Commit

Permalink
[preprocessor/folder] enforce not null on all text columns
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Jun 4, 2024
1 parent ec95cf0 commit 925a380
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
10 changes: 5 additions & 5 deletions preprocessor/folder/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions preprocessor/folder/database_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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);
`
18 changes: 9 additions & 9 deletions preprocessor/folder/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions preprocessor/folder/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 925a380

Please sign in to comment.