generated from ZEISS/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10304b3
commit d9ddfe9
Showing
19 changed files
with
1,159 additions
and
1,198 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
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,41 @@ | ||
package cmd | ||
|
||
import ( | ||
seed "github.com/zeiss/gorm-seed" | ||
"github.com/zeiss/knox/internal/adapters/database" | ||
"github.com/zeiss/knox/internal/models" | ||
|
||
"github.com/spf13/cobra" | ||
"gorm.io/driver/postgres" | ||
"gorm.io/gorm" | ||
"gorm.io/gorm/schema" | ||
) | ||
|
||
var Migrate = &cobra.Command{ | ||
Use: "migrate", | ||
Short: "Migrate the database", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
conn, err := gorm.Open(postgres.Open(config.Flags.DatabaseURI), &gorm.Config{ | ||
NamingStrategy: schema.NamingStrategy{ | ||
TablePrefix: config.Flags.DatabaseTablePrefix, | ||
}, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
store, err := seed.NewDatabase(conn, database.NewReadTx(), database.NewWriteTx()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return store.Migrate( | ||
cmd.Context(), | ||
&models.Environment{}, | ||
&models.Lock{}, | ||
&models.Project{}, | ||
&models.Snapshot{}, | ||
&models.State{}, | ||
) | ||
}, | ||
} |
This file was deleted.
Oops, something went wrong.
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,64 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/zeiss/fiber-goth/adapters" | ||
seed "github.com/zeiss/gorm-seed" | ||
"github.com/zeiss/knox/internal/models" | ||
|
||
"github.com/spf13/cobra" | ||
"gorm.io/driver/postgres" | ||
"gorm.io/gorm" | ||
"gorm.io/gorm/schema" | ||
) | ||
|
||
var seeds = []seed.Seed{ | ||
{ | ||
Name: "create team", | ||
Run: func(db *gorm.DB) error { | ||
team := adapters.GothTeam{ | ||
Name: "Zeiss", | ||
Slug: "zeiss", | ||
} | ||
|
||
err := db.Create(&team).Error | ||
if err != nil { | ||
return err | ||
} | ||
|
||
project := models.Project{ | ||
Name: "demo", | ||
TeamID: team.ID, | ||
} | ||
|
||
err = db.Create(&project).Error | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return db.Create([]models.Environment{ | ||
{ | ||
ProjectID: project.ID, | ||
Name: "dev", | ||
}, | ||
}).Error | ||
}, | ||
}, | ||
} | ||
|
||
var Seed = &cobra.Command{ | ||
Use: "seed", | ||
Short: "Seed the database", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
conn, err := gorm.Open(postgres.Open(config.Flags.DatabaseURI), &gorm.Config{ | ||
NamingStrategy: schema.NamingStrategy{ | ||
TablePrefix: config.Flags.DatabaseTablePrefix, | ||
}, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
seeder := seed.NewSeeder(conn) | ||
return seeder.Seed(cmd.Context(), seeds...) | ||
}, | ||
} |
Oops, something went wrong.