Compare commits

..

6 Commits
v5.2.0 ... main

Author SHA1 Message Date
f59ca53950 fix: correct user ID source in User model
All checks were successful
Gitea Build Check / Build (pull_request) Successful in 3m19s
Gitea Build Check / Build (push) Successful in 3m10s
Change 'user_id' field to 'text'
2025-01-29 15:07:29 +01:00
6f7c89a76b fix: incorrect struct field names for TagAlias and TagGroup
All checks were successful
Gitea Build Check / Build (pull_request) Successful in 2m56s
Gitea Build Check / Build (push) Successful in 2m56s
2025-01-28 14:05:48 +01:00
0e87b43339 fix: change tests to accept the bools for hard deletion 2025-01-28 14:04:51 +01:00
c9b0c71bef feat: add hard delete option to delete functions
Some checks failed
Gitea Build Check / Build (pull_request) Failing after 31s
2025-01-28 13:59:39 +01:00
ecbf139a9b feat(database): add ON DELETE CASCADE constraints
All checks were successful
Gitea Build Check / Build (pull_request) Successful in 3m5s
2025-01-28 13:39:26 +01:00
6f814e5b21 refactor: unified migrations and Tag* ID Changes
All checks were successful
Gitea Build Check / Build (pull_request) Successful in 3m8s
- unified the migrations
- added new IDs for Tag, TagAlias, TagGroup
- changed relevant functions to use the given IDs

BREAKING-CHANGE: Database needs to be cleared or migrated. Not compatible with Database v5
2025-01-28 13:27:11 +01:00
48 changed files with 477 additions and 468 deletions

View File

