-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: adding app name check * wip * wip * wip * moving migration to code * wip: adding app name in log * wip: moving sql logic to code * pg no rows handling * adding db migration call * fixing fetch app query * wip: adding pg multiple rows handling * audit log update
- Loading branch information
Showing
9 changed files
with
135 additions
and
75 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,61 @@ | ||
package dbMigration | ||
|
||
import ( | ||
appRepository "github.com/devtron-labs/devtron/internal/sql/repository/app" | ||
repository2 "github.com/devtron-labs/devtron/pkg/appStore/installedApp/repository" | ||
"go.uber.org/zap" | ||
"time" | ||
) | ||
|
||
type DbMigration interface { | ||
FixMultipleAppsForInstalledApp(appNameUniqueIdentifier string) (*appRepository.App, error) | ||
} | ||
|
||
type DbMigrationServiceImpl struct { | ||
logger *zap.SugaredLogger | ||
appRepository appRepository.AppRepository | ||
installedAppRepository repository2.InstalledAppRepository | ||
} | ||
|
||
func NewDbMigrationServiceImpl( | ||
logger *zap.SugaredLogger, appRepository appRepository.AppRepository, | ||
installedAppRepository repository2.InstalledAppRepository, | ||
) *DbMigrationServiceImpl { | ||
impl := &DbMigrationServiceImpl{ | ||
logger: logger, | ||
appRepository: appRepository, | ||
installedAppRepository: installedAppRepository, | ||
} | ||
return impl | ||
} | ||
|
||
func (impl DbMigrationServiceImpl) FixMultipleAppsForInstalledApp(appNameUniqueIdentifier string) (*appRepository.App, error) { | ||
installedApp, err := impl.installedAppRepository.GetInstalledAppByAppName(appNameUniqueIdentifier) | ||
if err != nil { | ||
impl.logger.Errorw("error in fetching installed app by unique identifier", "appNameUniqueIdentifier", appNameUniqueIdentifier, "err", err) | ||
return nil, err | ||
} | ||
validAppId := installedApp.AppId | ||
allActiveApps, err := impl.appRepository.FindAllActiveByName(appNameUniqueIdentifier) | ||
if err != nil { | ||
impl.logger.Errorw("error in fetching all active apps by name", "appName", appNameUniqueIdentifier, "err", err) | ||
return nil, err | ||
} | ||
var validApp *appRepository.App | ||
for _, activeApp := range allActiveApps { | ||
if activeApp.Id != validAppId { | ||
impl.logger.Info("duplicate entries found for app, marking app inactive ", "appName", appNameUniqueIdentifier) | ||
activeApp.Active = false | ||
activeApp.UpdatedOn = time.Now() | ||
activeApp.UpdatedBy = 1 | ||
err := impl.appRepository.Update(activeApp) | ||
if err != nil { | ||
impl.logger.Errorw("error in marking app inactive", "name", activeApp.AppName, "err", err) | ||
return nil, err | ||
} | ||
} else { | ||
validApp = activeApp | ||
} | ||
} | ||
return validApp, 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
Oops, something went wrong.