mirror of
https://github.com/mattermost/focalboard.git
synced 2024-11-27 08:31:20 +02:00
Initialise the store with a single user flag and pass it to the migrations (#2906)
This commit is contained in:
parent
d2c4a54d36
commit
74e39fa5bf
@ -61,7 +61,8 @@ func runServer(port int) (*server.Server, error) {
|
||||
AuthMode: "native",
|
||||
}
|
||||
|
||||
db, err := server.NewStore(config, logger)
|
||||
singleUser := len(sessionToken) > 0
|
||||
db, err := server.NewStore(config, singleUser, logger)
|
||||
if err != nil {
|
||||
fmt.Println("ERROR INITIALIZING THE SERVER STORE", err)
|
||||
return nil, err
|
||||
|
@ -135,7 +135,8 @@ func newTestServerWithLicense(singleUserToken string, licenseType LicenseType) *
|
||||
if err = logger.Configure("", cfg.LoggingCfgJSON, nil); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
innerStore, err := server.NewStore(cfg, logger)
|
||||
singleUser := len(singleUserToken) > 0
|
||||
innerStore, err := server.NewStore(cfg, singleUser, logger)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -183,7 +184,7 @@ func NewTestServerPluginMode() *server.Server {
|
||||
if err = logger.Configure("", cfg.LoggingCfgJSON, nil); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
innerStore, err := server.NewStore(cfg, logger)
|
||||
innerStore, err := server.NewStore(cfg, false, logger)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -219,7 +220,7 @@ func newTestServerLocalMode() *server.Server {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
db, err := server.NewStore(cfg, logger)
|
||||
db, err := server.NewStore(cfg, false, logger)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ func main() {
|
||||
config.Port = *pPort
|
||||
}
|
||||
|
||||
db, err := server.NewStore(config, logger)
|
||||
db, err := server.NewStore(config, singleUser, logger)
|
||||
if err != nil {
|
||||
logger.Fatal("server.NewStore ERROR", mlog.Err(err))
|
||||
}
|
||||
@ -232,7 +232,8 @@ func startServer(webPath string, filesPath string, port int, singleUserToken, db
|
||||
config.DBConfigString = dbConfigString
|
||||
}
|
||||
|
||||
db, err := server.NewStore(config, logger)
|
||||
singleUser := len(singleUserToken) > 0
|
||||
db, err := server.NewStore(config, singleUser, logger)
|
||||
if err != nil {
|
||||
logger.Fatal("server.NewStore ERROR", mlog.Err(err))
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ func New(params Params) (*Server, error) {
|
||||
return &server, nil
|
||||
}
|
||||
|
||||
func NewStore(config *config.Configuration, logger *mlog.Logger) (store.Store, error) {
|
||||
func NewStore(config *config.Configuration, isSingleUser bool, logger *mlog.Logger) (store.Store, error) {
|
||||
sqlDB, err := sql.Open(config.DBType, config.DBConfigString)
|
||||
if err != nil {
|
||||
logger.Error("connectDatabase failed", mlog.Err(err))
|
||||
@ -227,6 +227,7 @@ func NewStore(config *config.Configuration, logger *mlog.Logger) (store.Store, e
|
||||
Logger: logger,
|
||||
DB: sqlDB,
|
||||
IsPlugin: false,
|
||||
IsSingleUser: isSingleUser,
|
||||
}
|
||||
|
||||
var db store.Store
|
||||
|
@ -136,11 +136,12 @@ 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,
|
||||
"prefix": s.tablePrefix,
|
||||
"postgres": s.dbType == model.PostgresDBType,
|
||||
"sqlite": s.dbType == model.SqliteDBType,
|
||||
"mysql": s.dbType == model.MysqlDBType,
|
||||
"plugin": s.isPlugin,
|
||||
"singleUser": s.isSingleUser,
|
||||
}
|
||||
|
||||
migrationAssets := &embedded.AssetSource{
|
||||
|
@ -417,16 +417,27 @@ CREATE TABLE {{.prefix}}board_members (
|
||||
|
||||
CREATE INDEX idx_boardmembers_user_id ON {{.prefix}}board_members(user_id);
|
||||
|
||||
{{if .plugin}}
|
||||
{{- /* if we're in plugin, migrate channel memberships to the board */ -}}
|
||||
{{if .plugin}}
|
||||
INSERT INTO {{.prefix}}board_members (
|
||||
SELECT B.Id, CM.UserId, CM.Roles, (CM.UserId=B.created_by) OR CM.SchemeAdmin, CM.SchemeUser, FALSE, CM.SchemeGuest
|
||||
FROM {{.prefix}}boards AS B
|
||||
INNER JOIN ChannelMembers as CM ON CM.ChannelId=B.channel_id
|
||||
);
|
||||
{{else}}
|
||||
{{end}}
|
||||
|
||||
{{- /* if we're in personal server or desktop, create memberships for everyone */ -}}
|
||||
{{if and (not .plugin) (not .singleUser)}}
|
||||
{{- /* for personal server, create a membership per user and board */ -}}
|
||||
INSERT INTO {{.prefix}}board_members
|
||||
SELECT B.id, U.id, '', B.created_by=U.id, TRUE, FALSE, FALSE
|
||||
FROM {{.prefix}}boards AS B, {{.prefix}}users AS U;
|
||||
{{end}}
|
||||
|
||||
{{if and (not .plugin) .singleUser}}
|
||||
{{- /* for personal desktop, as we don't have users, create a membership */ -}}
|
||||
{{- /* per board with a fixed user id */ -}}
|
||||
INSERT INTO {{.prefix}}board_members
|
||||
SELECT B.id, 'single-user', '', TRUE, TRUE, FALSE, FALSE
|
||||
FROM {{.prefix}}boards AS B;
|
||||
{{end}}
|
||||
|
@ -16,6 +16,7 @@ type Params struct {
|
||||
Logger *mlog.Logger
|
||||
DB *sql.DB
|
||||
IsPlugin bool
|
||||
IsSingleUser bool
|
||||
NewMutexFn MutexFactory
|
||||
PluginAPI *plugin.API
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ type SQLStore struct {
|
||||
tablePrefix string
|
||||
connectionString string
|
||||
isPlugin bool
|
||||
isSingleUser bool
|
||||
logger *mlog.Logger
|
||||
NewMutexFn MutexFactory
|
||||
pluginAPI *plugin.API
|
||||
@ -47,6 +48,7 @@ func New(params Params) (*SQLStore, error) {
|
||||
connectionString: params.ConnectionString,
|
||||
logger: params.Logger,
|
||||
isPlugin: params.IsPlugin,
|
||||
isSingleUser: params.IsSingleUser,
|
||||
NewMutexFn: params.NewMutexFn,
|
||||
pluginAPI: params.PluginAPI,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user