@ -1,4 +1,4 @@
![Build Check Runner](https://git.anthrove.art/Anthrove/otter-space-sdk/v5/actions/workflows/build_check.yaml/badge.svg) ![Build Check Runner](https://git.anthrove.art/Anthrove/otter-space-sdk/v6/actions/workflows/build_check.yaml/badge.svg)
[![Bugs](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=bugs&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK) [![Bugs](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=bugs&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK)
[![Code Smells](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=code_smells&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK) [![Code Smells](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=code_smells&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK)
[![Coverage](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=coverage&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK) [![Coverage](https://sonarqube.dragse.de/api/project_badges/measure?project=Anthrove---OtterSpace-SDK&metric=coverage&token=sqb_96012ffdd64ce721d7f9c82bfa77aa27a5c1fd38)](https://sonarqube.dragse.de/dashboard?id=Anthrove---OtterSpace-SDK)
@ -22,7 +22,7 @@ The OtterSpace SDK is a Go package for interacting with the OtterSpace API. It p
To install the OtterSpace SDK, you can use `go get`: To install the OtterSpace SDK, you can use `go get`:
```shell ```shell
go get git.anthrove.art/Anthrove/otter-space-sdk/v5 go get git.anthrove.art/Anthrove/otter-space-sdk/v6
```` ````
## Usage ## Usage
@ -34,8 +34,8 @@ package main
import ( import (
"context" "context"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/database" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/database"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
) )
func main() { func main() {

45
go.mod
View File

@ -1,4 +1,4 @@
module git.anthrove.art/Anthrove/otter-space-sdk/v5 module git.anthrove.art/Anthrove/otter-space-sdk/v6
go 1.22.0 go 1.22.0
@ -6,28 +6,28 @@ require (
github.com/davecgh/go-spew v1.1.1 github.com/davecgh/go-spew v1.1.1
github.com/lib/pq v1.10.9 github.com/lib/pq v1.10.9
github.com/matoous/go-nanoid/v2 v2.1.0 github.com/matoous/go-nanoid/v2 v2.1.0
github.com/rubenv/sql-migrate v1.7.0 github.com/rubenv/sql-migrate v1.7.1
github.com/sirupsen/logrus v1.9.3 github.com/sirupsen/logrus v1.9.3
github.com/testcontainers/testcontainers-go v0.33.0 github.com/testcontainers/testcontainers-go v0.35.0
github.com/testcontainers/testcontainers-go/modules/postgres v0.33.0 github.com/testcontainers/testcontainers-go/modules/postgres v0.35.0
go.opentelemetry.io/contrib/bridges/otellogrus v0.5.0 go.opentelemetry.io/contrib/bridges/otellogrus v0.9.0
go.opentelemetry.io/otel v1.31.0 go.opentelemetry.io/otel v1.34.0
go.opentelemetry.io/otel/trace v1.31.0 go.opentelemetry.io/otel/trace v1.34.0
gorm.io/driver/postgres v1.5.9 gorm.io/driver/postgres v1.5.11
gorm.io/gorm v1.25.12 gorm.io/gorm v1.25.12
) )
require ( require (
dario.cat/mergo v1.0.1 // indirect dario.cat/mergo v1.0.1 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/distribution/reference v0.6.0 // indirect github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v27.3.1+incompatible // indirect github.com/docker/docker v27.5.1+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect
@ -39,38 +39,41 @@ require (
github.com/google/uuid v1.6.0 // indirect github.com/google/uuid v1.6.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.1 // indirect github.com/jackc/pgx/v5 v5.7.2 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect github.com/jinzhu/now v1.1.5 // indirect
github.com/klauspost/compress v1.17.11 // indirect github.com/klauspost/compress v1.17.11 // indirect
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect
github.com/magiconair/properties v1.8.7 // indirect github.com/magiconair/properties v1.8.9 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.6.0 // indirect github.com/moby/sys/sequential v0.6.0 // indirect
github.com/moby/sys/user v0.3.0 // indirect github.com/moby/sys/user v0.3.0 // indirect
github.com/moby/sys/userns v0.1.0 // indirect github.com/moby/sys/userns v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect github.com/moby/term v0.5.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/shirou/gopsutil/v3 v3.24.5 // indirect github.com/shirou/gopsutil/v3 v3.24.5 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/stretchr/testify v1.10.0 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.9.0 // indirect github.com/tklauser/numcpus v0.9.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 // indirect
go.opentelemetry.io/otel/log v0.7.0 // indirect go.opentelemetry.io/otel/log v0.10.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect go.opentelemetry.io/otel/metric v1.34.0 // indirect
go.opentelemetry.io/otel/sdk v1.28.0 // indirect go.opentelemetry.io/otel/sdk v1.28.0 // indirect
golang.org/x/crypto v0.28.0 // indirect golang.org/x/crypto v0.32.0 // indirect
golang.org/x/sync v0.8.0 // indirect golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.26.0 // indirect golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.19.0 // indirect golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

94
go.sum
View File

@ -2,8 +2,8 @@ dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
@ -21,8 +21,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/docker v27.3.1+incompatible h1:KttF0XoteNTicmUtBO0L2tP+J7FGRFTjaEF4k6WdhfI= github.com/docker/docker v27.5.1+incompatible h1:4PYU5dnBYqRQi0294d1FBECqT9ECWeQAIfE8q4YnPY8=
github.com/docker/docker v27.3.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker v27.5.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
@ -53,8 +53,8 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.7.1 h1:x7SYsPBYDkHDksogeSmZZ5xzThcTgRz++I5E+ePFUcs= github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI=
github.com/jackc/pgx/v5 v5.7.1/go.mod h1:e7O26IywZZ+naJtWWos6i6fvWK+29etgITqrqHLfoZA= github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
@ -73,12 +73,14 @@ github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 h1:7UMa6KCCMjZEMDtTVdcGu0B1GmmC7QJKiCCjyTAWQy0= github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 h1:7UMa6KCCMjZEMDtTVdcGu0B1GmmC7QJKiCCjyTAWQy0=
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k= github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/matoous/go-nanoid/v2 v2.1.0 h1:P64+dmq21hhWdtvZfEAofnvJULaRR1Yib0+PnU669bE= github.com/matoous/go-nanoid/v2 v2.1.0 h1:P64+dmq21hhWdtvZfEAofnvJULaRR1Yib0+PnU669bE=
github.com/matoous/go-nanoid/v2 v2.1.0/go.mod h1:KlbGNQ+FhrUNIHUxZdL63t7tl4LaPkZNpUULS8H4uVM= github.com/matoous/go-nanoid/v2 v2.1.0/go.mod h1:KlbGNQ+FhrUNIHUxZdL63t7tl4LaPkZNpUULS8H4uVM=
github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI= github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI=
github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mdelapenya/tlscert v0.1.0 h1:YTpF579PYUX475eOL+6zyEO3ngLTOUWck78NBuJVXaM=
github.com/mdelapenya/tlscert v0.1.0/go.mod h1:wrbyM/DwbFCeCeqdPX/8c6hNOqQgbf0rUDErE1uD+64=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk=
@ -89,8 +91,8 @@ github.com/moby/sys/user v0.3.0 h1:9ni5DlcW5an3SvRSx4MouotOygvzaXbaSrc/wGDFWPo=
github.com/moby/sys/user v0.3.0/go.mod h1:bG+tYYYJgaMtRKgEmuueC0hJEAZWwtIbZTB+85uoHjs= github.com/moby/sys/user v0.3.0/go.mod h1:bG+tYYYJgaMtRKgEmuueC0hJEAZWwtIbZTB+85uoHjs=
github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g= github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g=
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ=
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
@ -105,10 +107,10 @@ github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY= github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY=
github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg= github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/rubenv/sql-migrate v1.7.0 h1:HtQq1xyTN2ISmQDggnh0c9U3JlP8apWh8YO2jzlXpTI= github.com/rubenv/sql-migrate v1.7.1 h1:f/o0WgfO/GqNuVg+6801K/KW3WdDSupzSjDYODmiUq4=
github.com/rubenv/sql-migrate v1.7.0/go.mod h1:S4wtDEG1CKn+0ShpTtzWhFpHHI5PvCUtiGI+C+Z2THE= github.com/rubenv/sql-migrate v1.7.1/go.mod h1:Ob2Psprc0/3ggbM6wCzyYVFFuc6FyZrb2AS+ezLDFb4=
github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI= github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI=
github.com/shirou/gopsutil/v3 v3.24.5/go.mod h1:bsoOS1aStSs9ErQ1WWfxllSeS1K5D+U30r2NfcubMVk= github.com/shirou/gopsutil/v3 v3.24.5/go.mod h1:bsoOS1aStSs9ErQ1WWfxllSeS1K5D+U30r2NfcubMVk=
github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM=
@ -118,14 +120,16 @@ github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnj
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/testcontainers/testcontainers-go v0.33.0 h1:zJS9PfXYT5O0ZFXM2xxXfk4J5UMw/kRiISng037Gxdw= github.com/testcontainers/testcontainers-go v0.35.0 h1:uADsZpTKFAtp8SLK+hMwSaa+X+JiERHtd4sQAFmXeMo=
github.com/testcontainers/testcontainers-go v0.33.0/go.mod h1:W80YpTa8D5C3Yy16icheD01UTDu+LmXIA2Keo+jWtT8= github.com/testcontainers/testcontainers-go v0.35.0/go.mod h1:oEVBj5zrfJTrgjwONs1SsRbnBtH9OKl+IGl3UMcr2B4=
github.com/testcontainers/testcontainers-go/modules/postgres v0.33.0 h1:c+Gt+XLJjqFAejgX4hSpnHIpC9eAhvgI/TFWL/PbrFI= github.com/testcontainers/testcontainers-go/modules/postgres v0.35.0 h1:eEGx9kYzZb2cNhRbBrNOCL/YPOM7+RMJiy3bB+ie0/I=
github.com/testcontainers/testcontainers-go/modules/postgres v0.33.0/go.mod h1:I4DazHBoWDyf69ByOIyt3OdNjefiUx372459txOpQ3o= github.com/testcontainers/testcontainers-go/modules/postgres v0.35.0/go.mod h1:hfH71Mia/WWLBgMD2YctYcMlfsbnT0hflweL1dy8Q4s=
github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZb78yU= github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZb78yU=
github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY= github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY=
github.com/tklauser/numcpus v0.9.0 h1:lmyCHtANi8aRUgkckBgoDk1nHCux3n2cgkJLXdQGPDo= github.com/tklauser/numcpus v0.9.0 h1:lmyCHtANi8aRUgkckBgoDk1nHCux3n2cgkJLXdQGPDo=
@ -134,31 +138,33 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.opentelemetry.io/contrib/bridges/otellogrus v0.5.0 h1:T9cxTlfBz5go7dFWejO5E4JfeglWgWL1MRTPq9p8da0= go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
go.opentelemetry.io/contrib/bridges/otellogrus v0.5.0/go.mod h1:f6xZHPJ3A+RFc3Lfz4SoGIpfmVr4PEF4XM1H3fl+6/4= go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 h1:ZIg3ZT/aQ7AfKqdwp7ECpOK6vHqquXXuyTjIO8ZdmPs= go.opentelemetry.io/contrib/bridges/otellogrus v0.9.0 h1:8WlIPjiMRU8Pg86+JoBjdzXOKp9bWt2M9qiVbjjFUsg=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0/go.mod h1:DQAwmETtZV00skUwgD6+0U89g80NKsJE3DCKeLLPQMI= go.opentelemetry.io/contrib/bridges/otellogrus v0.9.0/go.mod h1:bkQ7eZh+3ruXMBGR2UfReI0EjxtkcsjsmQKJTh1N2Is=
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 h1:CV7UdSGJt/Ao6Gp4CXckLxVRRsRgDHoI8XjbL3PDl8s=
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0/go.mod h1:FRmFuRJfag1IZ2dPkHnEoSFVgTVPUd2qf5Vi69hLb8I=
go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=
go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 h1:Mne5On7VWdx7omSrSSZvM4Kw7cS7NQkOOmLcgscI51U= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 h1:Mne5On7VWdx7omSrSSZvM4Kw7cS7NQkOOmLcgscI51U=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0/go.mod h1:IPtUMKL4O3tH5y+iXVyAXqpAwMuzC1IrxVS81rummfE= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0/go.mod h1:IPtUMKL4O3tH5y+iXVyAXqpAwMuzC1IrxVS81rummfE=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 h1:IeMeyr1aBvBiPVYihXIaeIZba6b8E1bYp7lbdxK8CQg= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 h1:IeMeyr1aBvBiPVYihXIaeIZba6b8E1bYp7lbdxK8CQg=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0/go.mod h1:oVdCUtjq9MK9BlS7TtucsQwUcXcymNiEDjgDD2jMtZU= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0/go.mod h1:oVdCUtjq9MK9BlS7TtucsQwUcXcymNiEDjgDD2jMtZU=
go.opentelemetry.io/otel/log v0.7.0 h1:d1abJc0b1QQZADKvfe9JqqrfmPYQCz2tUSO+0XZmuV4= go.opentelemetry.io/otel/log v0.10.0 h1:1CXmspaRITvFcjA4kyVszuG4HjA61fPDxMb7q3BuyF0=
go.opentelemetry.io/otel/log v0.7.0/go.mod h1:2jf2z7uVfnzDNknKTO9G+ahcOAyWcp1fJmk/wJjULRo= go.opentelemetry.io/otel/log v0.10.0/go.mod h1:PbVdm9bXKku/gL0oFfUF4wwsQsOPlpo4VEqjvxih+FM=
go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE= go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ=
go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY= go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE=
go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE= go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE=
go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg= go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg=
go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys= go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k=
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I= go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I=
go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM= go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
@ -170,8 +176,8 @@ golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@ -180,14 +186,14 @@ golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44= golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44=
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@ -212,8 +218,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8= gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314=
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=

View File

@ -5,9 +5,9 @@ import (
"embed" "embed"
"fmt" "fmt"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/internal/utils" "git.anthrove.art/Anthrove/otter-space-sdk/v6/internal/utils"
otterError "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/error" otterError "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/error"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
migrate "github.com/rubenv/sql-migrate" migrate "github.com/rubenv/sql-migrate"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
@ -17,7 +17,7 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
const tracingName = "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/database" const tracingName = "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/database"
var ( var (
//go:embed migrations/*.sql //go:embed migrations/*.sql

View File

@ -4,8 +4,8 @@ import (
"context" "context"
"testing" "testing"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/test" "git.anthrove.art/Anthrove/otter-space-sdk/v6/test"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"gorm.io/gorm" "gorm.io/gorm"

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"errors" "errors"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/internal/utils" "git.anthrove.art/Anthrove/otter-space-sdk/v6/internal/utils"
otterError "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/error" otterError "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/error"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"gorm.io/gorm" "gorm.io/gorm"
@ -158,7 +158,7 @@ func GetUserFavoritesByID(ctx context.Context, id models.UserFavoriteID) (models
return userFavorites, nil return userFavorites, nil
} }
func DeleteUserFavorite(ctx context.Context, id models.UserFavoriteID) error { func DeleteUserFavorite(ctx context.Context, id models.UserFavoriteID, hardDelete bool) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteUserFavorite") ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteUserFavorite")
defer span.End() defer span.End()
@ -186,7 +186,15 @@ func DeleteUserFavorite(ctx context.Context, id models.UserFavoriteID) error {
return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.UserFavoriteIsWrongLength}) return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.UserFavoriteIsWrongLength})
} }
result := client.WithContext(ctx).Delete(&userFavorite, id) db := client
if hardDelete {
db = client.Unscoped()
} else {
db = client
}
result := db.WithContext(ctx).Delete(&userFavorite, id)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound})

View File

@ -7,8 +7,8 @@ import (
"testing" "testing"
"time" "time"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/test" "git.anthrove.art/Anthrove/otter-space-sdk/v6/test"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"gorm.io/gorm" "gorm.io/gorm"
@ -415,7 +415,7 @@ func TestUpdateUserFavorite(t *testing.T) {
// -- // --
// -- Delete UserFavorite // -- Delete UserFavorite
err = DeleteUserFavorite(ctx, validFavorite.ID) err = DeleteUserFavorite(ctx, validFavorite.ID, false)
if err != nil { if err != nil {
t.Fatalf("CreateUserFavorite err: %v", err) t.Fatalf("CreateUserFavorite err: %v", err)
} }
@ -745,7 +745,7 @@ func TestDeleteUserFavorite(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if err := DeleteUserFavorite(tt.args.ctx, tt.args.id); (err != nil) != tt.wantErr { if err := DeleteUserFavorite(tt.args.ctx, tt.args.id, false); (err != nil) != tt.wantErr {
t.Errorf("DeleteUserFavorite() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("DeleteUserFavorite() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })

View File

@ -14,9 +14,39 @@ CREATE TYPE TagType AS ENUM (
'lore', 'lore',
'meta', 'meta',
'invalid', 'invalid',
'copyright' 'copyright',
'Contributor',
'Unknown'
); );
CREATE TYPE ReportType AS ENUM (
'duplicate',
'missing_data',
'rating_abuse',
'illegal_content'
);
CREATE TYPE ReportState AS ENUM (
'pending_unclaimed',
'pending',
'approved',
'partial',
'rejected'
);
CREATE TYPE pool_category AS ENUM (
'series',
'collection'
);
CREATE TABLE "User"
(
id TEXT PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP WITH TIME ZONE NULL
);
CREATE TABLE "Post" CREATE TABLE "Post"
( (
id CHAR(25) PRIMARY KEY, id CHAR(25) PRIMARY KEY,
@ -29,35 +59,20 @@ CREATE TABLE "Post"
CREATE TABLE "Source" CREATE TABLE "Source"
( (
id CHAR(25) PRIMARY KEY, id CHAR(25) PRIMARY KEY,
display_name TEXT NULL, display_name TEXT NULL,
icon TEXT NULL, icon TEXT NULL,
domain TEXT NOT NULL UNIQUE, domain TEXT NOT NULL UNIQUE,
enabled BOOL DEFAULT FALSE,
meta JSON DEFAULT '{}',
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP WITH TIME ZONE NULL deleted_at TIMESTAMP WITH TIME ZONE NULL
); );
CREATE TABLE "Tag"
(
name TEXT PRIMARY KEY,
tag_type TagType,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP WITH TIME ZONE NULL
);
CREATE TABLE "User"
(
id TEXT PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP WITH TIME ZONE NULL
);
CREATE TABLE "PostReference" CREATE TABLE "PostReference"
( (
post_id TEXT REFERENCES "Post" (id), post_id CHAR(25) REFERENCES "Post" (id),
source_id TEXT REFERENCES "Source" (id), source_id CHAR(25) REFERENCES "Source" (id),
url TEXT NOT NULL, url TEXT NOT NULL,
full_file_url TEXT, full_file_url TEXT,
preview_file_url TEXT, preview_file_url TEXT,
@ -66,33 +81,45 @@ CREATE TABLE "PostReference"
PRIMARY KEY (post_id, source_id, url) PRIMARY KEY (post_id, source_id, url)
); );
CREATE TABLE "Tag"
(
id SERIAL PRIMARY KEY,
name TEXT UNIQUE,
tag_type TagType,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP WITH TIME ZONE NULL
);
CREATE TABLE "TagAlias" CREATE TABLE "TagAlias"
( (
name TEXT PRIMARY KEY, id SERIAL PRIMARY KEY,
tag_id TEXT REFERENCES "Tag" (name), name TEXT UNIQUE,
tag_id INT REFERENCES "Tag" (id),
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
); );
CREATE TABLE "TagGroup" CREATE TABLE "TagGroup"
( (
name TEXT PRIMARY KEY, id SERIAL PRIMARY KEY,
tag_id TEXT REFERENCES "Tag" (name), name TEXT UNIQUE,
tag_id INT REFERENCES "Tag" (id),
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
); );
CREATE TABLE "UserSource" CREATE TABLE "UserSource"
( (
id CHAR(25) PRIMARY KEY, id CHAR(25) PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP WITH TIME ZONE NULL NULL, deleted_at TIMESTAMP WITH TIME ZONE NULL NULL,
user_id TEXT REFERENCES "User" (id), user_id CHAR(25) REFERENCES "User" (id) ON DELETE CASCADE,
source_id TEXT REFERENCES "Source" (id), source_id TEXT REFERENCES "Source" (id),
scrape_time_interval TEXT, scrape_time_interval TEXT,
account_username TEXT, account_username TEXT,
account_id TEXT, account_id TEXT,
last_scrape_time TIMESTAMP WITH TIME ZONE, last_scrape_time TIMESTAMP WITH TIME ZONE,
account_validate BOOL DEFAULT FALSE, account_validate BOOL DEFAULT FALSE,
account_validation_key CHAR(25), account_validation_key CHAR(25),
UNIQUE (source_id, account_username, account_id) UNIQUE (source_id, account_username, account_id)
); );
@ -103,14 +130,69 @@ CREATE TABLE "UserFavorites"
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP WITH TIME ZONE NULL NULL, deleted_at TIMESTAMP WITH TIME ZONE NULL NULL,
user_id TEXT REFERENCES "User" (id), user_id TEXT REFERENCES "User" (id) ON DELETE CASCADE,
post_id TEXT REFERENCES "Post" (id), post_id CHAR(25) REFERENCES "Post" (id),
user_source_id CHAR(25) REFERENCES "UserSource" (id) user_source_id CHAR(25) REFERENCES "UserSource" (id) ON DELETE CASCADE
); );
CREATE INDEX idx_user_post_deleted ON "UserFavorites"(user_id, deleted_at);
CREATE INDEX idx_created_at ON "UserFavorites"(created_at);
CREATE TABLE "post_tags" CREATE TABLE "post_tags"
( (
post_id TEXT REFERENCES "Post" (id), post_id CHAR(25) REFERENCES "Post" (id),
tag_name TEXT REFERENCES "Tag" (name), tag_id INT REFERENCES "Tag" (id),
PRIMARY KEY (post_id, tag_name) PRIMARY KEY (post_id, tag_id)
); );
CREATE TABLE "Pool"
(
id CHAR(25) PRIMARY KEY,
name TEXT,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL,
category POOL_CATEGORY NOT NULL
);
CREATE TABLE "PoolPost"
(
pool_id CHAR(25) REFERENCES "Pool" (id) ON DELETE CASCADE,
post_id CHAR(25) REFERENCES "Post" (id),
order_position INT NOT NULL DEFAULT 0,
PRIMARY KEY (pool_id, post_id)
);
CREATE TABLE "PoolReference"
(
pool_id CHAR(25) REFERENCES "Pool" (id) ON DELETE CASCADE,
source_id CHAR(25) REFERENCES "Source" (id),
url TEXT NOT NULL,
PRIMARY KEY (pool_id, source_id, url)
);
CREATE TABLE "ScrapeHistory"
(
id CHAR(25) PRIMARY KEY,
user_source_id CHAR(25) NOT NULL REFERENCES "UserSource" (id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
finished_at TIMESTAMP NULL,
error TEXT NULL,
added_posts INT NOT NULL,
deleted_posts INT NOT NULL
);
CREATE TABLE "PostReport"
(
id CHAR(25) NOT NULL PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP WITH TIME ZONE NULL,
post_id CHAR(25) NOT NULL REFERENCES "Post" (id),
report_by TEXT NOT NULL REFERENCES "User" (id),
report_description TEXT NOT NULL,
audit_by TEXT NULL REFERENCES "User" (id),
audit_description TEXT NOT NULL,
report_type ReportType NOT NULL,
report_state ReportState NOT NULL
);

View File

@ -1,3 +0,0 @@
-- +migrate Up
CREATE INDEX idx_user_post_deleted ON "UserFavorites"(user_id, deleted_at);
CREATE INDEX idx_created_at ON "UserFavorites"(created_at);

View File

@ -0,0 +1,4 @@
-- +migrate Up
ALTER TABLE "UserSource"
ALTER COLUMN user_id TYPE TEXT;

View File

@ -1,28 +0,0 @@
-- +migrate Up
CREATE TYPE pool_category AS ENUM ('series', 'collection');
CREATE TABLE "Pool"
(
id CHAR(25) PRIMARY KEY,
name VARCHAR(75),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL,
category POOL_CATEGORY NOT NULL
);
CREATE TABLE "PoolPost"
(
pool_id CHAR(25) REFERENCES "Pool" (id),
post_id CHAR(25) REFERENCES "Post" (id),
order_position INT NOT NULL DEFAULT 0,
PRIMARY KEY (pool_id, post_id)
);
CREATE TABLE "PoolReference"
(
pool_id CHAR(25) REFERENCES "Pool" (id),
source_id CHAR(25) REFERENCES "Source" (id),
url TEXT NOT NULL,
PRIMARY KEY (pool_id, source_id, url)
);

View File

@ -1,11 +0,0 @@
-- +migrate Up
CREATE TABLE "ScrapeHistory"
(
scrape_task_id CHAR(25) PRIMARY KEY,
user_source_id CHAR(25) NOT NULL REFERENCES "UserSource" (id),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
finished_at TIMESTAMP NULL,
error TEXT NULL,
added_posts INT NOT NULL,
deleted_posts INT NOT NULL
);

View File

@ -1,13 +0,0 @@
-- +migrate Up
ALTER TABLE "PostReference"
ALTER COLUMN post_id TYPE CHAR(25),
ALTER COLUMN source_id TYPE CHAR(25);
ALTER TABLE post_tags
ALTER COLUMN post_id TYPE CHAR(25);
ALTER TABLE "UserFavorites"
ALTER COLUMN post_id TYPE CHAR(25);
ALTER TABLE "UserSource"
ALTER COLUMN source_id TYPE CHAR(25);

View File

@ -1,30 +0,0 @@
-- +migrate Up
CREATE TYPE ReportType AS ENUM (
'duplicate',
'missing_data',
'rating_abuse',
'illegal_content'
);
CREATE TYPE ReportState AS ENUM (
'pending_unclaimed',
'pending',
'approved',
'partial',
'rejected'
);
CREATE TABLE "PostReport"
(
id CHAR(25) NOT NULL PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP WITH TIME ZONE NULL,
post_id CHAR(25) NOT NULL REFERENCES "Post" (id),
report_by TEXT NOT NULL REFERENCES "User" (id),
report_description TEXT NOT NULL,
audit_by TEXT NULL REFERENCES "User" (id),
audit_description TEXT NOT NULL,
report_type ReportType NOT NULL,
report_state ReportState NOT NULL
);

View File

@ -1,4 +0,0 @@
-- +migrate Up
ALTER TYPE TagType ADD VALUE 'Contributor';
ALTER TYPE TagType ADD VALUE 'Unknown';

View File

@ -1,5 +0,0 @@
-- +migrate Up
ALTER TABLE "Pool"
ALTER
COLUMN name TYPE TEXT;

View File

@ -1,5 +0,0 @@
-- +migrate Up
ALTER TABLE "Source"
ADD COLUMN enabled BOOL DEFAULT FALSE,
ADD COLUMN meta JSON DEFAULT '{}';

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"errors" "errors"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/internal/utils" "git.anthrove.art/Anthrove/otter-space-sdk/v6/internal/utils"
otterError "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/error" otterError "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/error"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"gorm.io/gorm" "gorm.io/gorm"
@ -122,7 +122,7 @@ func UpdatePool(ctx context.Context, pool models.Pool) error {
return nil return nil
} }
func DeletePool(ctx context.Context, id models.PoolID) error { func DeletePool(ctx context.Context, id models.PoolID, hardDelete bool) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeletePool") ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeletePool")
defer span.End() defer span.End()
@ -150,7 +150,15 @@ func DeletePool(ctx context.Context, id models.PoolID) error {
return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.PoolIDIsWrongLength}) return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.PoolIDIsWrongLength})
} }
result := client.WithContext(ctx).Delete(&pool, "id = ?", id) db := client
if hardDelete {
db = client.Unscoped()
} else {
db = client
}
result := db.WithContext(ctx).Delete(&pool, "id = ?", id)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound})

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"errors" "errors"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/internal/utils" "git.anthrove.art/Anthrove/otter-space-sdk/v6/internal/utils"
otterError "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/error" otterError "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/error"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"gorm.io/gorm" "gorm.io/gorm"

View File

@ -6,8 +6,8 @@ import (
"reflect" "reflect"
"testing" "testing"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/test" "git.anthrove.art/Anthrove/otter-space-sdk/v6/test"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
) )

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"errors" "errors"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/internal/utils" "git.anthrove.art/Anthrove/otter-space-sdk/v6/internal/utils"
otterError "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/error" otterError "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/error"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"gorm.io/gorm" "gorm.io/gorm"

View File

@ -6,8 +6,8 @@ import (
"reflect" "reflect"
"testing" "testing"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/test" "git.anthrove.art/Anthrove/otter-space-sdk/v6/test"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
) )

View File

@ -7,8 +7,8 @@ import (
"testing" "testing"
"time" "time"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/test" "git.anthrove.art/Anthrove/otter-space-sdk/v6/test"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"gorm.io/gorm" "gorm.io/gorm"
@ -353,7 +353,7 @@ func TestDeletePool(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if err := DeletePool(tt.args.ctx, tt.args.id); (err != nil) != tt.wantErr { if err := DeletePool(tt.args.ctx, tt.args.id, false); (err != nil) != tt.wantErr {
t.Errorf("DeletePool() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("DeletePool() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"errors" "errors"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/internal/utils" "git.anthrove.art/Anthrove/otter-space-sdk/v6/internal/utils"
otterError "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/error" otterError "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/error"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"gorm.io/gorm" "gorm.io/gorm"
@ -166,7 +166,7 @@ func UpdatePost(ctx context.Context, anthrovePost models.Post) error {
return nil return nil
} }
func DeletePost(ctx context.Context, id models.PostID) error { func DeletePost(ctx context.Context, id models.PostID, hardDelete bool) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeletePost") ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeletePost")
defer span.End() defer span.End()
@ -194,7 +194,15 @@ func DeletePost(ctx context.Context, id models.PostID) error {
return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.PostIDIsWrongLength}) return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.PostIDIsWrongLength})
} }
result := client.WithContext(ctx).Delete(&userFavorite, "id = ?", id) db := client
if hardDelete {
db = client.Unscoped()
} else {
db = client
}
result := db.WithContext(ctx).Delete(&userFavorite, "id = ?", id)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound})

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"errors" "errors"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/internal/utils" "git.anthrove.art/Anthrove/otter-space-sdk/v6/internal/utils"
otterError "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/error" otterError "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/error"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"gorm.io/gorm" "gorm.io/gorm"
@ -132,7 +132,7 @@ func UpdatePostReport(ctx context.Context, postReport models.PostReport) error {
return nil return nil
} }
func DeletePostReport(ctx context.Context, id models.PostReportID) error { func DeletePostReport(ctx context.Context, id models.PostReportID, hardDelete bool) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeletePostReport") ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeletePostReport")
defer span.End() defer span.End()
@ -160,7 +160,15 @@ func DeletePostReport(ctx context.Context, id models.PostReportID) error {
return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.PostReportIDIsWrongLength}) return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.PostReportIDIsWrongLength})
} }
result := client.WithContext(ctx).Delete(&postReport, "id = ?", id) db := client
if hardDelete {
db = client.Unscoped()
} else {
db = client
}
result := db.WithContext(ctx).Delete(&postReport, "id = ?", id)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound})

