Add type to document
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -28,13 +28,14 @@ import (
|
||||
|
||||
type (
|
||||
Document struct {
|
||||
ID gid.GID `db:"id"`
|
||||
OrganizationID gid.GID `db:"organization_id"`
|
||||
OwnerID gid.GID `db:"owner_id"`
|
||||
Title string `db:"title"`
|
||||
CurrentPublishedVersion *int `db:"current_published_version"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
ID gid.GID `db:"id"`
|
||||
OrganizationID gid.GID `db:"organization_id"`
|
||||
OwnerID gid.GID `db:"owner_id"`
|
||||
Title string `db:"title"`
|
||||
DocumentType DocumentType `db:"document_type"`
|
||||
CurrentPublishedVersion *int `db:"current_published_version"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
Documents []*Document
|
||||
@@ -63,6 +64,7 @@ SELECT
|
||||
organization_id,
|
||||
owner_id,
|
||||
title,
|
||||
document_type,
|
||||
current_published_version,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -107,6 +109,7 @@ SELECT
|
||||
organization_id,
|
||||
owner_id,
|
||||
title,
|
||||
document_type,
|
||||
current_published_version,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -152,6 +155,7 @@ INSERT INTO
|
||||
organization_id,
|
||||
owner_id,
|
||||
title,
|
||||
document_type,
|
||||
current_published_version,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -162,6 +166,7 @@ VALUES (
|
||||
@organization_id,
|
||||
@owner_id,
|
||||
@title,
|
||||
@document_type,
|
||||
@current_published_version,
|
||||
@created_at,
|
||||
@updated_at
|
||||
@@ -174,6 +179,7 @@ VALUES (
|
||||
"organization_id": p.OrganizationID,
|
||||
"owner_id": p.OwnerID,
|
||||
"title": p.Title,
|
||||
"document_type": p.DocumentType,
|
||||
"current_published_version": p.CurrentPublishedVersion,
|
||||
"created_at": p.CreatedAt,
|
||||
"updated_at": p.UpdatedAt,
|
||||
@@ -212,6 +218,7 @@ SET
|
||||
title = @title,
|
||||
current_published_version = @current_published_version,
|
||||
owner_id = @owner_id,
|
||||
document_type = @document_type,
|
||||
updated_at = @updated_at
|
||||
WHERE %s
|
||||
AND id = @document_id
|
||||
@@ -224,6 +231,7 @@ WHERE %s
|
||||
"title": p.Title,
|
||||
"current_published_version": p.CurrentPublishedVersion,
|
||||
"owner_id": p.OwnerID,
|
||||
"document_type": p.DocumentType,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
@@ -250,6 +258,7 @@ WITH plcs AS (
|
||||
p.organization_id,
|
||||
p.owner_id,
|
||||
p.title,
|
||||
p.document_type,
|
||||
p.current_published_version,
|
||||
p.created_at,
|
||||
p.updated_at
|
||||
@@ -265,6 +274,7 @@ SELECT
|
||||
organization_id,
|
||||
owner_id,
|
||||
title,
|
||||
document_type,
|
||||
current_published_version,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -309,6 +319,7 @@ WITH plcs AS (
|
||||
p.organization_id,
|
||||
p.owner_id,
|
||||
p.title,
|
||||
p.document_type,
|
||||
p.current_published_version,
|
||||
p.created_at,
|
||||
p.updated_at
|
||||
@@ -324,6 +335,7 @@ SELECT
|
||||
organization_id,
|
||||
owner_id,
|
||||
title,
|
||||
document_type,
|
||||
current_published_version,
|
||||
created_at,
|
||||
updated_at
|
||||
|
||||
68
pkg/coredata/document_type.go
Normal file
68
pkg/coredata/document_type.go
Normal file
@@ -0,0 +1,68 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type (
|
||||
DocumentType string
|
||||
)
|
||||
|
||||
const (
|
||||
DocumentTypeOther DocumentType = "OTHER"
|
||||
DocumentTypeISMS DocumentType = "ISMS"
|
||||
DocumentTypePolicy DocumentType = "POLICY"
|
||||
)
|
||||
|
||||
func (dt DocumentType) MarshalText() ([]byte, error) {
|
||||
return []byte(dt.String()), nil
|
||||
}
|
||||
|
||||
func (dt *DocumentType) UnmarshalText(data []byte) error {
|
||||
val := string(data)
|
||||
|
||||
switch val {
|
||||
case DocumentTypeOther.String():
|
||||
*dt = DocumentTypeOther
|
||||
case DocumentTypeISMS.String():
|
||||
*dt = DocumentTypeISMS
|
||||
case DocumentTypePolicy.String():
|
||||
*dt = DocumentTypePolicy
|
||||
default:
|
||||
return fmt.Errorf("invalid DocumentType value: %q", val)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dt DocumentType) String() string {
|
||||
return string(dt)
|
||||
}
|
||||
|
||||
func (dt *DocumentType) Scan(value any) error {
|
||||
val, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid scan source for DocumentType, expected string got %T", value)
|
||||
}
|
||||
|
||||
return dt.UnmarshalText([]byte(val))
|
||||
}
|
||||
|
||||
func (dt DocumentType) Value() (driver.Value, error) {
|
||||
return dt.String(), nil
|
||||
}
|
||||
3
pkg/coredata/migrations/20250530T170253Z.sql
Normal file
3
pkg/coredata/migrations/20250530T170253Z.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
CREATE TYPE document_type AS ENUM ('OTHER', 'ISMS', 'POLICY');
|
||||
|
||||
ALTER TABLE documents ADD COLUMN document_type document_type NOT NULL DEFAULT 'POLICY';
|
||||
Reference in New Issue
Block a user