diff --git a/pkg/repositories/config/migrations.go b/pkg/repositories/config/migrations.go index 4bf102a..698c8b5 100644 --- a/pkg/repositories/config/migrations.go +++ b/pkg/repositories/config/migrations.go @@ -7,7 +7,6 @@ import ( "gorm.io/gorm" ) - func ListMigrations(db *gorm.DB) []*gormigrate.Migration { var Migrations []*gormigrate.Migration if db.Dialector.Name() == "postgres" { @@ -16,4 +15,3 @@ func ListMigrations(db *gorm.DB) []*gormigrate.Migration { Migrations = append(Migrations, fixupmigrations.Migrations...) return Migrations } - diff --git a/pkg/repositories/config/migrations/fixup/migrations.go b/pkg/repositories/config/migrations/fixup/migrations.go index 7d4e5d3..5a4b9ea 100644 --- a/pkg/repositories/config/migrations/fixup/migrations.go +++ b/pkg/repositories/config/migrations/fixup/migrations.go @@ -1,6 +1,7 @@ package fixupmigrations import ( + "database/sql/driver" "time" "github.com/go-gormigrate/gormigrate/v2" @@ -19,6 +20,15 @@ func (uuidString UUIDString) GormDBDataType(db *gorm.DB, field *schema.Field) st return "uuid" } +func (uuidString *UUIDString) Scan(value interface{}) error { + return nil +} + +// Value return json value, implement driver.Valuer interface +func (uuidString UUIDString) Value() (driver.Value, error) { + return uuidString, nil +} + type BaseModel struct { CreatedAt time.Time UpdatedAt time.Time @@ -27,12 +37,12 @@ type BaseModel struct { type ArtifactKey struct { DatasetProject string `gorm:"size:64;primary_key"` - // Can we use a smaller size fo dataset name? This is `flyte-task-` + // Can we use a smaller size fo dataset name? This is `flyte-task-` DatasetName string `gorm:"size:100;primary_key"` DatasetDomain string `gorm:"size:64;primary_key"` DatasetVersion string `gorm:"size:128;primary_key"` // This is a UUID - ArtifactID string `gorm:"size:36;primary_key"` + ArtifactID string `gorm:"size:36;primary_key"` } type Artifact struct { @@ -53,12 +63,11 @@ type ArtifactData struct { Location string `gorm:"size:2048"` } - type DatasetKey struct { - Project string `gorm:"size:64;primary_key"` // part of pkey, no index needed as it is first column in the pkey + Project string `gorm:"size:64;primary_key"` // part of pkey, no index needed as it is first column in the pkey // TODO: figure out what size this should be Name string `gorm:"size:100;primary_key;index:dataset_name_idx"` // part of pkey and has separate index for filtering - Domain string `gorm:"size:64;primary_key;index:dataset_domain_idx"` // part of pkey and has separate index for filtering + Domain string `gorm:"size:64;primary_key;index:dataset_domain_idx"` // part of pkey and has separate index for filtering Version string `gorm:"size:128;primary_key;index:dataset_version_idx"` // part of pkey and has separate index for filtering UUID UUIDString `gorm:"unique;type:uuid"` } @@ -74,7 +83,7 @@ type PartitionKey struct { BaseModel DatasetUUID UUIDString `gorm:"type:uuid;primary_key"` // TODO: figure out if this is used. - Name string `gorm:"size:100;primary_key"` + Name string `gorm:"size:100;primary_key"` } type TagKey struct { @@ -98,9 +107,9 @@ type Tag struct { type Partition struct { BaseModel DatasetUUID UUIDString `gorm:"primary_key;type:uuid"` - Key string `gorm:"primary_key"` - Value string `gorm:"primary_key"` - ArtifactID string `gorm:"primary_key;index"` // index for JOINs with the Tag/Labels table when querying artifacts + Key string `gorm:"primary_key"` + Value string `gorm:"primary_key"` + ArtifactID string `gorm:"primary_key;index"` // index for JOINs with the Tag/Labels table when querying artifacts } type ReservationKey struct { @@ -110,7 +119,7 @@ type ReservationKey struct { DatasetDomain string `gorm:"size:64;primary_key"` DatasetVersion string `gorm:"size:128;primary_key"` // TODO: figure out what size this should be - TagName string `gorm:"56;primary_key"` + TagName string `gorm:"56;primary_key"` } // Reservation tracks the metadata needed to allow diff --git a/pkg/repositories/config/migrations/noop/migrations.go b/pkg/repositories/config/migrations/noop/migrations.go index 90a6cbf..103a8fc 100644 --- a/pkg/repositories/config/migrations/noop/migrations.go +++ b/pkg/repositories/config/migrations/noop/migrations.go @@ -1,6 +1,7 @@ package noopmigrations import ( + "database/sql/driver" "time" "github.com/go-gormigrate/gormigrate/v2" @@ -19,6 +20,15 @@ func (uuidString UUIDString) GormDBDataType(db *gorm.DB, field *schema.Field) st return "uuid" } +func (uuidString *UUIDString) Scan(value interface{}) error { + return nil +} + +// Value return json value, implement driver.Valuer interface +func (uuidString UUIDString) Value() (driver.Value, error) { + return uuidString, nil +} + type BaseModel struct { CreatedAt time.Time UpdatedAt time.Time @@ -51,7 +61,6 @@ type ArtifactData struct { Location string } - type DatasetKey struct { Project string `gorm:"primary_key;"` // part of pkey, no index needed as it is first column in the pkey Name string `gorm:"primary_key;index:dataset_name_idx"` // part of pkey and has separate index for filtering @@ -70,7 +79,7 @@ type Dataset struct { type PartitionKey struct { BaseModel DatasetUUID UUIDString `gorm:"type:uuid;primary_key"` - Name string `gorm:"primary_key"` + Name string `gorm:"primary_key"` } type TagKey struct { @@ -92,9 +101,9 @@ type Tag struct { type Partition struct { BaseModel DatasetUUID UUIDString `gorm:"primary_key;type:uuid"` - Key string `gorm:"primary_key"` - Value string `gorm:"primary_key"` - ArtifactID string `gorm:"primary_key;index"` // index for JOINs with the Tag/Labels table when querying artifacts + Key string `gorm:"primary_key"` + Value string `gorm:"primary_key"` + ArtifactID string `gorm:"primary_key;index"` // index for JOINs with the Tag/Labels table when querying artifacts } type ReservationKey struct { diff --git a/pkg/repositories/factory.go b/pkg/repositories/factory.go index abf06de..fd4f4cf 100644 --- a/pkg/repositories/factory.go +++ b/pkg/repositories/factory.go @@ -2,6 +2,7 @@ package repositories import ( "context" + "github.com/flyteorg/flytestdlib/database" "github.com/flyteorg/datacatalog/pkg/repositories/errors" diff --git a/pkg/repositories/models/dataset.go b/pkg/repositories/models/dataset.go index 453c255..b4786df 100644 --- a/pkg/repositories/models/dataset.go +++ b/pkg/repositories/models/dataset.go @@ -1,6 +1,8 @@ package models import ( + "database/sql/driver" + "github.com/gofrs/uuid" "gorm.io/gorm" "gorm.io/gorm/schema" @@ -26,7 +28,7 @@ type Dataset struct { type PartitionKey struct { BaseModel DatasetUUID UUIDString `gorm:"type:uuid;primary_key"` - Name string `gorm:"primary_key"` + Name string `gorm:"primary_key"` } // BeforeCreate so that we set the UUID in golang rather than from a DB function call @@ -50,3 +52,12 @@ func (dataset UUIDString) GormDBDataType(db *gorm.DB, field *schema.Field) strin } return "uuid" } + +func (dataset *UUIDString) Scan(value interface{}) error { + return nil +} + +// Value return json value, implement driver.Valuer interface +func (dataset UUIDString) Value() (driver.Value, error) { + return dataset, nil +} diff --git a/pkg/repositories/models/partition.go b/pkg/repositories/models/partition.go index fb77fd5..53e6f16 100644 --- a/pkg/repositories/models/partition.go +++ b/pkg/repositories/models/partition.go @@ -6,7 +6,7 @@ package models type Partition struct { BaseModel DatasetUUID UUIDString `gorm:"primary_key;type:uuid"` - Key string `gorm:"primary_key"` - Value string `gorm:"primary_key"` - ArtifactID string `gorm:"primary_key;index"` // index for JOINs with the Tag/Labels table when querying artifacts + Key string `gorm:"primary_key"` + Value string `gorm:"primary_key"` + ArtifactID string `gorm:"primary_key;index"` // index for JOINs with the Tag/Labels table when querying artifacts }