View File

@ -7,8 +7,8 @@ import (
"testing" "testing"
"time" "time"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/test" "git.anthrove.art/Anthrove/otter-space-sdk/v6/test"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"gorm.io/gorm" "gorm.io/gorm"
@ -491,7 +491,7 @@ func TestDeletePostReport(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if err := DeletePostReport(tt.args.ctx, tt.args.id); (err != nil) != tt.wantErr { if err := DeletePostReport(tt.args.ctx, tt.args.id, false); (err != nil) != tt.wantErr {
t.Errorf("DeletePostReport() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("DeletePostReport() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })

View File

@ -7,8 +7,8 @@ import (
"testing" "testing"
"time" "time"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/test" "git.anthrove.art/Anthrove/otter-space-sdk/v6/test"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"gorm.io/gorm" "gorm.io/gorm"
@ -438,7 +438,7 @@ func TestDeletePost(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if err := DeletePost(tt.args.ctx, tt.args.id); (err != nil) != tt.wantErr { if err := DeletePost(tt.args.ctx, tt.args.id, false); (err != nil) != tt.wantErr {
t.Errorf("DeletePost() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("DeletePost() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })

View File

@ -3,7 +3,7 @@ package database
import ( import (
"math" "math"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"gorm.io/gorm" "gorm.io/gorm"
) )

View File

@ -5,8 +5,8 @@ import (
"reflect" "reflect"
"testing" "testing"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/test" "git.anthrove.art/Anthrove/otter-space-sdk/v6/test"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"gorm.io/gorm" "gorm.io/gorm"
@ -34,7 +34,7 @@ func TestPaginate(t *testing.T) {
// -- Create Tags to test with // -- Create Tags to test with
validTags := test.GenerateRandomTags(500) validTags := test.GenerateRandomTags(500)
err = CreateTagInBatch(ctx, validTags, len(validTags)) _, err = CreateTagInBatch(ctx, validTags, len(validTags))
if err != nil { if err != nil {
logger.Fatalf("Could not create tags: %v", err) logger.Fatalf("Could not create tags: %v", err)
} }
@ -149,7 +149,7 @@ func TestAdvancedPagination(t *testing.T) {
Type: models.General, Type: models.General,
}, },
} }
err = CreateTagInBatch(ctx, validTags, len(validTags)) _, err = CreateTagInBatch(ctx, validTags, len(validTags))
if err != nil { if err != nil {
logger.Fatalf("Could not create tags: %v", err) logger.Fatalf("Could not create tags: %v", err)
} }
@ -275,7 +275,7 @@ func TestOrderBy(t *testing.T) {
Type: models.General, Type: models.General,
}, },
} }
err = CreateTagInBatch(ctx, validTags, len(validTags)) _, err = CreateTagInBatch(ctx, validTags, len(validTags))
if err != nil { if err != nil {
logger.Fatalf("Could not create tags: %v", err) logger.Fatalf("Could not create tags: %v", err)
} }

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"errors" "errors"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/internal/utils" "git.anthrove.art/Anthrove/otter-space-sdk/v6/internal/utils"
otterError "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/error" otterError "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/error"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"gorm.io/gorm" "gorm.io/gorm"
@ -17,12 +17,12 @@ func CreateScrapeHistory(ctx context.Context, scrapeHistory models.ScrapeHistory
defer span.End() defer span.End()
localLogger = localLogger.WithFields(log.Fields{ localLogger = localLogger.WithFields(log.Fields{
"scrape_task_id": scrapeHistory.ScrapeTaskID, "id": scrapeHistory.ID,
"user_source_id": scrapeHistory.UserSourceID, "user_source_id": scrapeHistory.UserSourceID,
}) })
span.SetAttributes( span.SetAttributes(
attribute.String("scrape_task_id", string(scrapeHistory.ScrapeTaskID)), attribute.String("id", string(scrapeHistory.ID)),
attribute.String("user_source_id", string(scrapeHistory.UserSourceID)), attribute.String("user_source_id", string(scrapeHistory.UserSourceID)),
) )
@ -32,11 +32,11 @@ func CreateScrapeHistory(ctx context.Context, scrapeHistory models.ScrapeHistory
return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}) return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
} }
if len(scrapeHistory.ScrapeTaskID) == 0 { if len(scrapeHistory.ID) == 0 {
return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsEmpty}) return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsEmpty})
} }
if len(scrapeHistory.ScrapeTaskID) != 25 { if len(scrapeHistory.ID) != 25 {
return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsWrongLength}) return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsWrongLength})
} }
@ -65,11 +65,11 @@ func GetScrapeHistoryByID(ctx context.Context, id models.ScrapeTaskID) (models.S
defer span.End() defer span.End()
localLogger = localLogger.WithFields(log.Fields{ localLogger = localLogger.WithFields(log.Fields{
"scrape_task_id": id, "id": id,
}) })
span.SetAttributes( span.SetAttributes(
attribute.String("scrape_task_id", string(id)), attribute.String("id", string(id)),
) )
utils.HandleEvent(span, localLogger, "Starting get scrapeHistory by ID") utils.HandleEvent(span, localLogger, "Starting get scrapeHistory by ID")
@ -84,7 +84,7 @@ func GetScrapeHistoryByID(ctx context.Context, id models.ScrapeTaskID) (models.S
return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsWrongLength}) return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsWrongLength})
} }
result := client.WithContext(ctx).First(&post, "scrape_task_id = ?", id) result := client.WithContext(ctx).First(&post, "id = ?", id)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound}) return models.ScrapeHistory{}, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound})
@ -107,25 +107,25 @@ func UpdateScrapeHistory(ctx context.Context, scrapeHistory models.ScrapeHistory
defer span.End() defer span.End()
localLogger = localLogger.WithFields(log.Fields{ localLogger = localLogger.WithFields(log.Fields{
"scrape_task_id": scrapeHistory.ScrapeTaskID, "id": scrapeHistory.ID,
}) })
span.SetAttributes( span.SetAttributes(
attribute.String("scrape_task_id", string(scrapeHistory.ScrapeTaskID)), attribute.String("id", string(scrapeHistory.ID)),
) )
utils.HandleEvent(span, localLogger, "Starting scrapeHistory update") utils.HandleEvent(span, localLogger, "Starting scrapeHistory update")
if len(scrapeHistory.ScrapeTaskID) == 0 { if len(scrapeHistory.ID) == 0 {
return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsEmpty}) return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsEmpty})
} }
if len(scrapeHistory.ScrapeTaskID) != 25 { if len(scrapeHistory.ID) != 25 {
return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsWrongLength}) return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsWrongLength})
} }
updateScrapeHistory := models.ScrapeHistory{ updateScrapeHistory := models.ScrapeHistory{
ScrapeTaskID: scrapeHistory.ScrapeTaskID, ID: scrapeHistory.ID,
UserSourceID: scrapeHistory.UserSourceID, UserSourceID: scrapeHistory.UserSourceID,
FinishedAt: scrapeHistory.FinishedAt, FinishedAt: scrapeHistory.FinishedAt,
Error: scrapeHistory.Error, Error: scrapeHistory.Error,
@ -150,11 +150,11 @@ func DeleteScrapeHistory(ctx context.Context, id models.ScrapeTaskID) error {
defer span.End() defer span.End()
localLogger = localLogger.WithFields(log.Fields{ localLogger = localLogger.WithFields(log.Fields{
"scrape_task_id": id, "id": id,
}) })
span.SetAttributes( span.SetAttributes(
attribute.String("scrape_task_id", string(id)), attribute.String("id", string(id)),
) )
utils.HandleEvent(span, localLogger, "Starting delete scrapeHistory") utils.HandleEvent(span, localLogger, "Starting delete scrapeHistory")
@ -169,7 +169,7 @@ func DeleteScrapeHistory(ctx context.Context, id models.ScrapeTaskID) error {
return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsWrongLength}) return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.ScrapeTaskIDIsWrongLength})
} }
result := client.WithContext(ctx).Delete(&scrapeHistory, "scrape_task_id = ?", id) result := client.WithContext(ctx).Delete(&scrapeHistory, "id = ?", id)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound})

View File

@ -6,8 +6,8 @@ import (
"testing" "testing"
"time" "time"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/test" "git.anthrove.art/Anthrove/otter-space-sdk/v6/test"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"gorm.io/gorm" "gorm.io/gorm"
@ -81,7 +81,7 @@ func TestCreateScrapeHistory(t *testing.T) {
} }
validScrapeHistory := models.ScrapeHistory{ validScrapeHistory := models.ScrapeHistory{
ScrapeTaskID: "000000000000valid_task_id", ID: "000000000000valid_task_id",
UserSourceID: validUSerSource.ID, UserSourceID: validUSerSource.ID,
} }
@ -181,7 +181,7 @@ func TestGetScrapeHistoryByID(t *testing.T) {
} }
validScrapeHistory := models.ScrapeHistory{ validScrapeHistory := models.ScrapeHistory{
ScrapeTaskID: "000000000000valid_task_id", ID: "000000000000valid_task_id",
UserSourceID: validUSerSource.ID, UserSourceID: validUSerSource.ID,
} }
@ -279,7 +279,7 @@ func TestUpdateScrapeHistory(t *testing.T) {
} }
validScrapeHistory := models.ScrapeHistory{ validScrapeHistory := models.ScrapeHistory{
ScrapeTaskID: "000000000000valid_task_id", ID: "000000000000valid_task_id",
UserSourceID: validUSerSource.ID, UserSourceID: validUSerSource.ID,
} }
@ -299,7 +299,7 @@ func TestUpdateScrapeHistory(t *testing.T) {
wantErr bool wantErr bool
}{ }{
{"Valid Update", updatedScrapeHistory, false}, {"Valid Update", updatedScrapeHistory, false},
{"Empty ID", models.ScrapeHistory{ScrapeTaskID: ""}, true}, {"Empty ID", models.ScrapeHistory{ID: ""}, true},
} }
for _, tt := range tests { for _, tt := range tests {
@ -380,7 +380,7 @@ func TestDeleteScrapeHistory(t *testing.T) {
} }
validScrapeHistory := models.ScrapeHistory{ validScrapeHistory := models.ScrapeHistory{
ScrapeTaskID: "000000000000valid_task_id", ID: "000000000000valid_task_id",
UserSourceID: validUSerSource.ID, UserSourceID: validUSerSource.ID,
} }

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"errors" "errors"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/internal/utils" "git.anthrove.art/Anthrove/otter-space-sdk/v6/internal/utils"
otterError "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/error" otterError "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/error"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"gorm.io/gorm" "gorm.io/gorm"
@ -206,7 +206,7 @@ func GetSourceByDomain(ctx context.Context, sourceDomain models.SourceDomain) (m
return source, nil return source, nil
} }
func DeleteSource(ctx context.Context, id models.SourceID) error { func DeleteSource(ctx context.Context, id models.SourceID, hardDelete bool) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteSource") ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteSource")
defer span.End() defer span.End()
@ -234,7 +234,15 @@ func DeleteSource(ctx context.Context, id models.SourceID) error {
return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.SourceIDIsWrongLength}) return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.SourceIDIsWrongLength})
} }
result := client.WithContext(ctx).Delete(&source, id) db := client
if hardDelete {
db = client.Unscoped()
} else {
db = client
}
result := db.WithContext(ctx).Delete(&source, id)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound})

View File

@ -7,8 +7,8 @@ import (
"testing" "testing"
"time" "time"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/test" "git.anthrove.art/Anthrove/otter-space-sdk/v6/test"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"gorm.io/gorm" "gorm.io/gorm"
@ -530,7 +530,7 @@ func TestDeleteSource(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if err := DeleteSource(tt.args.ctx, tt.args.id); (err != nil) != tt.wantErr { if err := DeleteSource(tt.args.ctx, tt.args.id, false); (err != nil) != tt.wantErr {
t.Errorf("DeleteSource() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("DeleteSource() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"errors" "errors"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/internal/utils" "git.anthrove.art/Anthrove/otter-space-sdk/v6/internal/utils"
otterError "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/error" otterError "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/error"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"gorm.io/gorm" "gorm.io/gorm"
@ -57,7 +57,7 @@ func CreateTag(ctx context.Context, tagName models.TagName, tagType models.TagTy
return tag, nil return tag, nil
} }
func CreateTagInBatch(ctx context.Context, tags []models.Tag, batchSize int) error { func CreateTagInBatch(ctx context.Context, tags []models.Tag, batchSize int) ([]models.Tag, error) {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagInBatch") ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagInBatch")
defer span.End() defer span.End()
@ -74,39 +74,39 @@ func CreateTagInBatch(ctx context.Context, tags []models.Tag, batchSize int) err
utils.HandleEvent(span, localLogger, "Starting batch tag creation") utils.HandleEvent(span, localLogger, "Starting batch tag creation")
if client == nil { if client == nil {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}) return nil, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
} }
if tags == nil || len(tags) == 0 { if tags == nil || len(tags) == 0 {
return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.TagListIsEmpty}) return nil, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.TagListIsEmpty})
} }
if batchSize == 0 { if batchSize == 0 {
return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.BatchSizeIsEmpty}) return nil, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.BatchSizeIsEmpty})
} }
result := client.WithContext(ctx).CreateInBatches(&tags, batchSize) result := client.WithContext(ctx).CreateInBatches(&tags, batchSize)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) { if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DuplicateKey}) return nil, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DuplicateKey})
} }
return utils.HandleError(ctx, span, localLogger, result.Error) return nil, utils.HandleError(ctx, span, localLogger, result.Error)
} }
utils.HandleEvent(span, localLogger, "Batch tags created successfully") utils.HandleEvent(span, localLogger, "Batch tags created successfully")
return nil return tags, nil
} }
func DeleteTag(ctx context.Context, tagName models.TagName) error { func DeleteTag(ctx context.Context, tagID models.TagID, hardDelete bool) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteTag") ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteTag")
defer span.End() defer span.End()
localLogger = localLogger.WithFields(log.Fields{ localLogger = localLogger.WithFields(log.Fields{
"tag_name": tagName, "tag_id": tagID,
}) })
span.SetAttributes( span.SetAttributes(
attribute.String("tag_name", string(tagName)), attribute.Int64("tag_id", int64(tagID)),
) )
utils.HandleEvent(span, localLogger, "Starting tag deletion") utils.HandleEvent(span, localLogger, "Starting tag deletion")
@ -117,11 +117,15 @@ func DeleteTag(ctx context.Context, tagName models.TagName) error {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
} }
if len(tagName) == 0 { db := client
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.TagAliasNameIsEmpty})
if hardDelete {
db = client.Unscoped()
} else {
db = client
} }
result := client.WithContext(ctx).Delete(&tag, tagName) result := db.WithContext(ctx).Delete(&tag, tagID)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound})

View File

