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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae9a9de76ff2dba753f10923fb0f984acc0c0e2e4f2a626a15c0ae6622d64392
4
- data.tar.gz: ceeef4187f94f32b39569cf7f1e98c1a25559b1730c742f8c01073520456afce
3
+ metadata.gz: 10045af8e71603e4647d934f3b10afa96385ebca7dc678911ff5e443be0af638
4
+ data.tar.gz: c8fe68b60de2232967d242733764f1025b2c9d0b8884114c6480c7b345d0fd3b
5
5
  SHA512:
6
- metadata.gz: c2cec9308283d6d2ced937184b6e62b09bee329a10b7d65d69d369002dfb797b7e2b513611d64911d09cbaa50b7c00aec6480040f5955510297a20128528b443
7
- data.tar.gz: 4d901bf3b1a062683dd481398e4961447676af8ae97ef8d938b321c6b0774fdadde71ba69e4875859e138e1853be2f1a734db1bf0fbe72f5ea62695c67fb67e3
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.1)
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.0, < 2.0)
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 <<~SQL
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
@@ -10,5 +10,5 @@
10
10
  # License:: MIT
11
11
  module Fbe
12
12
  # Current version of the gem (changed by +.rultor.yml+ on every release)
13
- VERSION = '0.21.0' unless const_defined?(:VERSION)
13
+ VERSION = '0.21.1' unless const_defined?(:VERSION)
14
14
  end
@@ -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', &)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.21.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko