-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
halfway through adding database stuff
Signed-off-by: Yee Hing Tong <[email protected]>
- Loading branch information
1 parent
f04aa07
commit 651aa2a
Showing
16 changed files
with
611 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package shared | ||
|
||
import ( | ||
stdlibLogger "github.com/flyteorg/flyte/flytestdlib/logger" | ||
"github.com/go-gormigrate/gormigrate/v2" | ||
"github.com/flyteorg/flyte/flytestdlib/promutils" | ||
"github.com/spf13/cobra" | ||
) | ||
\ | ||
// NewMigrateCmd represents the migrate command | ||
func NewMigrateCmd(migs []*gormigrate.Migration) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "migrate", | ||
Short: "This command will run all the migrations for the database", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return migrions.Migrate(confi.GetDBConfig(), stdlibLogger.GetConfig(), promutils.NewScope("dbmigrate"), migrs) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package shared | ||
|
||
import ( | ||
stdlibLogger "github.com/flyteorg/flyte/flytestdlib/logger" | ||
"github.com/flyteorg/flyte/flytestdlib/promutils" | ||
"github.com/go-gormigrate/gormigrate/v2" | ||
"google.golang.org/grpc/codes" | ||
) | ||
|
||
func PGMigrate(cfg *DbConfig, logCfg *stdlibLogger.Config, _ promutils.Scope, migrations []*gormigrate.Migration) error { | ||
db, err := connection.OpenDbConnection(connection.NewPostgresDialector(cfg), cfg, logCfg) | ||
if err != nil { | ||
return serverErr.NewServerErrorf(codes.InvalidArgument, "Failed to open postgres connection to [%+s] with err: %+v", cfg.DbName, err) | ||
} | ||
|
||
if err := sharedmigrations.CreateDB(db, cfg.DbName); err != nil { | ||
return serverErr.NewServerErrorf(codes.Internal, "Failed to ensure db [%s] exists wth err: %v", cfg.DbName, err) | ||
} | ||
|
||
if len(migrations) > 0 { | ||
migrator := gormigrate.New(db, gormigrate.DefaultOptions, migrations) | ||
err = migrator.Migrate() | ||
if err != nil { | ||
return serverErr.NewServerErrorf(codes.Internal, "Failed to migrate database: %v", err) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package gormimpl | ||
|
||
import ( | ||
"github.com/go-gormigrate/gormigrate/v2" | ||
"gorm.io/gorm" | ||
) | ||
|
||
var Migrations = []*gormigrate.Migration{ | ||
{ | ||
ID: "2023-10-12-inits", | ||
Migrate: func(tx *gorm.DB) error { | ||
type Marker struct { | ||
} | ||
return tx.AutoMigrate( | ||
&Marker{}, | ||
) | ||
}, | ||
Rollback: func(tx *gorm.DB) error { | ||
return tx.Migrator().DropTable( | ||
"markers", | ||
) | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/artifact" | ||
) | ||
|
||
type ArtifactHandler interface { | ||
CreateArtifact(ctx context.Context, request *artifact.CreateArtifactRequest) (*artifact.CreateArtifactResponse, error) | ||
GetArtifact(ctx context.Context, request *artifact.GetArtifactRequest) (*artifact.GetArtifactResponse, error) | ||
} | ||
|
||
type TriggerHandler interface { | ||
CreateTrigger(ctx context.Context, request *artifact.CreateTriggerRequest) (*artifact.CreateTriggerResponse, error) | ||
DeleteTrigger(ctx context.Context, request *artifact.DeleteTriggerRequest) (*artifact.DeleteTriggerResponse, error) | ||
} | ||
|
||
type TagHandler interface { | ||
AddTag(ctx context.Context, request *artifact.AddTagRequest) (*artifact.AddTagResponse, error) | ||
} | ||
|
||
type LineageHandler interface { | ||
RegisterProducer(ctx context.Context, request *artifact.RegisterProducerRequest) (*artifact.RegisterResponse, error) | ||
RegisterConsumer(ctx context.Context, request *artifact.RegisterConsumerRequest) (*artifact.RegisterResponse, error) | ||
} | ||
|
||
type SearchHandler interface { | ||
SearchArtifacts(ctx context.Context, request *artifact.SearchArtifactsRequest) (*artifact.SearchArtifactsResponse, error) | ||
} |
Oops, something went wrong.