Skip to content

The only tool you need to know what is happening and how to fix it.

Hooks added

ddux31602bdf6f6d
diff --git a/backend/app/controllers/auth.controller.go b/backend/app/controllers/auth.controller.go
index 39b85d30..f575e24b 100644
--- a/backend/app/controllers/auth.controller.go
+++ b/backend/app/controllers/auth.controller.go
@@ -6,12 +6,15 @@ import (
"backend/app/models"
"backend/app/repositories"
"backend/app/services"
+ "database/sql"
"net/http"
"os"
"github.com/gin-gonic/gin"
)
+var PostRegistrationHooks []func(tx *sql.Tx, org *models.Organization, user *models.User) error
+
type authController struct{}
func (a authController) HasOrganizations(c *gin.Context) {
@@ -134,6 +137,13 @@ func (a authController) Register(c *gin.Context) {
return
}
+ for _, hook := range PostRegistrationHooks {
+ if err := hook(tx, org, user); err != nil {
+ c.AbortWithError(http.StatusInternalServerError, err)
+ return
+ }
+ }
+
project, err := repositories.ProjectRepository.CreateWithOrganization(tx, request.ProjectName, request.Framework, org.Id)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
diff --git a/backend/app/controllers/routes.go b/backend/app/controllers/routes.go
index fa2d9160..164225a5 100644
--- a/backend/app/controllers/routes.go
+++ b/backend/app/controllers/routes.go
@@ -8,6 +8,8 @@ import (
"github.com/gin-gonic/gin"
)
+var ExtensionRoutes []func(router *gin.RouterGroup)
+
type PaginationParams struct {
Page int `json:"page" binding:"min=1"`
PageSize int `json:"pageSize" binding:"min=1,max=100"`
@@ -93,4 +95,8 @@ func RegisterControllers(router *gin.RouterGroup) {
router.GET("/invitations/:token", InvitationController.GetInvitationInfo)
router.POST("/invitations/:token/accept", middleware.Transactional, InvitationController.AcceptInvitation)
router.POST("/invitations/:token/accept-existing", middleware.UseAppAuth, middleware.Transactional, InvitationController.AcceptExistingUser)
+
+ for _, register := range ExtensionRoutes {
+ register(router)
+ }
}
diff --git a/backend/app/migrations/migrations.go b/backend/app/migrations/migrations.go
index 9fb133fd..b8b77a78 100644
--- a/backend/app/migrations/migrations.go
+++ b/backend/app/migrations/migrations.go
@@ -13,6 +13,13 @@ import (
_ "github.com/lib/pq"
)
+type ExtensionMigration struct {
+ Source embed.FS
+ Path string
+}
+
+var ExtensionPostgresMigrations []ExtensionMigration
+
//go:embed ch/*.sql
var migrationsChFS embed.FS
@@ -76,6 +83,37 @@ func runMigrationsPostgres(connStr string) error {
return fmt.Errorf("postgres migration failed: %w", err)
}
+ for _, ext := range ExtensionPostgresMigrations {
+ if err := runExtensionMigrations(db, ext); err != nil {
+ return fmt.Errorf("extension migration failed: %w", err)
+ }
+ }
+
+ return nil
+}
+
+func runExtensionMigrations(db *sql.DB, ext ExtensionMigration) error {
+ source, err := iofs.New(ext.Source, ext.Path)
+ if err != nil {
+ return fmt.Errorf("failed to create extension migration source: %w", err)
+ }
+
+ driver, err := migratePg.WithInstance(db, &migratePg.Config{
+ MigrationsTable: "schema_migrations_ext",
+ })
+ if err != nil {
+ return fmt.Errorf("failed to create extension migration driver: %w", err)
+ }
+
+ m, err := migrate.NewWithInstance("iofs", source, "postgres", driver)
+ if err != nil {
+ return fmt.Errorf("failed to create extension migrate instance: %w", err)
+ }
+
+ if err := m.Up(); err != nil && err != migrate.ErrNoChange {
+ return fmt.Errorf("extension postgres migration failed: %w", err)
+ }
+
return nil
}
diff --git a/backend/app/models/models.go b/backend/app/models/models.go
index 611ba79b..376e44d3 100644
--- a/backend/app/models/models.go
+++ b/backend/app/models/models.go
@@ -4,6 +4,8 @@ import (
"github.com/tracewayapp/go-lightning/lit"
)
+var ExtensionModelRegistrations []func()
+
func Init() {
lit.RegisterModel[Project](lit.PostgreSQL)
lit.RegisterModel[User](lit.PostgreSQL)
@@ -14,4 +16,8 @@ func Init() {
lit.RegisterModel[InvitationWithInviter](lit.PostgreSQL)
lit.RegisterModel[UserOrganizationResponse](lit.PostgreSQL)
lit.RegisterModel[CountResult](lit.PostgreSQL)
+
+ for _, register := range ExtensionModelRegistrations {
+ register()
+ }
}