dendritejs tweaks for persisting sqlite DBs (#1058)

* Use uri.path so we don't have file: in the filename

* New go-sqlite-js version
This commit is contained in:
Kegsay 2020-05-22 12:28:48 +01:00 committed by GitHub
parent fbdcfdd256
commit 3daa2327ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 21 additions and 19 deletions

View file

@ -34,7 +34,7 @@ func NewDatabase(
case "postgres": case "postgres":
return nil, fmt.Errorf("Cannot use postgres implementation") return nil, fmt.Errorf("Cannot use postgres implementation")
case "file": case "file":
return sqlite3.NewDatabase(dataSourceName) return sqlite3.NewDatabase(uri.Path)
default: default:
return nil, fmt.Errorf("Cannot use postgres implementation") return nil, fmt.Errorf("Cannot use postgres implementation")
} }

View file

@ -36,7 +36,7 @@ func NewDatabase(
case "postgres": case "postgres":
return nil, fmt.Errorf("Cannot use postgres implementation") return nil, fmt.Errorf("Cannot use postgres implementation")
case "file": case "file":
return sqlite3.NewDatabase(dataSourceName, serverName) return sqlite3.NewDatabase(uri.Path, serverName)
default: default:
return nil, fmt.Errorf("Cannot use postgres implementation") return nil, fmt.Errorf("Cannot use postgres implementation")
} }

View file

@ -36,7 +36,7 @@ func NewDatabase(
case "postgres": case "postgres":
return nil, fmt.Errorf("Cannot use postgres implementation") return nil, fmt.Errorf("Cannot use postgres implementation")
case "file": case "file":
return sqlite3.NewDatabase(dataSourceName, serverName) return sqlite3.NewDatabase(uri.Path, serverName)
default: default:
return nil, fmt.Errorf("Cannot use postgres implementation") return nil, fmt.Errorf("Cannot use postgres implementation")
} }

View file

