Skip to content

Commit

Permalink
fix(server): handle transaction correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Mar 13, 2023
1 parent 8112f74 commit 4b164b2
Show file tree
Hide file tree
Showing 23 changed files with 302 additions and 307 deletions.
13 changes: 4 additions & 9 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
github.com/goccy/go-yaml v1.9.8 h1:5gMyLUeU1/6zl+WFfR1hN7D2kf+1/eRGa7DFtToiBvQ=
github.com/googleapis/gax-go v2.0.0+incompatible h1:j0GKcs05QVmm7yesiZq2+9cxHkNK9YM6zKx4D2qucQU=
github.com/nicksnyder/go-i18n/v2 v2.2.1 h1:aOzRCdwsJuoExfZhoiXHy4bjruwCMdt5otbYojM/PaA=
github.com/spf13/afero v1.9.3 h1:41FoI0fD7OR7mGcKE/aOiLkGreyf8ifIOQmJANWogMk=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
github.com/jpillora/opts v1.2.3 h1:Q0YuOM7y0BlunHJ7laR1TUxkUA7xW8A2rciuZ70xs8g=
github.com/posener/complete v1.2.2-0.20190308074557-af07aa5181b3 h1:GqpA1/5oN1NgsxoSA4RH0YWTaqvUlQNeOpHXD/JRbOQ=
2 changes: 1 addition & 1 deletion server/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func StartServer(t *testing.T, cfg *app.Config, useMongo bool) *httpexpect.Expec
var repos *repo.Container
if useMongo {
db := mongotest.Connect(t)(t)
repos = lo.Must(mongo.New(ctx, db))
repos = lo.Must(mongo.New(ctx, db, false))
} else {
repos = memory.New()
}
Expand Down
13 changes: 7 additions & 6 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ require (
github.com/paulmach/go.geojson v1.4.0
github.com/pkg/errors v0.9.1
github.com/ravilushqa/otelgqlgen v0.8.0
github.com/reearth/reearthx v0.0.0-20230206061553-f29144aee73b
github.com/reearth/reearthx v0.0.0-20230313110808-d00b7183549c
github.com/samber/lo v1.27.0
github.com/sendgrid/sendgrid-go v3.11.1+incompatible
github.com/sendgrid/sendgrid-go v3.12.0+incompatible
github.com/sirupsen/logrus v1.8.1
github.com/spf13/afero v1.9.3
github.com/square/mongo-lock v0.0.0-20201208161834-4db518ed7fb2
Expand Down Expand Up @@ -94,16 +94,17 @@ require (
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/imkira/go-interpol v1.0.0 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/maruel/panicparse/v2 v2.3.1 // indirect
github.com/matryer/moq v0.2.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/nicksnyder/go-i18n/v2 v2.2.1 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sendgrid/rest v2.6.6+incompatible // indirect
github.com/sendgrid/rest v2.6.9+incompatible // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/smartystreets/assertions v1.1.1 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
Expand Down Expand Up @@ -132,7 +133,7 @@ require (
go.uber.org/zap v1.21.0 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
27 changes: 18 additions & 9 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -395,20 +395,26 @@ github.com/logrusorgru/aurora/v3 v3.0.0/go.mod h1:vsR12bk5grlLvLXAYrBsb5Oc/N+LxA
github.com/magiconair/properties v1.7.4-0.20170902060319-8d7837e64d3c/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
github.com/maruel/panicparse/v2 v2.3.1 h1:NtJavmbMn0DyzmmSStE8yUsmPZrZmudPH7kplxBinOA=
github.com/maruel/panicparse/v2 v2.3.1/go.mod h1:s3UmQB9Fm/n7n/prcD2xBGDkwXD6y2LeZnhbEXvs9Dg=
github.com/matryer/moq v0.2.7 h1:RtpiPUM8L7ZSCbSwK+QcZH/E9tgqAkFjKQxsRs25b4w=
github.com/matryer/moq v0.2.7/go.mod h1:kITsx543GOENm48TUAQyJ9+SAvFSr7iGQXPoth/VUBk=
github.com/mattn/go-colorable v0.0.10-0.20170816031813-ad5389df28cd/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.2/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/maxatome/go-testdeep v1.11.0 h1:Tgh5efyCYyJFGUYiT0qxBSIDeXw0F5zSoatlou685kk=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/mapstructure v0.0.0-20170523030023-d0303fe80992/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.3.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
Expand Down Expand Up @@ -447,8 +453,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/ravilushqa/otelgqlgen v0.8.0 h1:x48k+D1GMgm87xhMO2Lekrr9YGzFbpG3yijn9GpxuAY=
github.com/ravilushqa/otelgqlgen v0.8.0/go.mod h1:6JO5YO2iY4POC7R6yB/L/RKXCcyISL8qQt5NnHOhh0o=
github.com/reearth/reearthx v0.0.0-20230206061553-f29144aee73b h1:9ab+hjIuPp3gXdenveYc1+ZFJ/7kwBh1VsdDwej0VO0=
github.com/reearth/reearthx v0.0.0-20230206061553-f29144aee73b/go.mod h1:iR+OzkAQWyqxmm9uRJm4J7iY8VQX85IqU15nVeOx0v8=
github.com/reearth/reearthx v0.0.0-20230313110808-d00b7183549c h1:6jhvsbF6V/EtzW09Ch7UuXl627Ls8wdU9TSMD7HNPH4=
github.com/reearth/reearthx v0.0.0-20230313110808-d00b7183549c/go.mod h1:AsJomXOp70gxN3lq8amcJ1Erd6gl7dwCj4P2K5ih4DM=
github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481/go.mod h1:C9WhFzY47SzYBIvzFqSvHIR6ROgDo4TtdTuRaOMjF/s=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand All @@ -460,10 +466,10 @@ github.com/samber/lo v1.27.0 h1:GOyDWxsblvqYobqsmUuMddPa2/mMzkKyojlXol4+LaQ=
github.com/samber/lo v1.27.0/go.mod h1:it33p9UtPMS7z72fP4gw/EIfQB2eI8ke7GR2wc6+Rhg=
github.com/savsgio/gotils v0.0.0-20210617111740-97865ed5a873 h1:N3Af8f13ooDKcIhsmFT7Z05CStZWu4C7Md0uDEy4q6o=
github.com/savsgio/gotils v0.0.0-20210617111740-97865ed5a873/go.mod h1:dmPawKuiAeG/aFYVs2i+Dyosoo7FNcm+Pi8iK6ZUrX8=
github.com/sendgrid/rest v2.6.6+incompatible h1:3rO5UTPhLQo6fjytWwdwRWclP101CqErg2klf8LneB4=
github.com/sendgrid/rest v2.6.6+incompatible/go.mod h1:kXX7q3jZtJXK5c5qK83bSGMdV6tsOE70KbHoqJls4lE=
github.com/sendgrid/sendgrid-go v3.11.1+incompatible h1:ai0+woZ3r/+tKLQExznak5XerOFoD6S7ePO0lMV8WXo=
github.com/sendgrid/sendgrid-go v3.11.1+incompatible/go.mod h1:QRQt+LX/NmgVEvmdRw0VT/QgUn499+iza2FnDca9fg8=
github.com/sendgrid/rest v2.6.9+incompatible h1:1EyIcsNdn9KIisLW50MKwmSRSK+ekueiEMJ7NEoxJo0=
github.com/sendgrid/rest v2.6.9+incompatible/go.mod h1:kXX7q3jZtJXK5c5qK83bSGMdV6tsOE70KbHoqJls4lE=
github.com/sendgrid/sendgrid-go v3.12.0+incompatible h1:/N2vx18Fg1KmQOh6zESc5FJB8pYwt5QFBDflYPh1KVg=
github.com/sendgrid/sendgrid-go v3.12.0+incompatible/go.mod h1:QRQt+LX/NmgVEvmdRw0VT/QgUn499+iza2FnDca9fg8=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
Expand Down Expand Up @@ -826,12 +832,15 @@ golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
3 changes: 2 additions & 1 deletion server/internal/app/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/reearth/reearth/server/internal/usecase/gateway"
"github.com/reearth/reearth/server/internal/usecase/repo"
"github.com/reearth/reearthx/log"
"github.com/reearth/reearthx/mongox"
"github.com/spf13/afero"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
Expand All @@ -36,7 +37,7 @@ func initReposAndGateways(ctx context.Context, conf *Config, debug bool) (*repo.
log.Fatalf("mongo error: %+v\n", err)
}

repos, err := mongorepo.New(ctx, client.Database("reearth"))
repos, err := mongorepo.New(ctx, client.Database("reearth"), mongox.IsTransactionAvailable(conf.DB))
if err != nil {
log.Fatalf("Failed to init mongo: %+v\n", err)
}
Expand Down
11 changes: 7 additions & 4 deletions server/internal/infrastructure/mongo/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ import (
"go.mongodb.org/mongo-driver/mongo"
)

func New(ctx context.Context, db *mongo.Database) (*repo.Container, error) {
func New(ctx context.Context, db *mongo.Database, useTransaction bool) (*repo.Container, error) {
lock, err := NewLock(db.Collection("locks"))
if err != nil {
return nil, err
}

client := mongox.NewClientWithDatabase(db)
if useTransaction {
client = client.WithTransaction()
}

c := &repo.Container{
Asset: NewAsset(client),
AuthRequest: authserver.NewMongo(client.WithCollection("authRequest")),
Expand All @@ -38,9 +42,9 @@ func New(ctx context.Context, db *mongo.Database) (*repo.Container, error) {
Workspace: NewWorkspace(client),
User: NewUser(client),
SceneLock: NewSceneLock(client),
Transaction: mongox.NewTransaction(client),
Policy: NewPolicy(client),
Lock: lock,
Transaction: client.Transaction(),
}

// init
Expand All @@ -49,8 +53,7 @@ func New(ctx context.Context, db *mongo.Database) (*repo.Container, error) {
}

// migration
m := migration.Client{Client: client, Config: c.Config}
if err := m.Migrate(ctx); err != nil {
if err := migration.Do(ctx, client, c.Config); err != nil {
return nil, err
}

Expand Down
105 changes: 48 additions & 57 deletions server/internal/infrastructure/mongo/migration/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,71 @@ package migration

import (
"context"
"fmt"
"errors"
"sync"

"github.com/reearth/reearth/server/internal/usecase/repo"
"github.com/reearth/reearthx/log"
"github.com/reearth/reearth/server/pkg/config"
"github.com/reearth/reearthx/mongox"
"github.com/reearth/reearthx/rerror"
"github.com/reearth/reearthx/usecasex"
"github.com/reearth/reearthx/usecasex/migration"
)

type DBClient = *mongox.Client
// To add a new migration, do the following command:
// go run github.com/reearth/reearthx/tools migrategen -d internal/infrastructure/mongo/migration -t DBClient -n "foobar"

type MigrationFunc = func(context.Context, DBClient) error
type DBClient = *mongox.Client

type Client struct {
Client *mongox.Client
Config repo.Config
func Do(ctx context.Context, db *mongox.Client, config repo.Config) error {
return migration.NewClient(db, NewConfig(config), migrations, 0).Migrate(ctx)
}

func (c Client) Migrate(ctx context.Context) (err error) {
config, err := c.Config.LockAndLoad(ctx)
if err != nil {
return fmt.Errorf("Failed to load config: %w", rerror.UnwrapErrInternal(err))
}
defer func() {
if err2 := c.Config.Unlock(ctx); err == nil && err2 != nil {
err = err2
}
}()

nextMigrations := config.NextMigrations(migrationKeys())
if len(nextMigrations) == 0 {
return nil
}
type Config struct {
c repo.Config
locked bool
current config.Config
m sync.Mutex
}

var tx usecasex.Tx
defer func() {
if tx != nil {
if err2 := tx.End(ctx); err == nil && err2 != nil {
err = err2
}
}
}()
func NewConfig(c repo.Config) *Config {
return &Config{c: c}
}

for _, m := range nextMigrations {
tx, err = c.Client.BeginTransaction()
if err != nil {
return err
}
func (c *Config) Begin(ctx context.Context) error {
c.m.Lock()
defer c.m.Unlock()

log.Infof("DB migration: %d\n", m)
if err := migrations[m](ctx, c.Client); err != nil {
return fmt.Errorf("Failed to exec migration %d: %w", m, rerror.UnwrapErrInternal(err))
}
conf, err := c.c.LockAndLoad(ctx)
if conf != nil {
c.current = *conf
}
if err == nil {
c.locked = true
}
return err
}

config.Migration = m
if err := c.Config.Save(ctx, config); err != nil {
return err
}
func (c *Config) End(ctx context.Context) error {
c.m.Lock()
defer c.m.Unlock()

tx.Commit()
if err := tx.End(ctx); err != nil {
tx = nil
return err
}
tx = nil
if err := c.c.Unlock(ctx); err != nil {
return err
}

c.locked = false
return nil
}

func migrationKeys() []int64 {
keys := make([]int64, 0, len(migrations))
for k := range migrations {
keys = append(keys, k)
func (c *Config) Current(ctx context.Context) (migration.Key, error) {
if !c.locked {
return 0, errors.New("config is not locked")
}
return keys
return c.current.Migration, nil
}

func (c *Config) Save(ctx context.Context, key migration.Key) error {
c.m.Lock()
defer c.m.Unlock()

c.current.Migration = key
return c.c.Save(ctx, &c.current)
}
4 changes: 3 additions & 1 deletion server/internal/infrastructure/mongo/migration/migrations.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions server/internal/usecase/interactor/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (i *Asset) FindByWorkspace(ctx context.Context, tid id.WorkspaceID, keyword
return Run2(
ctx, operator, i.repos,
Usecase().WithReadableWorkspaces(tid),
func() ([]*asset.Asset, *usecasex.PageInfo, error) {
func(ctx context.Context) ([]*asset.Asset, *usecasex.PageInfo, error) {
return i.repos.Asset.FindByWorkspace(ctx, tid, repo.AssetFilter{
Sort: sort,
Keyword: keyword,
Expand All @@ -53,7 +53,7 @@ func (i *Asset) Create(ctx context.Context, inp interfaces.CreateAssetParam, ope
Usecase().
WithWritableWorkspaces(inp.WorkspaceID).
Transaction(),
func() (*asset.Asset, error) {
func(ctx context.Context) (*asset.Asset, error) {
ws, err := i.repos.Workspace.FindByID(ctx, inp.WorkspaceID)
if err != nil {
return nil, err
Expand Down Expand Up @@ -103,7 +103,7 @@ func (i *Asset) Remove(ctx context.Context, aid id.AssetID, operator *usecase.Op
return Run1(
ctx, operator, i.repos,
Usecase().Transaction(),
func() (id.AssetID, error) {
func(ctx context.Context) (id.AssetID, error) {
asset, err := i.repos.Asset.FindByID(ctx, aid)
if err != nil {
return aid, err
Expand Down
Loading

0 comments on commit 4b164b2

Please sign in to comment.