Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deperate isPlugin and isSingleUser part - 2 #5

Merged
merged 2 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion server/boards/boardsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func NewBoardsApp(api model.ServicesAPI) (*BoardsApp, error) {
TablePrefix: cfg.DBTablePrefix,
Logger: logger,
DB: sqlDB,
IsPlugin: true,
NewMutexFn: func(name string) (*cluster.Mutex, error) {
return cluster.NewMutex(&mutexAPIAdapter{api: api}, name)
},
Expand Down
7 changes: 3 additions & 4 deletions server/integrationtests/clienttestlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ func newTestServerWithLicense(singleUserToken string, licenseType LicenseType) *
if err = logger.Configure("", cfg.LoggingCfgJSON, nil); err != nil {
panic(err)
}
singleUser := len(singleUserToken) > 0
innerStore, err := server.NewStore(cfg, singleUser, logger)
innerStore, err := server.NewStore(cfg, logger)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -199,7 +198,7 @@ func NewTestServerPluginMode() *server.Server {
if err = logger.Configure("", cfg.LoggingCfgJSON, nil); err != nil {
panic(err)
}
innerStore, err := server.NewStore(cfg, false, logger)
innerStore, err := server.NewStore(cfg, logger)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -235,7 +234,7 @@ func newTestServerLocalMode() *server.Server {
panic(err)
}

db, err := server.NewStore(cfg, false, logger)
db, err := server.NewStore(cfg, logger)
if err != nil {
panic(err)
}
Expand Down
4 changes: 1 addition & 3 deletions server/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func New(params Params) (*Server, error) {
return &server, nil
}

func NewStore(config *config.Configuration, isSingleUser bool, logger mlog.LoggerIFace) (store.Store, error) {
func NewStore(config *config.Configuration, logger mlog.LoggerIFace) (store.Store, error) {
sqlDB, err := sql.Open(config.DBType, config.DBConfigString)
if err != nil {
logger.Error("connectDatabase failed", mlog.Err(err))
Expand All @@ -223,8 +223,6 @@ func NewStore(config *config.Configuration, isSingleUser bool, logger mlog.Logge
TablePrefix: config.DBTablePrefix,
Logger: logger,
DB: sqlDB,
IsPlugin: false,
IsSingleUser: isSingleUser,
}

var db store.Store
Expand Down
30 changes: 10 additions & 20 deletions server/services/store/sqlstore/data_migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,18 @@ func (s *SQLStore) RunCategoryUUIDIDMigration() error {
return txErr
}

if s.isPlugin {
if err := s.createCategories(tx); err != nil {
if rollbackErr := tx.Rollback(); rollbackErr != nil {
s.logger.Error("category UUIDs insert categories transaction rollback error", mlog.Err(rollbackErr), mlog.String("methodName", "setSystemSetting"))
}
return err
if err := s.createCategories(tx); err != nil {
if rollbackErr := tx.Rollback(); rollbackErr != nil {
s.logger.Error("category UUIDs insert categories transaction rollback error", mlog.Err(rollbackErr), mlog.String("methodName", "setSystemSetting"))
}
return err
}

if err := s.createCategoryBoards(tx); err != nil {
if rollbackErr := tx.Rollback(); rollbackErr != nil {
s.logger.Error("category UUIDs insert category boards transaction rollback error", mlog.Err(rollbackErr), mlog.String("methodName", "setSystemSetting"))
}
return err
if err := s.createCategoryBoards(tx); err != nil {
if rollbackErr := tx.Rollback(); rollbackErr != nil {
s.logger.Error("category UUIDs insert category boards transaction rollback error", mlog.Err(rollbackErr), mlog.String("methodName", "setSystemSetting"))
}
return err
}

if err := s.setSystemSetting(tx, CategoryUUIDIDMigrationKey, strconv.FormatBool(true)); err != nil {
Expand Down Expand Up @@ -353,10 +351,6 @@ func (s *SQLStore) createCategoryBoards(db sq.BaseRunner) error {
// group messages. This function migrates all boards
// belonging to a DM to the best possible team.
func (s *SQLStore) RunTeamLessBoardsMigration() error {
if !s.isPlugin {
return nil
}

setting, err := s.GetSystemSetting(TeamLessBoardsMigrationKey)
if err != nil {
return fmt.Errorf("cannot get teamless boards migration state: %w", err)
Expand Down Expand Up @@ -555,10 +549,6 @@ func (s *SQLStore) getBoardUserTeams(tx sq.BaseRunner, board *model.Board) (map[
}

func (s *SQLStore) RunDeletedMembershipBoardsMigration() error {
if !s.isPlugin {
return nil
}

setting, err := s.GetSystemSetting(DeletedMembershipBoardsMigrationKey)
if err != nil {
return fmt.Errorf("cannot get deleted membership boards migration state: %w", err)
Expand Down Expand Up @@ -661,7 +651,7 @@ func (s *SQLStore) RunFixCollationsAndCharsetsMigration() error {
var collation string
var charSet string
var err error
if !s.isPlugin || os.Getenv("FOCALBOARD_UNIT_TESTING") == "1" {
if os.Getenv("FOCALBOARD_UNIT_TESTING") == "1" {
collation = "utf8mb4_general_ci"
charSet = "utf8mb4"
} else {
Expand Down
1 change: 0 additions & 1 deletion server/services/store/sqlstore/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func SetupTests(t *testing.T) (store.Store, func()) {
TablePrefix: "test_",
Logger: logger,
DB: sqlDB,
IsPlugin: false,
}
store, err := New(storeParams)
require.NoError(t, err)
Expand Down
32 changes: 14 additions & 18 deletions server/services/store/sqlstore/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,18 @@ func (s *SQLStore) getMigrationConnection() (*sql.DB, error) {
}

func (s *SQLStore) Migrate() error {
if s.isPlugin {
mutex, mutexErr := s.NewMutexFn("Boards_dbMutex")
if mutexErr != nil {
return fmt.Errorf("error creating database mutex: %w", mutexErr)
}

s.logger.Debug("Acquiring cluster lock for Focalboard migrations")
mutex.Lock()
defer func() {
s.logger.Debug("Releasing cluster lock for Focalboard migrations")
mutex.Unlock()
}()
mutex, mutexErr := s.NewMutexFn("Boards_dbMutex")
if mutexErr != nil {
return fmt.Errorf("error creating database mutex: %w", mutexErr)
}

s.logger.Debug("Acquiring cluster lock for Focalboard migrations")
mutex.Lock()
defer func() {
s.logger.Debug("Releasing cluster lock for Focalboard migrations")
mutex.Unlock()
}()

if err := s.EnsureSchemaMigrationFormat(); err != nil {
return err
}
Expand Down Expand Up @@ -148,12 +146,10 @@ func (s *SQLStore) Migrate() error {
}

params := map[string]interface{}{
"prefix": s.tablePrefix,
"postgres": s.dbType == model.PostgresDBType,
"sqlite": s.dbType == model.SqliteDBType,
"mysql": s.dbType == model.MysqlDBType,
"plugin": s.isPlugin,
"singleUser": s.isSingleUser,
"prefix": s.tablePrefix,
"postgres": s.dbType == model.PostgresDBType,
"sqlite": s.dbType == model.SqliteDBType,
"mysql": s.dbType == model.MysqlDBType,
}

migrationAssets := &embedded.AssetSource{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ func (bm *BoardsMigrator) Setup() error {
TablePrefix: tablePrefix,
Logger: logger,
DB: bm.db,
IsPlugin: bm.withMattermostMigrations,
NewMutexFn: func(name string) (*cluster.Mutex, error) {
return nil, fmt.Errorf("not implemented")
},
Expand Down
18 changes: 8 additions & 10 deletions server/services/store/sqlstore/migrationstests/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (
)

type TestHelper struct {
t *testing.T
f *foundation.Foundation
isPlugin bool
t *testing.T
f *foundation.Foundation
}

func (th *TestHelper) IsPostgres() bool {
Expand All @@ -33,20 +32,19 @@ func SetupPluginTestHelper(t *testing.T) (*TestHelper, func()) {
t.Skip("Skipping plugin mode test for SQLite")
}

return setupTestHelper(t, true)
return setupTestHelper(t)
}

func SetupTestHelper(t *testing.T) (*TestHelper, func()) {
return setupTestHelper(t, false)
return setupTestHelper(t)
}

func setupTestHelper(t *testing.T, isPlugin bool) (*TestHelper, func()) {
f := foundation.New(t, NewBoardsMigrator(isPlugin))
func setupTestHelper(t *testing.T) (*TestHelper, func()) {
f := foundation.New(t, NewBoardsMigrator(true))

th := &TestHelper{
t: t,
f: f,
isPlugin: isPlugin,
t: t,
f: f,
}

tearDown := func() {
Expand Down
4 changes: 1 addition & 3 deletions server/services/store/sqlstore/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ type Params struct {
TablePrefix string
Logger mlog.LoggerIFace
DB *sql.DB
IsPlugin bool
IsSingleUser bool
NewMutexFn MutexFactory
ServicesAPI servicesAPI
SkipMigrations bool
ConfigFn func() *mmModel.Config
}

func (p Params) CheckValid() error {
if p.IsPlugin && p.NewMutexFn == nil {
if p.NewMutexFn == nil {
return ErrStoreParam{name: "NewMutexFn", issue: "cannot be nil in plugin mode"}
}
return nil
Expand Down
4 changes: 0 additions & 4 deletions server/services/store/sqlstore/sqlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ type SQLStore struct {
tablePrefix string
connectionString string
dbPingAttempts int
isPlugin bool
isSingleUser bool
logger mlog.LoggerIFace
NewMutexFn MutexFactory
servicesAPI servicesAPI
Expand Down Expand Up @@ -51,8 +49,6 @@ func New(params Params) (*SQLStore, error) {
tablePrefix: params.TablePrefix,
connectionString: params.ConnectionString,
logger: params.Logger,
isPlugin: params.IsPlugin,
isSingleUser: params.IsSingleUser,
NewMutexFn: params.NewMutexFn,
servicesAPI: params.ServicesAPI,
configFn: params.ConfigFn,
Expand Down
73 changes: 0 additions & 73 deletions webapp/src/pages/changePasswordPage.scss

This file was deleted.

Loading