sqlite storage: Init schema in NewPool instead of NewProvider and add an option to disable

This commit is contained in:
Matt Joiner 2020-11-03 13:11:44 +11:00
parent d04622e4b3
commit 784345e9f7
1 changed files with 9 additions and 6 deletions

View File

@ -154,6 +154,7 @@ type NewPoolOpts struct {
NumConns int NumConns int
// Forces WAL, disables shared caching. // Forces WAL, disables shared caching.
ConcurrentBlobReads bool ConcurrentBlobReads bool
DontInitSchema bool
} }
// There's some overlap here with NewPoolOpts, and I haven't decided what needs to be done. For now, // There's some overlap here with NewPoolOpts, and I haven't decided what needs to be done. For now,
@ -190,6 +191,14 @@ func NewPool(opts NewPoolOpts) (_ ConnPool, _ ProviderOpts, err error) {
if err != nil { if err != nil {
return return
} }
if !opts.DontInitSchema {
conn := conns.Get(context.TODO())
defer conns.Put(conn)
err = initSchema(conn)
if err != nil {
return
}
}
return conns, ProviderOpts{ return conns, ProviderOpts{
NumConns: opts.NumConns, NumConns: opts.NumConns,
ConcurrentBlobRead: opts.ConcurrentBlobReads, ConcurrentBlobRead: opts.ConcurrentBlobReads,
@ -226,12 +235,6 @@ func NewProvider(pool ConnPool, opts ProviderOpts) (_ *provider, err error) {
if err != nil { if err != nil {
return return
} }
conn := pool.Get(context.TODO())
defer pool.Put(conn)
err = initSchema(conn)
if err != nil {
return
}
writes := make(chan writeRequest) writes := make(chan writeRequest)
prov := &provider{pool: pool, writes: writes, opts: opts} prov := &provider{pool: pool, writes: writes, opts: opts}
runtime.SetFinalizer(prov, func(p *provider) { runtime.SetFinalizer(prov, func(p *provider) {