@ -4,26 +4,26 @@ import (
"context" "context"
"errors" "errors"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/internal/utils" "git.anthrove.art/Anthrove/otter-space-sdk/v6/internal/utils"
otterError "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/error" otterError "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/error"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"gorm.io/gorm" "gorm.io/gorm"
) )
func CreateTagAlias(ctx context.Context, tagAliasName models.TagAliasName, tagName models.TagName) (models.TagAlias, error) { func CreateTagAlias(ctx context.Context, tagAliasName models.TagAliasName, tagID models.TagID) (models.TagAlias, error) {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagAlias") ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagAlias")
defer span.End() defer span.End()
localLogger = localLogger.WithFields(log.Fields{ localLogger = localLogger.WithFields(log.Fields{
"tag_alias_name": tagAliasName, "tag_alias_name": tagAliasName,
"tag_name": tagName, "tag_id": tagID,
}) })
span.SetAttributes( span.SetAttributes(
attribute.String("tag_alias_name", string(tagAliasName)), attribute.String("tag_alias_name", string(tagAliasName)),
attribute.String("tag_name", string(tagName)), attribute.Int64("tag_id", int64(tagID)),
) )
utils.HandleEvent(span, localLogger, "Starting tag alias creation") utils.HandleEvent(span, localLogger, "Starting tag alias creation")
@ -36,13 +36,9 @@ func CreateTagAlias(ctx context.Context, tagAliasName models.TagAliasName, tagNa
return models.TagAlias{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.TagAliasNameIsEmpty}) return models.TagAlias{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.TagAliasNameIsEmpty})
} }
if tagName == "" {
return models.TagAlias{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.TagNameIsEmpty})
}
tagAlias := models.TagAlias{ tagAlias := models.TagAlias{
Name: tagAliasName, Name: tagAliasName,
TagID: tagName, TagID: tagID,
} }
result := client.WithContext(ctx).Create(&tagAlias) result := client.WithContext(ctx).Create(&tagAlias)
@ -97,16 +93,16 @@ func CreateTagAliasInBatch(ctx context.Context, tagsAliases []models.TagAlias, b
return nil return nil
} }
func DeleteTagAlias(ctx context.Context, tagAliasName models.TagAliasName) error { func DeleteTagAlias(ctx context.Context, tagAliasID models.TagAliasID) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteTagAlias") ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteTagAlias")
defer span.End() defer span.End()
localLogger = localLogger.WithFields(log.Fields{ localLogger = localLogger.WithFields(log.Fields{
"tag_alias_name": tagAliasName, "tag_alias_id": tagAliasID,
}) })
span.SetAttributes( span.SetAttributes(
attribute.String("tag_alias_name", string(tagAliasName)), attribute.Int64("tag_alias_id", int64(tagAliasID)),
) )
utils.HandleEvent(span, localLogger, "Starting tag alias deletion") utils.HandleEvent(span, localLogger, "Starting tag alias deletion")
@ -117,11 +113,7 @@ func DeleteTagAlias(ctx context.Context, tagAliasName models.TagAliasName) error
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
} }
if len(tagAliasName) == 0 { result := client.WithContext(ctx).Delete(&tagAlias, tagAliasID)
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.TagAliasNameIsEmpty})
}
result := client.WithContext(ctx).Delete(&tagAlias, tagAliasName)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound})

View File

