From: Matt Joiner <anacrolix@gmail.com>
Date: Tue, 3 Nov 2020 02:11:44 +0000 (+1100)
Subject: sqlite storage: Init schema in NewPool instead of NewProvider and add an option to... 
X-Git-Tag: v1.19.0~45
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=784345e9f750215121001bd477cb2733a0ad4be8;p=btrtrc.git

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

diff --git a/storage/sqlite/sqlite-storage.go b/storage/sqlite/sqlite-storage.go
index 44af1fdf..8c2a770e 100644
--- a/storage/sqlite/sqlite-storage.go
+++ b/storage/sqlite/sqlite-storage.go
@@ -154,6 +154,7 @@ type NewPoolOpts struct {
 	NumConns int
 	// Forces WAL, disables shared caching.
 	ConcurrentBlobReads bool
+	DontInitSchema      bool
 }
 
 // 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 {
 		return
 	}
+	if !opts.DontInitSchema {
+		conn := conns.Get(context.TODO())
+		defer conns.Put(conn)
+		err = initSchema(conn)
+		if err != nil {
+			return
+		}
+	}
 	return conns, ProviderOpts{
 		NumConns:           opts.NumConns,
 		ConcurrentBlobRead: opts.ConcurrentBlobReads,
@@ -226,12 +235,6 @@ func NewProvider(pool ConnPool, opts ProviderOpts) (_ *provider, err error) {
 	if err != nil {
 		return
 	}
-	conn := pool.Get(context.TODO())
-	defer pool.Put(conn)
-	err = initSchema(conn)
-	if err != nil {
-		return
-	}
 	writes := make(chan writeRequest)
 	prov := &provider{pool: pool, writes: writes, opts: opts}
 	runtime.SetFinalizer(prov, func(p *provider) {