Skip to content

Commit

Permalink
✨ Change created_at field type
Browse files Browse the repository at this point in the history
  • Loading branch information
tosone committed Nov 24, 2023
1 parent 6e05eec commit b785d76
Show file tree
Hide file tree
Showing 85 changed files with 649 additions and 686 deletions.
7 changes: 4 additions & 3 deletions pkg/daemon/gc/gc_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ func (g gcRepository) deleteRepositoryCheck() {
log.Error().Err(err).Int64("RepositoryID", task.Repository.ID).Msg("Get repository by id failed")
continue
}
if !repositoryObj.UpdatedAt.Before(time.Now().Add(-1 * 24 * time.Duration(task.Runner.Rule.RetentionDay) * time.Hour)) {
continue
}
log.Info().Interface("repo", repositoryObj).Send()

Check warning on line 178 in pkg/daemon/gc/gc_repository.go

View check run for this annotation

Codecov / codecov/patch

pkg/daemon/gc/gc_repository.go#L178

Added line #L178 was not covered by tests
// if !repositoryObj.UpdatedAt.Before(time.Now().Add(-1 * 24 * time.Duration(task.Runner.Rule.RetentionDay) * time.Hour)) {
// continue
// }
}
g.deleteRepositoryChan <- task
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dal/dao/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (s *artifactService) Create(ctx context.Context, artifact *models.Artifact)
func (s *artifactService) FindWithLastPull(ctx context.Context, repositoryID int64, before time.Time, limit, last int64) ([]*models.Artifact, error) {
return s.tx.Artifact.WithContext(ctx).
Where(s.tx.Artifact.LastPull.Lt(sql.NullTime{Valid: true, Time: before})).
Or(s.tx.Artifact.LastPull.IsNull(), s.tx.Artifact.UpdatedAt.Lt(before)).
Or(s.tx.Artifact.LastPull.IsNull(), s.tx.Artifact.UpdatedAt.Lt(before.UTC().UnixMilli())).

Check warning on line 126 in pkg/dal/dao/artifact.go

View check run for this annotation

Codecov / codecov/patch

pkg/dal/dao/artifact.go#L126

Added line #L126 was not covered by tests
Where(s.tx.Artifact.ID.Gt(last), s.tx.Artifact.RepositoryID.Eq(repositoryID)).
Limit(int(limit)).Find()
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dal/dao/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *blobService) Create(ctx context.Context, blob *models.Blob) error {
func (s *blobService) FindWithLastPull(ctx context.Context, before time.Time, last, limit int64) ([]*models.Blob, error) {
return s.tx.Blob.WithContext(ctx).
Where(s.tx.Blob.LastPull.Lt(sql.NullTime{Valid: true, Time: before})).
Or(s.tx.Blob.LastPull.IsNull(), s.tx.Blob.UpdatedAt.Lt(before)).
Or(s.tx.Blob.LastPull.IsNull(), s.tx.Blob.UpdatedAt.Lt(before.UTC().UnixMilli())).
Where(s.tx.Blob.ID.Gt(last)).Find()
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/dal/dao/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (s *tagService) FindWithQuantityCursor(ctx context.Context, repositoryID in
func (s *tagService) FindWithDayCursor(ctx context.Context, repositoryID int64, day, limit int, last int64) ([]*models.Tag, error) {
q := s.tx.Tag.WithContext(ctx).Where(s.tx.Tag.RepositoryID.Eq(repositoryID)).Order(s.tx.Tag.UpdatedAt.Desc())
if last == 0 {
q = q.Where(s.tx.Tag.UpdatedAt.Gt(time.Now().Add(time.Hour * 24 * time.Duration(day))))
q = q.Where(s.tx.Tag.UpdatedAt.Gt(time.Now().Add(time.Hour * 24 * time.Duration(day)).UTC().UnixMilli()))

Check warning on line 164 in pkg/dal/dao/tag.go

View check run for this annotation

Codecov / codecov/patch

pkg/dal/dao/tag.go#L164

Added line #L164 was not covered by tests
} else {
q = q.Where(s.tx.Tag.ID.Gt(last))
}
Expand Down
140 changes: 70 additions & 70 deletions pkg/dal/migrations/mysql/0001_initialize.up.sql

Large diffs are not rendered by default.

116 changes: 58 additions & 58 deletions pkg/dal/migrations/postgresql/0001_initialize.up.sql

Large diffs are not rendered by default.

140 changes: 70 additions & 70 deletions pkg/dal/migrations/sqlite3/0001_initialize.up.sql

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions pkg/dal/models/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (

// Artifact represents an artifact
type Artifact struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand Down Expand Up @@ -160,8 +160,8 @@ WHERE

// ArtifactSbom represents an artifact sbom
type ArtifactSbom struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand All @@ -178,8 +178,8 @@ type ArtifactSbom struct {

// ArtifactVulnerability represents an artifact vulnerability
type ArtifactVulnerability struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand Down
6 changes: 2 additions & 4 deletions pkg/dal/models/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@
package models

import (
"time"

"gorm.io/plugin/soft_delete"

"github.com/go-sigma/sigma/pkg/types/enums"
)

// Audit represents a audit
type Audit struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand Down
4 changes: 2 additions & 2 deletions pkg/dal/models/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (

// Blob represents a blob
type Blob struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand Down
6 changes: 2 additions & 4 deletions pkg/dal/models/blob_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
package models

import (
"time"

"gorm.io/plugin/soft_delete"
)

type BlobUpload struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand Down
8 changes: 4 additions & 4 deletions pkg/dal/models/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (

// Builder represents a builder
type Builder struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand Down Expand Up @@ -75,8 +75,8 @@ type Builder struct {

// BuilderRunner represents a builder runner
type BuilderRunner struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand Down
6 changes: 2 additions & 4 deletions pkg/dal/models/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
package models

import (
"time"

"gorm.io/plugin/soft_delete"
)

// Cache cache
type Cache struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand Down
18 changes: 8 additions & 10 deletions pkg/dal/models/code_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@
package models

import (
"time"

"gorm.io/plugin/soft_delete"

"github.com/go-sigma/sigma/pkg/types/enums"
)

// CodeRepository ...
type CodeRepository struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand All @@ -47,8 +45,8 @@ type CodeRepository struct {

// CodeRepositoryBranch ...
type CodeRepositoryBranch struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand All @@ -58,8 +56,8 @@ type CodeRepositoryBranch struct {

// CodeRepositoryOwner ...
type CodeRepositoryOwner struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand All @@ -73,8 +71,8 @@ type CodeRepositoryOwner struct {

// CodeRepositoryCloneCredential ...
type CodeRepositoryCloneCredential struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand Down
63 changes: 24 additions & 39 deletions pkg/dal/models/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,10 @@ import (
"github.com/go-sigma/sigma/pkg/types/enums"
)

// DaemonLog represents an artifact
// type DaemonLog struct {
// CreatedAt time.Time
// UpdatedAt time.Time
// DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
// ID int64 `gorm:"primaryKey"`

// NamespaceID *int64
// Type enums.Daemon
// Action enums.AuditAction
// Resource string
// Status enums.TaskCommonStatus
// Message []byte
// }

// DaemonGcTagRule ...
type DaemonGcTagRule struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand All @@ -58,8 +43,8 @@ type DaemonGcTagRule struct {

// DaemonGcTagRunner ...
type DaemonGcTagRunner struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand All @@ -78,8 +63,8 @@ type DaemonGcTagRunner struct {

// DaemonGcTagRecords ...
type DaemonGcTagRecord struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand All @@ -93,8 +78,8 @@ type DaemonGcTagRecord struct {

// DaemonGcRepositoryRule ...
type DaemonGcRepositoryRule struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand All @@ -110,8 +95,8 @@ type DaemonGcRepositoryRule struct {

// DaemonGcRepositoryRunner ...
type DaemonGcRepositoryRunner struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand All @@ -130,8 +115,8 @@ type DaemonGcRepositoryRunner struct {

// DaemonGcRepositoryRecord ...
type DaemonGcRepositoryRecord struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand All @@ -145,8 +130,8 @@ type DaemonGcRepositoryRecord struct {

// DaemonGcArtifactRule ...
type DaemonGcArtifactRule struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand All @@ -161,8 +146,8 @@ type DaemonGcArtifactRule struct {
}

type DaemonGcArtifactRunner struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand All @@ -181,8 +166,8 @@ type DaemonGcArtifactRunner struct {

// DaemonGcArtifactRecord ...
type DaemonGcArtifactRecord struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand All @@ -196,8 +181,8 @@ type DaemonGcArtifactRecord struct {

// DaemonGcBlobRule ...
type DaemonGcBlobRule struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand All @@ -210,8 +195,8 @@ type DaemonGcBlobRule struct {

// DaemonGcBlobRunner ...
type DaemonGcBlobRunner struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand All @@ -229,8 +214,8 @@ type DaemonGcBlobRunner struct {
}

type DaemonGcBlobRecord struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand Down
6 changes: 2 additions & 4 deletions pkg/dal/models/locker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
package models

import (
"time"

"gorm.io/plugin/soft_delete"
)

// Locker locker
type Locker struct {
CreatedAt time.Time
UpdatedAt time.Time
CreatedAt int64 `gorm:"autoUpdateTime:milli"`
UpdatedAt int64 `gorm:"autoUpdateTime:milli"`
DeletedAt soft_delete.DeletedAt `gorm:"softDelete:milli"`
ID int64 `gorm:"primaryKey"`

Expand Down
Loading

0 comments on commit b785d76

Please sign in to comment.