@ -5,8 +5,8 @@ import (
"reflect" "reflect"
"testing" "testing"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/test" "git.anthrove.art/Anthrove/otter-space-sdk/v6/test"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
) )
@ -44,8 +44,9 @@ func TestCreateTagAlias(t *testing.T) {
// -- Create TagAlias to test with // -- Create TagAlias to test with
validTagAlias := models.TagAlias{ validTagAlias := models.TagAlias{
ID: 1,
Name: "valid_tag_alias_name", Name: "valid_tag_alias_name",
TagID: validTag.Name, TagID: validTag.ID,
} }
// -- // --
@ -53,7 +54,7 @@ func TestCreateTagAlias(t *testing.T) {
type args struct { type args struct {
ctx context.Context ctx context.Context
tagAliasName models.TagAliasName tagAliasName models.TagAliasName
tagName models.TagName tagID models.TagID
} }
tests := []struct { tests := []struct {
name string name string
@ -66,7 +67,7 @@ func TestCreateTagAlias(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
tagAliasName: validTagAlias.Name, tagAliasName: validTagAlias.Name,
tagName: validTag.Name, tagID: validTag.ID,
}, },
want: validTagAlias, want: validTagAlias,
wantErr: false, wantErr: false,
@ -76,7 +77,7 @@ func TestCreateTagAlias(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
tagAliasName: validTagAlias.Name, tagAliasName: validTagAlias.Name,
tagName: validTag.Name, tagID: validTag.ID,
}, },
want: models.TagAlias{}, want: models.TagAlias{},
wantErr: true, wantErr: true,
@ -86,17 +87,7 @@ func TestCreateTagAlias(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
tagAliasName: "", tagAliasName: "",
tagName: validTag.Name, tagID: validTag.ID,
},
want: models.TagAlias{},
wantErr: true,
},
{
name: "Test 04: tagName name is empty",
args: args{
ctx: ctx,
tagAliasName: validTagAlias.Name,
tagName: "",
}, },
want: models.TagAlias{}, want: models.TagAlias{},
wantErr: true, wantErr: true,
@ -104,7 +95,7 @@ func TestCreateTagAlias(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got, err := CreateTagAlias(tt.args.ctx, tt.args.tagAliasName, tt.args.tagName) got, err := CreateTagAlias(tt.args.ctx, tt.args.tagAliasName, tt.args.tagID)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("CreateTagAlias() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("CreateTagAlias() error = %v, wantErr %v", err, tt.wantErr)
return return
@ -138,14 +129,14 @@ func TestCreateTagAliasInBatch(t *testing.T) {
// -- Create Tags to test with // -- Create Tags to test with
validTags := test.GenerateRandomTags(5) validTags := test.GenerateRandomTags(5)
err = CreateTagInBatch(ctx, validTags, len(validTags)) tags, err := CreateTagInBatch(ctx, validTags, len(validTags))
if err != nil { if err != nil {
t.Fatalf("CreateTags err: %v", err) t.Fatalf("CreateTags err: %v", err)
} }
// -- // --
// -- Create TagAlias to test with // -- Create TagAlias to test with
validTagGroup := test.GenerateRandomTagAlias(validTags, 5) validTagGroup := test.GenerateRandomTagAlias(tags, 5)
// -- // --
// -- -- Tests // -- -- Tests
@ -239,7 +230,7 @@ func TestDeleteTagAlias(t *testing.T) {
// -- Create TagAlias to test with // -- Create TagAlias to test with
validTagAlias := models.TagAlias{ validTagAlias := models.TagAlias{
Name: "valid_tag_group_name", Name: "valid_tag_group_name",
TagID: validTag.Name, TagID: validTag.ID,
} }
validTagAlias, err = CreateTagAlias(ctx, validTagAlias.Name, validTagAlias.TagID) validTagAlias, err = CreateTagAlias(ctx, validTagAlias.Name, validTagAlias.TagID)
if err != nil { if err != nil {
@ -249,8 +240,8 @@ func TestDeleteTagAlias(t *testing.T) {
// -- -- Tests // -- -- Tests
type args struct { type args struct {
ctx context.Context ctx context.Context
tagAliasName models.TagAliasName tagAliasID models.TagAliasID
} }
tests := []struct { tests := []struct {
name string name string
@ -260,31 +251,23 @@ func TestDeleteTagAlias(t *testing.T) {
{ {
name: "Test 01: Valid TagAlias", name: "Test 01: Valid TagAlias",
args: args{ args: args{
ctx: ctx, ctx: ctx,
tagAliasName: validTagAlias.Name, tagAliasID: validTagAlias.ID,
}, },
wantErr: false, wantErr: false,
}, },
{ {
name: "Test 02: Not existing TagAlias", name: "Test 02: Not existing TagAlias",
args: args{ args: args{
ctx: ctx, ctx: ctx,
tagAliasName: validTagAlias.Name, tagAliasID: validTagAlias.ID,
}, },
wantErr: false, wantErr: false,
}, },
{
name: "Test 03: Empty TagAliasName ",
args: args{
ctx: ctx,
tagAliasName: "",
},
wantErr: true,
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if err := DeleteTagAlias(tt.args.ctx, tt.args.tagAliasName); (err != nil) != tt.wantErr { if err := DeleteTagAlias(tt.args.ctx, tt.args.tagAliasID); (err != nil) != tt.wantErr {
t.Errorf("DeleteTagAlias() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("DeleteTagAlias() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })

View File

@ -4,27 +4,27 @@ import (
"context" "context"
"errors" "errors"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/internal/utils" "git.anthrove.art/Anthrove/otter-space-sdk/v6/internal/utils"
otterError "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/error" otterError "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/error"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"gorm.io/gorm" "gorm.io/gorm"
) )
func CreateTagGroup(ctx context.Context, tagGroupName models.TagGroupName, tagName models.TagName) (models.TagGroup, error) { func CreateTagGroup(ctx context.Context, tagGroupName models.TagGroupName, tagID models.TagID) (models.TagGroup, error) {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagGroup") ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagGroup")
defer span.End() defer span.End()
localLogger = localLogger.WithFields(log.Fields{ localLogger = localLogger.WithFields(log.Fields{
"tag_group_name": tagGroupName, "tag_group_name": tagGroupName,
"tag_name": tagName, "tag_name": tagID,
}) })
span.SetAttributes( span.SetAttributes(
attribute.String("tag_group_name", string(tagGroupName)), attribute.String("tag_group_name", string(tagGroupName)),
attribute.String("tag_name", string(tagName)), attribute.Int64("tag_name", int64(tagID)),
) )
utils.HandleEvent(span, localLogger, "Starting tag group creation") utils.HandleEvent(span, localLogger, "Starting tag group creation")
@ -37,13 +37,9 @@ func CreateTagGroup(ctx context.Context, tagGroupName models.TagGroupName, tagNa
return models.TagGroup{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.TagGroupNameIsEmpty}) return models.TagGroup{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.TagGroupNameIsEmpty})
} }
if tagName == "" {
return models.TagGroup{}, utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.TagNameIsEmpty})
}
tagGroup := models.TagGroup{ tagGroup := models.TagGroup{
Name: tagGroupName, Name: tagGroupName,
TagID: tagName, TagID: tagID,
} }
result := client.WithContext(ctx).Create(&tagGroup) result := client.WithContext(ctx).Create(&tagGroup)
@ -100,16 +96,16 @@ func CreateTagGroupInBatch(ctx context.Context, tagsGroups []models.TagGroup, ba
return nil return nil
} }
func DeleteTagGroup(ctx context.Context, tagGroupName models.TagGroupName) error { func DeleteTagGroup(ctx context.Context, tagGroupID models.TagGroupID) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteTagGroup") ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteTagGroup")
defer span.End() defer span.End()
span.SetAttributes( span.SetAttributes(
attribute.String("tag_group_name", string(tagGroupName)), attribute.Int64("tag_group_id", int64(tagGroupID)),
) )
localLogger = localLogger.WithFields(log.Fields{ localLogger = localLogger.WithFields(log.Fields{
"tag_group_name": tagGroupName, "tag_group_id": tagGroupID,
}) })
utils.HandleEvent(span, localLogger, "Starting tag group deletion") utils.HandleEvent(span, localLogger, "Starting tag group deletion")
@ -120,11 +116,7 @@ func DeleteTagGroup(ctx context.Context, tagGroupName models.TagGroupName) error
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
} }
if len(tagGroupName) == 0 { result := client.WithContext(ctx).Delete(&tagGroup, tagGroupID)
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.TagGroupNameIsEmpty})
}
result := client.WithContext(ctx).Delete(&tagGroup, tagGroupName)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound})

View File

@ -5,8 +5,8 @@ import (
"reflect" "reflect"
"testing" "testing"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/test" "git.anthrove.art/Anthrove/otter-space-sdk/v6/test"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
) )
@ -44,8 +44,9 @@ func TestCreateTagGroup(t *testing.T) {
// -- Create TagGroup to test with // -- Create TagGroup to test with
validTagGroup := models.TagGroup{ validTagGroup := models.TagGroup{
ID: 1,
Name: "valid_tag_group_name", Name: "valid_tag_group_name",
TagID: validTag.Name, TagID: validTag.ID,
} }
// -- // --
@ -53,7 +54,7 @@ func TestCreateTagGroup(t *testing.T) {
type args struct { type args struct {
ctx context.Context ctx context.Context
tagGroupName models.TagGroupName tagGroupName models.TagGroupName
tagName models.TagName tagID models.TagID
} }
var tests = []struct { var tests = []struct {
name string name string
@ -66,7 +67,7 @@ func TestCreateTagGroup(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
tagGroupName: validTagGroup.Name, tagGroupName: validTagGroup.Name,
tagName: validTag.Name, tagID: validTag.ID,
}, },
want: validTagGroup, want: validTagGroup,
wantErr: false, wantErr: false,
@ -76,7 +77,7 @@ func TestCreateTagGroup(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
tagGroupName: validTagGroup.Name, tagGroupName: validTagGroup.Name,
tagName: validTag.Name, tagID: validTag.ID,
}, },
want: models.TagGroup{}, want: models.TagGroup{},
wantErr: true, wantErr: true,
@ -86,17 +87,7 @@ func TestCreateTagGroup(t *testing.T) {
args: args{ args: args{
ctx: ctx, ctx: ctx,
tagGroupName: "", tagGroupName: "",
tagName: validTag.Name, tagID: validTag.ID,
},
want: models.TagGroup{},
wantErr: true,
},
{
name: "Test 04: tagName name is empty",
args: args{
ctx: ctx,
tagGroupName: validTagGroup.Name,
tagName: "",
}, },
want: models.TagGroup{}, want: models.TagGroup{},
wantErr: true, wantErr: true,
@ -104,7 +95,7 @@ func TestCreateTagGroup(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got, err := CreateTagGroup(tt.args.ctx, tt.args.tagGroupName, tt.args.tagName) got, err := CreateTagGroup(tt.args.ctx, tt.args.tagGroupName, tt.args.tagID)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("CreateTagGroup() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("CreateTagGroup() error = %v, wantErr %v", err, tt.wantErr)
return return
@ -138,14 +129,14 @@ func TestCreateTagGroupInBatch(t *testing.T) {
// -- Create Tags to test with // -- Create Tags to test with
validTags := test.GenerateRandomTags(5) validTags := test.GenerateRandomTags(5)
err = CreateTagInBatch(ctx, validTags, len(validTags)) tags, err := CreateTagInBatch(ctx, validTags, len(validTags))
if err != nil { if err != nil {
t.Fatalf("CreateTags err: %v", err) t.Fatalf("CreateTags err: %v", err)
} }
// -- // --
// -- Create TagGroup to test with // -- Create TagGroup to test with
validTagGroup := test.GenerateRandomTagGroups(validTags, 5) validTagGroup := test.GenerateRandomTagGroups(tags, 5)
// -- // --
// -- -- Tests // -- -- Tests
@ -239,7 +230,7 @@ func TestDeleteTagGroup(t *testing.T) {
// -- Create TagGroup to test with // -- Create TagGroup to test with
validTagGroup := models.TagGroup{ validTagGroup := models.TagGroup{
Name: "valid_tag_group_name", Name: "valid_tag_group_name",
TagID: validTag.Name, TagID: validTag.ID,
} }
validTagGroup, err = CreateTagGroup(ctx, validTagGroup.Name, validTagGroup.TagID) validTagGroup, err = CreateTagGroup(ctx, validTagGroup.Name, validTagGroup.TagID)
if err != nil { if err != nil {
@ -249,8 +240,8 @@ func TestDeleteTagGroup(t *testing.T) {
// -- -- Tests // -- -- Tests
type args struct { type args struct {
ctx context.Context ctx context.Context
tagGroupName models.TagGroupName tagGroupID models.TagGroupID
} }
tests := []struct { tests := []struct {
name string name string
@ -260,31 +251,23 @@ func TestDeleteTagGroup(t *testing.T) {
{ {
name: "Test 01: Valid TagGroup", name: "Test 01: Valid TagGroup",
args: args{ args: args{
ctx: ctx, ctx: ctx,
tagGroupName: validTagGroup.Name, tagGroupID: validTagGroup.ID,
}, },
wantErr: false, wantErr: false,
}, },
{ {
name: "Test 02: Not existing TagGroup", name: "Test 02: Not existing TagGroup",
args: args{ args: args{
ctx: ctx, ctx: ctx,
tagGroupName: validTagGroup.Name, tagGroupID: validTagGroup.ID,
}, },
wantErr: false, wantErr: false,
}, },
{
name: "Test 03: Empty TagGroupName ",
args: args{
ctx: ctx,
tagGroupName: "",
},
wantErr: true,
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if err := DeleteTagGroup(tt.args.ctx, tt.args.tagGroupName); (err != nil) != tt.wantErr { if err := DeleteTagGroup(tt.args.ctx, tt.args.tagGroupID); (err != nil) != tt.wantErr {
t.Errorf("DeleteTagGroup() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("DeleteTagGroup() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })

View File

@ -5,8 +5,8 @@ import (
"reflect" "reflect"
"testing" "testing"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/test" "git.anthrove.art/Anthrove/otter-space-sdk/v6/test"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
) )
@ -33,6 +33,7 @@ func TestCreateTag(t *testing.T) {
// -- Create Tag to test with // -- Create Tag to test with
validTag := models.Tag{ validTag := models.Tag{
ID: 1,
Name: "valid_tag", Name: "valid_tag",
Type: models.General, Type: models.General,
} }
@ -41,6 +42,7 @@ func TestCreateTag(t *testing.T) {
// -- -- Tests // -- -- Tests
type args struct { type args struct {
ctx context.Context ctx context.Context
tagID models.TagID
tagName models.TagName tagName models.TagName
tagType models.TagType tagType models.TagType
} }
@ -54,6 +56,7 @@ func TestCreateTag(t *testing.T) {
name: "Test 01: Valid tag", name: "Test 01: Valid tag",
args: args{ args: args{
ctx: ctx, ctx: ctx,
tagID: validTag.ID,
tagType: validTag.Type, tagType: validTag.Type,
tagName: validTag.Name, tagName: validTag.Name,
}, },
@ -64,6 +67,7 @@ func TestCreateTag(t *testing.T) {
name: "Test 02: Duplicate tag", name: "Test 02: Duplicate tag",
args: args{ args: args{
ctx: ctx, ctx: ctx,
tagID: validTag.ID,
tagType: validTag.Type, tagType: validTag.Type,
tagName: validTag.Name, tagName: validTag.Name,
}, },
@ -179,7 +183,7 @@ func TestCreateTagInBatch(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if err := CreateTagInBatch(tt.args.ctx, tt.args.tags, tt.args.batchSize); (err != nil) != tt.wantErr { if _, err := CreateTagInBatch(tt.args.ctx, tt.args.tags, tt.args.batchSize); (err != nil) != tt.wantErr {
t.Errorf("CreateTagInBatch() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("CreateTagInBatch() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })
@ -219,8 +223,8 @@ func TestDeleteTag(t *testing.T) {
// -- -- Tests // -- -- Tests
type args struct { type args struct {
ctx context.Context ctx context.Context
tagName models.TagName tagID models.TagID
} }
tests := []struct { tests := []struct {
name string name string
@ -230,31 +234,23 @@ func TestDeleteTag(t *testing.T) {
{ {
name: "Test 01: Valid Tag", name: "Test 01: Valid Tag",
args: args{ args: args{
ctx: ctx, ctx: ctx,
tagName: validTag.Name, tagID: validTag.ID,
}, },
wantErr: false, wantErr: false,
}, },
{ {
name: "Test 02: Not existing Tag", name: "Test 02: Not existing Tag",
args: args{ args: args{
ctx: ctx, ctx: ctx,
tagName: validTag.Name, tagID: validTag.ID,
}, },
wantErr: false, wantErr: false,
}, },
{
name: "Test 03: Empty TagName ",
args: args{
ctx: ctx,
tagName: "",
},
wantErr: true,
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if err := DeleteTag(tt.args.ctx, tt.args.tagName); (err != nil) != tt.wantErr { if err := DeleteTag(tt.args.ctx, tt.args.tagID, false); (err != nil) != tt.wantErr {
t.Errorf("DeleteTag() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("DeleteTag() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"errors" "errors"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/internal/utils" "git.anthrove.art/Anthrove/otter-space-sdk/v6/internal/utils"
otterError "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/error" otterError "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/error"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"gorm.io/gorm" "gorm.io/gorm"
@ -75,7 +75,7 @@ func GetUserByID(ctx context.Context, id models.UserID) (models.User, error) {
return user, nil return user, nil
} }
func DeleteUser(ctx context.Context, id models.UserID) error { func DeleteUser(ctx context.Context, id models.UserID, hardDelete bool) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteUser") ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteUser")
defer span.End() defer span.End()
@ -95,7 +95,15 @@ func DeleteUser(ctx context.Context, id models.UserID) error {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
} }
result := client.WithContext(ctx).Delete(&user, id) db := client
if hardDelete {
db = client.Unscoped()
} else {
db = client
}
result := db.WithContext(ctx).Delete(&user, id)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound})

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"errors" "errors"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/internal/utils" "git.anthrove.art/Anthrove/otter-space-sdk/v6/internal/utils"
otterError "git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/error" otterError "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/error"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"gorm.io/gorm" "gorm.io/gorm"
@ -133,7 +133,7 @@ func GetUserSourceByID(ctx context.Context, id models.UserSourceID) (models.User
return user, nil return user, nil
} }
func DeleteUserSource(ctx context.Context, id models.UserSourceID) error { func DeleteUserSource(ctx context.Context, id models.UserSourceID, hardDelete bool) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteUserSource") ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteUserSource")
defer span.End() defer span.End()
@ -160,7 +160,15 @@ func DeleteUserSource(ctx context.Context, id models.UserSourceID) error {
return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.UserSourceIsWrongLength}) return utils.HandleError(ctx, span, localLogger, &otterError.EntityValidationFailed{Reason: otterError.UserSourceIsWrongLength})
} }
result := client.WithContext(ctx).Delete(&user, id) db := client
if hardDelete {
db = client.Unscoped()
} else {
db = client
}
result := db.WithContext(ctx).Delete(&user, id)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound}) return utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.NoDataFound})

View File

@ -7,8 +7,8 @@ import (
"testing" "testing"
"time" "time"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/test" "git.anthrove.art/Anthrove/otter-space-sdk/v6/test"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"gorm.io/gorm" "gorm.io/gorm"
@ -482,7 +482,7 @@ func TestDeleteUserSource(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if err := DeleteUserSource(tt.args.ctx, tt.args.id); (err != nil) != tt.wantErr { if err := DeleteUserSource(tt.args.ctx, tt.args.id, false); (err != nil) != tt.wantErr {
t.Errorf("DeleteUserSource() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("DeleteUserSource() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })

View File

@ -5,8 +5,8 @@ import (
"fmt" "fmt"
"testing" "testing"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/test" "git.anthrove.art/Anthrove/otter-space-sdk/v6/test"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
) )
@ -203,7 +203,7 @@ func TestDeleteUser(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if err := DeleteUser(tt.args.ctx, tt.args.id); (err != nil) != tt.wantErr { if err := DeleteUser(tt.args.ctx, tt.args.id, false); (err != nil) != tt.wantErr {
t.Errorf("DeleteUser() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("DeleteUser() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })

View File

@ -12,8 +12,11 @@ type (
SourceDomain string SourceDomain string
TagName string TagName string
TagID int64
TagGroupName string TagGroupName string
TagGroupID int64
TagAliasName string TagAliasName string
TagAliasID int64
ScrapeTimeInterval int ScrapeTimeInterval int
UserLastScrapeTime time.Time UserLastScrapeTime time.Time

View File

@ -5,7 +5,7 @@ import (
) )
type ScrapeHistory struct { type ScrapeHistory struct {
ScrapeTaskID ScrapeTaskID `json:"scrape_task_id" gorm:"primaryKey"` ID ScrapeTaskID `json:"scrape_task_id" gorm:"primaryKey"`
UserSourceID UserSourceID `json:"user_source_id" gorm:""` UserSourceID UserSourceID `json:"user_source_id" gorm:""`
CreatedAt time.Time `json:"created_at" gorm:""` CreatedAt time.Time `json:"created_at" gorm:""`
FinishedAt time.Time `json:"finished_at" gorm:""` FinishedAt time.Time `json:"finished_at" gorm:""`

View File

@ -2,7 +2,8 @@ package models
// Tag models // Tag models
type Tag struct { type Tag struct {
Name TagName `json:"name" gorm:"primaryKey"` ID TagID `json:"id" gorm:"primaryKey"`
Name TagName `json:"name"`
Type TagType `json:"type" gorm:"column:tag_type"` Type TagType `json:"type" gorm:"column:tag_type"`
Aliases []TagAlias `json:"aliases,omitempty" gorm:"foreignKey:TagID"` Aliases []TagAlias `json:"aliases,omitempty" gorm:"foreignKey:TagID"`
Groups []TagGroup `json:"groups,omitempty" gorm:"foreignKey:TagID"` Groups []TagGroup `json:"groups,omitempty" gorm:"foreignKey:TagID"`
@ -15,8 +16,9 @@ func (Tag) TableName() string {
// TagAlias model // TagAlias model
type TagAlias struct { type TagAlias struct {
Name TagAliasName `json:"name" gorm:"primaryKey"` ID TagAliasID `json:"id" gorm:"primaryKey"`
TagID TagName `json:"tag_id"` Name TagAliasName `json:"name"`
TagID TagID `json:"tag_id"`
} }
func (TagAlias) TableName() string { func (TagAlias) TableName() string {
@ -25,8 +27,9 @@ func (TagAlias) TableName() string {
// TagGroup model // TagGroup model
type TagGroup struct { type TagGroup struct {
Name TagGroupName `json:"name" gorm:"primaryKey"` ID TagGroupID `json:"id" gorm:"primaryKey"`
TagID TagName `json:"tag_id"` Name TagGroupName `json:"name"`
TagID TagID `json:"tag_id"`
} }
func (TagGroup) TableName() string { func (TagGroup) TableName() string {
@ -34,6 +37,7 @@ func (TagGroup) TableName() string {
} }
type TagsWithFrequency struct { type TagsWithFrequency struct {
ID int64 `json:"id" gorm:"primaryKey"`
Frequency int64 `json:"frequency"` Frequency int64 `json:"frequency"`
Tags Tag `json:"tags"` Tags Tag `json:"tags"`
} }

View File

@ -5,7 +5,7 @@ import (
"math/rand" "math/rand"
"time" "time"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
gonanoid "github.com/matoous/go-nanoid/v2" gonanoid "github.com/matoous/go-nanoid/v2"
"gorm.io/gorm" "gorm.io/gorm"
@ -38,11 +38,11 @@ func GenerateRandomTagGroups(tags []models.Tag, num int) []models.TagGroup {
for i := 0; i < num; i++ { for i := 0; i < num; i++ {
id, _ := gonanoid.New(10) id, _ := gonanoid.New(10)
groupName := fmt.Sprintf("tag_group_%s", id) groupName := fmt.Sprintf("tag_group_%s", id)
randomTag := tags[rand.Intn(len(tags))] // randomTag := tags[rand.Intn(len(tags))]
tagGroup := models.TagGroup{ tagGroup := models.TagGroup{
Name: models.TagGroupName(groupName), Name: models.TagGroupName(groupName),
TagID: randomTag.Name, TagID: tags[rand.Intn(len(tags))].ID,
} }
tagGroups = append(tagGroups, tagGroup) tagGroups = append(tagGroups, tagGroup)
@ -57,11 +57,11 @@ func GenerateRandomTagAlias(tags []models.Tag, num int) []models.TagAlias {
for i := 0; i < num; i++ { for i := 0; i < num; i++ {
id, _ := gonanoid.New(10) id, _ := gonanoid.New(10)
groupName := fmt.Sprintf("tag_alias_%s", id) groupName := fmt.Sprintf("tag_alias_%s", id)
randomTag := tags[rand.Intn(len(tags))] // randomTag := tags[rand.Intn(len(tags))]
tagAlias := models.TagAlias{ tagAlias := models.TagAlias{
Name: models.TagAliasName(groupName), Name: models.TagAliasName(groupName),
TagID: randomTag.Name, TagID: tags[rand.Intn(len(tags))].ID,
} }
tagAliases = append(tagAliases, tagAlias) tagAliases = append(tagAliases, tagAlias)

View File

@ -8,7 +8,7 @@ import (
"strings" "strings"
"time" "time"
"git.anthrove.art/Anthrove/otter-space-sdk/v5/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v6/pkg/models"
migrate "github.com/rubenv/sql-migrate" migrate "github.com/rubenv/sql-migrate"
postgrescontainer "github.com/testcontainers/testcontainers-go/modules/postgres" postgrescontainer "github.com/testcontainers/testcontainers-go/modules/postgres"
"gorm.io/driver/postgres" "gorm.io/driver/postgres"