Skip to content

Open source AI coding agent. Designed for large projects and real world tasks.

make user_id and org_id optional in repo_locks. also checking out an existing git branch is not a write operation that needs index.lock error handling. and neither is creating/deleting a branch.

Dane Schneider9ee00523f0a4
diff --git a/app/server/db/data_models.go b/app/server/db/data_models.go
index 0c1486a1..1b45d8ca 100644
--- a/app/server/db/data_models.go
+++ b/app/server/db/data_models.go
@@ -280,8 +280,8 @@ const (
type repoLock struct {
Id string `db:"id"`
- OrgId string `db:"org_id"`
- UserId string `db:"user_id"`
+ OrgId *string `db:"org_id"`
+ UserId *string `db:"user_id"`
PlanId string `db:"plan_id"`
Scope LockScope `db:"scope"`
Branch *string `db:"branch"`
diff --git a/app/server/db/git.go b/app/server/db/git.go
index cc7084c2..a2cd7ef4 100644
--- a/app/server/db/git.go
+++ b/app/server/db/git.go
@@ -127,29 +127,21 @@ func GitListBranches(orgId, planId string) ([]string, error) {
func GitCreateBranch(orgId, planId, branch, newBranch string) error {
dir := getPlanDir(orgId, planId)
- err := gitWriteOperation(func() error {
- res, err := exec.Command("git", "-C", dir, "checkout", "-b", newBranch).CombinedOutput()
- if err != nil {
- return fmt.Errorf("error creating git branch for dir: %s, err: %v, output: %s", dir, err, string(res))
- }
- return nil
- })
-
- return err
+ res, err := exec.Command("git", "-C", dir, "checkout", "-b", newBranch).CombinedOutput()
+ if err != nil {
+ return fmt.Errorf("error creating git branch for dir: %s, err: %v, output: %s", dir, err, string(res))
+ }
+ return nil
}
func GitDeleteBranch(orgId, planId, branchName string) error {
dir := getPlanDir(orgId, planId)
- err := gitWriteOperation(func() error {
- res, err := exec.Command("git", "-C", dir, "branch", "-D", branchName).CombinedOutput()
- if err != nil {
- return fmt.Errorf("error deleting git branch for dir: %s, err: %v, output: %s", dir, err, string(res))
- }
- return nil
- })
-
- return err
+ res, err := exec.Command("git", "-C", dir, "branch", "-D", branchName).CombinedOutput()
+ if err != nil {
+ return fmt.Errorf("error deleting git branch for dir: %s, err: %v, output: %s", dir, err, string(res))
+ }
+ return nil
}
func GitClearUncommittedChanges(orgId, planId string) error {
@@ -205,17 +197,13 @@ func gitCheckoutBranch(repoDir, branch string) error {
return nil
}
- err = gitWriteOperation(func() error {
- log.Println("checking out branch:", branch)
- res, err := exec.Command("git", "-C", repoDir, "checkout", branch).CombinedOutput()
- if err != nil {
- return fmt.Errorf("error checking out git branch for dir: %s, err: %v, output: %s", repoDir, err, string(res))
- }
-
- return nil
- })
+ log.Println("checking out branch:", branch)
+ res, err := exec.Command("git", "-C", repoDir, "checkout", branch).CombinedOutput()
+ if err != nil {
+ return fmt.Errorf("error checking out git branch for dir: %s, err: %v, output: %s", repoDir, err, string(res))
+ }
- return err
+ return nil
}
func gitRewindToSha(repoDir, sha string) error {
diff --git a/app/server/db/locks.go b/app/server/db/locks.go
index fe0ffb9e..cdea4343 100644
--- a/app/server/db/locks.go
+++ b/app/server/db/locks.go
@@ -192,13 +192,19 @@ func lockRepo(params LockRepoParams, numRetry int) (string, error) {
}
newLock := &repoLock{
- OrgId: orgId,
- UserId: userId,
PlanId: planId,
PlanBuildId: lockPlanBuildId,
Scope: scope,
Branch: lockBranch,
}
+
+ if orgId != "" {
+ newLock.OrgId = &orgId
+ }
+ if userId != "" {
+ newLock.UserId = &userId
+ }
+
// log.Println("newLock:")
// spew.Dump(newLock)
diff --git a/app/server/migrations/2024100900_update_locks.down.sql b/app/server/migrations/2024100900_update_locks.down.sql
new file mode 100644
index 00000000..28d38c67
--- /dev/null
+++ b/app/server/migrations/2024100900_update_locks.down.sql
@@ -0,0 +1,13 @@
+-- Revert user_id and org_id to NOT NULL if no NULL values exist
+DO $$
+BEGIN
+ -- Check for NULL values in user_id and org_id
+ IF EXISTS (SELECT 1 FROM repo_locks WHERE user_id IS NULL OR org_id IS NULL) THEN
+ RAISE EXCEPTION 'Cannot revert to NOT NULL, as there are rows with NULL values in user_id or org_id.';
+ ELSE
+ -- Proceed with setting the columns to NOT NULL
+ ALTER TABLE repo_locks
+ ALTER COLUMN user_id SET NOT NULL,
+ ALTER COLUMN org_id SET NOT NULL;
+ END IF;
+END $$;
diff --git a/app/server/migrations/2024100900_update_locks.up.sql b/app/server/migrations/2024100900_update_locks.up.sql
new file mode 100644
index 00000000..880a0b4a
--- /dev/null
+++ b/app/server/migrations/2024100900_update_locks.up.sql
@@ -0,0 +1,3 @@
+ALTER TABLE repo_locks
+ ALTER COLUMN user_id DROP NOT NULL,
+ ALTER COLUMN org_id DROP NOT NULL;