fbe 0.21.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/fbe/middleware/sqlite_store.rb +17 -6
- data/lib/fbe.rb +1 -1
- data/test/fbe/middleware/test_sqlite_store.rb +20 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10045af8e71603e4647d934f3b10afa96385ebca7dc678911ff5e443be0af638
|
4
|
+
data.tar.gz: c8fe68b60de2232967d242733764f1025b2c9d0b8884114c6480c7b345d0fd3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd3fc1d0b158be59858edf4292027e71c73bffd8c1cbc7ef45ae743c9e9b521fe4faf4ab1995999fad3e3c798107d75925d74cc3ae8fd130cc535901259d68fc
|
7
|
+
data.tar.gz: d7d494cf9f5c5f4b5899be7caad9d4fdaa5203483c8bdd450117ea86241b0894df164d16d2c42505fda6c7e50627c803ed58f5e9d7910c7406f77cd4cc601dfb
|
data/Gemfile.lock
CHANGED
@@ -180,7 +180,7 @@ GEM
|
|
180
180
|
regexp_parser (2.10.0)
|
181
181
|
retries (0.0.5)
|
182
182
|
rexml (3.4.1)
|
183
|
-
rubocop (1.76.
|
183
|
+
rubocop (1.76.2)
|
184
184
|
json (~> 2.3)
|
185
185
|
language_server-protocol (~> 3.17.0.2)
|
186
186
|
lint_roller (~> 1.1.0)
|
@@ -188,7 +188,7 @@ GEM
|
|
188
188
|
parser (>= 3.3.0.2)
|
189
189
|
rainbow (>= 2.2.2, < 4.0)
|
190
190
|
regexp_parser (>= 2.9.3, < 3.0)
|
191
|
-
rubocop-ast (>= 1.45.
|
191
|
+
rubocop-ast (>= 1.45.1, < 2.0)
|
192
192
|
ruby-progressbar (~> 1.7)
|
193
193
|
unicode-display_width (>= 2.4.0, < 4.0)
|
194
194
|
rubocop-ast (1.45.1)
|
@@ -126,17 +126,28 @@ class Fbe::Middleware::SqliteStore
|
|
126
126
|
@db ||=
|
127
127
|
SQLite3::Database.new(@path).tap do |d|
|
128
128
|
d.transaction do |t|
|
129
|
-
t.execute
|
130
|
-
CREATE TABLE IF NOT EXISTS cache(
|
131
|
-
key TEXT UNIQUE NOT NULL, value TEXT, touched_at TEXT NOT NULL
|
132
|
-
);
|
133
|
-
SQL
|
129
|
+
t.execute 'CREATE TABLE IF NOT EXISTS cache(key TEXT UNIQUE NOT NULL, value TEXT);'
|
134
130
|
t.execute 'CREATE INDEX IF NOT EXISTS cache_key_idx ON cache(key);'
|
135
|
-
t.execute 'CREATE INDEX IF NOT EXISTS cache_touched_at_idx ON cache(touched_at);'
|
136
131
|
t.execute 'CREATE TABLE IF NOT EXISTS meta(key TEXT UNIQUE NOT NULL, value TEXT);'
|
137
132
|
t.execute 'CREATE INDEX IF NOT EXISTS meta_key_idx ON meta(key);'
|
138
133
|
t.execute "INSERT INTO meta(key, value) VALUES('version', ?) ON CONFLICT(key) DO NOTHING;", [@version]
|
139
134
|
end
|
135
|
+
if d.execute("SELECT 1 FROM pragma_table_info('cache') WHERE name = 'touched_at';").dig(0, 0) != 1
|
136
|
+
d.transaction do |t|
|
137
|
+
t.execute 'ALTER TABLE cache ADD COLUMN touched_at TEXT;'
|
138
|
+
t.execute 'UPDATE cache set touched_at = ?;', [Time.now.utc.iso8601]
|
139
|
+
t.execute 'ALTER TABLE cache RENAME TO cache_old;'
|
140
|
+
t.execute <<~SQL
|
141
|
+
CREATE TABLE IF NOT EXISTS cache(
|
142
|
+
key TEXT UNIQUE NOT NULL, value TEXT, touched_at TEXT NOT NULL
|
143
|
+
);
|
144
|
+
SQL
|
145
|
+
t.execute 'INSERT INTO cache SELECT * FROM cache_old;'
|
146
|
+
t.execute 'DROP TABLE cache_old;'
|
147
|
+
t.execute 'CREATE INDEX IF NOT EXISTS cache_touched_at_idx ON cache(touched_at);'
|
148
|
+
end
|
149
|
+
d.execute 'VACUUM;'
|
150
|
+
end
|
140
151
|
found = d.execute("SELECT value FROM meta WHERE key = 'version' LIMIT 1;").dig(0, 0)
|
141
152
|
if found != @version
|
142
153
|
@loog.info("Version mismatch in SQLite cache: stored '#{found}' != current '#{@version}', cleaning up")
|
data/lib/fbe.rb
CHANGED
@@ -182,6 +182,26 @@ class SqliteStoreTest < Fbe::Test
|
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
185
|
+
def test_upgrade_sqlite_schema_for_add_touched_at_column
|
186
|
+
with_tmpfile('a.db') do |f|
|
187
|
+
SQLite3::Database.new(f).tap do |d|
|
188
|
+
d.execute 'CREATE TABLE IF NOT EXISTS cache(key TEXT UNIQUE NOT NULL, value TEXT);'
|
189
|
+
[
|
190
|
+
['key1', JSON.dump('value1')],
|
191
|
+
['key2', JSON.dump('value2')]
|
192
|
+
].each { d.execute 'INSERT INTO cache(key, value) VALUES(?1, ?2);', _1 }
|
193
|
+
d.execute 'CREATE TABLE IF NOT EXISTS meta(key TEXT UNIQUE NOT NULL, value TEXT);'
|
194
|
+
d.execute "INSERT INTO meta(key, value) VALUES('version', ?);", ['0.0.1']
|
195
|
+
end
|
196
|
+
Fbe::Middleware::SqliteStore.new(f, '0.0.1').then do |store|
|
197
|
+
assert_equal('value1', store.read('key1'))
|
198
|
+
assert_equal('value2', store.read('key2'))
|
199
|
+
rescue SQLite3::SQLException => e
|
200
|
+
assert_nil(e)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
185
205
|
private
|
186
206
|
|
187
207
|
def with_tmpfile(name = 'test.db', &)
|