Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

lint and uuid #105

Draft
wants to merge 1 commit into
base: mysql-support
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pkg/repositories/config/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"gorm.io/gorm"
)


func ListMigrations(db *gorm.DB) []*gormigrate.Migration {
var Migrations []*gormigrate.Migration
if db.Dialector.Name() == "postgres" {
Expand All @@ -16,4 +15,3 @@ func ListMigrations(db *gorm.DB) []*gormigrate.Migration {
Migrations = append(Migrations, fixupmigrations.Migrations...)
return Migrations
}

29 changes: 19 additions & 10 deletions pkg/repositories/config/migrations/fixup/migrations.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fixupmigrations

import (
"database/sql/driver"
"time"

"github.com/go-gormigrate/gormigrate/v2"
Expand All @@ -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
Expand All @@ -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-<task name>`
// Can we use a smaller size fo dataset name? This is `flyte-task-<task name>`
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 {
Expand All @@ -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"`
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
Expand Down
19 changes: 14 additions & 5 deletions pkg/repositories/config/migrations/noop/migrations.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package noopmigrations

import (
"database/sql/driver"
"time"

"github.com/go-gormigrate/gormigrate/v2"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/repositories/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package repositories

import (
"context"

"github.com/flyteorg/flytestdlib/database"

"github.com/flyteorg/datacatalog/pkg/repositories/errors"
Expand Down
13 changes: 12 additions & 1 deletion pkg/repositories/models/dataset.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package models

import (
"database/sql/driver"

"github.com/gofrs/uuid"
"gorm.io/gorm"
"gorm.io/gorm/schema"
Expand All @@ -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
Expand All @@ -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
}
6 changes: 3 additions & 3 deletions pkg/repositories/models/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}