@ -163,16 +163,16 @@ func main() {
cfg := &config.Dendrite{} cfg := &config.Dendrite{}
cfg.SetDefaults() cfg.SetDefaults()
cfg.Kafka.UseNaffka = true cfg.Kafka.UseNaffka = true
cfg.Database.Account = "file:dendritejs_account.db" cfg.Database.Account = "file:/idb/dendritejs_account.db"
cfg.Database.AppService = "file:dendritejs_appservice.db" cfg.Database.AppService = "file:/idb/dendritejs_appservice.db"
cfg.Database.Device = "file:dendritejs_device.db" cfg.Database.Device = "file:/idb/dendritejs_device.db"
cfg.Database.FederationSender = "file:dendritejs_fedsender.db" cfg.Database.FederationSender = "file:/idb/dendritejs_fedsender.db"
cfg.Database.MediaAPI = "file:dendritejs_mediaapi.db" cfg.Database.MediaAPI = "file:/idb/dendritejs_mediaapi.db"
cfg.Database.Naffka = "file:dendritejs_naffka.db" cfg.Database.Naffka = "file:/idb/dendritejs_naffka.db"
cfg.Database.PublicRoomsAPI = "file:dendritejs_publicrooms.db" cfg.Database.PublicRoomsAPI = "file:/idb/dendritejs_publicrooms.db"
cfg.Database.RoomServer = "file:dendritejs_roomserver.db" cfg.Database.RoomServer = "file:/idb/dendritejs_roomserver.db"
cfg.Database.ServerKey = "file:dendritejs_serverkey.db" cfg.Database.ServerKey = "file:/idb/dendritejs_serverkey.db"
cfg.Database.SyncAPI = "file:dendritejs_syncapi.db" cfg.Database.SyncAPI = "file:/idb/dendritejs_syncapi.db"
cfg.Kafka.Topics.UserUpdates = "user_updates" cfg.Kafka.Topics.UserUpdates = "user_updates"
cfg.Kafka.Topics.OutputTypingEvent = "output_typing_event" cfg.Kafka.Topics.OutputTypingEvent = "output_typing_event"
cfg.Kafka.Topics.OutputClientData = "output_client_data" cfg.Kafka.Topics.OutputClientData = "output_client_data"

View file

@ -33,7 +33,7 @@ func NewDatabase(
} }
switch uri.Scheme { switch uri.Scheme {
case "file": case "file":
return sqlite3.NewDatabase(dataSourceName) return sqlite3.NewDatabase(uri.Path)
case "postgres": case "postgres":
return nil, fmt.Errorf("Cannot use postgres implementation") return nil, fmt.Errorf("Cannot use postgres implementation")
default: default:

2
go.mod
View file

@ -16,7 +16,7 @@ require (
github.com/libp2p/go-libp2p-record v0.1.2 github.com/libp2p/go-libp2p-record v0.1.2
github.com/matrix-org/dugong v0.0.0-20171220115018-ea0a4690a0d5 github.com/matrix-org/dugong v0.0.0-20171220115018-ea0a4690a0d5
github.com/matrix-org/go-http-js-libp2p v0.0.0-20200518170932-783164aeeda4 github.com/matrix-org/go-http-js-libp2p v0.0.0-20200518170932-783164aeeda4
github.com/matrix-org/go-sqlite3-js v0.0.0-20200326102434-98eda28055bd github.com/matrix-org/go-sqlite3-js v0.0.0-20200522092705-bc8506ccbcf3
github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26
github.com/matrix-org/gomatrixserverlib v0.0.0-20200511154227-5cc71d36632b github.com/matrix-org/gomatrixserverlib v0.0.0-20200511154227-5cc71d36632b
github.com/matrix-org/naffka v0.0.0-20200422140631-181f1ee7401f github.com/matrix-org/naffka v0.0.0-20200422140631-181f1ee7401f

2
go.sum
View file

@ -354,6 +354,8 @@ github.com/matrix-org/go-http-js-libp2p v0.0.0-20200518170932-783164aeeda4 h1:eq
github.com/matrix-org/go-http-js-libp2p v0.0.0-20200518170932-783164aeeda4/go.mod h1:3WluEZ9QXSwU30tWYqktnpC1x9mwZKx1r8uAv8Iq+a4= github.com/matrix-org/go-http-js-libp2p v0.0.0-20200518170932-783164aeeda4/go.mod h1:3WluEZ9QXSwU30tWYqktnpC1x9mwZKx1r8uAv8Iq+a4=
github.com/matrix-org/go-sqlite3-js v0.0.0-20200326102434-98eda28055bd h1:C1FV4dRKF1uuGK8UH01+IoW6zZpfsTV1MvQimZvt418= github.com/matrix-org/go-sqlite3-js v0.0.0-20200326102434-98eda28055bd h1:C1FV4dRKF1uuGK8UH01+IoW6zZpfsTV1MvQimZvt418=
github.com/matrix-org/go-sqlite3-js v0.0.0-20200326102434-98eda28055bd/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo= github.com/matrix-org/go-sqlite3-js v0.0.0-20200326102434-98eda28055bd/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo=
github.com/matrix-org/go-sqlite3-js v0.0.0-20200522092705-bc8506ccbcf3 h1:Yb+Wlf/iHhWlLWd+kCgG+Fsg4Dc+xBl7hptfK7lD0zY=
github.com/matrix-org/go-sqlite3-js v0.0.0-20200522092705-bc8506ccbcf3/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo=
github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 h1:Hr3zjRsq2bhrnp3Ky1qgx/fzCtCALOoGYylh2tpS9K4= github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 h1:Hr3zjRsq2bhrnp3Ky1qgx/fzCtCALOoGYylh2tpS9K4=
github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0= github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0=
github.com/matrix-org/gomatrixserverlib v0.0.0-20200511154227-5cc71d36632b h1:nAmSc1KvQOumoRTz/LD68KyrB6Q5/6q7CmQ5Bswc2nM= github.com/matrix-org/gomatrixserverlib v0.0.0-20200511154227-5cc71d36632b h1:nAmSc1KvQOumoRTz/LD68KyrB6Q5/6q7CmQ5Bswc2nM=

View file

@ -264,7 +264,7 @@ func setupNaffka(cfg *config.Dendrite) (sarama.Consumer, sarama.SyncProducer) {
uri, err := url.Parse(string(cfg.Database.Naffka)) uri, err := url.Parse(string(cfg.Database.Naffka))
if err != nil || uri.Scheme == "file" { if err != nil || uri.Scheme == "file" {
db, err = sqlutil.Open(internal.SQLiteDriverName(), string(cfg.Database.Naffka), nil) db, err = sqlutil.Open(internal.SQLiteDriverName(), string(uri.Path), nil)
if err != nil { if err != nil {
logrus.WithError(err).Panic("Failed to open naffka database") logrus.WithError(err).Panic("Failed to open naffka database")
} }

View file

@ -41,7 +41,7 @@ func NewDatabase(
case "postgres": case "postgres":
return nil, fmt.Errorf("Cannot use postgres implementation") return nil, fmt.Errorf("Cannot use postgres implementation")
case "file": case "file":
return sqlite3.NewDatabase(dataSourceName, serverName, serverKey, serverKeyID) return sqlite3.NewDatabase(uri.Path, serverName, serverKey, serverKeyID)
default: default:
return nil, fmt.Errorf("Cannot use postgres implementation") return nil, fmt.Errorf("Cannot use postgres implementation")
} }

View file

@ -35,7 +35,7 @@ func Open(
case "postgres": case "postgres":
return nil, fmt.Errorf("Cannot use postgres implementation") return nil, fmt.Errorf("Cannot use postgres implementation")
case "file": case "file":
return sqlite3.Open(dataSourceName) return sqlite3.Open(uri.Path)
default: default:
return nil, fmt.Errorf("Cannot use postgres implementation") return nil, fmt.Errorf("Cannot use postgres implementation")
} }

View file

@ -31,7 +31,7 @@ func NewPublicRoomsServerDatabase(dataSourceName string) (Database, error) {
case "postgres": case "postgres":
return nil, fmt.Errorf("Cannot use postgres implementation") return nil, fmt.Errorf("Cannot use postgres implementation")
case "file": case "file":
return sqlite3.NewPublicRoomsServerDatabase(dataSourceName) return sqlite3.NewPublicRoomsServerDatabase(uri.Path)
default: default:
return nil, fmt.Errorf("Cannot use postgres implementation") return nil, fmt.Errorf("Cannot use postgres implementation")
} }