Pass-through DB Driver implementation (#17685)

* Pass-through DB Driver implementation

This is the first step in implementing a DB layer via RPC.

The plan is to migrate the mattermost-plugin-api to use
this DB connector so that all queries start to get
routed through this library.

And then we will add the DB query capability to the plugin RPC
API and route all queries via RPC. At that point, this will be
completely transparent to all plugins because they will already
be using the DB connector and everything will be behind the scenes
for them.

https://focalboard-community.octo.mattermost.com/workspace/zyoahc9uapdn3xdptac6jb69ic?id=285b80a3-257d-41f6-8cf4-ed80ca9d92e5&v=495cdb4d-c13a-4992-8eb9-80cfee2819a4&c=c7386db7-65fd-469b-8bcf-8dc8f8e61e4f

```release-note
NONE
```

* remove deprecated interfaces
Этот коммит содержится в:
Agniva De Sarker
2021-05-27 14:59:06 +05:30
коммит произвёл GitHub
родитель ff2fe1e62c
Коммит e35c78cac2
4 изменённых файлов: 222 добавлений и 13 удалений

Просмотреть файл

@@ -4,6 +4,7 @@
package sqlstore
import (
"database/sql"
"fmt"
"os"
"regexp"
@@ -20,6 +21,7 @@ import (
"github.com/mattermost/mattermost-server/v5/einterfaces/mocks"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/driver"
"github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/store/searchtest"
"github.com/mattermost/mattermost-server/v5/store/storetest"
@@ -95,6 +97,47 @@ func StoreTestWithSqlStore(t *testing.T, f func(*testing.T, store.Store, storete
}
}
func TestDBConnector(t *testing.T) {
testDrivers := []string{
model.DATABASE_DRIVER_POSTGRES,
model.DATABASE_DRIVER_MYSQL,
}
for _, dr := range testDrivers {
settings := makeSqlSettings(dr)
store := &SqlStore{
settings: settings,
}
connector, err := driver.NewConnector(*settings.DriverName, *settings.DataSource)
require.NoError(t, err)
db := sql.OpenDB(connector)
store.master = getDBMap(settings, db)
store.stores.post = newSqlPostStore(store, nil)
store.stores.channel = newSqlChannelStore(store, nil)
store.stores.team = newSqlTeamStore(store)
store.stores.thread = newSqlThreadStore(store)
store.stores.user = newSqlUserStore(store, nil)
store.stores.preference = newSqlPreferenceStore(store)
store.stores.bot = newSqlBotStore(store, nil)
store.stores.scheme = newSqlSchemeStore(store)
err = store.GetMaster().CreateTablesIfNotExists()
require.NoError(t, err)
store.stores.post.(*SqlPostStore).createIndexesIfNotExists()
store.stores.channel.(*SqlChannelStore).createIndexesIfNotExists()
t.Run(dr, func(t *testing.T) {
// Just testing post store for now.
// This will eventually go away when it is replaced with RPC.
storetest.TestPostStore(t, store, store)
})
store.Close()
}
}
func initStores() {
if testing.Short() {
return
@@ -109,8 +152,10 @@ func initStores() {
storeTypes = append(storeTypes, newStoreType("PostgreSQL", model.DATABASE_DRIVER_POSTGRES))
}
} else {
storeTypes = append(storeTypes, newStoreType("MySQL", model.DATABASE_DRIVER_MYSQL),
newStoreType("PostgreSQL", model.DATABASE_DRIVER_POSTGRES))
storeTypes = append(storeTypes,
newStoreType("MySQL", model.DATABASE_DRIVER_MYSQL),
newStoreType("PostgreSQL", model.DATABASE_DRIVER_POSTGRES),
)
}
defer func() {