-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: implement database module and abstract backend (#337)
* refactor(server): abstract database from backend Prepare for multi database driver support * feat(server): add db models * feat(db): add database migrations * feat(db): add support to postgres * feat: implement database store logic * refactor: use db module and abstract backend logic * fix(db): postgres migrate sql * feat(db): add database query tracing * refactor: move internal packages to server * fix(config): normalize sqlite database path * fix,feat: support custom log path and fix logging leak in hooks * fix(test): race condition * refactor: tidy up files and use middlewares * chore: add test for repo commit command Reference: #331 * fix: lint errors * fix: use utc time and fix git packp error format * fix: lint errors * fix: testscript on windows * chore: format sql files * fix: lint issues re-enable revive linter * refactor: clean up server/config * feat: add admin command to manage server * fix(db): use migration versions * chore: add deprecation warning. * refactor: move shared interfaces and errors to proto * fix: increase golangci lint timeout * feat: add move tests
- Loading branch information
1 parent
7cd0583
commit e398b4d
Showing
133 changed files
with
4,558 additions
and
3,257 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
run: | ||
tests: false | ||
timeout: 5m | ||
|
||
issues: | ||
include: | ||
|
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,75 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/charmbracelet/soft-serve/server/backend" | ||
"github.com/charmbracelet/soft-serve/server/config" | ||
"github.com/charmbracelet/soft-serve/server/db" | ||
"github.com/charmbracelet/soft-serve/server/db/migrate" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
adminCmd = &cobra.Command{ | ||
Use: "admin", | ||
Short: "Administrate the server", | ||
} | ||
|
||
migrateCmd = &cobra.Command{ | ||
Use: "migrate", | ||
Short: "Migrate the database to the latest version", | ||
PersistentPreRunE: initBackendContext, | ||
PersistentPostRunE: closeDBContext, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
ctx := cmd.Context() | ||
db := db.FromContext(ctx) | ||
if err := migrate.Migrate(ctx, db); err != nil { | ||
return fmt.Errorf("migration: %w", err) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
rollbackCmd = &cobra.Command{ | ||
Use: "rollback", | ||
Short: "Rollback the database to the previous version", | ||
PersistentPreRunE: initBackendContext, | ||
PersistentPostRunE: closeDBContext, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
ctx := cmd.Context() | ||
db := db.FromContext(ctx) | ||
if err := migrate.Rollback(ctx, db); err != nil { | ||
return fmt.Errorf("rollback: %w", err) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
syncHooksCmd = &cobra.Command{ | ||
Use: "sync-hooks", | ||
Short: "Update repository hooks", | ||
PersistentPreRunE: initBackendContext, | ||
PersistentPostRunE: closeDBContext, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
ctx := cmd.Context() | ||
cfg := config.FromContext(ctx) | ||
be := backend.FromContext(ctx) | ||
if err := initializeHooks(ctx, cfg, be); err != nil { | ||
return fmt.Errorf("initialize hooks: %w", err) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
adminCmd.AddCommand( | ||
syncHooksCmd, | ||
migrateCmd, | ||
rollbackCmd, | ||
) | ||
} |
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
Oops, something went wrong.